Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
finish override
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Oct 7, 2024
1 parent 9a3f90c commit ea1b3c3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
14 changes: 12 additions & 2 deletions kontrol-service/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,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,
SecretEnvVarOverrides: envVarOverrides,
EnvVarOverrides: secretEnvVarOverrides,
}
logrus.Infof("starting new dev flow for service %v on image %v", patch.Service, patch.Image)
patches = append(patches, patch)
Expand Down
31 changes: 30 additions & 1 deletion kontrol-service/engine/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/kurtosis-tech/stacktrace"
"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"
Expand Down Expand Up @@ -51,6 +50,36 @@ func GenerateProdDevCluster(baseClusterTopologyMaybeWithTemplateOverrides *resol
// TODO: find a better way to update deploymentSpec, this assumes there is only container in the pod
deploymentSpec.Template.Spec.Containers[0].Image = item.Image

// merge environment variables and env var overrides
envVarOverrides := map[string]corev1.EnvVar{}
for k, v := range item.EnvVarOverrides {
envVarOverrides[k] = corev1.EnvVar{
Name: k,
Value: v,
ValueFrom: nil,
}
}
for k, v := range item.SecretEnvVarOverrides {
envVarOverrides[k] = corev1.EnvVar{
Name: k,
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: v}, // assume v is the secret name
Key: k,
Optional: nil,
},
},
}
}
envVars := []corev1.EnvVar{}
for _, envVar := range deploymentSpec.Template.Spec.Containers[0].Env {
if override, ok := envVarOverrides[envVar.Name]; ok {
envVars = append(envVars, override)
} else {
envVars = append(envVars, envVar)
}
}

patches = append(patches, flow_spec.ServicePatch{
Service: devServiceName,
DeploymentSpec: deploymentSpec,
Expand Down
2 changes: 2 additions & 0 deletions kontrol-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.22.0

toolchain go1.22.3

replace github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api => ../../kardinal/libs/cli-kontrol-api

require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/dominikbraun/graph v0.23.0
Expand Down
2 changes: 0 additions & 2 deletions kontrol-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ 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-20240930151959-22270454aa6b h1:pJlgnXZCdSVl1ts0gDagES1TRWXzA/WOrKjl0SCSES0=
github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240930151959-22270454aa6b/go.mod h1:dQ+ZYcpSrex3FlfyYAvGuhIFHim+oJuJvslNp8rwuFo=
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240926004715-b5a991623aeb h1:rMT8EvgX+dFL0Aq2Ea1lBeIFxCPHPDSF59FktBnKhRs=
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240926004715-b5a991623aeb/go.mod h1:uUIEjxgSYw58hJgD1AwGOBE3LGPwLDiYtNmLGmnO8vI=
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 h1:YQTATifMUwZEtZYb0LVA7DK2pj8s71iY8rzweuUQ5+g=
Expand Down
6 changes: 4 additions & 2 deletions kontrol-service/types/flow_spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ea1b3c3

Please sign in to comment.