Skip to content

Commit 0bcbfca

Browse files
Correct regexp check in IsNodeUnmanagedByProvider
The IsNodeUnmanagedByProviderID function in the Azure Cloud Provider should return the inverse of regexp.Match in the case of checking the ProviderID
1 parent 8be25aa commit 0bcbfca

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/cloudprovider/providers/azure/azure_wrap.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
2828
"github.com/Azure/go-autorest/autorest"
2929
"github.com/golang/glog"
30-
3130
"k8s.io/apimachinery/pkg/types"
3231
cloudprovider "k8s.io/cloud-provider"
3332
)
@@ -302,5 +301,5 @@ func (az *Cloud) IsNodeUnmanaged(nodeName string) (bool, error) {
302301
// IsNodeUnmanagedByProviderID returns true if the node is not managed by Azure cloud provider.
303302
// All managed node's providerIDs are in format 'azure:///subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.Compute/.*'
304303
func (az *Cloud) IsNodeUnmanagedByProviderID(providerID string) bool {
305-
return azureNodeProviderIDRE.Match([]byte(providerID))
304+
return !azureNodeProviderIDRE.Match([]byte(providerID))
306305
}

pkg/cloudprovider/providers/azure/azure_wrap_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,38 @@ func TestIsNodeUnmanaged(t *testing.T) {
107107
assert.Equal(t, test.expected, real, test.name)
108108
}
109109
}
110+
111+
func TestIsNodeUnmanagedByProviderID(t *testing.T) {
112+
tests := []struct {
113+
providerID string
114+
expected bool
115+
name string
116+
}{
117+
{
118+
providerID: CloudProviderName + ":///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
119+
expected: false,
120+
},
121+
{
122+
providerID: CloudProviderName + "://",
123+
expected: true,
124+
},
125+
{
126+
providerID: ":///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
127+
expected: true,
128+
},
129+
{
130+
providerID: "aws:///subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroupName/providers/Microsoft.Compute/virtualMachines/k8s-agent-AAAAAAAA-0",
131+
expected: true,
132+
},
133+
{
134+
providerID: "k8s-agent-AAAAAAAA-0",
135+
expected: true,
136+
},
137+
}
138+
139+
az := getTestCloud()
140+
for _, test := range tests {
141+
isUnmanagedNode := az.IsNodeUnmanagedByProviderID(test.providerID)
142+
assert.Equal(t, test.expected, isUnmanagedNode, test.providerID)
143+
}
144+
}

0 commit comments

Comments
 (0)