Skip to content

Commit

Permalink
Add CephNFS functionality and related types
Browse files Browse the repository at this point in the history
Signed-off-by: Oded Viner <oviner@redhat.com>
  • Loading branch information
OdedViner committed Jan 9, 2025
1 parent 8561dee commit 0edeff8
Show file tree
Hide file tree
Showing 3 changed files with 26 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
12 changes: 11 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 All @@ -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)
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)
}

0 comments on commit 0edeff8

Please sign in to comment.