Merge pull request #67604 from feiskyer/cross-rg-nodes
Automatic merge from submit-queue (batch tested with PRs 66980, 67604, 67741, 67715). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add support of Azure cross resource group nodes **What this PR does / why we need it**: Part of feature [Cross resource group nodes](https://github.com/kubernetes/features/issues/604). This PR adds support of Azure cross resource group nodes that are labeled with `kubernetes.azure.com/resource-group=<rg-name>` and `alpha.service-controller.kubernetes.io/exclude-balancer=true` **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: See designs [here](https://github.com/kubernetes/community/pull/2479). **Release note**: ```release-note Azure cloud provider now supports cross resource group nodes that are labeled with `kubernetes.azure.com/resource-group=<rg-name>` and `alpha.service-controller.kubernetes.io/exclude-balancer=true` ``` /sig azure /kind feature
This commit is contained in:
@@ -956,6 +956,8 @@ func getTestCloud() (az *Cloud) {
|
||||
},
|
||||
nodeZones: map[string]sets.String{},
|
||||
nodeInformerSynced: func() bool { return true },
|
||||
nodeResourceGroups: map[string]string{},
|
||||
unmanagedNodes: sets.NewString(),
|
||||
}
|
||||
az.DisksClient = newFakeDisksClient()
|
||||
az.InterfacesClient = newFakeAzureInterfacesClient()
|
||||
@@ -1065,7 +1067,7 @@ func getClusterResources(az *Cloud, vmCount int, availabilitySetCount int) (clus
|
||||
az.InterfacesClient.CreateOrUpdate(ctx, az.Config.ResourceGroup, nicName, newNIC)
|
||||
|
||||
// create vm
|
||||
asID := az.getAvailabilitySetID(asName)
|
||||
asID := az.getAvailabilitySetID(az.Config.ResourceGroup, asName)
|
||||
newVM := compute.VirtualMachine{
|
||||
Name: &vmName,
|
||||
Location: &az.Config.Location,
|
||||
@@ -2771,3 +2773,100 @@ func TestGetResourceGroupFromDiskURI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetResourceGroups(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
nodeResourceGroups map[string]string
|
||||
expected sets.String
|
||||
informerSynced bool
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "cloud provider configured RG should be returned by default",
|
||||
nodeResourceGroups: map[string]string{},
|
||||
informerSynced: true,
|
||||
expected: sets.NewString("rg"),
|
||||
},
|
||||
{
|
||||
name: "cloud provider configured RG and node RGs should be returned",
|
||||
nodeResourceGroups: map[string]string{"node1": "rg1", "node2": "rg2"},
|
||||
informerSynced: true,
|
||||
expected: sets.NewString("rg", "rg1", "rg2"),
|
||||
},
|
||||
{
|
||||
name: "error should be returned if informer hasn't synced yet",
|
||||
nodeResourceGroups: map[string]string{"node1": "rg1", "node2": "rg2"},
|
||||
informerSynced: false,
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
|
||||
az := getTestCloud()
|
||||
for _, test := range tests {
|
||||
az.nodeResourceGroups = test.nodeResourceGroups
|
||||
if test.informerSynced {
|
||||
az.nodeInformerSynced = func() bool { return true }
|
||||
} else {
|
||||
az.nodeInformerSynced = func() bool { return false }
|
||||
}
|
||||
actual, err := az.GetResourceGroups()
|
||||
if test.expectError {
|
||||
assert.NotNil(t, err, test.name)
|
||||
continue
|
||||
}
|
||||
|
||||
assert.Nil(t, err, test.name)
|
||||
assert.Equal(t, test.expected, actual, test.name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNodeResourceGroup(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
nodeResourceGroups map[string]string
|
||||
node string
|
||||
expected string
|
||||
informerSynced bool
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "cloud provider configured RG should be returned by default",
|
||||
nodeResourceGroups: map[string]string{},
|
||||
informerSynced: true,
|
||||
node: "node1",
|
||||
expected: "rg",
|
||||
},
|
||||
{
|
||||
name: "node RGs should be returned",
|
||||
nodeResourceGroups: map[string]string{"node1": "rg1", "node2": "rg2"},
|
||||
informerSynced: true,
|
||||
node: "node1",
|
||||
expected: "rg1",
|
||||
},
|
||||
{
|
||||
name: "error should be returned if informer hasn't synced yet",
|
||||
nodeResourceGroups: map[string]string{"node1": "rg1", "node2": "rg2"},
|
||||
informerSynced: false,
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
|
||||
az := getTestCloud()
|
||||
for _, test := range tests {
|
||||
az.nodeResourceGroups = test.nodeResourceGroups
|
||||
if test.informerSynced {
|
||||
az.nodeInformerSynced = func() bool { return true }
|
||||
} else {
|
||||
az.nodeInformerSynced = func() bool { return false }
|
||||
}
|
||||
actual, err := az.GetNodeResourceGroup(test.node)
|
||||
if test.expectError {
|
||||
assert.NotNil(t, err, test.name)
|
||||
continue
|
||||
}
|
||||
|
||||
assert.Nil(t, err, test.name)
|
||||
assert.Equal(t, test.expected, actual, test.name)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user