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

Cleanup CloudProfile docker migration and Add Validation MachineImageVersion CRI #6480

Merged
merged 7 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions pkg/apis/core/validation/cloudprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,23 @@ func validateMachineImages(machineImages []core.MachineImage, fldPath *field.Pat
}

allErrs = append(allErrs, validateExpirableVersion(machineVersion.ExpirableVersion, helper.ToExpirableVersions(image.Versions), versionsPath)...)
allErrs = append(allErrs, validateContainerRuntimesInterfaces(machineVersion.CRI, versionsPath.Child("cri"))...)
allErrs = append(allErrs, validateContainerRuntimesInterfaces(machineVersion.CRI, image, versionsPath.Child("cri"))...)
allErrs = append(allErrs, validateMachineImageVersionArchitecture(machineVersion.Architectures, versionsPath.Child("architecture"))...)
}
}

return allErrs
}

func validateContainerRuntimesInterfaces(cris []core.CRI, fldPath *field.Path) field.ErrorList {
func validateContainerRuntimesInterfaces(cris []core.CRI, image core.MachineImage, fldPath *field.Path) field.ErrorList {
acumino marked this conversation as resolved.
Show resolved Hide resolved
allErrs := field.ErrorList{}
duplicateCRI := sets.String{}
hasDocker := false

if len(cris) == 0 {
allErrs = append(allErrs, field.Required(fldPath, fmt.Sprintf("must provide at least one supported container runtime for machine image %q", image.Name)))
acumino marked this conversation as resolved.
Show resolved Hide resolved
return allErrs
}

for i, cri := range cris {
criPath := fldPath.Index(i)
Expand All @@ -344,12 +350,20 @@ func validateContainerRuntimesInterfaces(cris []core.CRI, fldPath *field.Path) f
}
duplicateCRI.Insert(string(cri.Name))

if cri.Name == core.CRINameDocker {
hasDocker = true
}

if !availableWorkerCRINames.Has(string(cri.Name)) {
allErrs = append(allErrs, field.NotSupported(criPath, cri, availableWorkerCRINames.List()))
}
allErrs = append(allErrs, validateContainerRuntimes(cri.ContainerRuntimes, criPath.Child("containerRuntimes"))...)
}

if !hasDocker {
allErrs = append(allErrs, field.Required(fldPath, fmt.Sprintf("must provide docker as supported container runtime for machine image")))
acumino marked this conversation as resolved.
Show resolved Hide resolved
}

return allErrs
}

Expand Down
58 changes: 58 additions & 0 deletions pkg/apis/core/validation/cloudprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirableVersion: core.ExpirableVersion{
Version: "1.2.3",
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand Down Expand Up @@ -411,6 +412,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "3.4.6",
Classification: &supportedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand All @@ -422,6 +424,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "3.4.5",
Classification: &previewClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand Down Expand Up @@ -461,6 +464,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "0.1.2",
Classification: &supportedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand All @@ -472,6 +476,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "a.b.c",
Classification: &supportedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand Down Expand Up @@ -500,12 +505,14 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirationDate: expirationDate,
Classification: &previewClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
{
ExpirableVersion: core.ExpirableVersion{
Version: "0.1.1",
Classification: &supportedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand All @@ -518,6 +525,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirationDate: expirationDate,
Classification: &supportedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand All @@ -538,6 +546,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "0.1.2",
Classification: &classification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand All @@ -560,18 +569,21 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirableVersion: core.ExpirableVersion{
Version: "0.1.2",
},
CRI: []core.CRI{{Name: "docker"}},
Architectures: []string{"amd64", "arm64"},
},
{
ExpirableVersion: core.ExpirableVersion{
Version: "0.1.3",
},
CRI: []core.CRI{{Name: "docker"}},
Architectures: []string{"amd64"},
},
{
ExpirableVersion: core.ExpirableVersion{
Version: "0.1.4",
},
CRI: []core.CRI{{Name: "docker"}},
Architectures: []string{"arm64"},
},
},
Expand All @@ -591,6 +603,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirableVersion: core.ExpirableVersion{
Version: "0.1.2",
},
CRI: []core.CRI{{Name: "docker"}},
Architectures: []string{"foo"},
},
},
Expand All @@ -605,6 +618,32 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
})
})

It("should forbid if no cri is present", func() {
cloudProfile.Spec.MachineImages[0].Versions[0].CRI = nil

errorList := ValidateCloudProfile(cloudProfile)

Expect(errorList).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeRequired),
"Field": Equal("spec.machineImages[0].versions[0].cri"),
}))))
})

It("should forbid if docker container runtime interface not present", func() {
cloudProfile.Spec.MachineImages[0].Versions[0].CRI = []core.CRI{
{
Name: core.CRINameContainerD,
},
}

errorList := ValidateCloudProfile(cloudProfile)

Expect(errorList).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeRequired),
"Field": Equal("spec.machineImages[0].versions[0].cri"),
}))))
})

It("should forbid non-supported container runtime interface names", func() {
cloudProfile.Spec.MachineImages = []core.MachineImage{
{
Expand All @@ -618,6 +657,9 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
{
Name: "invalid-cri-name",
},
{
Name: "docker",
},
},
},
},
Expand All @@ -633,6 +675,9 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
{
Name: core.CRINameContainerD,
},
{
Name: "docker",
},
},
},
},
Expand All @@ -655,6 +700,9 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
{
Name: core.CRINameContainerD,
},
{
Name: "docker",
},
}

errorList := ValidateCloudProfile(cloudProfile)
Expand All @@ -678,6 +726,9 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
},
},
},
{
Name: "docker",
},
}

errorList := ValidateCloudProfile(cloudProfile)
Expand Down Expand Up @@ -898,6 +949,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "1.2.3",
Classification: &supportedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand Down Expand Up @@ -948,20 +1000,23 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
Version: "2135.6.2",
Classification: &deprecatedClassification,
},
CRI: []core.CRI{{Name: "docker"}},
},
{
ExpirableVersion: core.ExpirableVersion{
Version: "2135.6.1",
Classification: &deprecatedClassification,
ExpirationDate: dateInThePast,
},
CRI: []core.CRI{{Name: "docker"}},
},
{
ExpirableVersion: core.ExpirableVersion{
Version: "2135.6.0",
Classification: &deprecatedClassification,
ExpirationDate: dateInThePast,
},
CRI: []core.CRI{{Name: "docker"}},
},
}
cloudProfileNew.Spec.MachineImages[0].Versions = versions[0:1]
Expand Down Expand Up @@ -1028,6 +1083,7 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirableVersion: core.ExpirableVersion{
Version: "1.2.3",
},
CRI: []core.CRI{{Name: "docker"}},
},
},
},
Expand Down Expand Up @@ -1073,12 +1129,14 @@ var _ = Describe("CloudProfile Validation Tests ", func() {
ExpirableVersion: core.ExpirableVersion{
Version: "1.17.2",
},
CRI: []core.CRI{{Name: "docker"}},
},
{
ExpirableVersion: core.ExpirableVersion{
Version: "1.17.1",
ExpirationDate: dateInThePast,
},
CRI: []core.CRI{{Name: "docker"}},
},
}
cloudProfile.Spec.MachineImages[0].Versions = versions
Expand Down