From 0a2e169081415b9f075a5711437e14d1fa383205 Mon Sep 17 00:00:00 2001 From: richardlt Date: Wed, 4 Jan 2023 18:25:44 +0100 Subject: [PATCH] feat(hatchery:k8s): allow to add custom annotations --- engine/config.go | 3 +++ engine/hatchery/kubernetes/kubernetes.go | 7 +++++++ engine/hatchery/kubernetes/types.go | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/engine/config.go b/engine/config.go index 524be009ca..b0fca2efa9 100644 --- a/engine/config.go +++ b/engine/config.go @@ -516,6 +516,9 @@ func configSetStartupData(conf *Configuration) (string, error) { privateKey, _ := jws.NewRandomRSAKey() privateKeyPEM, _ := jws.ExportPrivateKey(privateKey) h.Kubernetes.RSAPrivateKey = string(privateKeyPEM) + var a kubernetes.CustomAnnotation + defaults.SetDefaults(&a) + conf.Hatchery.Kubernetes.CustomAnnotations = append(conf.Hatchery.Kubernetes.CustomAnnotations, a) } } diff --git a/engine/hatchery/kubernetes/kubernetes.go b/engine/hatchery/kubernetes/kubernetes.go index 02d1528941..8a95119e77 100644 --- a/engine/hatchery/kubernetes/kubernetes.go +++ b/engine/hatchery/kubernetes/kubernetes.go @@ -322,6 +322,13 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery }, } + // Set custom annotation on pod if needed + for _, a := range h.Config.CustomAnnotations { + if a.Key != "" && a.Value != "" { + podSchema.Annotations[a.Key] = a.Value + } + } + // Check here to add secret if needed if spawnArgs.Model.ModelDocker.Private { secretRegistryName, err := h.createRegistrySecret(ctx, *spawnArgs.Model) diff --git a/engine/hatchery/kubernetes/types.go b/engine/hatchery/kubernetes/types.go index f7c639a9da..fe4a3b3532 100644 --- a/engine/hatchery/kubernetes/types.go +++ b/engine/hatchery/kubernetes/types.go @@ -49,6 +49,13 @@ type HatcheryConfiguration struct { KubernetesClientCertData string `mapstructure:"clientCertData" toml:"clientCertData" default:"" commented:"true" comment:"Client certificate data (content, not path and not base64 encoded) for tls kubernetes (optional if no tls needed)" json:"-"` // KubernetesKeyData Client certificate data for tls kubernetes (optional if no tls needed) KubernetesClientKeyData string `mapstructure:"clientKeyData" toml:"clientKeyData" default:"" commented:"true" comment:"Client certificate data (content, not path and not base64 encoded) for tls kubernetes (optional if no tls needed)" json:"-"` + // CustomAnnotations that will be added to pods spawned by the hatchery + CustomAnnotations []CustomAnnotation `mapstructure:"customAnnotations" toml:"customAnnotations" default:"" commented:"true" comment:"CustomAnnotations that will be added to pods spawned by the hatchery" json:"-"` +} + +type CustomAnnotation struct { + Key string `mapstructure:"key" toml:"key" default:"" commented:"true" json:"-"` + Value string `mapstructure:"value" toml:"value" default:"" commented:"true" json:"-"` } // HatcheryKubernetes implements HatcheryMode interface for local usage