@@ -19,6 +19,7 @@ package app
1919
2020import (
2121 "context"
22+ "strconv"
2223 "strings"
2324
2425 mconfig "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
@@ -113,6 +114,17 @@ const (
113114 // is specified with PVC and is useful for granting shared access
114115 // to underlying hostpaths across multiple pods.
115116 //KeyPVAbsolutePath = "AbsolutePath"
117+
118+ //KeyXFSQuota enables/sets parameters for XFS Quota.
119+ // Example StorageClass snippet:
120+ // - name: XFSQuota
121+ // enabled: true
122+ // data:
123+ // softLimitGrace: "80%"
124+ // hardLimitGrace: "85%"
125+ KeyXFSQuota = "XFSQuota"
126+ KeyXfsQuotaSoftLimit = "softLimitGrace"
127+ KeyXfsQuotaHardLimit = "hardLimitGrace"
116128)
117129
118130const (
@@ -168,11 +180,17 @@ func (p *Provisioner) GetVolumeConfig(ctx context.Context, pvName string, pvc *c
168180 return nil , errors .Wrapf (err , "unable to read volume config: pvc {%v}" , pvc .ObjectMeta .Name )
169181 }
170182
183+ dataPvConfigMap , err := dataConfigToMap (pvConfig )
184+ if err != nil {
185+ return nil , errors .Wrapf (err , "unable to read volume config: pvc {%v}" , pvc .ObjectMeta .Name )
186+ }
187+
171188 c := & VolumeConfig {
172- pvName : pvName ,
173- pvcName : pvc .ObjectMeta .Name ,
174- scName : * scName ,
175- options : pvConfigMap ,
189+ pvName : pvName ,
190+ pvcName : pvc .ObjectMeta .Name ,
191+ scName : * scName ,
192+ options : pvConfigMap ,
193+ configData : dataPvConfigMap ,
176194 }
177195 return c , nil
178196}
@@ -262,6 +280,23 @@ func (c *VolumeConfig) GetPath() (string, error) {
262280 ValidateAndBuild ()
263281}
264282
283+ func (c * VolumeConfig ) IsXfsQuotaEnabled () bool {
284+ xfsQuotaEnabled := c .getEnabled (KeyXFSQuota )
285+ xfsQuotaEnabled = strings .TrimSpace (xfsQuotaEnabled )
286+
287+ enableXfsQuotaBool , err := strconv .ParseBool (xfsQuotaEnabled )
288+ //Default case
289+ // this means that we have hit either of the two cases below:
290+ // i. The value was something other than a straightforward
291+ // true or false
292+ // ii. The value was empty
293+ if err != nil {
294+ return false
295+ }
296+
297+ return enableXfsQuotaBool
298+ }
299+
265300//getValue is a utility function to extract the value
266301// of the `key` from the ConfigMap object - which is
267302// map[string]interface{map[string][string]}
@@ -283,6 +318,30 @@ func (c *VolumeConfig) getValue(key string) string {
283318 return ""
284319}
285320
321+ //Similar to getValue() above. Returns value of the
322+ // 'Enabled' parameter.
323+ func (c * VolumeConfig ) getEnabled (key string ) string {
324+ if configObj , ok := util .GetNestedField (c .options , key ).(map [string ]string ); ok {
325+ if val , p := configObj [string (mconfig .EnabledPTP )]; p {
326+ return val
327+ }
328+ }
329+ return ""
330+ }
331+
332+ //This is similar to getValue() and getEnabled().
333+ // This gets the value for a specific
334+ // 'Data' parameter key-value pair.
335+ func (c * VolumeConfig ) getData (key string , dataKey string ) string {
336+ if configData , ok := util .GetNestedField (c .configData , key ).(map [string ]string ); ok {
337+ if val , p := configData [dataKey ]; p {
338+ return val
339+ }
340+ }
341+ //Default case
342+ return ""
343+ }
344+
286345// GetStorageClassName extracts the StorageClass name from PVC
287346func GetStorageClassName (pvc * corev1.PersistentVolumeClaim ) * string {
288347 // Use beta annotation first
@@ -347,3 +406,25 @@ func GetImagePullSecrets(s string) []corev1.LocalObjectReference {
347406 }
348407 return list
349408}
409+
410+ func dataConfigToMap (pvConfig []mconfig.Config ) (map [string ]interface {}, error ) {
411+ m := map [string ]interface {}{}
412+
413+ for _ , configObj := range pvConfig {
414+ //No Data Parameter
415+ if configObj .Data == nil {
416+ continue
417+ }
418+
419+ configName := strings .TrimSpace (configObj .Name )
420+ confHierarchy := map [string ]interface {}{
421+ configName : configObj .Data ,
422+ }
423+ isMerged := util .MergeMapOfObjects (m , confHierarchy )
424+ if ! isMerged {
425+ return nil , errors .Errorf ("failed to transform cas config 'Data' for configName '%s' to map: failed to merge: %s" , configName , configObj )
426+ }
427+ }
428+
429+ return m , nil
430+ }
0 commit comments