Skip to content

Commit

Permalink
Merge pull request kubernetes#70135 from marc-sensenich/kubernetesgh-…
Browse files Browse the repository at this point in the history
…70126/azure-is-node-unmanaged-fix

Correct regexp check in IsNodeUnmanagedByProvider
  • Loading branch information
k8s-ci-robot authored Oct 24, 2018
2 parents c0974d7 + 0bcbfca commit 3905fb6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/cloudprovider/providers/azure/azure_wrap.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/services/network/mgmt/2017-09-01/network"
"github.com/Azure/go-autorest/autorest"
"github.com/golang/glog"

"k8s.io/apimachinery/pkg/types"
cloudprovider "k8s.io/cloud-provider"
)
Expand Down Expand Up @@ -302,5 +301,5 @@ func (az *Cloud) IsNodeUnmanaged(nodeName string) (bool, error) {
// IsNodeUnmanagedByProviderID returns true if the node is not managed by Azure cloud provider.
// All managed node's providerIDs are in format 'azure:///subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.Compute/.*'
func (az *Cloud) IsNodeUnmanagedByProviderID(providerID string) bool {
return azureNodeProviderIDRE.Match([]byte(providerID))
return !azureNodeProviderIDRE.Match([]byte(providerID))
}
35 changes: 35 additions & 0 deletions pkg/cloudprovider/providers/azure/azure_wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,38 @@ func TestIsNodeUnmanaged(t *testing.T) {
assert.Equal(t, test.expected, real, test.name)
}
}

func TestIsNodeUnmanagedByProviderID(t *testing.T) {
tests := []struct {
providerID string
expected bool
name string
}{
{
providerID: CloudProviderName + ":///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
expected: false,
},
{
providerID: CloudProviderName + "://",
expected: true,
},
{
providerID: ":///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
expected: true,
},
{
providerID: "aws:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
expected: true,
},
{
providerID: "k8s-agent-AAAAAAAA-0",
expected: true,
},
}

az := getTestCloud()
for _, test := range tests {
isUnmanagedNode := az.IsNodeUnmanagedByProviderID(test.providerID)
assert.Equal(t, test.expected, isUnmanagedNode, test.providerID)
}
}

0 comments on commit 3905fb6

Please sign in to comment.