mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
use SecretObject to reference iSCSI CHAP secret
Signed-off-by: Huamin Chen <hchen@redhat.com>
This commit is contained in:
@@ -245,6 +245,12 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
i.ISCSIInterface = "default"
|
||||
}
|
||||
},
|
||||
func(i *core.ISCSIPersistentVolumeSource, c fuzz.Continue) {
|
||||
i.ISCSIInterface = c.RandString()
|
||||
if i.ISCSIInterface == "" {
|
||||
i.ISCSIInterface = "default"
|
||||
}
|
||||
},
|
||||
func(d *core.DNSPolicy, c fuzz.Continue) {
|
||||
policies := []core.DNSPolicy{core.DNSClusterFirst, core.DNSDefault}
|
||||
*d = policies[c.Rand.Intn(len(policies))]
|
||||
|
||||
@@ -347,10 +347,10 @@ type PersistentVolumeSource struct {
|
||||
// Quobyte represents a Quobyte mount on the host that shares a pod's lifetime
|
||||
// +optional
|
||||
Quobyte *QuobyteVolumeSource
|
||||
// ISCSIVolumeSource represents an ISCSI resource that is attached to a
|
||||
// ISCSIPersistentVolumeSource represents an ISCSI resource that is attached to a
|
||||
// kubelet's host machine and then exposed to the pod.
|
||||
// +optional
|
||||
ISCSI *ISCSIVolumeSource
|
||||
ISCSI *ISCSIPersistentVolumeSource
|
||||
// FlexVolume represents a generic volume resource that is
|
||||
// provisioned/attached using an exec based plugin. This is an alpha feature and may change in future.
|
||||
// +optional
|
||||
@@ -793,6 +793,54 @@ type ISCSIVolumeSource struct {
|
||||
InitiatorName *string
|
||||
}
|
||||
|
||||
// ISCSIPersistentVolumeSource represents an ISCSI disk.
|
||||
// ISCSI volumes can only be mounted as read/write once.
|
||||
// ISCSI volumes support ownership management and SELinux relabeling.
|
||||
type ISCSIPersistentVolumeSource struct {
|
||||
// Required: iSCSI target portal
|
||||
// the portal is either an IP or ip_addr:port if port is other than default (typically TCP ports 860 and 3260)
|
||||
// +optional
|
||||
TargetPortal string
|
||||
// Required: target iSCSI Qualified Name
|
||||
// +optional
|
||||
IQN string
|
||||
// Required: iSCSI target lun number
|
||||
// +optional
|
||||
Lun int32
|
||||
// Optional: Defaults to 'default' (tcp). iSCSI interface name that uses an iSCSI transport.
|
||||
// +optional
|
||||
ISCSIInterface string
|
||||
// Filesystem type to mount.
|
||||
// Must be a filesystem type supported by the host operating system.
|
||||
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
|
||||
// TODO: how do we prevent errors in the filesystem from compromising the machine
|
||||
// +optional
|
||||
FSType string
|
||||
// Optional: Defaults to false (read/write). ReadOnly here will force
|
||||
// the ReadOnly setting in VolumeMounts.
|
||||
// +optional
|
||||
ReadOnly bool
|
||||
// Optional: list of iSCSI target portal ips for high availability.
|
||||
// the portal is either an IP or ip_addr:port if port is other than default (typically TCP ports 860 and 3260)
|
||||
// +optional
|
||||
Portals []string
|
||||
// Optional: whether support iSCSI Discovery CHAP authentication
|
||||
// +optional
|
||||
DiscoveryCHAPAuth bool
|
||||
// Optional: whether support iSCSI Session CHAP authentication
|
||||
// +optional
|
||||
SessionCHAPAuth bool
|
||||
// Optional: CHAP secret for iSCSI target and initiator authentication.
|
||||
// The secret is used if either DiscoveryCHAPAuth or SessionCHAPAuth is true
|
||||
// +optional
|
||||
SecretRef *SecretReference
|
||||
// Optional: Custom initiator name per volume.
|
||||
// If initiatorName is specified with iscsiInterface simultaneously, new iSCSI interface
|
||||
// <target portal>:<volume name> will be created for the connection.
|
||||
// +optional
|
||||
InitiatorName *string
|
||||
}
|
||||
|
||||
// Represents a Fibre Channel volume.
|
||||
// Fibre Channel volumes can only be mounted as read/write once.
|
||||
// Fibre Channel volumes support ownership management and SELinux relabeling.
|
||||
|
||||
@@ -249,6 +249,11 @@ func SetDefaults_ISCSIVolumeSource(obj *v1.ISCSIVolumeSource) {
|
||||
obj.ISCSIInterface = "default"
|
||||
}
|
||||
}
|
||||
func SetDefaults_ISCSIPersistentVolumeSource(obj *v1.ISCSIPersistentVolumeSource) {
|
||||
if obj.ISCSIInterface == "" {
|
||||
obj.ISCSIInterface = "default"
|
||||
}
|
||||
}
|
||||
func SetDefaults_AzureDiskVolumeSource(obj *v1.AzureDiskVolumeSource) {
|
||||
if obj.CachingMode == nil {
|
||||
obj.CachingMode = new(v1.AzureDataDiskCachingMode)
|
||||
|
||||
@@ -712,6 +712,46 @@ func validateGitRepoVolumeSource(gitRepo *core.GitRepoVolumeSource, fldPath *fie
|
||||
}
|
||||
|
||||
func validateISCSIVolumeSource(iscsi *core.ISCSIVolumeSource, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if len(iscsi.TargetPortal) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetPortal"), ""))
|
||||
}
|
||||
if len(iscsi.IQN) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("iqn"), ""))
|
||||
} else {
|
||||
if !strings.HasPrefix(iscsi.IQN, "iqn") && !strings.HasPrefix(iscsi.IQN, "eui") && !strings.HasPrefix(iscsi.IQN, "naa") {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("iqn"), iscsi.IQN, "must be valid format starting with iqn, eui, or naa"))
|
||||
} else if strings.HasPrefix(iscsi.IQN, "iqn") && !iscsiInitiatorIqnRegex.MatchString(iscsi.IQN) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("iqn"), iscsi.IQN, "must be valid format"))
|
||||
} else if strings.HasPrefix(iscsi.IQN, "eui") && !iscsiInitiatorEuiRegex.MatchString(iscsi.IQN) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("iqn"), iscsi.IQN, "must be valid format"))
|
||||
} else if strings.HasPrefix(iscsi.IQN, "naa") && !iscsiInitiatorNaaRegex.MatchString(iscsi.IQN) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("iqn"), iscsi.IQN, "must be valid format"))
|
||||
}
|
||||
}
|
||||
if iscsi.Lun < 0 || iscsi.Lun > 255 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("lun"), iscsi.Lun, validation.InclusiveRangeError(0, 255)))
|
||||
}
|
||||
if (iscsi.DiscoveryCHAPAuth || iscsi.SessionCHAPAuth) && iscsi.SecretRef == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("secretRef"), ""))
|
||||
}
|
||||
if iscsi.InitiatorName != nil {
|
||||
initiator := *iscsi.InitiatorName
|
||||
if !strings.HasPrefix(initiator, "iqn") && !strings.HasPrefix(initiator, "eui") && !strings.HasPrefix(initiator, "naa") {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("initiatorname"), initiator, "must be valid format starting with iqn, eui, or naa"))
|
||||
}
|
||||
if strings.HasPrefix(initiator, "iqn") && !iscsiInitiatorIqnRegex.MatchString(initiator) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("initiatorname"), initiator, "must be valid format"))
|
||||
} else if strings.HasPrefix(initiator, "eui") && !iscsiInitiatorEuiRegex.MatchString(initiator) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("initiatorname"), initiator, "must be valid format"))
|
||||
} else if strings.HasPrefix(initiator, "naa") && !iscsiInitiatorNaaRegex.MatchString(initiator) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("initiatorname"), initiator, "must be valid format"))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateISCSIPersistentVolumeSource(iscsi *core.ISCSIPersistentVolumeSource, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if len(iscsi.TargetPortal) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetPortal"), ""))
|
||||
@@ -735,6 +775,11 @@ func validateISCSIVolumeSource(iscsi *core.ISCSIVolumeSource, fldPath *field.Pat
|
||||
if (iscsi.DiscoveryCHAPAuth || iscsi.SessionCHAPAuth) && iscsi.SecretRef == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("secretRef"), ""))
|
||||
}
|
||||
if iscsi.SecretRef != nil {
|
||||
if len(iscsi.SecretRef.Name) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("secretRef", "name"), ""))
|
||||
}
|
||||
}
|
||||
if iscsi.InitiatorName != nil {
|
||||
initiator := *iscsi.InitiatorName
|
||||
if !strings.HasPrefix(initiator, "iqn") && !strings.HasPrefix(initiator, "eui") && !strings.HasPrefix(initiator, "naa") {
|
||||
@@ -1517,7 +1562,7 @@ func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList {
|
||||
allErrs = append(allErrs, field.Forbidden(specPath.Child("iscsi"), "may not specify more than 1 volume type"))
|
||||
} else {
|
||||
numVolumes++
|
||||
allErrs = append(allErrs, validateISCSIVolumeSource(pv.Spec.ISCSI, specPath.Child("iscsi"))...)
|
||||
allErrs = append(allErrs, validateISCSIPersistentVolumeSource(pv.Spec.ISCSI, specPath.Child("iscsi"))...)
|
||||
}
|
||||
if pv.Spec.ISCSI.InitiatorName != nil && len(pv.ObjectMeta.Name+":"+pv.Spec.ISCSI.TargetPortal) > 64 {
|
||||
tooLongErr := "Total length of <volume name>:<iscsi.targetPortal> must be under 64 characters if iscsi.initiatorName is specified."
|
||||
|
||||
Reference in New Issue
Block a user