Skip to content

Commit

Permalink
chore: removing webhooks from existence for the AKS provider (#156)
Browse files Browse the repository at this point in the history
* chore: removing all references to aks provider webhooks

* chore: removing webhook role

* fix: removing last reference to utils

* fix: removing image id

* fix: webhooks
  • Loading branch information
Bryce-Soghigian authored Feb 23, 2024
1 parent e42e41e commit d39bc20
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 347 deletions.
67 changes: 0 additions & 67 deletions charts/karpenter/templates/webhooks.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/Azure/karpenter-provider-azure/pkg/cloudprovider"
"github.com/Azure/karpenter-provider-azure/pkg/operator"
"github.com/Azure/karpenter-provider-azure/pkg/webhooks"

controllers "github.com/Azure/karpenter-provider-azure/pkg/controllers"
"sigs.k8s.io/karpenter/pkg/cloudprovider/metrics"
Expand Down Expand Up @@ -62,6 +61,5 @@ func main() {
aksCloudProvider,
op.InstanceProvider,
)...).
WithWebhooks(ctx, webhooks.NewWebhooks()...).
Start(ctx)
}
25 changes: 0 additions & 25 deletions pkg/apis/v1alpha2/aksnodeclass_defaults.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ limitations under the License.

package v1alpha2

func (in *AKSNodeClassSpec) IsEmptyImageID() bool {
return in.ImageID == nil || *in.ImageID == ""
}

func (in *AKSNodeClassSpec) GetImageVersion() string {
if in.ImageVersion == nil {
return ""
Expand Down
69 changes: 0 additions & 69 deletions pkg/apis/v1alpha2/aksnodeclass_validation.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/cloudprovider/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ func (c *CloudProvider) isImageVersionDrifted(
ctx context.Context, nodeClaim *corev1beta1.NodeClaim, nodeClass *v1alpha2.AKSNodeClass) (cloudprovider.DriftReason, error) {
logger := logging.FromContext(ctx)

if !nodeClass.Spec.IsEmptyImageID() {
// Note: ImageID takes priority ATM
return "", nil
}

id, err := utils.GetVMName(nodeClaim.Status.ProviderID)
if err != nil {
// TODO (charliedmcb): Do we need to handle vm not found here before its provisioned?
Expand Down
5 changes: 0 additions & 5 deletions pkg/providers/imagefamily/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ func NewProvider(kubernetesInterface kubernetes.Interface, kubernetesVersionCach

// Get returns Image ID for the given instance type. Images may vary due to architecture, accelerator, etc
func (p *Provider) Get(ctx context.Context, nodeClass *v1alpha2.AKSNodeClass, instanceType *cloudprovider.InstanceType, imageFamily ImageFamily) (string, error) {
if !nodeClass.Spec.IsEmptyImageID() {
logging.FromContext(ctx).Debugf("Using user-provided image %s", *nodeClass.Spec.ImageID)
return *nodeClass.Spec.ImageID, nil
}

defaultImages := imageFamily.DefaultImages()
for _, defaultImage := range defaultImages {
if err := instanceType.Requirements.Compatible(defaultImage.Requirements, v1alpha2.AllowUndefinedLabels); err == nil {
Expand Down
103 changes: 0 additions & 103 deletions pkg/providers/imagefamily/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,15 @@ limitations under the License.
package imagefamily_test

import (
"context"
"fmt"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/karpenter-provider-azure/pkg/apis/v1alpha2"
"github.com/Azure/karpenter-provider-azure/pkg/fake"
"github.com/Azure/karpenter-provider-azure/pkg/providers/imagefamily"
"github.com/Azure/karpenter-provider-azure/pkg/test"
"github.com/samber/lo"
"sigs.k8s.io/karpenter/pkg/cloudprovider"
)

var imageProvider *imagefamily.Provider

func TestAzure(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Providers/ImageProvider/Azure")
Expand All @@ -47,99 +37,6 @@ const (
latestImageVersion = "1.1686127203.20217"
)

var _ = BeforeSuite(func() {
location := fake.Region

defaultImageVersions := []*armcompute.CommunityGalleryImageVersion{
{
Name: lo.ToPtr("1.1686127203.20215"),
Location: &location,
Type: lo.ToPtr("Microsoft.Compute/galleries/images/versions"),
Properties: &armcompute.CommunityGalleryImageVersionProperties{
PublishedDate: lo.ToPtr(time.Now().Add(time.Minute * -10)),
},
},
{
Name: lo.ToPtr("1.1686127203.20213"),
Location: &location,
Type: lo.ToPtr("Microsoft.Compute/galleries/images/versions"),
Properties: &armcompute.CommunityGalleryImageVersionProperties{
PublishedDate: lo.ToPtr(time.Now().Add(time.Minute * -20)),
},
},
{
Name: lo.ToPtr(latestImageVersion),
Location: &location,
Type: lo.ToPtr("Microsoft.Compute/galleries/images/versions"),
Properties: &armcompute.CommunityGalleryImageVersionProperties{
PublishedDate: lo.ToPtr(time.Now().Add(time.Minute * -5)),
},
},
{
Name: lo.ToPtr(olderImageVersion),
Location: &location,
Type: lo.ToPtr("Microsoft.Compute/galleries/images/versions"),
Properties: &armcompute.CommunityGalleryImageVersionProperties{
PublishedDate: lo.ToPtr(time.Now().Add(time.Minute * -15)),
},
},
{
Name: lo.ToPtr("1.1686127203.20216"),
Location: &location,
Type: lo.ToPtr("Microsoft.Compute/galleries/images/versions"),
Properties: &armcompute.CommunityGalleryImageVersionProperties{
PublishedDate: lo.ToPtr(time.Now().Add(time.Minute * -7)),
},
},
}

versionsClient := &fake.CommunityGalleryImageVersionsAPI{}
versionsClient.ImageVersions.Append(defaultImageVersions...)
imageProvider = imagefamily.NewProvider(nil, nil, versionsClient, fake.Region)
})

func newTestNodeClass(imageID, imageVersion string) *v1alpha2.AKSNodeClass {
nodeClass := test.AKSNodeClass()

if imageID != "" {
nodeClass.Spec.ImageID = lo.ToPtr(imageID)
}
if imageVersion != "" {
nodeClass.Spec.ImageVersion = lo.ToPtr(imageVersion)
}
return nodeClass
}

var _ = Describe("Image ID Resolution", func() {
var (
nodeClassWithImageID = newTestNodeClass(testImageID, "")
nodeClassWithImageIDAndVersion = newTestNodeClass(testImageID, olderImageVersion)
nodeClassWithImageVersion = newTestNodeClass("", olderImageVersion)
)

DescribeTable("Resolution Of Image ID",
func(nodeClass *v1alpha2.AKSNodeClass, instanceType *cloudprovider.InstanceType, imageFamily interface{}, expectedImageID string) {
imageID, err := imageProvider.Get(context.Background(), nodeClass, instanceType, imagefamily.Ubuntu2204{})
Expect(imageID).To(Equal(expectedImageID))
Expect(err).To(BeNil())
},
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", imagefamily.AKSUbuntuPublicGalleryURL, imagefamily.Ubuntu2204Gen2CommunityImage, olderImageVersion)),
)

DescribeTable("Resolution Of Image ID",
func(communityImageName, publicGalleryURL, versionName string, expectedImageID string) {
imageID, err := imageProvider.GetImageID(communityImageName, publicGalleryURL, versionName)
Expect(imageID).To(Equal(expectedImageID))
Expect(err).To(BeNil())
},
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)),
)

})

var _ = Describe("Image ID Parsing", func() {
DescribeTable("Parse Image ID",
func(imageID string, expectedPublicGalleryURL, expectedCommunityImageName, expectedImageVersion string, expectError bool) {
Expand Down
7 changes: 2 additions & 5 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,8 @@ func newVMObject(
launchTemplate *launchtemplate.Template,
instanceType *corecloudprovider.InstanceType) armcompute.VirtualMachine {
// Build the image reference from template
imageReference := armcompute.ImageReference{}
if v1alpha2.IsComputeGalleryImageID(launchTemplate.ImageID) {
imageReference.ID = &launchTemplate.ImageID
} else {
imageReference.CommunityGalleryImageID = &launchTemplate.ImageID
imageReference := armcompute.ImageReference{
CommunityGalleryImageID: &launchTemplate.ImageID,
}
vm := armcompute.VirtualMachine{
Location: to.Ptr(location),
Expand Down
Loading

0 comments on commit d39bc20

Please sign in to comment.