Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.26] Skip unmanaged Nodes for instancesV2 #4298

Merged
merged 1 commit into from
Jul 19, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 27 additions & 3 deletions pkg/provider/azure_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ func (az *Cloud) InstanceExists(ctx context.Context, node *v1.Node) (bool, error
if node == nil {
return false, nil
}
unmanaged, err := az.IsNodeUnmanaged(node.Name)
if err != nil {
return false, err
}
if unmanaged {
klog.V(4).Infof("InstanceExists: omitting unmanaged node %q", node.Name)
return false, nil
}

providerID := node.Spec.ProviderID
if providerID == "" {
var err error
Expand Down Expand Up @@ -297,6 +306,14 @@ func (az *Cloud) InstanceShutdown(ctx context.Context, node *v1.Node) (bool, err
if node == nil {
return false, nil
}
unmanaged, err := az.IsNodeUnmanaged(node.Name)
if err != nil {
return false, err
}
if unmanaged {
klog.V(4).Infof("InstanceShutdown: omitting unmanaged node %q", node.Name)
return false, nil
}
providerID := node.Spec.ProviderID
if providerID == "" {
var err error
Expand Down Expand Up @@ -492,11 +509,18 @@ func (az *Cloud) CurrentNodeName(ctx context.Context, hostname string) (types.No
// translated into specific fields in the Node object on registration.
// Use the node.name or node.spec.providerID field to find the node in the cloud provider.
func (az *Cloud) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprovider.InstanceMetadata, error) {
meta := cloudprovider.InstanceMetadata{}
if node == nil {
return &cloudprovider.InstanceMetadata{}, nil
return &meta, nil
}
unmanaged, err := az.IsNodeUnmanaged(node.Name)
if err != nil {
return &meta, err
}
if unmanaged {
klog.V(4).Infof("InstanceMetadata: omitting unmanaged node %q", node.Name)
return &meta, nil
}

meta := cloudprovider.InstanceMetadata{}

if node.Spec.ProviderID != "" {
meta.ProviderID = node.Spec.ProviderID
Expand Down
16 changes: 15 additions & 1 deletion pkg/provider/azure_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-07-01/network"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/sets"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -878,7 +879,20 @@ func TestInstanceMetadata(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

t.Run("", func(t *testing.T) {
t.Run("instance not exists", func(t *testing.T) {
cloud := GetTestCloud(ctrl)
cloud.unmanagedNodes = sets.New("node0")

meta, err := cloud.InstanceMetadata(context.Background(), &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
},
})
assert.NoError(t, err)
assert.Equal(t, cloudprovider.InstanceMetadata{}, *meta)
})

t.Run("instance exists", func(t *testing.T) {
cloud := GetTestCloud(ctrl)
expectedVM := buildDefaultTestVirtualMachine("as", []string{"/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/networkInterfaces/k8s-agentpool1-00000000-nic-1"})
expectedVM.HardwareProfile = &compute.HardwareProfile{
Expand Down