Skip to content

Commit

Permalink
feat: add accessMode in storageClassMap
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
andyzhangx committed Jan 1, 2025
1 parent 69126cd commit 15a6cc2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data:
- "/scripts/shred.sh"
- "2"
volumeMode: Filesystem
accessMode: ReadWriteOnce
fsType: ext4
namePattern: "*"
---
Expand Down
2 changes: 2 additions & 0 deletions docs/provisioner.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ data:
# # intended to use as a formatted filesystem volume or to remain in block
# # state. Value of Filesystem is implied when omitted.
# volumeMode: Filesystem
# # Access mode of the volume. default to ReadWriteOnce if not specified.
# accessMode: ReadWriteOnce
# # The filesystem to format before mounting on the node. This applies
# # only when the volume source is a device and mode is Filesystem.
# # The default value is to auto-select a filesystem in Kubernetes if unspecified.
Expand Down
1 change: 1 addition & 0 deletions helm/examples/baremetal-default-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ classes:
- name: local-storage
hostDir: /mnt/disks
volumeMode: Filesystem
accessMode: ReadWriteOnce
storageClass:
# create and set storage class as default
isDefaultClass: true
2 changes: 2 additions & 0 deletions helm/provisioner/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ classes:
# The volume mode of created PersistentVolume object. Default to Filesystem
# if not specified.
volumeMode: Filesystem
# Access mode of the volume. default to ReadWriteOnce if not specified.
accessMode: ReadWriteOnce
# Filesystem type to mount.
# It applies only when the source path is a block device,
# and desire volume mode is Filesystem.
Expand Down
10 changes: 9 additions & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ type MountConfig struct {
// The volume mode of created PersistentVolume object,
// default to Filesystem if not specified.
VolumeMode string `json:"volumeMode" yaml:"volumeMode"`
// The access mode of created PersistentVolume object
// default to ReadWriteOnce if not specified.
AccessMode string `json:"accessMode" yaml:"accessMode"`
// Filesystem type to mount.
// It applies only when the source path is a block device,
// and desire volume mode is Filesystem.
Expand Down Expand Up @@ -180,6 +183,7 @@ type LocalPVConfig struct {
AffinityAnn string
NodeAffinity *v1.VolumeNodeAffinity
VolumeMode v1.PersistentVolumeMode
AccessMode v1.PersistentVolumeAccessMode
MountOptions []string
FsType *string
Labels map[string]string
Expand Down Expand Up @@ -248,14 +252,18 @@ func CreateLocalPVSpec(config *LocalPVConfig) *v1.PersistentVolume {
},
},
AccessModes: []v1.PersistentVolumeAccessMode{
v1.ReadWriteOnce,
config.AccessMode,
},
StorageClassName: config.StorageClass,
VolumeMode: &config.VolumeMode,
MountOptions: config.MountOptions,
},
}

if config.AccessMode == "" {
pv.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}
}

if config.UseAlphaAPI {
pv.ObjectMeta.Annotations[AlphaStorageNodeAffinityAnnotation] = config.AffinityAnn
} else {
Expand Down
9 changes: 7 additions & 2 deletions pkg/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ func (d *Discoverer) discoverVolumesAtPath(class string, config common.MountConf
}

var capacityByte int64
desiredAccessMode := v1.ReadWriteOnce
if config.AccessMode != "" {
desiredAccessMode = v1.PersistentVolumeAccessMode(config.AccessMode)
}
desireVolumeMode := v1.PersistentVolumeMode(config.VolumeMode)
switch volMode {
case v1.PersistentVolumeBlock:
Expand Down Expand Up @@ -345,7 +349,7 @@ func (d *Discoverer) discoverVolumesAtPath(class string, config common.MountConf
continue
}

err = d.createPV(file, class, reclaimPolicy, mountOptions, config, capacityByte, desireVolumeMode, startTime)
err = d.createPV(file, class, reclaimPolicy, mountOptions, config, capacityByte, desireVolumeMode, desiredAccessMode, startTime)
if err != nil {
discoErrors = append(discoErrors, err)
}
Expand All @@ -367,7 +371,7 @@ func generatePVName(file, node, class string) string {
return fmt.Sprintf("local-pv-%x", h.Sum32())
}

func (d *Discoverer) createPV(file, class string, reclaimPolicy v1.PersistentVolumeReclaimPolicy, mountOptions []string, config common.MountConfig, capacityByte int64, volMode v1.PersistentVolumeMode, startTime time.Time) error {
func (d *Discoverer) createPV(file, class string, reclaimPolicy v1.PersistentVolumeReclaimPolicy, mountOptions []string, config common.MountConfig, capacityByte int64, volMode v1.PersistentVolumeMode, accessMode v1.PersistentVolumeAccessMode, startTime time.Time) error {
pvName := generatePVName(file, d.Node.Name, class)
outsidePath := filepath.Join(config.HostDir, file)

Expand All @@ -382,6 +386,7 @@ func (d *Discoverer) createPV(file, class string, reclaimPolicy v1.PersistentVol
ReclaimPolicy: reclaimPolicy,
ProvisionerName: d.Name,
VolumeMode: volMode,
AccessMode: accessMode,
Labels: d.Labels,
MountOptions: mountOptions,
SetPVOwnerRef: d.SetPVOwnerRef,
Expand Down

0 comments on commit 15a6cc2

Please sign in to comment.