Skip to content

Commit d62c78f

Browse files
authored
Merge pull request #5412 from fabriziopandini/provent-last-applied-configuration-propagation
🐛Prevents kubectl.kubernetes.io/last-applied-configuration annotation to be propagated to templates generated by ClusterClass
2 parents a60f5f5 + d343609 commit d62c78f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

controllers/topology/desired_state.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,15 @@ func templateToTemplate(in templateToInput) *unstructured.Unstructured {
578578
labels[clusterv1.ClusterTopologyOwnedLabel] = ""
579579
template.SetLabels(labels)
580580

581-
// Enforce cloned from annotations.
581+
// Enforce cloned from annotations and removes the kubectl last-applied-configuration annotation
582+
// because we don't want to propagate it to the cloned template objects.
582583
annotations := template.GetAnnotations()
583584
if annotations == nil {
584585
annotations = map[string]string{}
585586
}
586587
annotations[clusterv1.TemplateClonedFromNameAnnotation] = in.templateClonedFromRef.Name
587588
annotations[clusterv1.TemplateClonedFromGroupKindAnnotation] = in.templateClonedFromRef.GroupVersionKind().GroupKind().String()
589+
delete(annotations, corev1.LastAppliedConfigAnnotation)
588590
template.SetAnnotations(annotations)
589591

590592
// Ensure the generated template gets a meaningful name.

controllers/topology/desired_state_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,13 @@ func TestTemplateToTemplate(t *testing.T) {
11741174
template := builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infrastructureClusterTemplate").
11751175
WithSpecFields(map[string]interface{}{"spec.template.spec.fakeSetting": true}).
11761176
Build()
1177+
annotations := template.GetAnnotations()
1178+
if annotations == nil {
1179+
annotations = map[string]string{}
1180+
}
1181+
annotations[corev1.LastAppliedConfigAnnotation] = "foo"
1182+
template.SetAnnotations(annotations)
1183+
11771184
cluster := &clusterv1.Cluster{
11781185
ObjectMeta: metav1.ObjectMeta{
11791186
Name: "cluster1",
@@ -1282,6 +1289,7 @@ func assertTemplateToTemplate(g *WithT, in assertTemplateInput) {
12821289
}
12831290
g.Expect(in.obj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromGroupKindAnnotation, in.templateRef.GroupVersionKind().GroupKind().String()))
12841291
g.Expect(in.obj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromNameAnnotation, in.templateRef.Name))
1292+
g.Expect(in.obj.GetAnnotations()).ToNot(HaveKey(corev1.LastAppliedConfigAnnotation))
12851293
for k, v := range in.annotations {
12861294
g.Expect(in.obj.GetAnnotations()).To(HaveKeyWithValue(k, v))
12871295
}

0 commit comments

Comments
 (0)