From cf84a55b67d9c4da8c45de7c040e994d55d8ac20 Mon Sep 17 00:00:00 2001 From: Leela Venkaiah G Date: Fri, 19 Apr 2024 12:26:49 +0530 Subject: [PATCH] api: remove storageclassclaim api & migration controller we can't create storageclaims from storageclassclaim withough migrating the underlying storage and having this API & controllers might create more problems than what is solves. Signed-off-by: Leela Venkaiah G --- PROJECT | 8 - api/v1alpha1/storageclaim_types.go | 7 - api/v1alpha1/storageclassclaim_types.go | 89 ------------ api/v1alpha1/zz_generated.deepcopy.go | 114 --------------- config/rbac/role.yaml | 26 ---- .../storageclassclaim_migration_controller.go | 137 ------------------ main.go | 8 - 7 files changed, 389 deletions(-) delete mode 100644 api/v1alpha1/storageclassclaim_types.go delete mode 100644 controllers/storageclassclaim_migration_controller.go diff --git a/PROJECT b/PROJECT index 79f7b584..85efe3a6 100644 --- a/PROJECT +++ b/PROJECT @@ -20,14 +20,6 @@ resources: kind: StorageClient path: github.com/red-hat-storage/ocs-client-operator/api/v1alpha1 version: v1alpha1 -- api: - crdVersion: v1 - namespaced: true - domain: openshift.io - group: ocs - kind: StorageClassClaim - path: github.com/red-hat-storage/ocs-client-operator/api/v1alpha1 - version: v1alpha1 - api: crdVersion: v1 namespaced: true diff --git a/api/v1alpha1/storageclaim_types.go b/api/v1alpha1/storageclaim_types.go index 9dd59f14..d6369002 100644 --- a/api/v1alpha1/storageclaim_types.go +++ b/api/v1alpha1/storageclaim_types.go @@ -44,13 +44,6 @@ type StorageClaimStatus struct { Phase storageClaimState `json:"phase,omitempty"` } -// TODO: remove after storageclassclaim migration controller and storageclassclaim is deleted - -type StorageClientNamespacedName struct { - Name string `json:"name"` - Namespace string `json:"namespace"` -} - // StorageClaimSpec defines the desired state of StorageClaim type StorageClaimSpec struct { //+kubebuilder:validation:Enum=block;sharedfile diff --git a/api/v1alpha1/storageclassclaim_types.go b/api/v1alpha1/storageclassclaim_types.go deleted file mode 100644 index 6e1d2d25..00000000 --- a/api/v1alpha1/storageclassclaim_types.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2022 Red Hat, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type storageClassClaimState string - -const ( - // StorageClassClaimInitializing represents Initializing state of StorageClassClaim - StorageClassClaimInitializing storageClassClaimState = "Initializing" - // StorageClassClaimValidating represents Validating state of StorageClassClaim - StorageClassClaimValidating storageClassClaimState = "Validating" - // StorageClassClaimFailed represents Failed state of StorageClassClaim - StorageClassClaimFailed storageClassClaimState = "Failed" - // StorageClassClaimCreating represents Configuring state of StorageClassClaim - StorageClassClaimCreating storageClassClaimState = "Creating" - // StorageClassClaimConfiguring represents Configuring state of StorageClassClaim - StorageClassClaimConfiguring storageClassClaimState = "Configuring" - // StorageClassClaimReady represents Ready state of StorageClassClaim - StorageClassClaimReady storageClassClaimState = "Ready" - // StorageClassClaimDeleting represents Deleting state of StorageClassClaim - StorageClassClaimDeleting storageClassClaimState = "Deleting" -) - -// StorageClassClaimStatus defines the observed state of StorageClassClaim -type StorageClassClaimStatus struct { - Phase storageClassClaimState `json:"phase,omitempty"` - SecretNames []string `json:"secretNames,omitempty"` -} - -// StorageClassClaimSpec defines the desired state of StorageClassClaim -type StorageClassClaimSpec struct { - //+kubebuilder:validation:Enum=blockpool;sharedfilesystem - Type string `json:"type"` - EncryptionMethod string `json:"encryptionMethod,omitempty"` - StorageProfile string `json:"storageProfile,omitempty"` - StorageClient *StorageClientNamespacedName `json:"storageClient"` -} - -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:resource:scope=Cluster -//+kubebuilder:printcolumn:name="StorageType",type="string",JSONPath=".spec.type" -//+kubebuilder:printcolumn:name="StorageProfile",type="string",JSONPath=".spec.storageProfile" -//+kubebuilder:printcolumn:name="StorageClientName",type="string",JSONPath=".spec.storageClient.name" -//+kubebuilder:printcolumn:name="StorageClientNamespace",type="string",JSONPath=".spec.storageClient.namespace" -//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" - -// StorageClassClaim is the Schema for the storageclassclaims API -// +kubebuilder:deprecatedversion:warning="StorageClassClaim API is deprecated and will be removed in future version, please use StorageClaim API instead." -type StorageClassClaim struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - //+kubebuilder:validation:Required - //+kubebuilder:validation:XValidation:rule="oldSelf == self",message="spec is immutable" - Spec StorageClassClaimSpec `json:"spec"` - Status StorageClassClaimStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -// StorageClassClaimList contains a list of StorageClassClaim -type StorageClassClaimList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []StorageClassClaim `json:"items"` -} - -func init() { - SchemeBuilder.Register(&StorageClassClaim{}, &StorageClassClaimList{}) -} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 2827ce82..ae9507fe 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -114,105 +114,6 @@ func (in *StorageClaimStatus) DeepCopy() *StorageClaimStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageClassClaim) DeepCopyInto(out *StorageClassClaim) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassClaim. -func (in *StorageClassClaim) DeepCopy() *StorageClassClaim { - if in == nil { - return nil - } - out := new(StorageClassClaim) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *StorageClassClaim) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageClassClaimList) DeepCopyInto(out *StorageClassClaimList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]StorageClassClaim, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassClaimList. -func (in *StorageClassClaimList) DeepCopy() *StorageClassClaimList { - if in == nil { - return nil - } - out := new(StorageClassClaimList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *StorageClassClaimList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageClassClaimSpec) DeepCopyInto(out *StorageClassClaimSpec) { - *out = *in - if in.StorageClient != nil { - in, out := &in.StorageClient, &out.StorageClient - *out = new(StorageClientNamespacedName) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassClaimSpec. -func (in *StorageClassClaimSpec) DeepCopy() *StorageClassClaimSpec { - if in == nil { - return nil - } - out := new(StorageClassClaimSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageClassClaimStatus) DeepCopyInto(out *StorageClassClaimStatus) { - *out = *in - if in.SecretNames != nil { - in, out := &in.SecretNames, &out.SecretNames - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassClaimStatus. -func (in *StorageClassClaimStatus) DeepCopy() *StorageClassClaimStatus { - if in == nil { - return nil - } - out := new(StorageClassClaimStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *StorageClient) DeepCopyInto(out *StorageClient) { *out = *in @@ -272,21 +173,6 @@ func (in *StorageClientList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageClientNamespacedName) DeepCopyInto(out *StorageClientNamespacedName) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClientNamespacedName. -func (in *StorageClientNamespacedName) DeepCopy() *StorageClientNamespacedName { - if in == nil { - return nil - } - out := new(StorageClientNamespacedName) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *StorageClientSpec) DeepCopyInto(out *StorageClientSpec) { *out = *in diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 67d94a23..a5055aca 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -169,32 +169,6 @@ rules: - get - patch - update -- apiGroups: - - ocs.openshift.io - resources: - - storageclassclaims - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - ocs.openshift.io - resources: - - storageclassclaims/finalizers - verbs: - - update -- apiGroups: - - ocs.openshift.io - resources: - - storageclassclaims/status - verbs: - - get - - patch - - update - apiGroups: - ocs.openshift.io resources: diff --git a/controllers/storageclassclaim_migration_controller.go b/controllers/storageclassclaim_migration_controller.go deleted file mode 100644 index 552d2085..00000000 --- a/controllers/storageclassclaim_migration_controller.go +++ /dev/null @@ -1,137 +0,0 @@ -package controllers - -import ( - "context" - "fmt" - - "github.com/go-logr/logr" - "github.com/red-hat-storage/ocs-client-operator/api/v1alpha1" - corev1 "k8s.io/api/core/v1" - kerrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/builder" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/predicate" -) - -const ( - // for migration of storageclassclaims to storageclaims - storageClassClaimFinalizer = "storageclassclaim.ocs.openshift.io" -) - -// StorageClassClaimReconcile migrates StorageClassClaim objects to StorageClaim -type StorageClassClaimMigrationReconciler struct { - client.Client - Scheme *runtime.Scheme - - log logr.Logger - ctx context.Context -} - -func (r *StorageClassClaimMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error { - onlyCreateEvent := predicate.Funcs{ - CreateFunc: func(event.CreateEvent) bool { - return true - }, - DeleteFunc: func(event.DeleteEvent) bool { - return false - }, - UpdateFunc: func(event.UpdateEvent) bool { - return false - }, - GenericFunc: func(event.GenericEvent) bool { - return false - }, - } - return ctrl.NewControllerManagedBy(mgr). - For(&v1alpha1.StorageClassClaim{}, builder.WithPredicates(onlyCreateEvent)). - Complete(r) -} - -//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclassclaims,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclassclaims/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclassclaims/finalizers,verbs=update - -func (r *StorageClassClaimMigrationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - - r.log = log.FromContext(ctx) - r.ctx = ctx - r.log.Info("Starting reconcile.") - - storageClassClaim := &v1alpha1.StorageClassClaim{} - storageClassClaim.Name = req.Name - - if err := r.get(storageClassClaim); err != nil && !kerrors.IsNotFound(err) { - r.log.Error(err, fmt.Sprintf("failed to get storageclassclaim %q", storageClassClaim.Name)) - return ctrl.Result{}, err - } - - storageClaim := &v1alpha1.StorageClaim{} - storageClaim.Name = storageClassClaim.Name - - switch storageClassClaim.Spec.Type { - case "blockpool": - storageClaim.Spec.Type = "block" - case "sharedfilesystem": - storageClaim.Spec.Type = "sharedfile" - } - - storageClaim.Spec.EncryptionMethod = storageClassClaim.Spec.EncryptionMethod - storageClaim.Spec.StorageProfile = storageClassClaim.Spec.StorageProfile - if storageClassClaim.Spec.StorageClient != nil { - storageClaim.Spec.StorageClient = storageClassClaim.Spec.StorageClient.Name - } - - r.log.Info(fmt.Sprintf("Migrating storageclassclaim %q", storageClassClaim.Name)) - if err := r.create(storageClaim); err != nil && !kerrors.IsAlreadyExists(err) { - return ctrl.Result{}, fmt.Errorf("failed to create storageclaims %q: %v", storageClaim.Name, err) - } - - for idx := range storageClassClaim.Status.SecretNames { - secret := &corev1.Secret{} - secret.Name = storageClassClaim.Status.SecretNames[idx] - secret.Namespace = storageClassClaim.Spec.StorageClient.Namespace - if err := r.delete(secret); err != nil { - return ctrl.Result{}, fmt.Errorf("failed to delete secret %s: %v", client.ObjectKeyFromObject(secret), err) - } - } - - // remove finalizer on existing storageclassclaim - finalizerUpdated := controllerutil.RemoveFinalizer(storageClassClaim, storageClassClaimFinalizer) - if finalizerUpdated { - if err := r.update(storageClassClaim); err != nil { - return ctrl.Result{}, fmt.Errorf("failed to remove finalizer on storageclassclaim %q: %v", storageClassClaim.Name, err) - } - } - - // migration is successful delete the storageclassclaim - if err := r.delete(storageClassClaim); err != nil { - return ctrl.Result{}, fmt.Errorf("failed to delete storageclassclaim %q: %v", storageClassClaim.Name, err) - } - - r.log.Info(fmt.Sprintf("Successfully migrated storageclassclaim %q to storageclass %q", storageClassClaim.Name, storageClaim.Name)) - return ctrl.Result{}, nil -} - -func (r *StorageClassClaimMigrationReconciler) get(obj client.Object, opts ...client.GetOption) error { - return r.Get(r.ctx, client.ObjectKeyFromObject(obj), obj, opts...) -} - -func (r *StorageClassClaimMigrationReconciler) create(obj client.Object, opts ...client.CreateOption) error { - return r.Create(r.ctx, obj, opts...) -} - -func (r *StorageClassClaimMigrationReconciler) update(obj client.Object, opts ...client.UpdateOption) error { - return r.Update(r.ctx, obj, opts...) -} - -func (r *StorageClassClaimMigrationReconciler) delete(obj client.Object, opts ...client.DeleteOption) error { - if err := r.Delete(r.ctx, obj, opts...); err != nil && !kerrors.IsNotFound(err) { - return err - } - return nil -} diff --git a/main.go b/main.go index 816665f0..8e372553 100644 --- a/main.go +++ b/main.go @@ -171,14 +171,6 @@ func main() { os.Exit(1) } - if err = (&controllers.StorageClassClaimMigrationReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "StorageClassClaim") - os.Exit(1) - } - if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { setupLog.Error(err, "unable to set up health check") os.Exit(1)