Skip to content
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

Support volume image / image pull secret #416

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/storage/v1alpha1/volume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type VolumeSpec struct {
ClaimRef *commonv1alpha1.LocalUIDReference `json:"claimRef,omitempty"`
// Resources is a description of the volume's resources and capacity.
Resources corev1.ResourceList `json:"resources,omitempty"`
// Image is an optional image to bootstrap the volume with.
Image string `json:"image,omitempty"`
// ImagePullSecretRef is an optional secret for pulling the image of a volume.
ImagePullSecretRef *corev1.LocalObjectReference `json:"imagePullSecretRef,omitempty"`
// Tolerations define tolerations the Volume has. Only any VolumePool whose taints
// covered by Tolerations will be considered to host the Volume.
Tolerations []commonv1alpha1.Toleration `json:"tolerations,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions apis/storage/v1alpha1/volumeclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type VolumeClaimSpec struct {
Selector *metav1.LabelSelector `json:"selector,omitempty"`
// Resources are the requested Volume resources.
Resources corev1.ResourceList `json:"resources"`
// Image is an optional image to bootstrap the volume with.
Image string `json:"image,omitempty"`
// ImagePullSecretRef is an optional secret for pulling the image of a volume.
ImagePullSecretRef *corev1.LocalObjectReference `json:"imagePullSecretRef,omitempty"`
// VolumeClassRef references the VolumeClass used by the Volume.
VolumeClassRef corev1.LocalObjectReference `json:"volumeClassRef"`
}
Expand Down
8 changes: 8 additions & 0 deletions apis/storage/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions apis/storage/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions apis/storage/validation/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,43 @@ func ValidateVolume(volume *storage.Volume) field.ErrorList {
return allErrs
}

func validateVolumeSpec(volumeSpec *storage.VolumeSpec, fldPath *field.Path) field.ErrorList {
func validateVolumeSpec(spec *storage.VolumeSpec, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList

if volumeSpec.VolumeClassRef == (corev1.LocalObjectReference{}) {
if spec.VolumeClassRef == (corev1.LocalObjectReference{}) {
allErrs = append(allErrs, field.Required(fldPath.Child("volumeClassRef"), "must specify a volume class ref"))
}
for _, msg := range apivalidation.NameIsDNSLabel(volumeSpec.VolumeClassRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumeClassRef").Child("name"), volumeSpec.VolumeClassRef.Name, msg))
for _, msg := range apivalidation.NameIsDNSLabel(spec.VolumeClassRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumeClassRef").Child("name"), spec.VolumeClassRef.Name, msg))
}

allErrs = append(allErrs, metav1validation.ValidateLabels(volumeSpec.VolumePoolSelector, fldPath.Child("volumePoolSelector"))...)
allErrs = append(allErrs, metav1validation.ValidateLabels(spec.VolumePoolSelector, fldPath.Child("volumePoolSelector"))...)

if volumeSpec.VolumePoolRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(volumeSpec.VolumePoolRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumePoolRef").Child("name"), volumeSpec.VolumePoolRef.Name, msg))
if spec.VolumePoolRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(spec.VolumePoolRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumePoolRef").Child("name"), spec.VolumePoolRef.Name, msg))
}
}

if volumeSpec.ClaimRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(volumeSpec.ClaimRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("claimRef").Child("name"), volumeSpec.ClaimRef.Name, msg))
if spec.ClaimRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(spec.ClaimRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("claimRef").Child("name"), spec.ClaimRef.Name, msg))
}
}

storageValue, ok := volumeSpec.Resources[corev1.ResourceStorage]
storageValue, ok := spec.Resources[corev1.ResourceStorage]
if !ok {
allErrs = append(allErrs, field.Required(fldPath.Child("resources").Key(string(corev1.ResourceStorage)), ""))
} else {
allErrs = append(allErrs, onmetalapivalidation.ValidatePositiveQuantity(storageValue, fldPath.Child("resources").Key(string(corev1.ResourceStorage)))...)
}

if spec.ImagePullSecretRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(spec.ImagePullSecretRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("imagePullSecretRef").Child("name"), spec.ImagePullSecretRef.Name, msg))
}
}

return allErrs
}

Expand Down
8 changes: 8 additions & 0 deletions apis/storage/validation/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ var _ = Describe("Volume", func() {
},
ContainElement(InvalidField("spec.claimRef.name")),
),
Entry("invalid image pull secret ref name",
&storage.Volume{
Spec: storage.VolumeSpec{
ImagePullSecretRef: &corev1.LocalObjectReference{Name: "foo*"},
},
},
ContainElement(InvalidField("spec.imagePullSecretRef.name")),
),
Entry("no resources[storage]",
&storage.Volume{},
ContainElement(RequiredField("spec.resources[storage]")),
Expand Down
24 changes: 15 additions & 9 deletions apis/storage/validation/volumeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,37 @@ func ValidateVolumeClaim(volumeClaim *storage.VolumeClaim) field.ErrorList {
return allErrs
}

func validateVolumeClaimSpec(volumeClaimSpec *storage.VolumeClaimSpec, fldPath *field.Path) field.ErrorList {
func validateVolumeClaimSpec(spec *storage.VolumeClaimSpec, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList

if volumeClaimSpec.VolumeClassRef == (corev1.LocalObjectReference{}) {
if spec.VolumeClassRef == (corev1.LocalObjectReference{}) {
allErrs = append(allErrs, field.Required(fldPath.Child("volumeClassRef"), "must specify a volume class ref"))
}
for _, msg := range apivalidation.NameIsDNSLabel(volumeClaimSpec.VolumeClassRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumeClassRef").Child("name"), volumeClaimSpec.VolumeClassRef.Name, msg))
for _, msg := range apivalidation.NameIsDNSLabel(spec.VolumeClassRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumeClassRef").Child("name"), spec.VolumeClassRef.Name, msg))
}

allErrs = append(allErrs, metav1validation.ValidateLabelSelector(volumeClaimSpec.Selector, fldPath.Child("selector"))...)
allErrs = append(allErrs, metav1validation.ValidateLabelSelector(spec.Selector, fldPath.Child("selector"))...)

if volumeClaimSpec.VolumeRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(volumeClaimSpec.VolumeRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumeRef").Child("name"), volumeClaimSpec.VolumeRef.Name, msg))
if spec.VolumeRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(spec.VolumeRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("volumeRef").Child("name"), spec.VolumeRef.Name, msg))
}
}

storageValue, ok := volumeClaimSpec.Resources[corev1.ResourceStorage]
storageValue, ok := spec.Resources[corev1.ResourceStorage]
if !ok {
allErrs = append(allErrs, field.Required(fldPath.Child("resources").Key(string(corev1.ResourceStorage)), ""))
} else {
allErrs = append(allErrs, onmetalapivalidation.ValidatePositiveQuantity(storageValue, fldPath.Child("resources").Key(string(corev1.ResourceStorage)))...)
}

if spec.ImagePullSecretRef != nil {
for _, msg := range apivalidation.NameIsDNSLabel(spec.ImagePullSecretRef.Name, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("imagePullSecretRef").Child("name"), spec.ImagePullSecretRef.Name, msg))
}
}

return allErrs
}

Expand Down
8 changes: 8 additions & 0 deletions apis/storage/validation/volumeclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ var _ = Describe("VolumeClaim", func() {
},
ContainElement(InvalidField("spec.volumeClassRef.name")),
),
Entry("invalid image pull secret ref name",
&storage.VolumeClaim{
Spec: storage.VolumeClaimSpec{
ImagePullSecretRef: &corev1.LocalObjectReference{Name: "foo*"},
},
},
ContainElement(InvalidField("spec.imagePullSecretRef.name")),
),
Entry("invalid volume ref name",
&storage.VolumeClaim{
Spec: storage.VolumeClaimSpec{
Expand Down
4 changes: 4 additions & 0 deletions apis/storage/volume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type VolumeSpec struct {
ClaimRef *commonv1alpha1.LocalUIDReference
// Resources is a description of the volume's resources and capacity.
Resources corev1.ResourceList
// Image is an optional image to bootstrap the volume with.
Image string
// ImagePullSecretRef is an optional secret for pulling the image of a volume.
ImagePullSecretRef *corev1.LocalObjectReference
// Tolerations define tolerations the Volume has. Only a VolumePool whose taints
// covered by Tolerations will be considered to host the Volume.
Tolerations []commonv1alpha1.Toleration
Expand Down
4 changes: 4 additions & 0 deletions apis/storage/volumeclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type VolumeClaimSpec struct {
Selector *metav1.LabelSelector
// Resources are the requested Volume resources.
Resources corev1.ResourceList
// Image is an optional image to bootstrap the volume with.
Image string
// ImagePullSecretRef is an optional secret for pulling the image of a volume.
ImagePullSecretRef *corev1.LocalObjectReference
// VolumeClassRef references the VolumeClass used by the Volume.
VolumeClassRef corev1.LocalObjectReference
}
Expand Down
10 changes: 10 additions & 0 deletions apis/storage/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions docs/api-reference/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ Kubernetes core/v1.ResourceList
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image is an optional image to bootstrap the volume with.</p>
</td>
</tr>
<tr>
<td>
<code>imagePullSecretRef</code><br/>
<em>
<a href="https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#localobjectreference-v1-core">
Kubernetes core/v1.LocalObjectReference
</a>
</em>
</td>
<td>
<p>ImagePullSecretRef is an optional secret for pulling the image of a volume.</p>
</td>
</tr>
<tr>
<td>
<code>tolerations</code><br/>
<em>
<a href="/api-reference/common/#common.onmetal.de/v1alpha1.Toleration">
Expand Down Expand Up @@ -266,6 +290,30 @@ Kubernetes core/v1.ResourceList
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image is an optional image to bootstrap the volume with.</p>
</td>
</tr>
<tr>
<td>
<code>imagePullSecretRef</code><br/>
<em>
<a href="https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#localobjectreference-v1-core">
Kubernetes core/v1.LocalObjectReference
</a>
</em>
</td>
<td>
<p>ImagePullSecretRef is an optional secret for pulling the image of a volume.</p>
</td>
</tr>
<tr>
<td>
<code>volumeClassRef</code><br/>
<em>
<a href="https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#localobjectreference-v1-core">
Expand Down Expand Up @@ -589,6 +637,30 @@ Kubernetes core/v1.ResourceList
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image is an optional image to bootstrap the volume with.</p>
</td>
</tr>
<tr>
<td>
<code>imagePullSecretRef</code><br/>
<em>
<a href="https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#localobjectreference-v1-core">
Kubernetes core/v1.LocalObjectReference
</a>
</em>
</td>
<td>
<p>ImagePullSecretRef is an optional secret for pulling the image of a volume.</p>
</td>
</tr>
<tr>
<td>
<code>volumeClassRef</code><br/>
<em>
<a href="https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#localobjectreference-v1-core">
Expand Down Expand Up @@ -983,6 +1055,30 @@ Kubernetes core/v1.ResourceList
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
</em>
</td>
<td>
<p>Image is an optional image to bootstrap the volume with.</p>
</td>
</tr>
<tr>
<td>
<code>imagePullSecretRef</code><br/>
<em>
<a href="https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#localobjectreference-v1-core">
Kubernetes core/v1.LocalObjectReference
</a>
</em>
</td>
<td>
<p>ImagePullSecretRef is an optional secret for pulling the image of a volume.</p>
</td>
</tr>
<tr>
<td>
<code>tolerations</code><br/>
<em>
<a href="/api-reference/common/#common.onmetal.de/v1alpha1.Toleration">
Expand Down
Loading