From be483829827dd46805beeef09ea54ab08929866c Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Tue, 19 Feb 2019 21:58:03 -0500 Subject: [PATCH 1/2] Handle unsupported platform errors gracefully --- pkg/controller/clusterstorage/clusterstorage_controller.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/controller/clusterstorage/clusterstorage_controller.go b/pkg/controller/clusterstorage/clusterstorage_controller.go index f307bf329..4e74c4ba3 100644 --- a/pkg/controller/clusterstorage/clusterstorage_controller.go +++ b/pkg/controller/clusterstorage/clusterstorage_controller.go @@ -30,6 +30,7 @@ import ( ) var log = logf.Log.WithName("controller_clusterstorage") +var unsupportedPlatformError = errors.New("unsupported platform") const ( // OwnerLabelNamespace is the label key for the owner namespace @@ -192,7 +193,8 @@ func (r *ReconcileClusterStorage) syncStatus(clusterOperator *configv1.ClusterOp } v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, notProgressing) - if err != nil { + // if error is anything other than unsupported platform, we are failing + if err != nil && err != unsupportedPlatformError { failing := configv1.ClusterOperatorStatusCondition{ Type: configv1.OperatorFailing, Status: configv1.ConditionTrue, @@ -247,7 +249,7 @@ func newStorageClassForCluster(cm *corev1.ConfigMap) (*storagev1.StorageClass, e return resourceread.ReadStorageClassV1OrDie(generated.MustAsset("assets/openstack.yaml")), nil } - return nil, errors.New("unsupported platform") + return nil, unsupportedPlatformError } func getPlatform(cm *corev1.ConfigMap) (*installer.Platform, error) { From d94365df883c018da074748de7b5fd34abde940e Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 20 Feb 2019 10:47:58 -0500 Subject: [PATCH 2/2] Add reason to status condition when unsupported --- .../clusterstorage_controller.go | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/pkg/controller/clusterstorage/clusterstorage_controller.go b/pkg/controller/clusterstorage/clusterstorage_controller.go index 4e74c4ba3..fa7169a29 100644 --- a/pkg/controller/clusterstorage/clusterstorage_controller.go +++ b/pkg/controller/clusterstorage/clusterstorage_controller.go @@ -192,35 +192,42 @@ func (r *ReconcileClusterStorage) syncStatus(clusterOperator *configv1.ClusterOp Status: configv1.ConditionFalse, } v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, notProgressing) + var message string // if error is anything other than unsupported platform, we are failing - if err != nil && err != unsupportedPlatformError { - failing := configv1.ClusterOperatorStatusCondition{ - Type: configv1.OperatorFailing, - Status: configv1.ConditionTrue, - Reason: "Error", - Message: err.Error(), - } - v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, failing) + if err != nil { + if err != unsupportedPlatformError { + failing := configv1.ClusterOperatorStatusCondition{ + Type: configv1.OperatorFailing, + Status: configv1.ConditionTrue, + Reason: "Error", + Message: err.Error(), + } + v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, failing) - unavailable := configv1.ClusterOperatorStatusCondition{ - Type: configv1.OperatorAvailable, - Status: configv1.ConditionFalse, - } - v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, unavailable) + unavailable := configv1.ClusterOperatorStatusCondition{ + Type: configv1.OperatorAvailable, + Status: configv1.ConditionFalse, + } + v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, unavailable) - updateErr := r.client.Status().Update(context.TODO(), clusterOperator) - if updateErr != nil { - log.Error(updateErr, "Failed to update ClusterOperator status") - return updateErr + updateErr := r.client.Status().Update(context.TODO(), clusterOperator) + if updateErr != nil { + log.Error(updateErr, "Failed to update ClusterOperator status") + return updateErr + } + return nil } - return nil + message = "Unsupported platform for storageclass creation" } available := configv1.ClusterOperatorStatusCondition{ Type: configv1.OperatorAvailable, Status: configv1.ConditionTrue, } + if message != "" { + available.Message = message + } v1helpers.SetStatusCondition(&clusterOperator.Status.Conditions, available) notFailing := configv1.ClusterOperatorStatusCondition{