From 3fb3999d7588e0fe0b3a41124818be3842cd5cd1 Mon Sep 17 00:00:00 2001 From: Gianluca Mardente Date: Thu, 26 Nov 2026 16:17:08 +0100 Subject: [PATCH] Surface missing per-cluster ConfigMap and reduce log noise A cluster annotated with a per-cluster patches ConfigMap that does not exist failed silently: the error was only logged (3 lines every 10s), with no ClassifierReport status and no event. The failure is now recorded in the ClassifierReport (Failed, with the missing ConfigMap in failureMessage) and a ClassifierFailed Warning event is emitted. Also: - updateLabelsOnCluster only updates the cluster when a label changed. - Errors which only say a request is still waiting (queued, in progress, still being provisioned/removed) are logged at debug, not as errors, and never replace a real failure. - "agent in managed cluster is not healthy" is logged at debug; the message is in the ClassifierReport status. - removeClassifierReports and removeClusterClassifierReports ignore NotFound on Delete. --- controllers/classifier_controller.go | 37 +++++++-- controllers/classifier_controller_test.go | 81 +++++++++++++++++++ controllers/classifier_deployer.go | 58 +++++++++---- controllers/classifier_deployer_test.go | 40 +++++++++ controllers/classifier_report_collection.go | 6 +- .../classifier_report_collection_test.go | 36 +++++++++ controllers/events.go | 35 ++++++++ controllers/events_test.go | 38 +++++++++ controllers/export_test.go | 2 + 9 files changed, 307 insertions(+), 26 deletions(-) diff --git a/controllers/classifier_controller.go b/controllers/classifier_controller.go index fadce45..8b39936 100644 --- a/controllers/classifier_controller.go +++ b/controllers/classifier_controller.go @@ -222,7 +222,7 @@ func (r *ClassifierReconciler) reconcileDelete( f := getHandlersForFeature(libsveltosv1beta1.FeatureClassifier) err = r.undeployClassifier(ctx, classifierScope, f, logger) if err != nil { - logger.V(logs.LogInfo).Error(err, "failed to undeploy") + logRequeueReason(logger, err, "failed to undeploy") return reconcile.Result{RequeueAfter: deleteRequeueAfter}, nil } @@ -264,6 +264,17 @@ func (r *ClassifierReconciler) reconcileDelete( return reconcile.Result{}, nil } +// logRequeueReason logs why the Classifier is requeued. A request which has not completed yet is expected +// and is not logged as an error: with many Classifiers or clusters that floods the log. +func logRequeueReason(logger logr.Logger, err error, msg string) { + if isWaiting(err) { + logger.V(logs.LogDebug).Info(msg, "reason", err.Error()) + return + } + + logger.V(logs.LogInfo).Error(err, msg) +} + func (r *ClassifierReconciler) reconcileNormal( ctx context.Context, classifierScope *scope.ClassifierScope, @@ -332,7 +343,7 @@ func (r *ClassifierReconciler) reconcileNormal( if err := r.deployClassifier(ctx, classifierScope, f, logger); err != nil { // No event here: the error is also returned while the deployment is still in progress. // Terminal failures are recorded per cluster, in deployClassifier. - logger.V(logs.LogInfo).Error(err, "failed to deploy") + logRequeueReason(logger, err, "failed to deploy") return reconcile.Result{RequeueAfter: normalRequeueAfter}, nil } @@ -753,15 +764,19 @@ func (r *ClassifierReconciler) updateLabelsOnCluster(ctx context.Context, return err } + labels := cluster.GetLabels() + if labels == nil { + labels = make(map[string]string) + } + + labelsChanged := false for i := range classifierScope.Classifier.Spec.ClassifierLabels { label := classifierScope.Classifier.Spec.ClassifierLabels[i] if manager.CanManageLabel(classifierScope.Classifier, cluster.GetNamespace(), cluster.GetName(), label.Key, clusterType) { - labels := cluster.GetLabels() - if labels == nil { - labels = make(map[string]string) + if currentValue, exists := labels[label.Key]; !exists || currentValue != label.Value { + labels[label.Key] = label.Value + labelsChanged = true } - labels[label.Key] = label.Value - cluster.SetLabels(labels) } else { l := logger.WithValues("label", label.Key) l.V(logs.LogInfo).Info("cannot manage label") @@ -769,7 +784,13 @@ func (r *ClassifierReconciler) updateLabelsOnCluster(ctx context.Context, } } - return r.Update(ctx, cluster) + // Only update the cluster if labels were actually modified: this runs on every reconciliation + if labelsChanged { + cluster.SetLabels(labels) + return r.Update(ctx, cluster) + } + + return nil } func (r *ClassifierReconciler) updateMaps(ctx context.Context, classifierScope *scope.ClassifierScope) error { diff --git a/controllers/classifier_controller_test.go b/controllers/classifier_controller_test.go index de47b4b..0ff264f 100644 --- a/controllers/classifier_controller_test.go +++ b/controllers/classifier_controller_test.go @@ -34,6 +34,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "sigs.k8s.io/controller-runtime/pkg/client/interceptor" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -451,6 +452,86 @@ var _ = Describe("Classifier: Reconciler", func() { } }) + It("updateLabelsOnMatchingClusters does not update a cluster whose labels are already set", func() { + cluster := &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: randomString(), + Name: randomString(), + }, + } + + managedLabels := make([]string, 0) + for i := range classifier.Spec.ClassifierLabels { + managedLabels = append(managedLabels, classifier.Spec.ClassifierLabels[i].Key) + } + + matchingStatuses := []libsveltosv1beta1.MachingClusterStatus{ + { + ClusterRef: corev1.ObjectReference{ + Namespace: cluster.Namespace, + Name: cluster.Name, + Kind: clusterKind, + APIVersion: clusterv1.GroupVersion.String(), + }, + ManagedLabels: managedLabels, + }, + } + + initObjects := []client.Object{ + classifier, + cluster, + } + + clusterUpdates := 0 + c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...). + WithObjects(initObjects...). + WithInterceptorFuncs(interceptor.Funcs{ + Update: func(ctx context.Context, cl client.WithWatch, obj client.Object, + opts ...client.UpdateOption) error { + + if _, ok := obj.(*clusterv1.Cluster); ok { + clusterUpdates++ + } + return cl.Update(ctx, obj, opts...) + }, + }).Build() + + reconciler := &controllers.ClassifierReconciler{ + Client: c, + Scheme: scheme, + ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + ClassifierMap: make(map[corev1.ObjectReference]*libsveltosset.Set), + Mux: sync.Mutex{}, + Logger: logger, + } + + classifierScope, err := scope.NewClassifierScope(scope.ClassifierScopeParams{ + Client: c, + Logger: logger, + Classifier: classifier, + ControllerName: classifierControllerName, + }) + Expect(err).To(BeNil()) + + Expect(addTypeInformationToObject(scheme, cluster)).To(Succeed()) + + currentMatchingClusters := map[corev1.ObjectReference]bool{ + {Namespace: cluster.Namespace, Name: cluster.Name, APIVersion: cluster.APIVersion, Kind: cluster.Kind}: true, + } + Expect(controllers.RegisterMatchingClusters(reconciler, context.TODO(), classifier, currentMatchingClusters, + logger)).To(Succeed()) + + // The labels are missing: the cluster is updated + Expect(controllers.UpdateLabelsOnMatchingClusters(reconciler, context.TODO(), classifierScope, + matchingStatuses, logger)).To(Succeed()) + Expect(clusterUpdates).To(Equal(1)) + + // The labels are already set: reconciling again must not update the cluster + Expect(controllers.UpdateLabelsOnMatchingClusters(reconciler, context.TODO(), classifierScope, + matchingStatuses, logger)).To(Succeed()) + Expect(clusterUpdates).To(Equal(1)) + }) + It("removeAllRegistrations removes all label registrations", func() { label := randomString() clusterNamespace := randomString() diff --git a/controllers/classifier_deployer.go b/controllers/classifier_deployer.go index 2c577b4..00fab77 100644 --- a/controllers/classifier_deployer.go +++ b/controllers/classifier_deployer.go @@ -182,7 +182,7 @@ func (r *ClassifierReconciler) deployClassifier(ctx context.Context, classifierS clusterInfo, err := r.processClassifier(ctx, classifierScope, r.ControlPlaneEndpoint, cluster, f, l) if err != nil { - errorSeen = err + errorSeen = keepFailure(errorSeen, err) } if clusterInfo != nil { if updateErr := updateClassifierReportDeploymentStatus(ctx, r.Client, @@ -203,7 +203,7 @@ func (r *ClassifierReconciler) deployClassifier(ctx context.Context, classifierS return errorSeen } if !allProcessed { - return fmt.Errorf("request to deploy Classifier is still queued in one ore more clusters") + return errors.New(msgStillQueued) } return nil } @@ -264,7 +264,7 @@ func (r *ClassifierReconciler) undeployClassifier(ctx context.Context, classifie if r.Deployer.IsInProgress(c.Namespace, c.Name, classifier.Name, f.id, clusterproxy.GetClusterType(c), false) { logger.V(logs.LogDebug).Info("provisioning is in progress") - return fmt.Errorf("deploying %s still in progress. Wait before cleanup", f.id) + return errors.New(msgDeployInProgress) } _, err = clusterproxy.GetCluster(ctx, r.Client, c.Namespace, c.Name, clusterproxy.GetClusterType(c)) @@ -923,7 +923,7 @@ func undeployClassifierInPullMode(ctx context.Context, c client.Client, } else if agentStatus.FailureMessage != nil { retError = errors.New(*agentStatus.FailureMessage) } else { - return errors.New("agent is removing classifier instance") + return errors.New(msgAgentRemoving) } } @@ -949,7 +949,7 @@ func undeployClassifierInPullMode(ctx context.Context, c client.Client, return retError } - return fmt.Errorf("agent cleanup request is queued") + return errors.New(msgAgentCleanupQueued) } func (r *ClassifierReconciler) convertResultStatus(result deployer.Result) *libsveltosv1beta1.SveltosFeatureStatus { @@ -1033,7 +1033,7 @@ func (r *ClassifierReconciler) removeClassifier(ctx context.Context, classifierS // parallel some resources might end stale. if r.Deployer.IsInProgress(cluster.Namespace, cluster.Name, classifier.Name, f.id, clusterproxy.GetClusterType(cluster), false) { logger.V(logs.LogDebug).Info("deploy is in progress") - return false, fmt.Errorf("deploy of %s in cluster still in progress. Wait before redeploying", f.id) + return false, errors.New(msgDeployInProgress) } result := r.Deployer.GetResult(ctx, cluster.Namespace, cluster.Name, classifier.Name, f.id, clusterproxy.GetClusterType(cluster), true) @@ -1041,7 +1041,7 @@ func (r *ClassifierReconciler) removeClassifier(ctx context.Context, classifierS if status != nil { if *status == libsveltosv1beta1.SveltosStatusProvisioning { - return false, fmt.Errorf("feature is still being removed") + return false, errors.New(msgStillBeingRemoved) } if *status == libsveltosv1beta1.SveltosStatusRemoved { return true, nil @@ -1056,7 +1056,7 @@ func (r *ClassifierReconciler) removeClassifier(ctx context.Context, classifierS return false, err } - return false, fmt.Errorf("cleanup request is queued") + return false, errors.New(msgCleanupQueued) } // canProceed returns true if cluster is ready to be programmed and it is not paused. @@ -1263,7 +1263,7 @@ func (r *ClassifierReconciler) processClassifier(ctx context.Context, classifier // Get Classifier Spec hash (at this very precise moment) currentHash, err := r.getCurrentHash(ctx, classifierScope, cpEndpoint, cluster, f, logger) if err != nil { - return nil, err + return r.getCurrentHashFailure(ctx, classifierScope.Classifier.Name, cluster, err), err } classifier := classifierScope.Classifier @@ -1293,7 +1293,9 @@ func (r *ClassifierReconciler) processClassifier(ctx context.Context, classifier } if !isHealthy { failureMessage := "agent in managed cluster is not healthy." - logger.V(logs.LogInfo).Info(failureMessage) + // Not logged at info level: it is repeated at every reconciliation for as long as the agent is not + // healthy. The failure message is recorded in the ClassifierReport. + logger.V(logs.LogDebug).Info(failureMessage) clusterInfo.FailureMessage = &failureMessage clusterInfo.Status = libsveltosv1beta1.SveltosStatusFailedNonRetriable return clusterInfo, nil @@ -1312,7 +1314,7 @@ func (r *ClassifierReconciler) processClassifier(ctx context.Context, classifier msg := "cleanup is in progress" clusterInfo.FailureMessage = &msg logger.V(logs.LogDebug).Info(msg) - return clusterInfo, fmt.Errorf("cleanup of %s in cluster still in progress. Wait before redeploying", f.id) + return clusterInfo, errors.New(msgCleanupInProgress) } // Get the Classifier hash when Classifier was last deployed in this cluster (if ever) @@ -1342,6 +1344,28 @@ func (r *ClassifierReconciler) processClassifier(ctx context.Context, classifier return r.proceedProcessingClassifier(ctx, classifier, cluster, isPullMode, isConfigSame, currentHash, f, logger) } +// getCurrentHashFailure returns the ClusterInfo recording that the hash of the Classifier could not be evaluated +// for the cluster, for instance because a ConfigMap with patches referenced by an annotation of the cluster does +// not exist. Without it, the failure would be visible only in the logs: no status and no event. +// The hash of the last deployment is kept: nothing was deployed, so it must not change. +// It returns nil when the hash of the last deployment cannot be read: the failure is then only returned. +func (r *ClassifierReconciler) getCurrentHashFailure(ctx context.Context, classifierName string, + cluster *corev1.ObjectReference, hashErr error) *libsveltosv1beta1.ClusterInfo { + + hash, _, err := r.getClassifierInClusterHashAndStatus(ctx, classifierName, cluster) + if err != nil { + return nil + } + + failureMessage := hashErr.Error() + return &libsveltosv1beta1.ClusterInfo{ + Cluster: *cluster, + Hash: hash, + FailureMessage: &failureMessage, + Status: libsveltosv1beta1.SveltosStatusFailed, + } +} + func (r *ClassifierReconciler) proceedProcessingClassifier(ctx context.Context, classifier *libsveltosv1beta1.Classifier, cluster *corev1.ObjectReference, isPullMode, isConfigSame bool, currentHash []byte, f feature, logger logr.Logger, ) (*libsveltosv1beta1.ClusterInfo, error) { @@ -1393,7 +1417,7 @@ func (r *ClassifierReconciler) proceedProcessingClassifier(ctx context.Context, return clusterInfo, nil } if *deployerStatus == libsveltosv1beta1.SveltosStatusProvisioning { - return clusterInfo, fmt.Errorf("classifier is still being provisioned") + return clusterInfo, errors.New(msgStillProvisioning) } } else if isConfigSame && currentStatus != nil && *currentStatus == libsveltosv1beta1.SveltosStatusProvisioned { logger.V(logs.LogDebug).Info("already deployed") @@ -1544,7 +1568,7 @@ func (r *ClassifierReconciler) proceedDeployingClassifierInPullMode(ctx context. return clusterInfo, err } - return clusterInfo, fmt.Errorf("request to deploy queued") + return clusterInfo, errors.New(msgDeployQueued) } // If SveltosCluster is in pull mode, verify whether agent has pulled and successuffly deployed it. @@ -2711,9 +2735,11 @@ func getPerClusterPatches(ctx context.Context, c client.Client, patches, err := getSveltosApplierPatchesNew(ctx, c, configMapNamespace, configMapName, logger) if err != nil { - logger.Error(err, "failed to get ConfigMap with patches", - "configMapNamespace", configMapNamespace, "configMapName", configMapName) - return nil, err + // The error is not logged here: it is returned with its context, recorded as the failure message of + // the cluster in the ClassifierReport and reported by the caller. Logging it here as well would + // repeat it, on every retry. + return nil, fmt.Errorf("failed to get ConfigMap %s/%s referenced by annotation %s: %w", + configMapNamespace, configMapName, annotationKey, err) } logger.V(logs.LogDebug).Info(fmt.Sprintf("got patches from ConfigMap %s/%s", diff --git a/controllers/classifier_deployer_test.go b/controllers/classifier_deployer_test.go index 6df42f3..fdb23b1 100644 --- a/controllers/classifier_deployer_test.go +++ b/controllers/classifier_deployer_test.go @@ -454,6 +454,46 @@ var _ = Describe("Classifier Deployer", func() { Expect(clusterInfo.Status).To(Equal(libsveltosv1beta1.SveltosStatusProvisioning)) }) + It("processClassifier reports a failure when a ConfigMap with patches referenced by the cluster does not exist", func() { + dep := fakedeployer.GetClient(context.TODO(), logger, testEnv.Client) + Expect(dep.RegisterFeatureID(libsveltosv1beta1.FeatureClassifier)).To(Succeed()) + + classifierReconciler := getClassifierReconciler(testEnv.Client, dep) + classifier := getClassifierInstance(randomString()) + classifierScope := getClassifierScope(testEnv.Client, logger, classifier) + + cluster := prepareCluster() + + missingConfigMapName := randomString() + Eventually(func() error { + currentCluster := &clusterv1.Cluster{} + err := testEnv.Get(context.TODO(), + types.NamespacedName{Namespace: cluster.Namespace, Name: cluster.Name}, currentCluster) + if err != nil { + return err + } + currentCluster.Annotations = map[string]string{ + perClusterPatchAnnotation: missingConfigMapName, + } + return testEnv.Update(context.TODO(), currentCluster) + }, timeout, pollingInterval).Should(Succeed()) + + f := controllers.GetHandlersForFeature(libsveltosv1beta1.FeatureClassifier) + var clusterInfo *libsveltosv1beta1.ClusterInfo + Eventually(func() bool { + var err error + clusterInfo, err = controllers.ProcessClassifier(classifierReconciler, context.TODO(), classifierScope, "", + getClusterRef(cluster), f, logger) + return err != nil && apierrors.IsNotFound(err) + }, timeout, pollingInterval).Should(BeTrue()) + + // The failure is returned as a ClusterInfo too, so that it is recorded in the ClassifierReport + Expect(clusterInfo).ToNot(BeNil()) + Expect(clusterInfo.Status).To(Equal(libsveltosv1beta1.SveltosStatusFailed)) + Expect(clusterInfo.FailureMessage).ToNot(BeNil()) + Expect(*clusterInfo.FailureMessage).To(ContainSubstring(missingConfigMapName)) + }) + It("processClassifier detects classifier does not need to be deployed in cluster", func() { dep := fakedeployer.GetClient(context.TODO(), logger, testEnv.Client) diff --git a/controllers/classifier_report_collection.go b/controllers/classifier_report_collection.go index 6a5d59b..fc786ae 100644 --- a/controllers/classifier_report_collection.go +++ b/controllers/classifier_report_collection.go @@ -105,7 +105,8 @@ func removeClassifierReports(ctx context.Context, c client.Client, classifier *l for i := range classifierReportList.Items { cr := &classifierReportList.Items[i] err = c.Delete(ctx, cr) - if err != nil { + // The ClassifierReport may already be gone: removed by another reconciliation + if err != nil && !apierrors.IsNotFound(err) { return err } } @@ -134,7 +135,8 @@ func removeClusterClassifierReports(ctx context.Context, c client.Client, cluste for i := range classifierReportList.Items { cr := &classifierReportList.Items[i] err = c.Delete(ctx, cr) - if err != nil { + // The ClassifierReport may already be gone: removed by another reconciliation + if err != nil && !apierrors.IsNotFound(err) { return err } } diff --git a/controllers/classifier_report_collection_test.go b/controllers/classifier_report_collection_test.go index 620b7cc..0a277a3 100644 --- a/controllers/classifier_report_collection_test.go +++ b/controllers/classifier_report_collection_test.go @@ -34,6 +34,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "sigs.k8s.io/controller-runtime/pkg/client/interceptor" "github.com/projectsveltos/classifier/controllers" libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" @@ -151,6 +152,41 @@ var _ = Describe("Classifier Deployer", func() { Expect(len(classifierReportList.Items)).To(BeZero()) }) + It("removeClassifierReports and removeClusterClassifierReports ignore a ClassifierReport which is already gone", func() { + clusterType := libsveltosv1beta1.ClusterTypeCapi + clusterNamespace := randomString() + clusterName := randomString() + + classifierReport := getClassifierReport(classifier.Name, clusterNamespace, clusterName) + classifierReport.Labels = libsveltosv1beta1.GetClassifierReportLabels( + classifier.Name, clusterName, &clusterType) + initObjects := []client.Object{classifierReport} + + // The ClassifierReport is listed and removed by someone else before this reconciliation deletes it + c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...). + WithObjects(initObjects...). + WithInterceptorFuncs(interceptor.Funcs{ + Delete: func(ctx context.Context, cl client.WithWatch, obj client.Object, + opts ...client.DeleteOption) error { + + _ = cl.Delete(ctx, obj, opts...) + return cl.Delete(ctx, obj, opts...) + }, + }).Build() + + Expect(controllers.RemoveClassifierReports(context.TODO(), c, classifier, logger)).To(Succeed()) + + recreated := classifierReport.DeepCopy() + recreated.ResourceVersion = "" + Expect(c.Create(context.TODO(), recreated)).To(Succeed()) + Expect(controllers.RemoveClusterClassifierReports(context.TODO(), c, clusterNamespace, clusterName, + clusterType, logger)).To(Succeed()) + + classifierReportList := &libsveltosv1beta1.ClassifierReportList{} + Expect(c.List(context.TODO(), classifierReportList)).To(Succeed()) + Expect(len(classifierReportList.Items)).To(BeZero()) + }) + It("removeClusterClassifierReports deletes all ClassifierReport for a given cluster instance", func() { clusterType := libsveltosv1beta1.ClusterTypeCapi clusterNamespace := randomString() diff --git a/controllers/events.go b/controllers/events.go index 93d15c5..7836499 100644 --- a/controllers/events.go +++ b/controllers/events.go @@ -28,6 +28,41 @@ import ( "github.com/projectsveltos/libsveltos/lib/eventreasons" ) +// The errors returned while a request to deploy or to clean up has been made and has not completed yet. They are +// not failures: the Classifier is requeued until the request completes. +const ( + msgDeployQueued = "request to deploy queued" + msgDeployInProgress = "deploy is in progress. Wait before cleanup or redeploying" + msgCleanupQueued = "cleanup request is queued" + msgCleanupInProgress = "cleanup is in progress. Wait before redeploying" + msgAgentCleanupQueued = "agent cleanup request is queued" + msgAgentRemoving = "agent is removing classifier instance" + msgStillProvisioning = "classifier is still being provisioned" + msgStillBeingRemoved = "feature is still being removed" + msgStillQueued = "request to deploy Classifier is still queued in one ore more clusters" +) + +// isWaiting returns true when err only says a request to deploy or to clean up has not completed yet. +func isWaiting(err error) bool { + switch err.Error() { + case msgDeployQueued, msgDeployInProgress, msgCleanupQueued, msgCleanupInProgress, msgAgentCleanupQueued, + msgAgentRemoving, msgStillProvisioning, msgStillBeingRemoved, msgStillQueued: + + return true + } + + return false +} + +// keepFailure returns the error to report once err has been seen after seen: the last error wins, except +// that an error which only says a request is still waiting never replaces a failure. +func keepFailure(seen, err error) error { + if seen != nil && isWaiting(err) { + return seen + } + return err +} + // recordWarningf records a Warning event on regarding. It does nothing when no recorder is set. // The note is capped, so an oversized message is not rejected by the API server. Identical events // are aggregated by the recorder, so notes must not contain anything that changes between diff --git a/controllers/events_test.go b/controllers/events_test.go index 2c7fcec..040a0be 100644 --- a/controllers/events_test.go +++ b/controllers/events_test.go @@ -182,3 +182,41 @@ var _ = Describe("ManagementClusterClassifier events", func() { Expect(recorded).To(HavePrefix("Warning ClassifierFailed failed to build cluster sets: ")) }) }) + +var _ = Describe("errors only saying a request is still waiting", func() { + waiting := []string{ + "request to deploy queued", + "cleanup request is queued", + "classifier is still being provisioned", + "request to deploy Classifier is still queued in one ore more clusters", + "agent cleanup request is queued", + "agent is removing classifier instance", + "feature is still being removed", + } + + It("isWaiting is true for a request which has not completed yet", func() { + for _, m := range waiting { + Expect(controllers.IsWaiting(errors.New(m))).To(BeTrue(), m) + } + }) + + It("isWaiting is false for a failure", func() { + Expect(controllers.IsWaiting(errors.New("ConfigMap does-not-exist not found"))).To(BeFalse()) + }) + + It("keepFailure reports the last error when it is a failure", func() { + first := errors.New("first failure") + last := errors.New("last failure") + Expect(controllers.KeepFailure(nil, last)).To(Equal(last)) + Expect(controllers.KeepFailure(first, last)).To(Equal(last)) + Expect(controllers.KeepFailure(errors.New(waiting[0]), last)).To(Equal(last)) + }) + + It("keepFailure does not replace an error with one only saying a request is still waiting", func() { + failure := errors.New("ConfigMap does-not-exist not found") + Expect(controllers.KeepFailure(failure, errors.New(waiting[0]))).To(Equal(failure)) + + stillWaiting := errors.New(waiting[1]) + Expect(controllers.KeepFailure(nil, stillWaiting)).To(Equal(stillWaiting)) + }) +}) diff --git a/controllers/export_test.go b/controllers/export_test.go index bd9cce0..0668111 100644 --- a/controllers/export_test.go +++ b/controllers/export_test.go @@ -111,6 +111,8 @@ var ( var ( RecordWarningf = recordWarningf UnmanagedLabelKeys = unmanagedLabelKeys + IsWaiting = isWaiting + KeepFailure = keepFailure ) var (