From 0bcbfca9cd44cd0941e8fe92e3bfe436d56e991c Mon Sep 17 00:00:00 2001 From: Marc Sensenich Date: Tue, 23 Oct 2018 16:26:00 +0000 Subject: [PATCH] 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 --- .../providers/azure/azure_wrap.go | 3 +- .../providers/azure/azure_wrap_test.go | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/cloudprovider/providers/azure/azure_wrap.go b/pkg/cloudprovider/providers/azure/azure_wrap.go index b19fc3b4c4dd4..0f393a6074223 100644 --- a/pkg/cloudprovider/providers/azure/azure_wrap.go +++ b/pkg/cloudprovider/providers/azure/azure_wrap.go @@ -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" ) @@ -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//resourceGroups//providers/Microsoft.Compute/.*' func (az *Cloud) IsNodeUnmanagedByProviderID(providerID string) bool { - return azureNodeProviderIDRE.Match([]byte(providerID)) + return !azureNodeProviderIDRE.Match([]byte(providerID)) } diff --git a/pkg/cloudprovider/providers/azure/azure_wrap_test.go b/pkg/cloudprovider/providers/azure/azure_wrap_test.go index 8c7ba0ee4daba..3ac2bfc6b5535 100644 --- a/pkg/cloudprovider/providers/azure/azure_wrap_test.go +++ b/pkg/cloudprovider/providers/azure/azure_wrap_test.go @@ -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) + } +}