-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate
MachineImage
architectures against providerConfig
- Loading branch information
1 parent
7906e7f
commit d593314
Showing
2 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,11 +101,11 @@ var _ = Describe("NamespacedCloudProfile Validator", func() { | |
namespacedCloudProfile.Spec.MachineImages = []core.MachineImage{ | ||
{ | ||
Name: "image-1", | ||
Versions: []core.MachineImageVersion{{ExpirableVersion: core.ExpirableVersion{Version: "1.1"}}}, | ||
Versions: []core.MachineImageVersion{{ExpirableVersion: core.ExpirableVersion{Version: "1.1"}, Architectures: []string{"amd64"}}}, | ||
}, | ||
{ | ||
Name: "image-2", | ||
Versions: []core.MachineImageVersion{{ExpirableVersion: core.ExpirableVersion{Version: "2.0"}}}, | ||
Versions: []core.MachineImageVersion{{ExpirableVersion: core.ExpirableVersion{Version: "2.0"}, Architectures: []string{"amd64"}}}, | ||
}, | ||
} | ||
namespacedCloudProfile.Spec.MachineTypes = []core.MachineType{ | ||
|
@@ -147,7 +147,7 @@ var _ = Describe("NamespacedCloudProfile Validator", func() { | |
{ | ||
Name: "image-1", | ||
Versions: []core.MachineImageVersion{ | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.0"}}, | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.0"}, Architectures: []string{"amd64"}}, | ||
}, | ||
}, | ||
} | ||
|
@@ -179,7 +179,7 @@ var _ = Describe("NamespacedCloudProfile Validator", func() { | |
{ | ||
Name: "image-1", | ||
Versions: []core.MachineImageVersion{ | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.2"}}, | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.2"}, Architectures: []string{"amd64"}}, | ||
}, | ||
}, | ||
} | ||
|
@@ -196,6 +196,10 @@ var _ = Describe("NamespacedCloudProfile Validator", func() { | |
"Field": Equal("spec.providerConfig.machineImages[0].versions[0]"), | ||
"BadValue": Equal("[email protected]"), | ||
"Detail": Equal("machine image version is not defined in the NamespacedCloudProfile"), | ||
})), PointTo(MatchFields(IgnoreExtras, Fields{ | ||
"Type": Equal(field.ErrorTypeForbidden), | ||
"Field": Equal("spec.providerConfig.machineImages"), | ||
"Detail": Equal("machine image version [email protected] has an excess entry for architecture \"amd64\", which is not defined in the machineImages spec"), | ||
})))) | ||
}) | ||
|
||
|
@@ -225,7 +229,7 @@ var _ = Describe("NamespacedCloudProfile Validator", func() { | |
{ | ||
Name: "image-3", | ||
Versions: []core.MachineImageVersion{ | ||
{ExpirableVersion: core.ExpirableVersion{Version: "3.0"}}, | ||
{ExpirableVersion: core.ExpirableVersion{Version: "3.0"}, Architectures: []string{"amd64"}}, | ||
}, | ||
}, | ||
} | ||
|
@@ -240,6 +244,47 @@ var _ = Describe("NamespacedCloudProfile Validator", func() { | |
})))) | ||
}) | ||
|
||
It("should fail for NamespacedCloudProfile specifying new spec.machineImages without the according version and architecture entries in the provider config", func() { | ||
namespacedCloudProfile.Spec.ProviderConfig = &runtime.RawExtension{Raw: []byte(`{ | ||
"apiVersion":"azure.provider.extensions.gardener.cloud/v1alpha1", | ||
"kind":"CloudProfileConfig", | ||
"machineImages":[ | ||
{"name":"image-1","versions":[ | ||
{"version":"1.1","id":"image-id-1","architecture":"arm64"}, | ||
{"version":"1.1","id":"image-id-2","architecture":"amd64"}, | ||
{"version":"1.1-fallback","id":"image-id-3"} | ||
]} | ||
] | ||
}`)} | ||
namespacedCloudProfile.Spec.MachineImages = []core.MachineImage{ | ||
{ | ||
Name: "image-1", | ||
Versions: []core.MachineImageVersion{ | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.1"}, Architectures: []string{"amd64", "arm64"}}, | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.1-fallback"}, Architectures: []string{"arm64"}}, | ||
{ExpirableVersion: core.ExpirableVersion{Version: "1.1-missing"}, Architectures: []string{"arm64"}}, | ||
}, | ||
}, | ||
} | ||
|
||
Expect(fakeClient.Create(ctx, cloudProfile)).To(Succeed()) | ||
|
||
err := namespacedCloudProfileValidator.Validate(ctx, namespacedCloudProfile, nil) | ||
Expect(err).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{ | ||
"Type": Equal(field.ErrorTypeForbidden), | ||
"Field": Equal("spec.providerConfig.machineImages"), | ||
"Detail": Equal("machine image version [email protected] has an excess entry for architecture \"amd64\", which is not defined in the machineImages spec"), | ||
})), PointTo(MatchFields(IgnoreExtras, Fields{ | ||
"Type": Equal(field.ErrorTypeRequired), | ||
"Field": Equal("spec.providerConfig.machineImages"), | ||
"Detail": Equal("machine image version [email protected] is not defined in the NamespacedCloudProfile providerConfig"), | ||
})), PointTo(MatchFields(IgnoreExtras, Fields{ | ||
"Type": Equal(field.ErrorTypeRequired), | ||
"Field": Equal("spec.providerConfig.machineImages"), | ||
"Detail": Equal("machine image version [email protected] is not defined in the NamespacedCloudProfile providerConfig"), | ||
})))) | ||
}) | ||
|
||
It("should succeed for NamespacedCloudProfile specifying new spec.machineTypes without an according entry in the provider config", func() { | ||
// By default, project administrators should be able to define new machine types in the NamespacedCloudProfile. | ||
// This should not be dependent on them being able to edit the provider config. | ||
|