instancetype: Add missing test defaulting to cluster when inferring
A simple missing test asserting that the default kind is used when no
kind is found while inferring defaults.
@@ -1123,6 +1123,52 @@ var _ = Describe("VirtualMachine Mutator", func() {
}, apiinstancetype.DefaultPreferenceAnnotation,
),
)
+
+ DescribeTable("should use cluster kind when default kind is not provided while inferring defaults", func(instancetypeMatcher *v1.InstancetypeMatcher, preferenceMatcher *v1.PreferenceMatcher) {
+ vm.Spec.Instancetype = instancetypeMatcher
+ vm.Spec.Preference = preferenceMatcher
+ pvcWithoutKindAnnotations := &k8sv1.PersistentVolumeClaim{
+ ObjectMeta: k8smetav1.ObjectMeta{
+ Name: "pvcWithoutKindAnnotations",
+ Namespace: vm.Namespace,
+ Annotations: map[string]string{
+ apiinstancetype.DefaultInstancetypeAnnotation: defaultInferedNameFromPVC,
+ apiinstancetype.DefaultPreferenceAnnotation: defaultInferedNameFromPVC,
+ },
+ },
+ }
+ _, err := virtClient.CoreV1().PersistentVolumeClaims(vm.Namespace).Create(context.Background(), pvcWithoutKindAnnotations, k8smetav1.CreateOptions{})
+ Expect(err).ToNot(HaveOccurred())
+ vm.Spec.Template.Spec.Volumes = []v1.Volume{{
+ Name: inferVolumeName,
+ VolumeSource: v1.VolumeSource{
+ PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
+ PersistentVolumeClaimVolumeSource: k8sv1.PersistentVolumeClaimVolumeSource{
+ ClaimName: pvcWithoutKindAnnotations.Name,
+ },
+ },
+ },
+ }}
+ vmSpec, _ := getVMSpecMetaFromResponse()
+ if instancetypeMatcher != nil {
+ Expect(vmSpec.Instancetype.Kind).To(Equal(apiinstancetype.ClusterSingularResourceName))
+ }
+ if preferenceMatcher != nil {
+ Expect(vmSpec.Preference.Kind).To(Equal(apiinstancetype.ClusterSingularPreferenceResourceName))
+ }
+ },
+ Entry("for InstancetypeMatcher",
+ &v1.InstancetypeMatcher{
+ InferFromVolume: inferVolumeName,
+ }, nil,
+ ),
+ Entry("for PreferenceMatcher",
+ nil,
+ &v1.PreferenceMatcher{
+ InferFromVolume: inferVolumeName,
+ },
+ ),
+ )
})
Context("failure tests", func() {
