@@ -26,6 +26,7 @@ import (
2626
2727 snapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
2828 v1 "k8s.io/api/core/v1"
29+ scv1 "k8s.io/api/storage/v1"
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031 "k8s.io/apimachinery/pkg/util/wait"
3132 "k8s.io/client-go/kubernetes"
@@ -67,6 +68,40 @@ func createCephfsStorageClass(
6768 return err
6869 }
6970
71+ err = updateStorageClassParameters (& sc , params , enablePool , f )
72+ if err != nil {
73+ return err
74+ }
75+
76+ return createStorageClass (c , & sc )
77+ }
78+
79+ func createCephfsStorageClassWaitForFirstConsumer (c kubernetes.Interface , f * framework.Framework ,
80+ enablePool bool ,
81+ params map [string ]string ) error {
82+ scPath := fmt .Sprintf ("%s/%s" , cephFSExamplePath , "storageclass.yaml" )
83+ sc , err := getStorageClass (scPath )
84+ if err != nil {
85+ return err
86+ }
87+
88+ err = updateStorageClassParameters (& sc , params , enablePool , f )
89+ if err != nil {
90+ return err
91+ }
92+
93+ // Set the volume binding mode to WaitForFirstConsumer
94+ value := scv1 .VolumeBindingWaitForFirstConsumer
95+ sc .VolumeBindingMode = & value
96+
97+ return createStorageClass (c , & sc )
98+ }
99+
100+ func updateStorageClassParameters (sc * scv1.StorageClass , params map [string ]string , enablePool bool , f * framework.Framework ) error {
101+ if sc == nil {
102+ return fmt .Errorf ("StorageClass is nil" )
103+ }
104+
70105 sc .Parameters ["fsName" ] = fileSystemName
71106 sc .Parameters ["csi.storage.k8s.io/provisioner-secret-namespace" ] = cephCSINamespace
72107 sc .Parameters ["csi.storage.k8s.io/provisioner-secret-name" ] = cephFSProvisionerSecretName
@@ -93,18 +128,20 @@ func createCephfsStorageClass(
93128
94129 // fetch and set fsID from the cluster if not set in params
95130 if _ , found := params ["clusterID" ]; ! found {
96- var fsID string
97- fsID , err = getClusterID (f )
131+ fsID , err := getClusterID (f )
98132 if err != nil {
99133 return fmt .Errorf ("failed to get clusterID: %w" , err )
100134 }
101135 sc .Parameters ["clusterID" ] = fsID
102136 }
103137
104- timeout := time .Duration (deployTimeout ) * time .Minute
138+ return nil
139+ }
105140
141+ func createStorageClass (c kubernetes.Interface , sc * scv1.StorageClass ) error {
142+ timeout := time .Duration (deployTimeout ) * time .Minute
106143 return wait .PollUntilContextTimeout (context .TODO (), poll , timeout , true , func (ctx context.Context ) (bool , error ) {
107- _ , err = c .StorageV1 ().StorageClasses ().Create (ctx , & sc , metav1.CreateOptions {})
144+ _ , err : = c .StorageV1 ().StorageClasses ().Create (ctx , sc , metav1.CreateOptions {})
108145 if err != nil {
109146 framework .Logf ("error creating StorageClass %q: %v" , sc .Name , err )
110147 if isRetryableAPIError (err ) {
0 commit comments