Skip to content

Commit

Permalink
BREAKING CHANGE(aksnodeclass): removing imageVersion from CRD (#531)
Browse files Browse the repository at this point in the history
* remove imageVersion from CRD

* changes removing imageVersion field from code

* minor additional cleanup

---------

Co-authored-by: Charlie McBride <[email protected]>
  • Loading branch information
charliedmcb and Charlie McBride authored Oct 18, 2024
1 parent b8fa120 commit 4ce57d9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 89 deletions.
3 changes: 0 additions & 3 deletions pkg/apis/crds/karpenter.azure.com_aksnodeclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ spec:
- Ubuntu2204
- AzureLinux
type: string
imageVersion:
description: ImageVersion is the image version that instances use.
type: string
osDiskSizeGB:
default: 128
description: osDiskSizeGB is the size of the OS disk in GB.
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/v1alpha2/aksnodeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ type AKSNodeClassSpec struct {
// +kubebuilder:default=Ubuntu2204
// +kubebuilder:validation:Enum:={Ubuntu2204,AzureLinux}
ImageFamily *string `json:"imageFamily,omitempty"`
// ImageVersion is the image version that instances use.
// +optional
ImageVersion *string `json:"imageVersion,omitempty"`
// Tags to be applied on Azure resources like instances.
// +optional
Tags map[string]string `json:"tags,omitempty"`
Expand Down
24 changes: 0 additions & 24 deletions pkg/apis/v1alpha2/aksnodeclass_utils.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (c *CloudProvider) IsDrifted(ctx context.Context, nodeClaim *corev1beta1.No
if k8sVersionDrifted != "" {
return k8sVersionDrifted, nil
}
imageVersionDrifted, err := c.isImageVersionDrifted(ctx, nodeClaim, nodeClass)
imageVersionDrifted, err := c.isImageVersionDrifted(ctx, nodeClaim)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *CloudProvider) isK8sVersionDrifted(ctx context.Context, nodeClaim *core
// Feel reassessing this within the future with a potential minor refactor would be best to fix the gocyclo.
// nolint: gocyclo
func (c *CloudProvider) isImageVersionDrifted(
ctx context.Context, nodeClaim *corev1beta1.NodeClaim, nodeClass *v1alpha2.AKSNodeClass) (cloudprovider.DriftReason, error) {
ctx context.Context, nodeClaim *corev1beta1.NodeClaim) (cloudprovider.DriftReason, error) {
logger := logging.FromContext(ctx)

id, err := utils.GetVMName(nodeClaim.Status.ProviderID)
Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *CloudProvider) isImageVersionDrifted(
return "", err
}

expectedImageID, err := c.imageProvider.GetImageID(ctx, communityImageName, publicGalleryURL, nodeClass.Spec.GetImageVersion())
expectedImageID, err := c.imageProvider.GetImageID(ctx, communityImageName, publicGalleryURL)
if err != nil {
return "", err
}
Expand Down
30 changes: 14 additions & 16 deletions pkg/providers/imagefamily/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (p *Provider) Get(ctx context.Context, nodeClass *v1alpha2.AKSNodeClass, in
for _, defaultImage := range defaultImages {
if err := instanceType.Requirements.Compatible(defaultImage.Requirements, v1alpha2.AllowUndefinedLabels); err == nil {
communityImageName, publicGalleryURL := defaultImage.CommunityImage, defaultImage.PublicGalleryURL
return p.GetImageID(ctx, communityImageName, publicGalleryURL, nodeClass.Spec.GetImageVersion())
return p.GetImageID(ctx, communityImageName, publicGalleryURL)
}
}

Expand All @@ -92,29 +92,27 @@ func (p *Provider) KubeServerVersion(ctx context.Context) (string, error) {
}

// Input versionName == "" to get the latest version
func (p *Provider) GetImageID(ctx context.Context, communityImageName, publicGalleryURL, versionName string) (string, error) {
key := fmt.Sprintf("%s/%s/%s", publicGalleryURL, communityImageName, versionName)
func (p *Provider) GetImageID(ctx context.Context, communityImageName, publicGalleryURL string) (string, error) {
key := fmt.Sprintf("%s/%s", publicGalleryURL, communityImageName)
imageID, found := p.imageCache.Get(key)
if found {
return imageID.(string), nil
}

if versionName == "" {
pager := p.imageVersionsClient.NewListPager(p.location, publicGalleryURL, communityImageName, nil)
topImageVersionCandidate := armcompute.CommunityGalleryImageVersion{}
for pager.More() {
page, err := pager.NextPage(context.Background())
if err != nil {
return "", err
}
for _, imageVersion := range page.CommunityGalleryImageVersionList.Value {
if lo.IsEmpty(topImageVersionCandidate) || imageVersion.Properties.PublishedDate.After(*topImageVersionCandidate.Properties.PublishedDate) {
topImageVersionCandidate = *imageVersion
}
pager := p.imageVersionsClient.NewListPager(p.location, publicGalleryURL, communityImageName, nil)
topImageVersionCandidate := armcompute.CommunityGalleryImageVersion{}
for pager.More() {
page, err := pager.NextPage(context.Background())
if err != nil {
return "", err
}
for _, imageVersion := range page.CommunityGalleryImageVersionList.Value {
if lo.IsEmpty(topImageVersionCandidate) || imageVersion.Properties.PublishedDate.After(*topImageVersionCandidate.Properties.PublishedDate) {
topImageVersionCandidate = *imageVersion
}
}
versionName = lo.FromPtr(topImageVersionCandidate.Name)
}
versionName := lo.FromPtr(topImageVersionCandidate.Name)

selectedImageID := BuildImageID(publicGalleryURL, communityImageName, versionName)
if p.cm.HasChanged(key, selectedImageID) {
Expand Down
35 changes: 0 additions & 35 deletions test/suites/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,41 +111,6 @@ var _ = Describe("Drift", func() {
env.EventuallyExpectNotFound(pod, nodeClaim, node)
SetDefaultEventuallyTimeout(5 * time.Minute)
})
It("should upgrade nodes using drift based on node image version change", func() {
// TODO: Get these dynamically
startingImageVersion := "202404.09.0"
upgradedImageVersion := "202404.16.0"

nodeClass.Spec.ImageVersion = &startingImageVersion

By(fmt.Sprintf("creating pod %s, nodepool %s, and nodeclass %s", pod.Name, nodePool.Name, nodeClass.Name))
env.ExpectCreated(pod, nodeClass, nodePool)

By(fmt.Sprintf("expect pod %s to be healthy", pod.Name))
env.EventuallyExpectHealthy(pod)

By("expect created node count to be 1")
env.ExpectCreatedNodeCount("==", 1)

nodeClaim := env.EventuallyExpectCreatedNodeClaimCount("==", 1)[0]
node := env.EventuallyExpectNodeCount("==", 1)[0]

By(fmt.Sprintf("waiting for nodeClass %s update", nodeClass.Name))
nodeClass.Spec.ImageVersion = &upgradedImageVersion
env.ExpectCreatedOrUpdated(nodeClass)

By(fmt.Sprintf("waiting for nodeclaim %s to be marked as drifted", nodeClaim.Name))
env.EventuallyExpectDrifted(nodeClaim)

By(fmt.Sprintf("waiting for pod %s to to update", pod.Name))
delete(pod.Annotations, corev1beta1.DoNotDisruptAnnotationKey)
env.ExpectUpdated(pod)

By(fmt.Sprintf("expect pod %s, nodeclaim %s, and node %s to eventually not exist", pod.Name, nodeClaim.Name, node.Name))
SetDefaultEventuallyTimeout(10 * time.Minute)
env.EventuallyExpectNotFound(pod, nodeClaim, node)
SetDefaultEventuallyTimeout(5 * time.Minute)
})
It("should mark the nodeclaim as drifted for SubnetDrift if AKSNodeClass subnet id changes", func() {
env.ExpectCreated(pod, nodeClass, nodePool)

Expand Down

0 comments on commit 4ce57d9

Please sign in to comment.