Skip to content

Commit

Permalink
ci: make presubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-Soghigian committed Feb 11, 2025
1 parent 8e7abd4 commit f566bef
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.1
controller-gen.kubebuilder.io/version: v0.17.2
name: aksnodeclasses.karpenter.azure.com
spec:
group: karpenter.azure.com
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Azure/karpenter-provider-azure

go 1.23.6
go 1.23

require (
github.com/Azure/azure-kusto-go v0.16.1
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/crds/karpenter.azure.com_aksnodeclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.1
controller-gen.kubebuilder.io/version: v0.17.2
name: aksnodeclasses.karpenter.azure.com
spec:
group: karpenter.azure.com
Expand Down
29 changes: 14 additions & 15 deletions test/pkg/environment/azure/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ type Environment struct {
}

type Vars struct {
NodeResourceGroup string
Region string
SubscriptionID string
VNETResourceGroup string
ACRName string
ClusterName string
NodeResourceGroup string
Region string
SubscriptionID string
VNETResourceGroup string
ACRName string
ClusterName string
ClusterResourceGroup string
}
type AzureClients struct {
Expand All @@ -67,18 +67,17 @@ func NewEnvironment(t *testing.T) *Environment {
azureEnv := &Environment{
Environment: env,
Vars: Vars{
SubscriptionID: os.Getenv("AZURE_SUBSCRIPTION_ID"),
ClusterName: os.Getenv("AZURE_CLUSTER_NAME"),
SubscriptionID: os.Getenv("AZURE_SUBSCRIPTION_ID"),
ClusterName: os.Getenv("AZURE_CLUSTER_NAME"),
ClusterResourceGroup: os.Getenv("AZURE_RESOURCE_GROUP"),
ACRName: os.Getenv("AZURE_ACR_NAME"),
Region: lo.Ternary(os.Getenv("AZURE_LOCATION") == "", "westus2", os.Getenv("AZURE_LOCATION")),

ACRName: os.Getenv("AZURE_ACR_NAME"),
Region: lo.Ternary(os.Getenv("AZURE_LOCATION") == "", "westus2", os.Getenv("AZURE_LOCATION")),
},
}
defaultNodeRG := fmt.Sprintf("MC_%s_%s_%s", azureEnv.ClusterResourceGroup, azureEnv.ClusterName, azureEnv.Region)
azureEnv.VNETResourceGroup = lo.Ternary(os.Getenv("VNET_RESOURCE_GROUP")=="", defaultNodeRG, os.Getenv("VNET_RESOURCE_GROUP"))
azureEnv.NodeResourceGroup = defaultNodeRG

defaultNodeRG := fmt.Sprintf("MC_%s_%s_%s", azureEnv.ClusterResourceGroup, azureEnv.ClusterName, azureEnv.Region)
azureEnv.VNETResourceGroup = lo.Ternary(os.Getenv("VNET_RESOURCE_GROUP") == "", defaultNodeRG, os.Getenv("VNET_RESOURCE_GROUP"))
azureEnv.NodeResourceGroup = defaultNodeRG

cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
Expand Down
30 changes: 23 additions & 7 deletions test/pkg/environment/azure/expectations.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/*
Portions Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package azure

import (
"fmt"
"context"
"fmt"
"strings"
"time"

"github.com/samber/lo"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -39,17 +55,17 @@ func (env *Environment) EventuallyExpectKarpenterNicsToBeDeleted() {

func (env *Environment) ExpectCreatedInterface(networkInterface armnetwork.Interface) {
GinkgoHelper()
poller, err := env.InterfacesClient.BeginCreateOrUpdate(env.Context, env.NodeResourceGroup, lo.FromPtr(networkInterface.Name), networkInterface, nil)
Expect(err).ToNot(HaveOccurred())
poller, err := env.InterfacesClient.BeginCreateOrUpdate(env.Context, env.NodeResourceGroup, lo.FromPtr(networkInterface.Name), networkInterface, nil)
Expect(err).ToNot(HaveOccurred())
_, err = poller.PollUntilDone(env.Context, nil)
Expect(err).ToNot(HaveOccurred())
}

func (env *Environment) GetClusterSubnet() *armnetwork.Subnet {
GinkgoHelper()
vnet, err := getVNET(env.Context, env.VNETClient, env.VNETResourceGroup)
Expect(err).ToNot(HaveOccurred())
return vnet.Properties.Subnets[0]
vnet, err := getVNET(env.Context, env.VNETClient, env.VNETResourceGroup)
Expect(err).ToNot(HaveOccurred())
return vnet.Properties.Subnets[0]
}

func getVNET(ctx context.Context, client *armnetwork.VirtualNetworksClient, vnetRG string) (*armnetwork.VirtualNetwork, error) {
Expand Down
18 changes: 8 additions & 10 deletions test/suites/azuregarbagecollection/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ var _ = AfterEach(func() { env.AfterEach() })
var _ = Describe("gc", func() {
It("should garbage collect network interfaces created by karpenter", func() {
env.ExpectCreatedInterface(armnetwork.Interface{
Name: lo.ToPtr("orphan-nic"),
Name: lo.ToPtr("orphan-nic"),
Location: lo.ToPtr(env.Region),
Tags: azkarptest.ManagedTags("default"),
Tags: azkarptest.ManagedTags("default"),
Properties: &armnetwork.InterfacePropertiesFormat{
IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
{
Name: lo.ToPtr("ip-config"),
Name: lo.ToPtr("ip-config"),
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
Primary: lo.ToPtr(true),
Subnet: env.GetClusterSubnet(),
Primary: lo.ToPtr(true),
Subnet: env.GetClusterSubnet(),
PrivateIPAllocationMethod: lo.ToPtr(armnetwork.IPAllocationMethodDynamic),
},
},
},
},

},
})
env.EventuallyExpectKarpenterNicsToBeDeleted()
})
env.EventuallyExpectKarpenterNicsToBeDeleted()
})
})

0 comments on commit f566bef

Please sign in to comment.