-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data volume source image #751
Changes from 6 commits
fd1e856
c00c822
648306b
43cf20d
9802b76
bfc9b2e
3dccc37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,7 @@ The worker configuration contains: | |
|
||
If you attach the disk with `SCRATCH` type, either an `NVMe` interface or a `SCSI` interface must be specified. | ||
It is only meaningful to provide this volume interface if only `SCRATCH` data volumes are used. | ||
|
||
* Volume Encryption config that specifies values for `kmsKeyName` and `kmsKeyServiceAccountName`. | ||
* The `kmsKeyName` is the | ||
key name of the cloud kms disk encryption key and must be specified if CMEK disk encryption is needed. | ||
|
@@ -166,6 +167,12 @@ The worker configuration contains: | |
gcloud projects add-iam-policy-binding projectId --member | ||
serviceAccount:[email protected] --role roles/cloudkms.cryptoKeyEncrypterDecrypter | ||
``` | ||
|
||
* Setting a volume image with `dataVolume.sourceImage`. | ||
However, this parameter should only be used with particular caution. | ||
For example Gardenlinux works with filesystem LABELs only and creating another disk form the very same image causes the LABELs to be duplicated. | ||
See: https://github.com/gardener/gardener-extension-provider-gcp/issues/323 | ||
|
||
* Service Account with their specified scopes, authorized for this worker. | ||
|
||
Service accounts created in advance that generate access tokens that can be accessed through the metadata server and used to authenticate applications on the instance. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,8 @@ spec: | |
# encryption: # Encryption Details | ||
# kmsKeyName: "projects/projectId/locations/<zoneName>/keyRings/<keyRingName>/cryptoKeys/alpha" | ||
# kmsKeyServiceAccount: "[email protected]" | ||
# dataVolume: # provider specific dataVolume configuration | ||
# sourceImage: "projects/sap-se-gcp-gardenlinux/global/images/..." | ||
# gpu: | ||
# acceleratorType: nvidia-tesla-t4 | ||
# count: 1 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
|
||
"github.com/gardener/gardener/pkg/apis/core" | ||
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1" | ||
"golang.org/x/exp/slices" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
@@ -22,8 +23,9 @@ import ( | |
var ( | ||
validVolumeLocalSSDInterfacesTypes = sets.New("NVME", "SCSI") | ||
|
||
providerFldPath = field.NewPath("providerConfig") | ||
volumeFldPath = providerFldPath.Child("volume") | ||
providerFldPath = field.NewPath("providerConfig") | ||
volumeFldPath = providerFldPath.Child("volume") | ||
dataVolumeFldPath = providerFldPath.Child("dataVolume") | ||
) | ||
|
||
// ValidateWorkerConfig validates a WorkerConfig object. | ||
|
@@ -42,6 +44,9 @@ func ValidateWorkerConfig(workerConfig *gcp.WorkerConfig, dataVolumes []core.Dat | |
allErrs = append(allErrs, validateDiskEncryption(workerConfig.Volume.Encryption, volumeFldPath.Child("encryption"))...) | ||
} | ||
allErrs = append(allErrs, validateNodeTemplate(workerConfig.NodeTemplate, providerFldPath.Child("nodeTemplate"))...) | ||
if workerConfig.DataVolumes != nil { | ||
allErrs = append(allErrs, validateDataVolumeNames(workerConfig.DataVolumes, dataVolumes)...) | ||
} | ||
} | ||
|
||
return allErrs | ||
|
@@ -120,22 +125,54 @@ func validateDataVolume(workerConfig *gcp.WorkerConfig, volume core.DataVolume, | |
allErrs = append(allErrs, field.Required(fldPath.Child("type"), "must not be empty")) | ||
return allErrs | ||
} | ||
if *volume.Type == worker.VolumeTypeScratch { | ||
|
||
allErrs = append(allErrs, validateScratchDisk(*volume.Type, workerConfig)...) | ||
|
||
return allErrs | ||
} | ||
|
||
func validateScratchDisk(volumeType string, workerConfig *gcp.WorkerConfig) field.ErrorList { | ||
allErrs := field.ErrorList{} | ||
|
||
interfacePath := volumeFldPath.Child("interface") | ||
encryptionPath := volumeFldPath.Child("encryption") | ||
|
||
if volumeType == worker.VolumeTypeScratch { | ||
if workerConfig == nil || workerConfig.Volume == nil || workerConfig.Volume.LocalSSDInterface == nil { | ||
allErrs = append(allErrs, field.Required(volumeFldPath.Child("interface"), fmt.Sprintf("must be set when using %s volumes", worker.VolumeTypeScratch))) | ||
allErrs = append(allErrs, field.Required(interfacePath, fmt.Sprintf("must be set when using %s volumes", worker.VolumeTypeScratch))) | ||
} else { | ||
if !validVolumeLocalSSDInterfacesTypes.Has(*workerConfig.Volume.LocalSSDInterface) { | ||
allErrs = append(allErrs, field.NotSupported(volumeFldPath.Child("interface"), *workerConfig.Volume.LocalSSDInterface, validVolumeLocalSSDInterfacesTypes.UnsortedList())) | ||
allErrs = append(allErrs, field.NotSupported(interfacePath, *workerConfig.Volume.LocalSSDInterface, validVolumeLocalSSDInterfacesTypes.UnsortedList())) | ||
} | ||
} | ||
// DiskEncryption not allowed for type SCRATCH | ||
if workerConfig != nil && workerConfig.Volume != nil && workerConfig.Volume.Encryption != nil { | ||
allErrs = append(allErrs, field.Invalid(volumeFldPath.Child("encryption"), *workerConfig.Volume.Encryption, fmt.Sprintf("must not be set in combination with %s volumes", worker.VolumeTypeScratch))) | ||
allErrs = append(allErrs, field.Invalid(encryptionPath, *workerConfig.Volume.Encryption, fmt.Sprintf("must not be set in combination with %s volumes", worker.VolumeTypeScratch))) | ||
} | ||
} else { | ||
// LocalSSDInterface only allowed for type SCRATCH | ||
if workerConfig != nil && workerConfig.Volume != nil && workerConfig.Volume.LocalSSDInterface != nil { | ||
allErrs = append(allErrs, field.Invalid(volumeFldPath.Child("interface"), *workerConfig.Volume.LocalSSDInterface, fmt.Sprintf("is only allowed for type %s", worker.VolumeTypeScratch))) | ||
allErrs = append(allErrs, field.Invalid(encryptionPath, *workerConfig.Volume.LocalSSDInterface, fmt.Sprintf("is only allowed for type %s", worker.VolumeTypeScratch))) | ||
} | ||
} | ||
return allErrs | ||
} | ||
|
||
func validateDataVolumeNames(workerConfigDataVolumes []gcp.DataVolume, dataVolumes []core.DataVolume) field.ErrorList { | ||
allErrs := field.ErrorList{} | ||
|
||
// Extracting a dataVolume names | ||
var dataVolumeNames []string | ||
for _, dv := range dataVolumes { | ||
dataVolumeNames = append(dataVolumeNames, dv.Name) | ||
} | ||
|
||
for _, configDataVolume := range workerConfigDataVolumes { | ||
if !slices.Contains(dataVolumeNames, configDataVolume.Name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: instead of constructing if slices.ContainsFunc(workerConfigDataVolumes, func(volume gcp.DataVolume) bool {
return volume.Name == configDataVolume.Name
}) {
continue
}
allErrs = append(allErrs, field.Invalid(
dataVolumeFldPath,
configDataVolume.Name,
fmt.Sprintf("could not find dataVolume with name %s", configDataVolume.Name))) |
||
allErrs = append(allErrs, field.Invalid( | ||
dataVolumeFldPath, | ||
configDataVolume.Name, | ||
fmt.Sprintf("could not find dataVolume with name %s", configDataVolume.Name))) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(apologies for delay in reviewing. was on sick leave.)
Just for confirmation: I assume this new validation routine was introduced since we didn't any validation before to enforce this section in the usage document:
"If you attach the disk with SCRATCH type, either an NVMe interface or a SCSI interface must be specified. It is only meaningful to provide this volume interface if only SCRATCH data volumes are used."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the validation for the SCRATCH disk type was present and has now been slightly refined.
A new validation rule requires that the workerConfigDataVolume name must correspond to a dataVolume name.