Skip to content

Commit

Permalink
Ceph(fix): Updates on StorageClass won't work.
Browse files Browse the repository at this point in the history
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 <rajasing@redhat.com>
  • Loading branch information
RAJAT SINGH committed Jul 2, 2020
1 parent 63796eb commit 8073646
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion hack/latest-csv-checksum.md5
@@ -1 +1 @@
1708c158c6610cc1d24725b992f0990b
013302e894cd54a7fe31a31050f9a73a
45 changes: 27 additions & 18 deletions pkg/controller/storagecluster/initialization_reconciler.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"

"github.com/go-logr/logr"
ocsv1 "github.com/openshift/ocs-operator/pkg/apis/ocs/v1"
Expand Down Expand Up @@ -54,30 +55,38 @@ func (r *ReconcileStorageCluster) ensureStorageClasses(instance *ocsv1.StorageCl

func (r *ReconcileStorageCluster) createStorageClasses(scs []*storagev1.StorageClass, reqLogger logr.Logger) error {
for _, sc := range scs {
existing := storagev1.StorageClass{}
err := r.client.Get(context.TODO(), types.NamespacedName{Name: sc.Name, Namespace: sc.Namespace}, &existing)
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)
}

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):
if errors.IsNotFound(err) {
// Since the StorageClass is not found, we will create a new one
reqLogger.Info(fmt.Sprintf("Creating StorageClass %s", sc.Name))
err = r.client.Create(context.TODO(), sc)
if err != nil {
return err
}
} else if err != nil {
return err
} else {
if existing.DeletionTimestamp != nil {
return fmt.Errorf("failed to restore storageclass %s because it is marked for deletion", existing.Name)
}
if !reflect.DeepEqual(sc.Parameters, existing.Parameters) {
// Since we have to update the existing StorageClass
// So, we will delete the existing storageclass and create a new one
reqLogger.Info(fmt.Sprintf("StorageClass %s needs to be updated, deleting it", existing.Name))
err = r.client.Delete(context.TODO(), existing)
if err != nil {
return err
}
reqLogger.Info(fmt.Sprintf("Creating StorageClass %s", sc.Name))
existing.ObjectMeta.OwnerReferences = sc.ObjectMeta.OwnerReferences
sc.ObjectMeta = existing.ObjectMeta
err = r.client.Create(context.TODO(), sc)
if err != nil {
return err
}
}
}
}
return nil
Expand Down

0 comments on commit 8073646

Please sign in to comment.