Skip to content

Commit b6963e6

Browse files
committed
fix: reconcile ownership label before content-equality check
Address PR review feedback: - Label reconciliation now runs before content comparison so leftover CMs from the old static-template path get their managed-by label adopted even when content already matches PlatformConfig. - Add prod/OpenShift override note to DefaultSpiffeHelperConfig. - Add test for label adoption on leftover CMs. RHAIENG-4939 Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Ian Miller <milleryan2003@gmail.com>
1 parent c7996d1 commit b6963e6

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

kagenti-operator/internal/controller/agentruntime_controller.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,15 +1082,21 @@ func (r *AgentRuntimeReconciler) ensureSpiffeHelperConfigMap(ctx context.Context
10821082
return fmt.Errorf("failed to check spiffe-helper-config in %s: %w", namespace, err)
10831083
}
10841084

1085-
if existing.Data["helper.conf"] == cfg.Spiffe.HelperConfig {
1086-
return nil
1087-
}
1085+
needsUpdate := existing.Data["helper.conf"] != cfg.Spiffe.HelperConfig
10881086

1089-
existing.Data = desired.Data
10901087
if existing.Labels == nil {
10911088
existing.Labels = make(map[string]string)
10921089
}
1093-
existing.Labels[LabelManagedBy] = LabelManagedByValue
1090+
if existing.Labels[LabelManagedBy] != LabelManagedByValue {
1091+
existing.Labels[LabelManagedBy] = LabelManagedByValue
1092+
needsUpdate = true
1093+
}
1094+
1095+
if !needsUpdate {
1096+
return nil
1097+
}
1098+
1099+
existing.Data = desired.Data
10941100
if err := r.Update(ctx, existing); err != nil {
10951101
return fmt.Errorf("failed to update spiffe-helper-config in %s: %w", namespace, err)
10961102
}

kagenti-operator/internal/controller/agentruntime_controller_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,32 @@ var _ = Describe("AgentRuntime Controller", func() {
897897
Expect(result.Data["helper.conf"]).To(Equal("same_content"))
898898
})
899899

900+
It("should adopt label on leftover CM with matching content", func() {
901+
existing := &corev1.ConfigMap{
902+
ObjectMeta: metav1.ObjectMeta{
903+
Name: "spiffe-helper-config",
904+
Namespace: shTestNS,
905+
Labels: map[string]string{"app.kubernetes.io/managed-by": "kustomize"},
906+
},
907+
Data: map[string]string{"helper.conf": "same_content"},
908+
}
909+
Expect(k8sClient.Create(ctx, existing)).To(Succeed())
910+
911+
r := newReconciler()
912+
r.GetPlatformConfig = func() *webhookconfig.PlatformConfig {
913+
cfg := webhookconfig.CompiledDefaults()
914+
cfg.Spiffe.HelperConfig = "same_content"
915+
return cfg
916+
}
917+
918+
Expect(r.ensureSpiffeHelperConfigMap(ctx, shTestNS)).To(Succeed())
919+
920+
result := &corev1.ConfigMap{}
921+
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "spiffe-helper-config", Namespace: shTestNS}, result)).To(Succeed())
922+
Expect(result.Data["helper.conf"]).To(Equal("same_content"))
923+
Expect(result.Labels[LabelManagedBy]).To(Equal(LabelManagedByValue))
924+
})
925+
900926
It("should use CompiledDefaults when GetPlatformConfig is nil", func() {
901927
r := newReconciler()
902928
Expect(r.ensureSpiffeHelperConfigMap(ctx, shTestNS)).To(Succeed())

kagenti-operator/internal/webhook/config/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77

88
// DefaultSpiffeHelperConfig is the default helper.conf content for spiffe-helper.
99
// Keep in sync with charts/kagenti-operator/values.yaml defaults.spiffe.helperConfig.
10+
// The jwt_audience below targets a local dev Keycloak. Production and OpenShift
11+
// deployments MUST override this via Helm values (defaults.spiffe.helperConfig)
12+
// to set the in-cluster Keycloak audience.
1013
const DefaultSpiffeHelperConfig = `agent_address = "/spiffe-workload-api/spire-agent.sock"
1114
cmd = ""
1215
cmd_args = ""

0 commit comments

Comments
 (0)