Skip to content

Commit

Permalink
test: refactored Public Gallery URLS back into imagefamily
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-Soghigian committed Jan 19, 2024
1 parent 31a6d53 commit 55991d9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 37 deletions.
6 changes: 3 additions & 3 deletions pkg/providers/imagefamily/azlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ 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),
),
},
{
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),
),
},
{
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),
Expand Down
15 changes: 4 additions & 11 deletions pkg/providers/imagefamily/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)),
)

})
Expand All @@ -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))
})
})
5 changes: 5 additions & 0 deletions pkg/providers/imagefamily/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 10 additions & 23 deletions pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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)
Expand Down

0 comments on commit 55991d9

Please sign in to comment.