Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@ func isClusterProfileProcessed(ctx context.Context, c client.Client,
if cp.Name == ownerName || len(cp.Spec.HelmCharts) == 0 {
return true, nil
}
if cp.DeletionTimestamp != nil && !cp.DeletionTimestamp.IsZero() {
return true, nil
}
if hasDeletionTimestamp && cp.CreationTimestamp.After(deletionTime) {
return true, nil
}
Expand Down Expand Up @@ -822,6 +825,9 @@ func isProfileProcessed(ctx context.Context, c client.Client,
if p.Name == ownerName || len(p.Spec.HelmCharts) == 0 {
return true, nil
}
if p.DeletionTimestamp != nil && !p.DeletionTimestamp.IsZero() {
return true, nil
}
if hasDeletionTimestamp && p.CreationTimestamp.After(deletionTime) {
return true, nil
}
Expand Down
35 changes: 35 additions & 0 deletions controllers/handlers_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2026,4 +2026,39 @@ var _ = Describe("allMatchingProfilesProcessed", func() {
Expect(err).To(BeNil())
Expect(processed).To(BeTrue())
})

It("returns true when a matching ClusterProfile is being deleted and its ClusterSummary is gone", func() {
s, err := setupScheme()
Expect(err).To(BeNil())

// cpB matches the cluster and has HelmCharts, but is being deleted — its
// ClusterSummary was already cleaned up as part of the deletion flow.
now := metav1.Now()
cpB := &configv1beta1.ClusterProfile{
ObjectMeta: metav1.ObjectMeta{
Name: randomString(),
DeletionTimestamp: &now,
Finalizers: []string{"test-finalizer"},
},
Spec: configv1beta1.Spec{
ClusterSelector: libsveltosv1beta1.Selector{
LabelSelector: metav1.LabelSelector{
MatchLabels: map[string]string{testEnvLabelKey: testProductionValue},
},
},
HelmCharts: []configv1beta1.HelmChart{
{ReleaseName: randomString(), ReleaseNamespace: randomString(),
RepositoryURL: randomString(), ChartName: randomString(), ChartVersion: randomString()},
},
},
}

// no ClusterSummary for cpB — it was already deleted during profile cleanup
c := fake.NewClientBuilder().WithScheme(s).WithObjects(cluster, cpB).Build()

processed, err := controllers.AllMatchingProfilesProcessed(context.TODO(), c,
clusterSummary, textlogger.NewLogger(textlogger.NewConfig()))
Expect(err).To(BeNil())
Expect(processed).To(BeTrue())
})
})