From 5623795ff559f4c13bf3abb64486a2d0af8d2214 Mon Sep 17 00:00:00 2001 From: RAJAT SINGH Date: Sat, 27 Jun 2020 13:03:00 +0530 Subject: [PATCH] Ceph(fix): Updates on StorageClass won't work. This PR fixes the issue, where the updates given on StorageClass were not working.Now,the cluster will delete the existing sc and create a new one when requested for updation. Signed-off-by: RAJAT SINGH --- hack/latest-csv-checksum.md5 | 2 +- .../initialization_reconciler.go | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hack/latest-csv-checksum.md5 b/hack/latest-csv-checksum.md5 index 3f86fabbbd..142dc8a1cb 100644 --- a/hack/latest-csv-checksum.md5 +++ b/hack/latest-csv-checksum.md5 @@ -1 +1 @@ -88dfa9ce39fe3b7a5e82518f66a86717 \ No newline at end of file +013302e894cd54a7fe31a31050f9a73a \ No newline at end of file diff --git a/pkg/controller/storagecluster/initialization_reconciler.go b/pkg/controller/storagecluster/initialization_reconciler.go index 2851524b8d..5f64441364 100644 --- a/pkg/controller/storagecluster/initialization_reconciler.go +++ b/pkg/controller/storagecluster/initialization_reconciler.go @@ -65,22 +65,22 @@ func (r *ReconcileStorageCluster) createStorageClasses(scs []*storagev1.StorageC existing := storagev1.StorageClass{} err := r.client.Get(context.TODO(), types.NamespacedName{Name: sc.Name, Namespace: sc.Namespace}, &existing) - switch { - case err == nil: - if existing.DeletionTimestamp != nil { - reqLogger.Info(fmt.Sprintf("Unable to restore init object because %s is marked for deletion", existing.Name)) - return fmt.Errorf("failed to restore initialization object %s because it is marked for deletion", existing.Name) + if err == nil || errors.IsNotFound(err) { + if err == nil { + if existing.DeletionTimestamp != nil { + reqLogger.Info(fmt.Sprintf("Unable to restore init object because %s is marked for deletion", existing.Name)) + return fmt.Errorf("failed to restore initialization object %s because it is marked for deletion", existing.Name) + } + reqLogger.Info("Deleteing StorageClass %s", existing.Name) + err = r.client.Delete(context.TODO(), &existing) + if err != nil { + reqLogger.Error(err, "unable to delete StorageClass") + return err + } } - reqLogger.Info(fmt.Sprintf("Restoring original StorageClass %s", sc.Name)) existing.ObjectMeta.OwnerReferences = sc.ObjectMeta.OwnerReferences sc.ObjectMeta = existing.ObjectMeta - - err = r.client.Update(context.TODO(), sc) - if err != nil { - return err - } - case errors.IsNotFound(err): reqLogger.Info(fmt.Sprintf("Creating StorageClass %s", sc.Name)) err = r.client.Create(context.TODO(), sc) if err != nil {