Skip to content

Commit

Permalink
Merge pull request #5412 from fabriziopandini/provent-last-applied-co…
Browse files Browse the repository at this point in the history
…nfiguration-propagation

🐛Prevents kubectl.kubernetes.io/last-applied-configuration annotation to be propagated to templates generated by ClusterClass
  • Loading branch information
k8s-ci-robot committed Oct 11, 2021
2 parents a60f5f5 + d343609 commit d62c78f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion controllers/topology/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,15 @@ func templateToTemplate(in templateToInput) *unstructured.Unstructured {
labels[clusterv1.ClusterTopologyOwnedLabel] = ""
template.SetLabels(labels)

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

// Ensure the generated template gets a meaningful name.
Expand Down
8 changes: 8 additions & 0 deletions controllers/topology/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,13 @@ func TestTemplateToTemplate(t *testing.T) {
template := builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infrastructureClusterTemplate").
WithSpecFields(map[string]interface{}{"spec.template.spec.fakeSetting": true}).
Build()
annotations := template.GetAnnotations()
if annotations == nil {
annotations = map[string]string{}
}
annotations[corev1.LastAppliedConfigAnnotation] = "foo"
template.SetAnnotations(annotations)

cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand Down Expand Up @@ -1282,6 +1289,7 @@ func assertTemplateToTemplate(g *WithT, in assertTemplateInput) {
}
g.Expect(in.obj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromGroupKindAnnotation, in.templateRef.GroupVersionKind().GroupKind().String()))
g.Expect(in.obj.GetAnnotations()).To(HaveKeyWithValue(clusterv1.TemplateClonedFromNameAnnotation, in.templateRef.Name))
g.Expect(in.obj.GetAnnotations()).ToNot(HaveKey(corev1.LastAppliedConfigAnnotation))
for k, v := range in.annotations {
g.Expect(in.obj.GetAnnotations()).To(HaveKeyWithValue(k, v))
}
Expand Down

0 comments on commit d62c78f

Please sign in to comment.