Skip to content

Commit

Permalink
Merge pull request #676 from flavio/fix-boolean-flags
Browse files Browse the repository at this point in the history
fix: handle enable monitoring boolean flag
  • Loading branch information
flavio authored Mar 12, 2024
2 parents e7db4cf + 251ad8a commit 92a0aa6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/admission/policy-server-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (r *Reconciler) deployment(configMapVersion string, policyServer *policiesv
if r.MetricsEnabled {
templateAnnotations[constants.OptelInjectAnnotation] = "true" //nolint:goconst

envvar := corev1.EnvVar{Name: constants.PolicyServerEnableMetricsEnvVar, Value: "1"}
envvar := corev1.EnvVar{Name: constants.PolicyServerEnableMetricsEnvVar, Value: "true"}
if index := envVarsContainVariable(admissionContainer.Env, constants.PolicyServerEnableMetricsEnvVar); index >= 0 {
admissionContainer.Env[index] = envvar
} else {
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/admission/policy-server-deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,15 @@ func TestPolicyServerDeploymentMetricConfigurationWithValueDefinedByUser(t *test
policyServer := &policiesv1.PolicyServer{
Spec: policiesv1.PolicyServerSpec{
Image: "image",
Env: []corev1.EnvVar{{Name: constants.PolicyServerEnableMetricsEnvVar, Value: "0"}, {Name: constants.PolicyServerLogFmtEnvVar, Value: "invalid"}},
Env: []corev1.EnvVar{{Name: constants.PolicyServerEnableMetricsEnvVar, Value: "false"}, {Name: constants.PolicyServerLogFmtEnvVar, Value: "invalid"}},
},
}
deployment := reconciler.deployment("v1", policyServer)
hasMetricEnvvar := false
for _, envvar := range deployment.Spec.Template.Spec.Containers[0].Env {
if envvar.Name == constants.PolicyServerEnableMetricsEnvVar {
hasMetricEnvvar = true
if envvar.Value != "1" {
if envvar.Value != "true" {
t.Error("Present but not reconciled {} value", constants.PolicyServerEnableMetricsEnvVar)
}
}
Expand All @@ -504,7 +504,7 @@ func TestPolicyServerDeploymentTracingConfigurationWithValueDefinedByUser(t *tes
policyServer := &policiesv1.PolicyServer{
Spec: policiesv1.PolicyServerSpec{
Image: "image",
Env: []corev1.EnvVar{{Name: constants.PolicyServerEnableMetricsEnvVar, Value: "0"}, {Name: constants.PolicyServerLogFmtEnvVar, Value: "invalid"}},
Env: []corev1.EnvVar{{Name: constants.PolicyServerEnableMetricsEnvVar, Value: "false"}, {Name: constants.PolicyServerLogFmtEnvVar, Value: "invalid"}},
},
}
deployment := reconciler.deployment("v1", policyServer)
Expand Down

0 comments on commit 92a0aa6

Please sign in to comment.