Skip to content

Commit bd90477

Browse files
authored
Merge pull request #1415 from Ankitasw/backoff-config
Expose cloud provider backoff config
2 parents 4340e1d + bd47575 commit bd90477

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

api/v1alpha4/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,16 @@ type AddressRecord struct {
518518
// CloudProviderConfigOverrides represents the fields that can be overridden in azure cloud provider config.
519519
type CloudProviderConfigOverrides struct {
520520
RateLimits []RateLimitSpec `json:"rateLimits,omitempty"`
521+
BackOffs BackOffConfig `json:"backOffs,omitempty"`
522+
}
523+
524+
// BackOffConfig indicates the back-off config options.
525+
type BackOffConfig struct {
526+
CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"`
527+
CloudProviderBackoffRetries int `json:"cloudProviderBackoffRetries,omitempty"`
528+
CloudProviderBackoffExponent *resource.Quantity `json:"cloudProviderBackoffExponent,omitempty"`
529+
CloudProviderBackoffDuration int `json:"cloudProviderBackoffDuration,omitempty"`
530+
CloudProviderBackoffJitter *resource.Quantity `json:"cloudProviderBackoffJitter,omitempty"`
521531
}
522532

523533
// RateLimitSpec represents the rate limit configuration for a particular kind of resource.

api/v1alpha4/zz_generated.deepcopy.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusters.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,28 @@ spec:
482482
cloudProviderConfigOverrides:
483483
description: 'CloudProviderConfigOverrides is an optional set of configuration values that can be overridden in azure cloud provider config. This is only a subset of options that are available in azure cloud provider config. Some values for the cloud provider config are inferred from other parts of cluster api provider azure spec, and may not be available for overrides. See: https://kubernetes-sigs.github.io/cloud-provider-azure/install/configs Note: All cloud provider config values can be customized by creating the secret beforehand. CloudProviderConfigOverrides is only used when the secret is managed by the Azure Provider.'
484484
properties:
485+
backOffs:
486+
description: BackOffConfig indicates the back-off config options.
487+
properties:
488+
cloudProviderBackoff:
489+
type: boolean
490+
cloudProviderBackoffDuration:
491+
type: integer
492+
cloudProviderBackoffExponent:
493+
anyOf:
494+
- type: integer
495+
- type: string
496+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
497+
x-kubernetes-int-or-string: true
498+
cloudProviderBackoffJitter:
499+
anyOf:
500+
- type: integer
501+
- type: string
502+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
503+
x-kubernetes-int-or-string: true
504+
cloudProviderBackoffRetries:
505+
type: integer
506+
type: object
485507
rateLimits:
486508
items:
487509
description: 'RateLimitSpec represents the rate limit configuration for a particular kind of resource. Eg. loadBalancerRateLimit is used to configure rate limits for load balancers. This eventually gets converted to CloudProviderRateLimitConfig that cloud-provider-azure expects. See: https://github.com/kubernetes-sigs/cloud-provider-azure/blob/d585c2031925b39c925624302f22f8856e29e352/pkg/provider/azure_ratelimit.go#L25 We cannot use CloudProviderRateLimitConfig directly because floating point values are not supported in controller-tools. See: https://github.com/kubernetes-sigs/controller-tools/issues/245'

controllers/helpers.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ func (cpc *CloudProviderConfig) overrideFromSpec(d azure.ClusterScoper) *CloudPr
301301
cpc.AvailabilitySetRateLimit = toCloudProviderRateLimitConfig(rateLimit.Config)
302302
}
303303
}
304+
305+
cpc.BackOffConfig = toCloudProviderBackOffConfig(d.CloudProviderConfigOverrides().BackOffs)
304306
return cpc
305307
}
306308

@@ -341,6 +343,7 @@ type CloudProviderConfig struct {
341343
UseInstanceMetadata bool `json:"useInstanceMetadata"`
342344
UserAssignedIdentityID string `json:"userAssignedIdentityId,omitempty"`
343345
CloudProviderRateLimitConfig
346+
BackOffConfig
344347
}
345348

346349
// CloudProviderRateLimitConfig represents the rate limiting configurations in azure cloud provider config.
@@ -375,6 +378,31 @@ type RateLimitConfig struct {
375378
CloudProviderRateLimitBucketWrite int `json:"cloudProviderRateLimitBucketWrite,omitempty"`
376379
}
377380

381+
// BackOffConfig indicates the back-off config options.
382+
// This is a copy of the struct used in cloud-provider-azure: https://github.com/kubernetes-sigs/cloud-provider-azure/blob/d585c2031925b39c925624302f22f8856e29e352/pkg/azureclients/azure_client_config.go#L48
383+
type BackOffConfig struct {
384+
CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"`
385+
CloudProviderBackoffRetries int `json:"cloudProviderBackoffRetries,omitempty"`
386+
CloudProviderBackoffExponent float64 `json:"cloudProviderBackoffExponent,omitempty"`
387+
CloudProviderBackoffDuration int `json:"cloudProviderBackoffDuration,omitempty"`
388+
CloudProviderBackoffJitter float64 `json:"cloudProviderBackoffJitter,omitempty"`
389+
}
390+
391+
// toCloudProviderBackOffConfig returns converts infrav1.BackOffConfig to BackOffConfig that is required with the cloud provider.
392+
func toCloudProviderBackOffConfig(source infrav1.BackOffConfig) BackOffConfig {
393+
backOffConfig := BackOffConfig{}
394+
backOffConfig.CloudProviderBackoff = source.CloudProviderBackoff
395+
if source.CloudProviderBackoffExponent != nil {
396+
backOffConfig.CloudProviderBackoffExponent = source.CloudProviderBackoffExponent.AsApproximateFloat64()
397+
}
398+
backOffConfig.CloudProviderBackoffRetries = source.CloudProviderBackoffRetries
399+
if source.CloudProviderBackoffJitter != nil {
400+
backOffConfig.CloudProviderBackoffJitter = source.CloudProviderBackoffJitter.AsApproximateFloat64()
401+
}
402+
backOffConfig.CloudProviderBackoffDuration = source.CloudProviderBackoffDuration
403+
return backOffConfig
404+
}
405+
378406
func reconcileAzureSecret(ctx context.Context, log logr.Logger, kubeclient client.Client, owner metav1.OwnerReference, new *corev1.Secret, clusterName string) error {
379407
ctx, span := tele.Tracer().Start(ctx, "controllers.reconcileAzureSecret")
380408
defer span.End()

controllers/helpers_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ func TestGetCloudProviderConfig(t *testing.T) {
139139
expectedControlPlaneConfig: rateLimitsControlPlaneCloudConfig,
140140
expectedWorkerNodeConfig: rateLimitsWorkerNodeCloudConfig,
141141
},
142+
"with back-off config": {
143+
cluster: cluster,
144+
azureCluster: withbackOffConfig(*azureCluster),
145+
identityType: infrav1.VMIdentityNone,
146+
expectedControlPlaneConfig: backOffCloudConfig,
147+
expectedWorkerNodeConfig: backOffCloudConfig,
148+
},
142149
}
143150

144151
os.Setenv(auth.ClientID, "fooClient")
@@ -331,6 +338,19 @@ func withRateLimits(ac infrav1.AzureCluster) *infrav1.AzureCluster {
331338
return &ac
332339
}
333340

341+
func withbackOffConfig(ac infrav1.AzureCluster) *infrav1.AzureCluster {
342+
cloudProviderBackOffExponent := resource.MustParse("1.2")
343+
backOff := infrav1.BackOffConfig{
344+
CloudProviderBackoff: true,
345+
CloudProviderBackoffRetries: 1,
346+
CloudProviderBackoffExponent: &cloudProviderBackOffExponent,
347+
CloudProviderBackoffDuration: 60,
348+
CloudProviderBackoffJitter: &cloudProviderBackOffExponent,
349+
}
350+
ac.Spec.CloudProviderConfigOverrides = &infrav1.CloudProviderConfigOverrides{BackOffs: backOff}
351+
return &ac
352+
}
353+
334354
func newAzureClusterWithCustomVnet(name, location string) *infrav1.AzureCluster {
335355
return &infrav1.AzureCluster{
336356
ObjectMeta: metav1.ObjectMeta{
@@ -567,5 +587,30 @@ const (
567587
"loadBalancerRateLimit": {
568588
"cloudProviderRateLimitBucket": 10
569589
}
590+
}`
591+
backOffCloudConfig = `{
592+
"cloud": "AzurePublicCloud",
593+
"tenantId": "fooTenant",
594+
"subscriptionId": "baz",
595+
"aadClientId": "fooClient",
596+
"aadClientSecret": "fooSecret",
597+
"resourceGroup": "bar",
598+
"securityGroupName": "foo-node-nsg",
599+
"securityGroupResourceGroup": "bar",
600+
"location": "bar",
601+
"vmType": "vmss",
602+
"vnetName": "foo-vnet",
603+
"vnetResourceGroup": "bar",
604+
"subnetName": "foo-node-subnet",
605+
"routeTableName": "foo-node-routetable",
606+
"loadBalancerSku": "Standard",
607+
"maximumLoadBalancerRuleCount": 250,
608+
"useManagedIdentityExtension": false,
609+
"useInstanceMetadata": true,
610+
"cloudProviderBackoff": true,
611+
"cloudProviderBackoffRetries": 1,
612+
"cloudProviderBackoffExponent": 1.2000000000000002,
613+
"cloudProviderBackoffDuration": 60,
614+
"cloudProviderBackoffJitter": 1.2000000000000002
570615
}`
571616
)

0 commit comments

Comments
 (0)