diff --git a/controller/dataplane/konnect_extension.go b/controller/dataplane/konnect_extension.go index 050a419dd..150047294 100644 --- a/controller/dataplane/konnect_extension.go +++ b/controller/dataplane/konnect_extension.go @@ -57,11 +57,12 @@ func applyDataPlaneKonnectExtension(ctx context.Context, cl client.Client, datap d.WithVolume(kongInKonnectClusterCertVolume(konnectExt.Spec.AuthConfiguration.ClusterCertificateSecretRef.Name)) d.WithVolumeMount(kongInKonnectClusterVolumeMount(), consts.DataPlaneProxyContainerName) - // Only KonnectID currently supported. It's existence is enforced via CEL. - envSet := dputils.KongInKonnectDefaults( - *konnectExt.Spec.ControlPlaneRef.KonnectID, - konnectExt.Spec.ControlPlaneRegion, - konnectExt.Spec.ServerHostname) + // KonnectID is the only supported type for now, and its presence is guaranteed by a proper CEL rule. + envSet := dputils.KongInKonnectDefaults(dputils.KongInKonnectParams{ + ControlPlane: *konnectExt.Spec.ControlPlaneRef.KonnectID, + Region: konnectExt.Spec.ControlPlaneRegion, + Server: konnectExt.Spec.ServerHostname, + }) dputils.FillDataPlaneProxyContainerEnvs(nil, &d.Spec.Template, envSet) dataplane.Spec.Deployment.PodTemplateSpec = &d.Spec.Template diff --git a/controller/dataplane/konnect_extension_test.go b/controller/dataplane/konnect_extension_test.go index c170c5ef7..947263941 100644 --- a/controller/dataplane/konnect_extension_test.go +++ b/controller/dataplane/konnect_extension_test.go @@ -258,12 +258,11 @@ func TestApplyDataPlaneKonnectExtension(t *testing.T) { func getKongInKonnectEnvVars(konnectExt operatorv1alpha1.DataPlaneKonnectExtension) []corev1.EnvVar { envSet := []corev1.EnvVar{} - envMap := dputils.KongInKonnectDefaults( - *konnectExt.Spec.ControlPlaneRef.KonnectID, - konnectExt.Spec.ControlPlaneRegion, - konnectExt.Spec.ServerHostname, - ) - for k, v := range envMap { + for k, v := range dputils.KongInKonnectDefaults(dputils.KongInKonnectParams{ + ControlPlane: *konnectExt.Spec.ControlPlaneRef.KonnectID, + Region: konnectExt.Spec.ControlPlaneRegion, + Server: konnectExt.Spec.ServerHostname, + }) { envSet = append(envSet, corev1.EnvVar{ Name: k, Value: v, diff --git a/internal/utils/dataplane/env.go b/internal/utils/dataplane/env.go index 18529de2c..5ed155a27 100644 --- a/internal/utils/dataplane/env.go +++ b/internal/utils/dataplane/env.go @@ -52,17 +52,21 @@ var kongInKonnectDefaultsTemplate = map[string]string{ "KONG_VITALS": "off", } +// KongInKonnectParams is a struct that holds the parameters needed to customize +// the KongInKonnectDefaultsTemplate map. +type KongInKonnectParams struct { + ControlPlane string + Region string + Server string +} + // KongInKonnectDefaults returnes the map of Konnect-related env vars properly configured. -func KongInKonnectDefaults( - controlPlane, - region, - server string, -) map[string]string { +func KongInKonnectDefaults(params KongInKonnectParams) map[string]string { newEnvSet := make(map[string]string, len(kongInKonnectDefaultsTemplate)) for k, v := range kongInKonnectDefaultsTemplate { - v = strings.ReplaceAll(v, "", controlPlane) - v = strings.ReplaceAll(v, "", region) - v = strings.ReplaceAll(v, "", server) + v = strings.ReplaceAll(v, "", params.ControlPlane) + v = strings.ReplaceAll(v, "", params.Region) + v = strings.ReplaceAll(v, "", params.Server) newEnvSet[k] = v } return newEnvSet