Skip to content
Merged
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
16 changes: 14 additions & 2 deletions migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
logs "github.com/projectsveltos/libsveltos/lib/logsettings"
)

// runMigration lists all Classifier instances and migrates any that still carry
Expand All @@ -60,7 +61,7 @@ func runMigration(ctx context.Context, c client.Client, log logr.Logger) error {
"clusterInfoCount", len(classifier.Status.ClusterInfo), //nolint:staticcheck // deprecated, migration only
"matchingCount", len(classifier.Status.MachingClusterStatuses)) //nolint:staticcheck // deprecated, migration only

if err := migrateOneClassifier(ctx, c, classifier); err != nil {
if err := migrateOneClassifier(ctx, c, classifier, log); err != nil {
return fmt.Errorf("migrating classifier %s: %w", classifier.Name, err)
}

Expand All @@ -73,7 +74,7 @@ func runMigration(ctx context.Context, c client.Client, log logr.Logger) error {

// migrateOneClassifier migrates one Classifier instance and clears the deprecated arrays.
func migrateOneClassifier(ctx context.Context, c client.Client,
classifier *libsveltosv1beta1.Classifier) error {
classifier *libsveltosv1beta1.Classifier, log logr.Logger) error {

type clusterData struct {
ref corev1.ObjectReference
Expand Down Expand Up @@ -115,6 +116,17 @@ func migrateOneClassifier(ctx context.Context, c client.Client,
}

for _, d := range byCluster {
ns := &corev1.Namespace{}
if err := c.Get(ctx, types.NamespacedName{Name: d.ref.Namespace}, ns); err != nil {
if apierrors.IsNotFound(err) {
log.V(logs.LogDebug).Info("skipping stale cluster entry (namespace gone)",
"classifier", classifier.Name,
"cluster", d.ref.Name,
"namespace", d.ref.Namespace)
continue
}
return fmt.Errorf("checking namespace %s: %w", d.ref.Namespace, err)
}
if err := upsertMigrationClassifierReport(ctx, c, classifier.Name, &d.ref,
d.hash, d.deploymentStatus, d.failureMessage,
d.managedLabels, d.unmanagedLabels); err != nil {
Expand Down