From 0edeff8810301a24b2ea1720bcbad109ea7e9eda Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Thu, 9 Jan 2025 17:00:53 +0200 Subject: [PATCH] Add CephNFS functionality and related types Signed-off-by: Oded Viner --- api/v1/storagecluster_types.go | 5 +++++ controllers/storagecluster/cephnfs.go | 12 +++++++++++- controllers/storagecluster/cephnfs_test.go | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/v1/storagecluster_types.go b/api/v1/storagecluster_types.go index 3c2cca95e2..7f0a34545e 100644 --- a/api/v1/storagecluster_types.go +++ b/api/v1/storagecluster_types.go @@ -475,6 +475,11 @@ type NFSSpec struct { // +kubebuilder:validation:MaxLength=253 // +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ StorageClassName string `json:"storageClassName,omitempty"` + // LogLevel set logging level + // Log levels: NIV_NULL | NIV_FATAL | NIV_MAJ | NIV_CRIT | NIV_WARN | NIV_EVENT | NIV_INFO | NIV_DEBUG | NIV_MID_DEBUG | NIV_FULL_DEBUG | NB_LOG_LEVEL + // +optional + LogLevel string `json:"logLevel,omitempty"` + ReconcileStrategy string `json:"reconcileStrategy,omitempty"` } // MonitoringSpec controls the configuration of resources for exposing OCS metrics diff --git a/controllers/storagecluster/cephnfs.go b/controllers/storagecluster/cephnfs.go index 1afba04504..091e653593 100644 --- a/controllers/storagecluster/cephnfs.go +++ b/controllers/storagecluster/cephnfs.go @@ -36,6 +36,7 @@ func (r *StorageClusterReconciler) newCephNFSInstances(initData *ocsv1.StorageCl // set high PriorityClassName for the NFS pods, since this will block io for // pods using NFS volumes. PriorityClassName: openshiftUserCritical, + LogLevel: initData.Spec.NFS.LogLevel, }, }, }, @@ -55,7 +56,10 @@ func (obj *ocsCephNFS) ensureCreated(r *StorageClusterReconciler, instance *ocsv if instance.Spec.NFS == nil || !instance.Spec.NFS.Enable { return reconcile.Result{}, nil } - + reconcileStrategy := ReconcileStrategy(instance.Spec.NFS.ReconcileStrategy) + if reconcileStrategy == ReconcileStrategyIgnore { + return reconcile.Result{}, nil + } cephNFSes, err := r.newCephNFSInstances(instance) if err != nil { return reconcile.Result{}, err @@ -74,6 +78,9 @@ func (obj *ocsCephNFS) ensureCreated(r *StorageClusterReconciler, instance *ocsv r.Log.Info("Restoring original CephNFS.", "CephNFS", klog.KRef(cephNFS.Namespace, cephNFS.Name)) existingCephNFS.ObjectMeta.OwnerReferences = cephNFS.ObjectMeta.OwnerReferences existingCephNFS.Spec = cephNFS.Spec + if instance.Spec.NFS.LogLevel != "" { + existingCephNFS.Spec.Server.LogLevel = instance.Spec.NFS.LogLevel + } err = r.Client.Update(ctxTODO, &existingCephNFS) if err != nil { r.Log.Error(err, "Unable to update CephNFS.", "CephNFS", klog.KRef(cephNFS.Namespace, cephNFS.Name)) @@ -98,6 +105,9 @@ func (obj *ocsCephNFS) ensureCreated(r *StorageClusterReconciler, instance *ocsv // ensureDeleted deletes the CephNFS resource owned by the StorageCluster func (obj *ocsCephNFS) ensureDeleted(r *StorageClusterReconciler, sc *ocsv1.StorageCluster) (reconcile.Result, error) { + if sc.Spec.NFS == nil || !sc.Spec.NFS.Enable { + return reconcile.Result{}, nil + } ctxTODO := context.TODO() foundCephNFS := &cephv1.CephNFS{} cephNFSes, err := r.newCephNFSInstances(sc) diff --git a/controllers/storagecluster/cephnfs_test.go b/controllers/storagecluster/cephnfs_test.go index 4f2d34a473..bd3c045d48 100644 --- a/controllers/storagecluster/cephnfs_test.go +++ b/controllers/storagecluster/cephnfs_test.go @@ -72,3 +72,13 @@ func assertCephNFSService(t *testing.T, reconciler StorageClusterReconciler, cr assert.Equal(t, expectedAf[0].ObjectMeta.Name, actualNFSService.ObjectMeta.Name) assert.Equal(t, expectedAf[0].Spec, actualNFSService.Spec) } + +func TestNfsLogLevelParam(t *testing.T) { + var objects []client.Object + t, reconciler, cr, _ := initStorageClusterResourceCreateUpdateTest(t, objects, nil) + cr.Spec.NFS = &api.NFSSpec{ + LogLevel: "NIV_DEBUG", + } + expectedAf, _ := reconciler.newCephNFSInstances(cr) + assert.Equal(t, "NIV_DEBUG", expectedAf[0].Spec.Server.LogLevel) +}