mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Merge pull request #75580 from suker200/azure_routetable_rg
Add azure_route support routeTableResourceGroup
This commit is contained in:
commit
2fa5be1633
@ -96,6 +96,8 @@ type Config struct {
|
|||||||
SecurityGroupName string `json:"securityGroupName" yaml:"securityGroupName"`
|
SecurityGroupName string `json:"securityGroupName" yaml:"securityGroupName"`
|
||||||
// (Optional in 1.6) The name of the route table attached to the subnet that the cluster is deployed in
|
// (Optional in 1.6) The name of the route table attached to the subnet that the cluster is deployed in
|
||||||
RouteTableName string `json:"routeTableName" yaml:"routeTableName"`
|
RouteTableName string `json:"routeTableName" yaml:"routeTableName"`
|
||||||
|
// The name of the resource group that the RouteTable is deployed in
|
||||||
|
RouteTableResourceGroup string `json:"routeTableResourceGroup" yaml:"routeTableResourceGroup"`
|
||||||
// (Optional) The name of the availability set that should be used as the load balancer backend
|
// (Optional) The name of the availability set that should be used as the load balancer backend
|
||||||
// If this is set, the Azure cloudprovider will only add nodes from that availability set to the load
|
// If this is set, the Azure cloudprovider will only add nodes from that availability set to the load
|
||||||
// balancer backend pool. If this is not set, and multiple agent pools (availability sets) are used, then
|
// balancer backend pool. If this is not set, and multiple agent pools (availability sets) are used, then
|
||||||
@ -231,6 +233,10 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.RouteTableResourceGroup == "" {
|
||||||
|
config.RouteTableResourceGroup = config.ResourceGroup
|
||||||
|
}
|
||||||
|
|
||||||
if config.VMType == "" {
|
if config.VMType == "" {
|
||||||
// default to standard vmType if not set.
|
// default to standard vmType if not set.
|
||||||
config.VMType = vmTypeStandard
|
config.VMType = vmTypeStandard
|
||||||
|
@ -429,7 +429,7 @@ func (az *Cloud) CreateOrUpdateRouteTable(routeTable network.RouteTable) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp, err := az.RouteTablesClient.CreateOrUpdate(ctx, az.ResourceGroup, az.RouteTableName, routeTable)
|
resp, err := az.RouteTablesClient.CreateOrUpdate(ctx, az.RouteTableResourceGroup, az.RouteTableName, routeTable)
|
||||||
return az.processHTTPResponse(nil, "", resp, err)
|
return az.processHTTPResponse(nil, "", resp, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,7 +442,7 @@ func (az *Cloud) createOrUpdateRouteTableWithRetry(routeTable network.RouteTable
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp, err := az.RouteTablesClient.CreateOrUpdate(ctx, az.ResourceGroup, az.RouteTableName, routeTable)
|
resp, err := az.RouteTablesClient.CreateOrUpdate(ctx, az.RouteTableResourceGroup, az.RouteTableName, routeTable)
|
||||||
return az.processHTTPRetryResponse(nil, "", resp, err)
|
return az.processHTTPRetryResponse(nil, "", resp, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -453,7 +453,7 @@ func (az *Cloud) CreateOrUpdateRoute(route network.Route) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp, err := az.RoutesClient.CreateOrUpdate(ctx, az.ResourceGroup, az.RouteTableName, *route.Name, route)
|
resp, err := az.RoutesClient.CreateOrUpdate(ctx, az.RouteTableResourceGroup, az.RouteTableName, *route.Name, route)
|
||||||
klog.V(10).Infof("RoutesClient.CreateOrUpdate(%s): end", *route.Name)
|
klog.V(10).Infof("RoutesClient.CreateOrUpdate(%s): end", *route.Name)
|
||||||
return az.processHTTPResponse(nil, "", resp, err)
|
return az.processHTTPResponse(nil, "", resp, err)
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ func (az *Cloud) createOrUpdateRouteWithRetry(route network.Route) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp, err := az.RoutesClient.CreateOrUpdate(ctx, az.ResourceGroup, az.RouteTableName, *route.Name, route)
|
resp, err := az.RoutesClient.CreateOrUpdate(ctx, az.RouteTableResourceGroup, az.RouteTableName, *route.Name, route)
|
||||||
klog.V(10).Infof("RoutesClient.CreateOrUpdate(%s): end", *route.Name)
|
klog.V(10).Infof("RoutesClient.CreateOrUpdate(%s): end", *route.Name)
|
||||||
return az.processHTTPRetryResponse(nil, "", resp, err)
|
return az.processHTTPRetryResponse(nil, "", resp, err)
|
||||||
})
|
})
|
||||||
@ -479,7 +479,7 @@ func (az *Cloud) DeleteRouteWithName(routeName string) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp, err := az.RoutesClient.Delete(ctx, az.ResourceGroup, az.RouteTableName, routeName)
|
resp, err := az.RoutesClient.Delete(ctx, az.RouteTableResourceGroup, az.RouteTableName, routeName)
|
||||||
klog.V(10).Infof("RoutesClient.Delete(%s,%s): end", az.RouteTableName, routeName)
|
klog.V(10).Infof("RoutesClient.Delete(%s,%s): end", az.RouteTableName, routeName)
|
||||||
return az.processHTTPResponse(nil, "", resp, err)
|
return az.processHTTPResponse(nil, "", resp, err)
|
||||||
}
|
}
|
||||||
@ -493,7 +493,7 @@ func (az *Cloud) deleteRouteWithRetry(routeName string) error {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
resp, err := az.RoutesClient.Delete(ctx, az.ResourceGroup, az.RouteTableName, routeName)
|
resp, err := az.RoutesClient.Delete(ctx, az.RouteTableResourceGroup, az.RouteTableName, routeName)
|
||||||
klog.V(10).Infof("RoutesClient.Delete(%s,%s): end", az.RouteTableName, routeName)
|
klog.V(10).Infof("RoutesClient.Delete(%s,%s): end", az.RouteTableName, routeName)
|
||||||
return az.processHTTPRetryResponse(nil, "", resp, err)
|
return az.processHTTPRetryResponse(nil, "", resp, err)
|
||||||
})
|
})
|
||||||
|
@ -35,7 +35,7 @@ func TestDeleteRoute(t *testing.T) {
|
|||||||
cloud := &Cloud{
|
cloud := &Cloud{
|
||||||
RoutesClient: fakeRoutes,
|
RoutesClient: fakeRoutes,
|
||||||
Config: Config{
|
Config: Config{
|
||||||
ResourceGroup: "foo",
|
RouteTableResourceGroup: "foo",
|
||||||
RouteTableName: "bar",
|
RouteTableName: "bar",
|
||||||
Location: "location",
|
Location: "location",
|
||||||
},
|
},
|
||||||
@ -100,7 +100,7 @@ func TestCreateRoute(t *testing.T) {
|
|||||||
RoutesClient: fakeRoutes,
|
RoutesClient: fakeRoutes,
|
||||||
vmSet: fakeVM,
|
vmSet: fakeVM,
|
||||||
Config: Config{
|
Config: Config{
|
||||||
ResourceGroup: "foo",
|
RouteTableResourceGroup: "foo",
|
||||||
RouteTableName: "bar",
|
RouteTableName: "bar",
|
||||||
Location: "location",
|
Location: "location",
|
||||||
},
|
},
|
||||||
@ -115,7 +115,7 @@ func TestCreateRoute(t *testing.T) {
|
|||||||
Location: &cloud.Location,
|
Location: &cloud.Location,
|
||||||
}
|
}
|
||||||
fakeTable.FakeStore = map[string]map[string]network.RouteTable{}
|
fakeTable.FakeStore = map[string]map[string]network.RouteTable{}
|
||||||
fakeTable.FakeStore[cloud.ResourceGroup] = map[string]network.RouteTable{
|
fakeTable.FakeStore[cloud.RouteTableResourceGroup] = map[string]network.RouteTable{
|
||||||
cloud.RouteTableName: expectedTable,
|
cloud.RouteTableName: expectedTable,
|
||||||
}
|
}
|
||||||
route := cloudprovider.Route{TargetNode: "node", DestinationCIDR: "1.2.3.4/24"}
|
route := cloudprovider.Route{TargetNode: "node", DestinationCIDR: "1.2.3.4/24"}
|
||||||
@ -179,7 +179,7 @@ func TestCreateRouteTableIfNotExists_Exists(t *testing.T) {
|
|||||||
cloud := &Cloud{
|
cloud := &Cloud{
|
||||||
RouteTablesClient: fake,
|
RouteTablesClient: fake,
|
||||||
Config: Config{
|
Config: Config{
|
||||||
ResourceGroup: "foo",
|
RouteTableResourceGroup: "foo",
|
||||||
RouteTableName: "bar",
|
RouteTableName: "bar",
|
||||||
Location: "location",
|
Location: "location",
|
||||||
},
|
},
|
||||||
@ -192,7 +192,7 @@ func TestCreateRouteTableIfNotExists_Exists(t *testing.T) {
|
|||||||
Location: &cloud.Location,
|
Location: &cloud.Location,
|
||||||
}
|
}
|
||||||
fake.FakeStore = map[string]map[string]network.RouteTable{}
|
fake.FakeStore = map[string]map[string]network.RouteTable{}
|
||||||
fake.FakeStore[cloud.ResourceGroup] = map[string]network.RouteTable{
|
fake.FakeStore[cloud.RouteTableResourceGroup] = map[string]network.RouteTable{
|
||||||
cloud.RouteTableName: expectedTable,
|
cloud.RouteTableName: expectedTable,
|
||||||
}
|
}
|
||||||
err := cloud.createRouteTableIfNotExists("clusterName", &cloudprovider.Route{TargetNode: "node", DestinationCIDR: "1.2.3.4/16"})
|
err := cloud.createRouteTableIfNotExists("clusterName", &cloudprovider.Route{TargetNode: "node", DestinationCIDR: "1.2.3.4/16"})
|
||||||
@ -210,7 +210,7 @@ func TestCreateRouteTableIfNotExists_NotExists(t *testing.T) {
|
|||||||
cloud := &Cloud{
|
cloud := &Cloud{
|
||||||
RouteTablesClient: fake,
|
RouteTablesClient: fake,
|
||||||
Config: Config{
|
Config: Config{
|
||||||
ResourceGroup: "foo",
|
RouteTableResourceGroup: "foo",
|
||||||
RouteTableName: "bar",
|
RouteTableName: "bar",
|
||||||
Location: "location",
|
Location: "location",
|
||||||
},
|
},
|
||||||
@ -229,7 +229,7 @@ func TestCreateRouteTableIfNotExists_NotExists(t *testing.T) {
|
|||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
table := fake.FakeStore[cloud.ResourceGroup][cloud.RouteTableName]
|
table := fake.FakeStore[cloud.RouteTableResourceGroup][cloud.RouteTableName]
|
||||||
if *table.Location != *expectedTable.Location {
|
if *table.Location != *expectedTable.Location {
|
||||||
t.Errorf("mismatch: %s vs %s", *table.Location, *expectedTable.Location)
|
t.Errorf("mismatch: %s vs %s", *table.Location, *expectedTable.Location)
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ func TestCreateRouteTable(t *testing.T) {
|
|||||||
cloud := &Cloud{
|
cloud := &Cloud{
|
||||||
RouteTablesClient: fake,
|
RouteTablesClient: fake,
|
||||||
Config: Config{
|
Config: Config{
|
||||||
ResourceGroup: "foo",
|
RouteTableResourceGroup: "foo",
|
||||||
RouteTableName: "bar",
|
RouteTableName: "bar",
|
||||||
Location: "location",
|
Location: "location",
|
||||||
},
|
},
|
||||||
|
@ -64,6 +64,7 @@ func TestParseConfig(t *testing.T) {
|
|||||||
"primaryScaleSetName": "primaryScaleSetName",
|
"primaryScaleSetName": "primaryScaleSetName",
|
||||||
"resourceGroup": "resourceGroup",
|
"resourceGroup": "resourceGroup",
|
||||||
"routeTableName": "routeTableName",
|
"routeTableName": "routeTableName",
|
||||||
|
"routeTableResourceGroup": "routeTableResourceGroup",
|
||||||
"securityGroupName": "securityGroupName",
|
"securityGroupName": "securityGroupName",
|
||||||
"subnetName": "subnetName",
|
"subnetName": "subnetName",
|
||||||
"subscriptionId": "subscriptionId",
|
"subscriptionId": "subscriptionId",
|
||||||
@ -101,6 +102,7 @@ func TestParseConfig(t *testing.T) {
|
|||||||
PrimaryScaleSetName: "primaryScaleSetName",
|
PrimaryScaleSetName: "primaryScaleSetName",
|
||||||
ResourceGroup: "resourcegroup",
|
ResourceGroup: "resourcegroup",
|
||||||
RouteTableName: "routeTableName",
|
RouteTableName: "routeTableName",
|
||||||
|
RouteTableResourceGroup: "routeTableResourceGroup",
|
||||||
SecurityGroupName: "securityGroupName",
|
SecurityGroupName: "securityGroupName",
|
||||||
SubnetName: "subnetName",
|
SubnetName: "subnetName",
|
||||||
UseInstanceMetadata: true,
|
UseInstanceMetadata: true,
|
||||||
@ -941,6 +943,7 @@ func getTestCloud() (az *Cloud) {
|
|||||||
},
|
},
|
||||||
ResourceGroup: "rg",
|
ResourceGroup: "rg",
|
||||||
VnetResourceGroup: "rg",
|
VnetResourceGroup: "rg",
|
||||||
|
RouteTableResourceGroup: "rg",
|
||||||
Location: "westus",
|
Location: "westus",
|
||||||
VnetName: "vnet",
|
VnetName: "vnet",
|
||||||
SubnetName: "subnet",
|
SubnetName: "subnet",
|
||||||
@ -1524,6 +1527,7 @@ func TestNewCloudFromJSON(t *testing.T) {
|
|||||||
"aadClientCertPath": "--aad-client-cert-path--",
|
"aadClientCertPath": "--aad-client-cert-path--",
|
||||||
"aadClientCertPassword": "--aad-client-cert-password--",
|
"aadClientCertPassword": "--aad-client-cert-password--",
|
||||||
"resourceGroup": "--resource-group--",
|
"resourceGroup": "--resource-group--",
|
||||||
|
"routeTableResourceGroup": "--route-table-resource-group--",
|
||||||
"location": "--location--",
|
"location": "--location--",
|
||||||
"subnetName": "--subnet-name--",
|
"subnetName": "--subnet-name--",
|
||||||
"securityGroupName": "--security-group-name--",
|
"securityGroupName": "--security-group-name--",
|
||||||
@ -1557,7 +1561,8 @@ aadClientSecret: --aad-client-secret--
|
|||||||
validateEmptyConfig(t, config)
|
validateEmptyConfig(t, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Configuration deserialization (yaml)
|
// Test Configuration deserialization (yaml) without
|
||||||
|
// specific resource group for the route table
|
||||||
func TestNewCloudFromYAML(t *testing.T) {
|
func TestNewCloudFromYAML(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
tenantId: --tenant-id--
|
tenantId: --tenant-id--
|
||||||
@ -1567,6 +1572,7 @@ aadClientSecret: --aad-client-secret--
|
|||||||
aadClientCertPath: --aad-client-cert-path--
|
aadClientCertPath: --aad-client-cert-path--
|
||||||
aadClientCertPassword: --aad-client-cert-password--
|
aadClientCertPassword: --aad-client-cert-password--
|
||||||
resourceGroup: --resource-group--
|
resourceGroup: --resource-group--
|
||||||
|
routeTableResourceGroup: --route-table-resource-group--
|
||||||
location: --location--
|
location: --location--
|
||||||
subnetName: --subnet-name--
|
subnetName: --subnet-name--
|
||||||
securityGroupName: --security-group-name--
|
securityGroupName: --security-group-name--
|
||||||
@ -1609,6 +1615,9 @@ func validateConfig(t *testing.T, config string) {
|
|||||||
if azureCloud.ResourceGroup != "--resource-group--" {
|
if azureCloud.ResourceGroup != "--resource-group--" {
|
||||||
t.Errorf("got incorrect value for ResourceGroup")
|
t.Errorf("got incorrect value for ResourceGroup")
|
||||||
}
|
}
|
||||||
|
if azureCloud.RouteTableResourceGroup != "--route-table-resource-group--" {
|
||||||
|
t.Errorf("got incorrect value for RouteTableResourceGroup")
|
||||||
|
}
|
||||||
if azureCloud.Location != "--location--" {
|
if azureCloud.Location != "--location--" {
|
||||||
t.Errorf("got incorrect value for Location")
|
t.Errorf("got incorrect value for Location")
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ func (az *Cloud) newRouteTableCache() (*timedCache, error) {
|
|||||||
getter := func(key string) (interface{}, error) {
|
getter := func(key string) (interface{}, error) {
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
rt, err := az.RouteTablesClient.Get(ctx, az.ResourceGroup, key, "")
|
rt, err := az.RouteTablesClient.Get(ctx, az.RouteTableResourceGroup, key, "")
|
||||||
exists, message, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
|
Loading…
Reference in New Issue
Block a user