Skip to content

Commit

Permalink
chore: add support for ReadWriteOncePod access mode
Browse files Browse the repository at this point in the history
Signed-off-by: William Phetsinorath <william.phetsinorath@shikanime.studio>
  • Loading branch information
shikanime committed Oct 24, 2024
1 parent e7db6e7 commit 28ad886
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
16 changes: 14 additions & 2 deletions csi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ func getVolumeOptions(volumeID string, volOptions map[string]string) (*longhornc
vol.StaleReplicaTimeout = defaultStaleReplicaTimeout
}

if exclusive, ok := volOptions["exclusive"]; ok {
isExclusive, err := strconv.ParseBool(exclusive)
if err != nil {
return nil, errors.Wrap(err, "invalid parameter exclusive")
}
if isExclusive && vol.AccessMode == string(longhorn.AccessModeReadWriteOnce) {
vol.AccessMode = string(longhorn.AccessModeReadWriteOncePod)
}
}

if share, ok := volOptions["share"]; ok {
isShared, err := strconv.ParseBool(share)
if err != nil {
Expand All @@ -115,11 +125,13 @@ func getVolumeOptions(volumeID string, volOptions map[string]string) (*longhornc

if isShared {
vol.AccessMode = string(longhorn.AccessModeReadWriteMany)
} else {
vol.AccessMode = string(longhorn.AccessModeReadWriteOnce)
}
}

if vol.AccessMode == "" {
vol.AccessMode = string(longhorn.AccessModeReadWriteOnce)
}

if migratable, ok := volOptions["migratable"]; ok {
isMigratable, err := strconv.ParseBool(migratable)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion datastore/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,11 @@ func NewPVManifest(size int64, pvName, volumeName, storageClassName, fsType stri
// NewPVCManifestForVolume returns a new PersistentVolumeClaim object for a longhorn volume
func NewPVCManifestForVolume(v *longhorn.Volume, pvName, ns, pvcName, storageClassName string) *corev1.PersistentVolumeClaim {
accessMode := corev1.ReadWriteOnce
if v.Spec.AccessMode == longhorn.AccessModeReadWriteMany {
switch v.Spec.AccessMode {
case longhorn.AccessModeReadWriteMany:
accessMode = corev1.ReadWriteMany
case longhorn.AccessModeReadWriteOncePod:
accessMode = corev1.ReadWriteOncePod
}

return NewPVCManifest(v.Spec.Size, pvName, ns, pvcName, storageClassName, accessMode)
Expand Down
5 changes: 3 additions & 2 deletions k8s/pkg/apis/longhorn/v1beta1/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ const (
type AccessMode string

const (
AccessModeReadWriteOnce = AccessMode("rwo")
AccessModeReadWriteMany = AccessMode("rwx")
AccessModeReadWriteOnce = AccessMode("rwo")
AccessModeReadWriteOncePod = AccessMode("rwop")
AccessModeReadWriteMany = AccessMode("rwx")
)

type ReplicaAutoBalance string
Expand Down
7 changes: 4 additions & 3 deletions k8s/pkg/apis/longhorn/v1beta2/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ const (
DataLocalityStrictLocal = DataLocality("strict-local")
)

// +kubebuilder:validation:Enum=rwo;rwx
// +kubebuilder:validation:Enum=rwo;rwop,rwx
type AccessMode string

const (
AccessModeReadWriteOnce = AccessMode("rwo")
AccessModeReadWriteMany = AccessMode("rwx")
AccessModeReadWriteOnce = AccessMode("rwo")
AccessModeReadWriteOncePod = AccessMode("rwop")
AccessModeReadWriteMany = AccessMode("rwx")
)

// +kubebuilder:validation:Enum=ignored;disabled;least-effort;best-effort
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func ValidateDataLocality(mode longhorn.DataLocality) error {
}

func ValidateAccessMode(mode longhorn.AccessMode) error {
if mode != longhorn.AccessModeReadWriteMany && mode != longhorn.AccessModeReadWriteOnce {
if mode != longhorn.AccessModeReadWriteMany && mode != longhorn.AccessModeReadWriteOnce && mode != longhorn.AccessModeReadWriteOncePod {
return fmt.Errorf("invalid access mode: %v", mode)
}
return nil
Expand Down

0 comments on commit 28ad886

Please sign in to comment.