From 912192e57b83e776880ab183133a9eb156e5c169 Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Wed, 8 Jan 2025 15:16:57 +0200 Subject: [PATCH] Add StorageCluster.spec.nfs.LogLevel in storagecluster CR This commit introduces a new parameter, `spec.nfs.LogLevel`, to the StorageCluster CR. The `LogLevel` parameter allows users to configure the log level for NFS, improving flexibility and control over logging behavior. This addition aims to enhance the user experience by enabling finer-grained logging settings for debugging and monitoring purposes. Signed-off-by: Oded Viner --- api/v1/storagecluster_types.go | 5 +++++ config/crd/bases/ocs.openshift.io_storageclusters.yaml | 7 +++++++ controllers/storagecluster/cephnfs.go | 9 ++++++++- controllers/storagecluster/cephnfs_test.go | 10 ++++++++++ .../crds/ocs/ocs.openshift.io_storageclusters.yaml | 7 +++++++ deploy/ocs-operator/manifests/storagecluster.crd.yaml | 7 +++++++ .../ocs-operator/api/v4/v1/storagecluster_types.go | 5 +++++ .../ocs-operator/api/v4/v1/storagecluster_types.go | 5 +++++ 8 files changed, 54 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/config/crd/bases/ocs.openshift.io_storageclusters.yaml b/config/crd/bases/ocs.openshift.io_storageclusters.yaml index 58d12491a6..a8925d04aa 100644 --- a/config/crd/bases/ocs.openshift.io_storageclusters.yaml +++ b/config/crd/bases/ocs.openshift.io_storageclusters.yaml @@ -2618,6 +2618,13 @@ spec: enable: description: Enable specifies whether to enable NFS. type: boolean + logLevel: + description: |- + 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 + type: string + reconcileStrategy: + type: string storageClassName: description: StorageClassName specifies the name of the storage class created for NFS diff --git a/controllers/storagecluster/cephnfs.go b/controllers/storagecluster/cephnfs.go index 1afba04504..cf3b6a2855 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)) 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) +} diff --git a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml index 58d12491a6..a8925d04aa 100644 --- a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml +++ b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml @@ -2618,6 +2618,13 @@ spec: enable: description: Enable specifies whether to enable NFS. type: boolean + logLevel: + description: |- + 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 + type: string + reconcileStrategy: + type: string storageClassName: description: StorageClassName specifies the name of the storage class created for NFS diff --git a/deploy/ocs-operator/manifests/storagecluster.crd.yaml b/deploy/ocs-operator/manifests/storagecluster.crd.yaml index 58d12491a6..a8925d04aa 100644 --- a/deploy/ocs-operator/manifests/storagecluster.crd.yaml +++ b/deploy/ocs-operator/manifests/storagecluster.crd.yaml @@ -2618,6 +2618,13 @@ spec: enable: description: Enable specifies whether to enable NFS. type: boolean + logLevel: + description: |- + 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 + type: string + reconcileStrategy: + type: string storageClassName: description: StorageClassName specifies the name of the storage class created for NFS diff --git a/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go b/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go index 3c2cca95e2..7f0a34545e 100644 --- a/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go +++ b/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/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/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go index 3c2cca95e2..7f0a34545e 100644 --- a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go +++ b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/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