Skip to content
Open
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
6 changes: 4 additions & 2 deletions pkg/provider/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,11 @@ func (ss *ScaleSet) EnsureHostInPool(_ *v1.Service, nodeName types.NodeName, bac
}

logger.Error(err, "failed to get vmss vm", "vmName", vmName)
if !errors.Is(err, ErrorNotVmssInstance) {
return "", "", "", nil, err
if errors.Is(err, ErrorNotVmssInstance) {
klog.Infof("EnsureHostInPool: skipping node %s because it is not a VMSS instance", vmName)
return "", "", "", nil, nil
}
return "", "", "", nil, err
}
statuses := vm.GetInstanceViewStatus()
vmPowerState := vmutil.GetVMPowerState(vm.Name, statuses)
Expand Down
8 changes: 7 additions & 1 deletion pkg/provider/virtualmachine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,21 @@ func FromVirtualMachineScaleSetVM(vm *compute.VirtualMachineScaleSetVM, opt Mana
}

func (vm *VirtualMachine) IsVirtualMachine() bool {
if vm == nil {
return false
}
return vm.Variant == VariantVirtualMachine
}

func (vm *VirtualMachine) IsVirtualMachineScaleSetVM() bool {
if vm == nil {
return false
}
return vm.Variant == VariantVirtualMachineScaleSetVM
}

func (vm *VirtualMachine) ManagedByVMSS() bool {
return vm.Manage == VMSS
return vm != nil && vm.Manage == VMSS
}

func (vm *VirtualMachine) AsVirtualMachine() *compute.VirtualMachine {
Expand Down
43 changes: 43 additions & 0 deletions pkg/provider/virtualmachine/virtualmachine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2024 The Kubernetes Authors.

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 virtualmachine

import (
"testing"

"sigs.k8s.io/cloud-provider-azure/pkg/consts"
)

func TestNilVirtualMachine(t *testing.T) {
var vm *VirtualMachine

if vm.IsVirtualMachine() {
t.Error("nil VirtualMachine should return false for IsVirtualMachine()")
}
if vm.IsVirtualMachineScaleSetVM() {
t.Error("nil VirtualMachine should return false for IsVirtualMachineScaleSetVM()")
}
if vm.ManagedByVMSS() {
t.Error("nil VirtualMachine should return false for ManagedByVMSS()")
}
if vm.GetInstanceViewStatus() != nil {
t.Error("nil VirtualMachine should return nil for GetInstanceViewStatus()")
}
if vm.GetProvisioningState() != consts.ProvisioningStateUnknown {
t.Errorf("nil VirtualMachine should return %q for GetProvisioningState(), got %q", consts.ProvisioningStateUnknown, vm.GetProvisioningState())
}
}