diff --git a/pkg/providers/imagefamily/azlinux.go b/pkg/providers/imagefamily/azlinux.go index cf0afe9e2..53b03f9ba 100644 --- a/pkg/providers/imagefamily/azlinux.go +++ b/pkg/providers/imagefamily/azlinux.go @@ -47,7 +47,7 @@ func (u AzureLinux) DefaultImages() []DefaultImageOutput { return []DefaultImageOutput{ { CommunityImage: AzureLinuxGen2CommunityImage, - PublicGalleryURL: v1alpha2.AKSAzureLinuxPublicGalleryURL, + PublicGalleryURL: AKSAzureLinuxPublicGalleryURL, Requirements: scheduling.NewRequirements( scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, corev1beta1.ArchitectureAmd64), scheduling.NewRequirement(v1alpha2.LabelSKUHyperVGeneration, v1.NodeSelectorOpIn, v1alpha2.HyperVGenerationV2), @@ -55,7 +55,7 @@ func (u AzureLinux) DefaultImages() []DefaultImageOutput { }, { CommunityImage: AzureLinuxGen1CommunityImage, - PublicGalleryURL: v1alpha2.AKSAzureLinuxPublicGalleryURL, + PublicGalleryURL: AKSAzureLinuxPublicGalleryURL, Requirements: scheduling.NewRequirements( scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, corev1beta1.ArchitectureAmd64), scheduling.NewRequirement(v1alpha2.LabelSKUHyperVGeneration, v1.NodeSelectorOpIn, v1alpha2.HyperVGenerationV1), @@ -63,7 +63,7 @@ func (u AzureLinux) DefaultImages() []DefaultImageOutput { }, { CommunityImage: AzureLinuxGen2ArmCommunityImage, - PublicGalleryURL: v1alpha2.AKSAzureLinuxPublicGalleryURL, + PublicGalleryURL: AKSAzureLinuxPublicGalleryURL, Requirements: scheduling.NewRequirements( scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, corev1beta1.ArchitectureArm64), scheduling.NewRequirement(v1alpha2.LabelSKUHyperVGeneration, v1.NodeSelectorOpIn, v1alpha2.HyperVGenerationV2), diff --git a/pkg/providers/imagefamily/image_test.go b/pkg/providers/imagefamily/image_test.go index bfbb7f278..ed6217730 100644 --- a/pkg/providers/imagefamily/image_test.go +++ b/pkg/providers/imagefamily/image_test.go @@ -125,7 +125,7 @@ var _ = Describe("Image ID Resolution", func() { }, Entry("Image ID is specified in the NodeClass", nodeClassWithImageID, &cloudprovider.InstanceType{}, imagefamily.Ubuntu2204{}, testImageID), Entry("Image ID and ImageVersion are specified in the NodeClass", nodeClassWithImageIDAndVersion, &cloudprovider.InstanceType{}, imagefamily.Ubuntu2204{}, testImageID), - Entry("ImageVersion is specified in the NodeClass", nodeClassWithImageVersion, &cloudprovider.InstanceType{}, imagefamily.Ubuntu2204{}, fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", v1alpha2.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion)), + Entry("ImageVersion is specified in the NodeClass", nodeClassWithImageVersion, &cloudprovider.InstanceType{}, imagefamily.Ubuntu2204{}, fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", imagefamily.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion)), ) DescribeTable("Resolution Of Image ID", @@ -134,8 +134,8 @@ var _ = Describe("Image ID Resolution", func() { Expect(imageID).To(Equal(expectedImageID)) Expect(err).To(BeNil()) }, - Entry("Image version is empty, should get latest", imagefamily.Ubuntu2204Gen2CommunityImage, v1alpha2.AKSUbuntuPublicGalleryURL, "", fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", v1alpha2.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, latestImageVersion)), - Entry("Image version is specified, should use it", imagefamily.Ubuntu2204Gen2CommunityImage, v1alpha2.AKSUbuntuPublicGalleryURL, olderImageVersion, fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", v1alpha2.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion)), + Entry("Image version is empty, should get latest", imagefamily.Ubuntu2204Gen2CommunityImage, imagefamily.AKSUbuntuPublicGalleryURL, "", fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", imagefamily.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, latestImageVersion)), + Entry("Image version is specified, should use it", imagefamily.Ubuntu2204Gen2CommunityImage, imagefamily.AKSUbuntuPublicGalleryURL, olderImageVersion, fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", imagefamily.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion)), ) }) @@ -153,15 +153,8 @@ var _ = Describe("Image ID Parsing", func() { Expect(communityImageName).To(Equal(expectedCommunityImageName)) Expect(imageVersion).To(Equal(expectedImageVersion)) }, - Entry("Valid image id should parse", fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", v1alpha2.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion), v1alpha2.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion, nil), + Entry("Valid image id should parse", fmt.Sprintf("/CommunityGalleries/%s/images/%s/versions/%s", imagefamily.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion), imagefamily.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion, nil), Entry("invalid image id should not parse", "badimageid", "", "", "", true), Entry("empty image id should not parse", "badimageid", "", "", "", true), ) }) - -var _ = Describe("ImageFamily Name", func() { - It("should return the correct image family name", func() { - Expect(imagefamily.Ubuntu2204{}.Name()).To(Equal(v1alpha2.Ubuntu2204ImageFamily)) - Expect(imagefamily.AzureLinux{}.Name()).To(Equal(v1alpha2.AzureLinuxImageFamily)) - }) -}) diff --git a/pkg/providers/imagefamily/types.go b/pkg/providers/imagefamily/types.go index acb58cce3..38fe94b6e 100644 --- a/pkg/providers/imagefamily/types.go +++ b/pkg/providers/imagefamily/types.go @@ -22,6 +22,11 @@ import ( "github.com/aws/karpenter-core/pkg/scheduling" ) +const ( + AKSUbuntuPublicGalleryURL = "AKSUbuntu-38d80f77-467a-481f-a8d4-09b6d4220bd2" + AKSAzureLinuxPublicGalleryURL = "AKSAzureLinux-f7c7cda5-1c9a-4bdc-a222-9614c968580b" +) + // DefaultImageOutput is the Stub of an Image we return from an ImageFamily De type DefaultImageOutput struct { CommunityImage string diff --git a/pkg/providers/instancetype/suite_test.go b/pkg/providers/instancetype/suite_test.go index 0014ffe3f..910ca9038 100644 --- a/pkg/providers/instancetype/suite_test.go +++ b/pkg/providers/instancetype/suite_test.go @@ -60,6 +60,7 @@ import ( "github.com/Azure/karpenter/pkg/apis/v1alpha2" "github.com/Azure/karpenter/pkg/cloudprovider" "github.com/Azure/karpenter/pkg/fake" + "github.com/Azure/karpenter/pkg/providers/imagefamily" "github.com/Azure/karpenter/pkg/providers/instancetype" "github.com/Azure/karpenter/pkg/providers/loadbalancer" "github.com/Azure/karpenter/pkg/test" @@ -762,15 +763,14 @@ var _ = Describe("InstanceType Provider", func() { Context("ImageProvider + Image Family", func() { DescribeTable("should select the right image for a given instance type", func(instanceType string, imageFamily string, expectedImageDefinition string, expectedGalleryURL string) { - nC := test.AKSNodeClass() - nC.Spec.ImageFamily = lo.ToPtr(imageFamily) + nodeClass.Spec.ImageFamily = lo.ToPtr(imageFamily) coretest.ReplaceRequirements(nodePool, v1.NodeSelectorRequirement{ Key: v1.LabelInstanceTypeStable, Operator: v1.NodeSelectorOpIn, Values: []string{instanceType}, }) - nodePool.Spec.Template.Spec.NodeClassRef = &corev1beta1.NodeClassReference{Name: nC.Name} - ExpectApplied(ctx, env.Client, nodePool, nC) + nodePool.Spec.Template.Spec.NodeClassRef = &corev1beta1.NodeClassReference{Name: nodeClass.Name} + ExpectApplied(ctx, env.Client, nodePool, nodeClass) pod := coretest.UnschedulablePod(coretest.PodOptions{}) ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod) ExpectScheduled(ctx, env.Client, pod) @@ -788,17 +788,17 @@ var _ = Describe("InstanceType Provider", func() { azureEnv.Reset() }, Entry("Gen2, Gen1 instance type with AKSUbuntu image family", - "Standard_D2_v5", "Ubuntu2204", "2204gen2containerd", v1alpha2.AKSUbuntuPublicGalleryURL), + "Standard_D2_v5", v1alpha2.Ubuntu2204ImageFamily, imagefamily.Ubuntu2204Gen2CommunityImage, imagefamily.AKSUbuntuPublicGalleryURL), Entry("Gen1 instance type with AKSUbuntu image family", - "Standard_D2_v3", "Ubuntu2204", "2204containerd", v1alpha2.AKSUbuntuPublicGalleryURL), + "Standard_D2_v3", v1alpha2.Ubuntu2204ImageFamily, imagefamily.Ubuntu2204Gen1CommunityImage, imagefamily.AKSUbuntuPublicGalleryURL), Entry("ARM instance type with AKSUbuntu image family", - "Standard_D16plds_v5", "Ubuntu2204", "2204gen2arm64containerd", v1alpha2.AKSUbuntuPublicGalleryURL), + "Standard_D16plds_v5", v1alpha2.Ubuntu2204ImageFamily, imagefamily.Ubuntu2204Gen2ArmCommunityImage, imagefamily.AKSUbuntuPublicGalleryURL), Entry("Gen2 instance type with AzureLinux image family", - "Standard_D2_v5", "AzureLinux", "V2gen2", v1alpha2.AKSAzureLinuxPublicGalleryURL), + "Standard_D2_v5", v1alpha2.AzureLinuxImageFamily, imagefamily.AzureLinuxGen2CommunityImage, imagefamily.AKSAzureLinuxPublicGalleryURL), Entry("Gen1 instance type with AzureLinux image family", - "Standard_D2_v3", "AzureLinux", "V2", v1alpha2.AKSAzureLinuxPublicGalleryURL), + "Standard_D2_v3", v1alpha2.AzureLinuxImageFamily, imagefamily.AzureLinuxGen1CommunityImage, imagefamily.AKSAzureLinuxPublicGalleryURL), Entry("ARM instance type with AzureLinux image family", - "Standard_D16plds_v5", "AzureLinux", "V2gen2arm64", v1alpha2.AKSAzureLinuxPublicGalleryURL), + "Standard_D16plds_v5", v1alpha2.AzureLinuxImageFamily, imagefamily.AzureLinuxGen2ArmCommunityImage, imagefamily.AKSAzureLinuxPublicGalleryURL), ) }) Context("Instance Types", func() { @@ -808,19 +808,6 @@ var _ = Describe("InstanceType Provider", func() { ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod) ExpectScheduled(ctx, env.Client, pod) }) - It("should support provisioning with Azure Linux", func() { - nodeClass.Spec.ImageFamily = lo.ToPtr(v1alpha2.AzureLinuxImageFamily) - ExpectApplied(ctx, env.Client, nodePool, nodeClass) - pod := coretest.UnschedulablePod(coretest.PodOptions{}) - ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod) - ExpectScheduled(ctx, env.Client, pod) - - Expect(azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(1)) - vm := azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM - Expect(vm.Properties.StorageProfile.ImageReference).ToNot(BeNil()) - Expect(vm.Properties.StorageProfile.ImageReference.CommunityGalleryImageID).ToNot(BeNil()) - Expect(strings.HasPrefix(*vm.Properties.StorageProfile.ImageReference.CommunityGalleryImageID, "/CommunityGalleries/AKSAzureLinux-f7c7cda5-1c9a-4bdc-a222-9614c968580b")).To(BeTrue()) - }) Context("VM profile", func() { It("should have OS disk and network interface set to auto-delete", func() { ExpectApplied(ctx, env.Client, nodePool, nodeClass)