diff --git a/flake.lock b/flake.lock index ba0e62b..815f3aa 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -46,11 +46,11 @@ ] }, "locked": { - "lastModified": 1725515722, - "narHash": "sha256-+gljgHaflZhQXtr3WjJrGn8NXv7MruVPAORSufuCFnw=", + "lastModified": 1728509152, + "narHash": "sha256-tQo1rg3TlwgyI8eHnLvZSlQx9d/o2Rb4oF16TfaTOw0=", "owner": "nix-community", "repo": "gomod2nix", - "rev": "1c6fd4e862bf2f249c9114ad625c64c6c29a8a08", + "rev": "d5547e530464c562324f171006fc8f639aa01c9f", "type": "github" }, "original": { @@ -107,11 +107,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1723556749, - "narHash": "sha256-+CHVZnTnIYRLYsARInHYoWkujzcRkLY/gXm3s5bE52o=", + "lastModified": 1726320982, + "narHash": "sha256-RuVXUwcYwaUeks6h3OLrEmg14z9aFXdWppTWPMTwdQw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4a92571f9207810b559c9eac203d1f4d79830073", + "rev": "8f7492cce28977fbf8bd12c72af08b1f6c7c3e49", "type": "github" }, "original": { @@ -123,11 +123,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1725930920, - "narHash": "sha256-RVhD9hnlTT2nJzPHlAqrWqCkA7T6CYrP41IoVRkciZM=", + "lastModified": 1728740863, + "narHash": "sha256-u+rxA79a0lyhG+u+oPBRtTDtzz8kvkc9a6SWSt9ekVc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "44a71ff39c182edaf25a7ace5c9454e7cba2c658", + "rev": "a3f9ad65a0bf298ed5847629a57808b97e6e8077", "type": "github" }, "original": { diff --git a/go.work.sum b/go.work.sum index a613c81..c5633e0 100644 --- a/go.work.sum +++ b/go.work.sum @@ -152,6 +152,8 @@ github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240814135254-a07 github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240814135254-a0724da5a551/go.mod h1:Zlbpg7q5pTUaddoMN9zaraCNvvuD4KJNPPC8WyUF8DI= github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240814140453-975ebac24b93 h1:hijv6grblylZS82qnFei4L3t/60MD0cPVV0XDrHUL9I= github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240814140453-975ebac24b93/go.mod h1:Zlbpg7q5pTUaddoMN9zaraCNvvuD4KJNPPC8WyUF8DI= +github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241003172041-a1632d5aecd8 h1:I/XvDVzAUvSAo586Qy/ioFfnyk8lXIsYGwmyeoE08W0= +github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241003172041-a1632d5aecd8/go.mod h1:dQ+ZYcpSrex3FlfyYAvGuhIFHim+oJuJvslNp8rwuFo= github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240814135254-a0724da5a551 h1:D+ct39Xc/rE4nvgyueIZyc44dFm+Gyp3C9daAjlxjIw= github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240814135254-a0724da5a551/go.mod h1:lj6oLhpXgnc9ZaulV7jysgRaeZUDPK6XiM2TxpcGRqM= github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240814140453-975ebac24b93 h1:s5cXvxg52er5nMCy+9v9wR+4nv+CxHOzXwIf2q2vRA0= diff --git a/kontrol-service/api/server.go b/kontrol-service/api/server.go index 6ce2b1d..69c01b2 100644 --- a/kontrol-service/api/server.go +++ b/kontrol-service/api/server.go @@ -199,9 +199,19 @@ func (sv *Server) PostTenantUuidFlowCreate(_ context.Context, request api.PostTe patches := []flow_spec.ServicePatchSpec{} for _, serviceUpdate := range serviceUpdates { + envVarOverrides := map[string]string{} + if serviceUpdate.EnvVarOverrides != nil { + envVarOverrides = *serviceUpdate.EnvVarOverrides + } + secretEnvVarOverrides := map[string]string{} + if serviceUpdate.SecretEnvVarOverrides != nil { + secretEnvVarOverrides = *serviceUpdate.SecretEnvVarOverrides + } patch := flow_spec.ServicePatchSpec{ - Service: serviceUpdate.ServiceName, - Image: serviceUpdate.ImageLocator, + Service: serviceUpdate.ServiceName, + Image: serviceUpdate.ImageLocator, + EnvVarOverrides: envVarOverrides, + SecretEnvVarOverrides: secretEnvVarOverrides, } logrus.Infof("starting new dev flow for service %v on image %v", patch.Service, patch.Image) patches = append(patches, patch) diff --git a/kontrol-service/engine/docker.go b/kontrol-service/engine/docker.go index a0e2fa3..1a51492 100644 --- a/kontrol-service/engine/docker.go +++ b/kontrol-service/engine/docker.go @@ -9,7 +9,6 @@ import ( "github.com/samber/lo" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" - corev1 "k8s.io/api/core/v1" net "k8s.io/api/networking/v1" gateway "sigs.k8s.io/gateway-api/apis/v1" @@ -52,6 +51,9 @@ func GenerateProdDevCluster(baseClusterTopologyMaybeWithTemplateOverrides *resol clonedWorkloadSpec := workloadSpec.DeepCopy() // TODO: find a better way to update deploymentSpec, this assumes there is only container in the pod + clonedWorkloadSpec.DeploymentSpec.Template.Spec.Containers[0].Image = item.Image + clonedWorkloadSpec.DeploymentSpec.Template.Spec.Containers[0].Env = applyEnvVarOverrides(item.EnvVarOverrides, item.SecretEnvVarOverrides, clonedWorkloadSpec.DeploymentSpec.Template.Spec.Containers[0].Env) + clonedWorkloadSpec.GetTemplateSpec().Containers[0].Image = item.Image patches = append(patches, flow_spec.ServicePatch{ @@ -73,6 +75,50 @@ func GenerateProdDevCluster(baseClusterTopologyMaybeWithTemplateOverrides *resol return clusterTopology, nil } +func applyEnvVarOverrides( + envVarOverrides map[string]string, + secretEnvVarOverrides map[string]string, + envVars []corev1.EnvVar) []corev1.EnvVar { + // merge environment variables and env var overrides + translatedOverrides := map[string]corev1.EnvVar{} + for envVarName, envVarVal := range envVarOverrides { + translatedOverrides[envVarName] = corev1.EnvVar{ + Name: envVarName, + Value: envVarVal, + ValueFrom: nil, + } + } + + for envVarName, envVarValue := range secretEnvVarOverrides { + translatedOverrides[envVarName] = corev1.EnvVar{ + Name: envVarName, + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: envVarValue}, // assume v is the secret name + Key: envVarName, + Optional: nil, + }, + }, + } + } + + newEnvVars := []corev1.EnvVar{} + for _, envVar := range envVars { + if override, ok := translatedOverrides[envVar.Name]; ok { + newEnvVars = append(newEnvVars, override) + delete(translatedOverrides, envVar.Name) + } else { + newEnvVars = append(newEnvVars, envVar) + } + } + + for _, envVar := range translatedOverrides { + newEnvVars = append(newEnvVars, envVar) + } + + return newEnvVars +} + func generateClusterTopology( serviceConfigs []apitypes.ServiceConfig, deploymentConfigs []apitypes.DeploymentConfig, diff --git a/kontrol-service/go.mod b/kontrol-service/go.mod index b88f6a2..ebf89b4 100644 --- a/kontrol-service/go.mod +++ b/kontrol-service/go.mod @@ -1,13 +1,11 @@ module kardinal.kontrol-service -go 1.22.0 - -toolchain go1.22.3 +go 1.22.3 require ( github.com/DATA-DOG/go-sqlmock v1.5.2 github.com/dominikbraun/graph v0.23.0 - github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241003172041-a1632d5aecd8 + github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241018141142-4fcbab801cec github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20241003172041-a1632d5aecd8 github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 github.com/labstack/echo/v4 v4.12.0 diff --git a/kontrol-service/go.sum b/kontrol-service/go.sum index 8473ae3..09cde54 100644 --- a/kontrol-service/go.sum +++ b/kontrol-service/go.sum @@ -77,8 +77,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241003172041-a1632d5aecd8 h1:I/XvDVzAUvSAo586Qy/ioFfnyk8lXIsYGwmyeoE08W0= -github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241003172041-a1632d5aecd8/go.mod h1:dQ+ZYcpSrex3FlfyYAvGuhIFHim+oJuJvslNp8rwuFo= +github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241018141142-4fcbab801cec h1:YoOp+25EgKbVrM+CVro9PoGqRidB+BY7Xo6rqGTguZ0= +github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20241018141142-4fcbab801cec/go.mod h1:dQ+ZYcpSrex3FlfyYAvGuhIFHim+oJuJvslNp8rwuFo= github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20241003172041-a1632d5aecd8 h1:+7d/CazuTvkgdY+ppb+vEjvvq0Un0qbUYfnlt3atAKo= github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20241003172041-a1632d5aecd8/go.mod h1:uUIEjxgSYw58hJgD1AwGOBE3LGPwLDiYtNmLGmnO8vI= github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 h1:YQTATifMUwZEtZYb0LVA7DK2pj8s71iY8rzweuUQ5+g= diff --git a/kontrol-service/gomod2nix.toml b/kontrol-service/gomod2nix.toml index 2629785..f7d26c3 100644 --- a/kontrol-service/gomod2nix.toml +++ b/kontrol-service/gomod2nix.toml @@ -278,8 +278,8 @@ schema = 3 version = "v0.2.0" hash = "sha256-fadcWxZOORv44oak3jTxm6YcITcFxdGt4bpn869HxUE=" [mod."github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api"] - version = "v0.0.0-20241003172041-a1632d5aecd8" - hash = "sha256-UhlNzM0NsEB3YStUvT6KNWMKsw7bQvvhFSdxiVryG+s=" + version = "v0.0.0-20241018141142-4fcbab801cec" + hash = "sha256-xTRlIXQhn2n0pmWfjg34Fhb3Fo5cRGUolkiaARa6f14=" [mod."github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api"] version = "v0.0.0-20241003172041-a1632d5aecd8" hash = "sha256-jJPe/rGOg0G1D64rOWk303FF3+uYS5vHfs3lOXhR4tQ=" diff --git a/kontrol-service/main.go b/kontrol-service/main.go index 87f11df..78ecfc0 100644 --- a/kontrol-service/main.go +++ b/kontrol-service/main.go @@ -2,17 +2,16 @@ package main import ( "flag" - "net/http" - "os" - "runtime/debug" - "strconv" - cli_api "github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api/api/golang/server" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/sirupsen/logrus" "kardinal.kontrol-service/api" "kardinal.kontrol-service/database" + "net/http" + "os" + "runtime/debug" + "strconv" ) func main() { diff --git a/kontrol-service/types/flow_spec/spec.go b/kontrol-service/types/flow_spec/spec.go index ef7ebb8..ec98657 100644 --- a/kontrol-service/types/flow_spec/spec.go +++ b/kontrol-service/types/flow_spec/spec.go @@ -6,6 +6,8 @@ type FlowPatchSpec struct { } type ServicePatchSpec struct { - Service string - Image string + Service string + Image string + EnvVarOverrides map[string]string + SecretEnvVarOverrides map[string]string }