Skip to content

Commit

Permalink
Add StorageCluster.spec.nfs.LogLevel in storagecluster CR
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
OdedViner committed Jan 9, 2025
1 parent 8561dee commit 912192e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/v1/storagecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/ocs.openshift.io_storageclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion controllers/storagecluster/cephnfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand All @@ -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
Expand All @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions controllers/storagecluster/cephnfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions deploy/ocs-operator/manifests/storagecluster.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 912192e

Please sign in to comment.