Skip to content

Commit

Permalink
feat(provisioner): prefer StorageClass config over PVC config
Browse files Browse the repository at this point in the history
In the typical use-case for the provisioner, an admin sets the config on the
StorageClass, and a user sets the config on the PVC. The admin's config may
set boundaries on to the volumes which the PVC config map try to override.
Preferring StorageClass config when there is a conflict may be the right way
to go.

Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Jun 28, 2024
1 parent 4f4692c commit a7ada41
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions cmd/provisioner-localpv/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const (
k8sNodeLabelKeyHostname = "kubernetes.io/hostname"
)

//GetVolumeConfig creates a new VolumeConfig struct by
// GetVolumeConfig creates a new VolumeConfig struct by
// parsing and merging the configuration provided in the PVC/SC
// annotation - cas.openebs.io/config with the
// default configuration of the provisioner.
Expand All @@ -169,13 +169,19 @@ func (p *Provisioner) GetVolumeConfig(ctx context.Context, pvName string, pvc *c
}
}

// extract and merge the cas config from persistentvolumeclaim
// Extract and merge the cas config from persistentvolumeclaim.
// TODO: Validation checks for what all cas-config options can be
// set on the PVC.
pvcCASConfigStr := pvc.Annotations[string(mconfig.CASConfigKey)]
klog.V(4).Infof("PVC %v has config:%v", pvc.Name, pvcCASConfigStr)
if len(strings.TrimSpace(pvcCASConfigStr)) != 0 {
pvcCASConfig, err := cast.UnMarshallToConfig(pvcCASConfigStr)
if err == nil {
pvConfig = cast.MergeConfig(pvcCASConfig, pvConfig)
// Config keys which already exist (SC config),
// will be skipped
// i.e. SC config will have precedence over PVC config,
// if both have the same keys
pvConfig = cast.MergeConfig(pvConfig, pvcCASConfig)
} else {
return nil, errors.Wrapf(err, "failed to get config: invalid pvc config {%v}", pvcCASConfigStr)
}
Expand All @@ -184,13 +190,6 @@ func (p *Provisioner) GetVolumeConfig(ctx context.Context, pvName string, pvc *c
//TODO : extract and merge the cas volume config from pvc
//This block can be added once validation checks are added
// as to the type of config that can be passed via PVC
//pvcCASConfigStr := pvc.ObjectMeta.Annotations[string(mconfig.CASConfigKey)]
//if len(strings.TrimSpace(pvcCASConfigStr)) != 0 {
// pvcCASConfig, err := cast.UnMarshallToConfig(pvcCASConfigStr)
// if err == nil {
// pvConfig = cast.MergeConfig(pvcCASConfig, pvConfig)
// }
//}

pvConfigMap, err := cast.ConfigToMap(pvConfig)
if err != nil {
Expand Down

0 comments on commit a7ada41

Please sign in to comment.