Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources"
azStorage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/to"
"k8s.io/utils/ptr"

apiv1 "k8s.io/api/core/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
Expand Down Expand Up @@ -521,7 +521,7 @@ func (as *AgentPool) deleteBlob(accountName, vhdContainer, vhdBlob string) error
}

keys := *storageKeysResult.Keys
client, err := azStorage.NewBasicClientOnSovereignCloud(accountName, to.String(keys[0].Value), as.manager.env)
client, err := azStorage.NewBasicClientOnSovereignCloud(accountName, ptr.Deref(keys[0].Value, ""), as.manager.env)
if err != nil {
return err
}
Expand Down
48 changes: 24 additions & 24 deletions cluster-autoscaler/cloudprovider/azure/azure_agent_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/storageaccountclient/mockstorageaccountclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/vmclient/mockvmclient"
providerazureconsts "sigs.k8s.io/cloud-provider-azure/pkg/consts"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources"
"github.com/Azure/go-autorest/autorest/date"
"github.com/Azure/go-autorest/autorest/to"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
Expand Down Expand Up @@ -62,14 +62,14 @@ func newTestAgentPool(manager *AzureManager, name string) *AgentPool {
func getExpectedVMs() []compute.VirtualMachine {
expectedVMs := []compute.VirtualMachine{
{
Name: to.StringPtr("000-0-00000000-0"),
ID: to.StringPtr("/subscriptions/sub/resourceGroups/rg/providers/provider/0"),
Tags: map[string]*string{"poolName": to.StringPtr("as")},
Name: ptr.To("000-0-00000000-0"),
ID: ptr.To("/subscriptions/sub/resourceGroups/rg/providers/provider/0"),
Tags: map[string]*string{"poolName": ptr.To("as")},
VirtualMachineProperties: &compute.VirtualMachineProperties{
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{
OsType: compute.OperatingSystemTypesLinux,
Vhd: &compute.VirtualHardDisk{URI: to.StringPtr("https://foo.blob/vhds/bar.vhd")},
Vhd: &compute.VirtualHardDisk{URI: ptr.To("https://foo.blob/vhds/bar.vhd")},
},
},
NetworkProfile: &compute.NetworkProfile{
Expand All @@ -80,9 +80,9 @@ func getExpectedVMs() []compute.VirtualMachine {
},
},
{
Name: to.StringPtr("00000000001"),
ID: to.StringPtr("/subscriptions/sub/resourceGroups/rg/providers/provider/0"),
Tags: map[string]*string{"poolName": to.StringPtr("as")},
Name: ptr.To("00000000001"),
ID: ptr.To("/subscriptions/sub/resourceGroups/rg/providers/provider/0"),
Tags: map[string]*string{"poolName": ptr.To("as")},
VirtualMachineProperties: &compute.VirtualMachineProperties{
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{OsType: compute.OperatingSystemTypesWindows},
Expand Down Expand Up @@ -115,30 +115,30 @@ func TestDeleteOutdatedDeployments(t *testing.T) {
{
deployments: map[string]resources.DeploymentExtended{
"non-cluster-autoscaler-0000": {
Name: to.StringPtr("non-cluster-autoscaler-0000"),
Name: ptr.To("non-cluster-autoscaler-0000"),
Properties: &resources.DeploymentPropertiesExtended{
ProvisioningState: to.StringPtr("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)},
},
},
"cluster-autoscaler-0000": {
Name: to.StringPtr("cluster-autoscaler-0000"),
Name: ptr.To("cluster-autoscaler-0000"),
Properties: &resources.DeploymentPropertiesExtended{
ProvisioningState: to.StringPtr("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
Timestamp: &date.Time{Time: timeBenchMark},
},
},
"cluster-autoscaler-0001": {
Name: to.StringPtr("cluster-autoscaler-0001"),
Name: ptr.To("cluster-autoscaler-0001"),
Properties: &resources.DeploymentPropertiesExtended{
ProvisioningState: to.StringPtr("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
Timestamp: &date.Time{Time: timeBenchMark.Add(time.Minute)},
},
},
"cluster-autoscaler-0002": {
Name: to.StringPtr("cluster-autoscaler-0002"),
Name: ptr.To("cluster-autoscaler-0002"),
Properties: &resources.DeploymentPropertiesExtended{
ProvisioningState: to.StringPtr("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)},
},
},
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestAgentPoolGetVMsFromCache(t *testing.T) {
testAS := newTestAgentPool(newTestAzureManager(t), "testAS")
expectedVMs := []compute.VirtualMachine{
{
Tags: map[string]*string{"poolName": to.StringPtr("testAS")},
Tags: map[string]*string{"poolName": ptr.To("testAS")},
},
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func TestGetVMIndexes(t *testing.T) {
assert.Equal(t, 2, len(sortedIndexes))
assert.Equal(t, 2, len(indexToVM))

expectedVMs[0].ID = to.StringPtr("foo")
expectedVMs[0].ID = ptr.To("foo")
mockVMClient.EXPECT().List(gomock.Any(), as.manager.config.ResourceGroup).Return(expectedVMs, nil)
err = as.manager.forceRefresh()
assert.NoError(t, err)
Expand All @@ -223,7 +223,7 @@ func TestGetVMIndexes(t *testing.T) {
assert.Nil(t, sortedIndexes)
assert.Nil(t, indexToVM)

expectedVMs[0].Name = to.StringPtr("foo")
expectedVMs[0].Name = ptr.To("foo")
mockVMClient.EXPECT().List(gomock.Any(), as.manager.config.ResourceGroup).Return(expectedVMs, nil)
err = as.manager.forceRefresh()
sortedIndexes, indexToVM, err = as.GetVMIndexes()
Expand Down Expand Up @@ -501,11 +501,11 @@ func TestAgentPoolNodes(t *testing.T) {
as := newTestAgentPool(newTestAzureManager(t), "as")
expectedVMs := []compute.VirtualMachine{
{
Tags: map[string]*string{"poolName": to.StringPtr("as")},
ID: to.StringPtr(""),
Tags: map[string]*string{"poolName": ptr.To("as")},
ID: ptr.To(""),
},
{
Tags: map[string]*string{"poolName": to.StringPtr("as")},
Tags: map[string]*string{"poolName": ptr.To("as")},
ID: &testValidProviderID0,
},
}
Expand All @@ -524,8 +524,8 @@ func TestAgentPoolNodes(t *testing.T) {

expectedVMs = []compute.VirtualMachine{
{
Tags: map[string]*string{"poolName": to.StringPtr("as")},
ID: to.StringPtr("foo"),
Tags: map[string]*string{"poolName": ptr.To("as")},
ID: ptr.To("foo"),
},
}
mockVMClient.EXPECT().List(gomock.Any(), as.manager.config.ResourceGroup).Return(expectedVMs, nil)
Expand Down
7 changes: 2 additions & 5 deletions cluster-autoscaler/cloudprovider/azure/azure_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/skewer"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
providerazureconsts "sigs.k8s.io/cloud-provider-azure/pkg/consts"
Expand Down Expand Up @@ -295,11 +294,9 @@ func (m *azureCache) fetchVirtualMachines() (map[string][]compute.VirtualMachine
if vmPoolName == nil {
vmPoolName = tags[legacyAgentpoolNameTag]
}
if vmPoolName == nil {
continue
if vmPoolName != nil {
instances[*vmPoolName] = append(instances[*vmPoolName], instance)
}

instances[to.String(vmPoolName)] = append(instances[to.String(vmPoolName)], instance)
}
return instances, nil
}
Expand Down
6 changes: 3 additions & 3 deletions cluster-autoscaler/cloudprovider/azure/azure_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
providerazureconsts "sigs.k8s.io/cloud-provider-azure/pkg/consts"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v5"
"github.com/Azure/go-autorest/autorest/to"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"k8s.io/utils/ptr"
)

func TestFetchVMsPools(t *testing.T) {
Expand All @@ -40,7 +40,7 @@ func TestFetchVMsPools(t *testing.T) {
vmsPool := getTestVMsAgentPool(false)
vmssPoolType := armcontainerservice.AgentPoolTypeVirtualMachineScaleSets
vmssPool := armcontainerservice.AgentPool{
Name: to.StringPtr("vmsspool1"),
Name: ptr.To("vmsspool1"),
Properties: &armcontainerservice.ManagedClusterAgentPoolProfileProperties{
Type: &vmssPoolType,
},
Expand All @@ -54,7 +54,7 @@ func TestFetchVMsPools(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(vmsPoolMap))

_, ok := vmsPoolMap[to.String(vmsPool.Name)]
_, ok := vmsPoolMap[ptr.Deref(vmsPool.Name, "")]
assert.True(t, ok)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources"
"github.com/Azure/go-autorest/autorest/to"

apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/vmclient/mockvmclient"
Expand Down Expand Up @@ -74,7 +74,7 @@ func newTestAzureManager(t *testing.T) *AzureManager {
deploymentClient: &DeploymentClientMock{
FakeStore: map[string]resources.DeploymentExtended{
"deployment": {
Name: to.StringPtr("deployment"),
Name: ptr.To("deployment"),
Properties: &resources.DeploymentPropertiesExtended{Template: map[string]interface{}{
resourcesFieldName: []interface{}{
map[string]interface{}{
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestHasInstance(t *testing.T) {
mockVMSSVMClient.EXPECT().List(gomock.Any(), provider.azureManager.config.ResourceGroup, "test-asg", gomock.Any()).Return(expectedVMSSVMs, nil).AnyTimes()
vmssType := armcontainerservice.AgentPoolTypeVirtualMachineScaleSets
vmssPool := armcontainerservice.AgentPool{
Name: to.StringPtr("test-asg"),
Name: ptr.To("test-asg"),
Properties: &armcontainerservice.ManagedClusterAgentPoolProfileProperties{
Type: &vmssType,
},
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestMixedNodeGroups(t *testing.T) {

vmssType := armcontainerservice.AgentPoolTypeVirtualMachineScaleSets
vmssPool := armcontainerservice.AgentPool{
Name: to.StringPtr("test-asg"),
Name: ptr.To("test-asg"),
Properties: &armcontainerservice.ManagedClusterAgentPoolProfileProperties{
Type: &vmssType,
},
Expand Down
6 changes: 3 additions & 3 deletions cluster-autoscaler/cloudprovider/azure/azure_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources"
"github.com/Azure/go-autorest/autorest/date"
"github.com/Azure/go-autorest/autorest/to"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/utils/ptr"
azclient "sigs.k8s.io/cloud-provider-azure/pkg/azclient"
azclients "sigs.k8s.io/cloud-provider-azure/pkg/azureclients"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/vmssclient/mockvmssclient"
Expand Down Expand Up @@ -1069,9 +1069,9 @@ func TestFetchExplicitNodeGroups(t *testing.T) {
testAS.manager.azClient.deploymentClient = &DeploymentClientMock{
FakeStore: map[string]resources.DeploymentExtended{
"cluster-autoscaler-0001": {
Name: to.StringPtr("cluster-autoscaler-0001"),
Name: ptr.To("cluster-autoscaler-0001"),
Properties: &resources.DeploymentPropertiesExtended{
ProvisioningState: to.StringPtr("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)},
},
},
Expand Down
10 changes: 5 additions & 5 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/config/dynamic"
"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
klog "k8s.io/klog/v2"
"k8s.io/utils/ptr"
"sigs.k8s.io/cloud-provider-azure/pkg/retry"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
)

var (
Expand Down Expand Up @@ -209,7 +209,7 @@ func (scaleSet *ScaleSet) getCurSize() (int64, *GetVMSSFailedError) {
// // If VMSS state is updating, return the currentSize which would've been proactively incremented or decremented by CA
// // unless it's -1. In that case, its better to initialize it.
// if scaleSet.curSize != -1 && set.VirtualMachineScaleSetProperties != nil &&
// strings.EqualFold(to.String(set.VirtualMachineScaleSetProperties.ProvisioningState), string(compute.GalleryProvisioningStateUpdating)) {
// strings.EqualFold(ptr.Deref(set.VirtualMachineScaleSetProperties.ProvisioningState, ""), string(compute.GalleryProvisioningStateUpdating)) {
// klog.V(3).Infof("VMSS %q is in updating state, returning cached size: %d", scaleSet.Name, scaleSet.curSize)
// return scaleSet.curSize, nil
// }
Expand Down Expand Up @@ -869,10 +869,10 @@ func (scaleSet *ScaleSet) cseErrors(extensions *[]compute.VirtualMachineExtensio
failed := false
if extensions != nil {
for _, extension := range *extensions {
if strings.EqualFold(to.String(extension.Name), vmssCSEExtensionName) && extension.Statuses != nil {
if strings.EqualFold(ptr.Deref(extension.Name, ""), vmssCSEExtensionName) && extension.Statuses != nil {
for _, status := range *extension.Statuses {
if status.Level == "Error" {
errs = append(errs, to.String(status.Message))
errs = append(errs, ptr.Deref(status.Message, ""))
failed = true
}
}
Expand All @@ -888,7 +888,7 @@ func (scaleSet *ScaleSet) getSKU() string {
klog.Errorf("Failed to get information for VMSS (%q): %v", scaleSet.Name, err)
return ""
}
return to.String(vmssInfo.Sku.Name)
return ptr.Deref(vmssInfo.Sku.Name, "")
}

func (scaleSet *ScaleSet) verifyNodeGroup(instance *azureRef, commonNgID string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/to"

"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
)

/*
Expand Down Expand Up @@ -227,7 +227,7 @@ func (scaleSet *ScaleSet) instanceStatusFromVM(vm *compute.VirtualMachineScaleSe
case string(compute.GalleryProvisioningStateFailed):
status.State = cloudprovider.InstanceRunning

klog.V(3).Infof("VM %s reports failed provisioning state with power state: %s, eligible for fast delete: %s", to.String(vm.ID), powerState, strconv.FormatBool(scaleSet.enableFastDeleteOnFailedProvisioning))
klog.V(3).Infof("VM %s reports failed provisioning state with power state: %s, eligible for fast delete: %s", ptr.Deref(vm.ID, ""), powerState, strconv.FormatBool(scaleSet.enableFastDeleteOnFailedProvisioning))
if scaleSet.enableFastDeleteOnFailedProvisioning {
// Provisioning can fail both during instance creation or after the instance is running.
// Per https://learn.microsoft.com/en-us/azure/virtual-machines/states-billing#provisioning-states,
Expand All @@ -253,12 +253,12 @@ func (scaleSet *ScaleSet) instanceStatusFromVM(vm *compute.VirtualMachineScaleSe
// Add vmssCSE Provisioning Failed Message in error info body for vmssCSE Extensions if enableDetailedCSEMessage is true
if scaleSet.enableDetailedCSEMessage && vm.InstanceView != nil {
if err, failed := scaleSet.cseErrors(vm.InstanceView.Extensions); failed {
klog.V(3).Infof("VM %s reports CSE failure: %v, with provisioning state %s, power state %s", to.String(vm.ID), err, to.String(vm.ProvisioningState), powerState)
klog.V(3).Infof("VM %s reports CSE failure: %v, with provisioning state %s, power state %s", ptr.Deref(vm.ID, ""), err, ptr.Deref(vm.ProvisioningState, ""), powerState)
status.State = cloudprovider.InstanceCreating
errorInfo := &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OtherErrorClass,
ErrorCode: vmssExtensionProvisioningFailed,
ErrorMessage: fmt.Sprintf("%s: %v", to.String(vm.Name), err),
ErrorMessage: fmt.Sprintf("%s: %v", ptr.Deref(vm.Name, ""), err),
}
status.ErrorInfo = errorInfo
}
Expand Down
Loading
Loading