Skip to content

Commit 36c6c4f

Browse files
authored
Expose ingress configuration options for missing backends (#3342)
* Expose configuration for missing backends This PR adds command line flags to specify whether the the controller should tolerate missing backend services and actions. If the flags are not specified, the default value will be to tolerate missing backend actions and services (which is the current behavior.) The code changes here are simply to thread these values through to `enhanced_backend_builder.go`, and rely on them rather than using the `defaultTolerateNonExistentBackendService` and `defaultTolerateNonExistentBackendAction` constant fields. The logic here is already unit tested, so no new tests have been added. * add new settings to values.yaml
1 parent 22ce8e9 commit 36c6c4f

File tree

10 files changed

+50
-20
lines changed

10 files changed

+50
-20
lines changed

config/webhook/manifests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
apiVersion: admissionregistration.k8s.io/v1
32
kind: MutatingWebhookConfiguration
43
metadata:

controllers/ingress/group_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewGroupReconciler(cloud aws.Cloud, k8sClient client.Client, eventRecorder
5151

5252
annotationParser := annotations.NewSuffixAnnotationParser(annotations.AnnotationPrefixIngress)
5353
authConfigBuilder := ingress.NewDefaultAuthConfigBuilder(annotationParser)
54-
enhancedBackendBuilder := ingress.NewDefaultEnhancedBackendBuilder(k8sClient, annotationParser, authConfigBuilder)
54+
enhancedBackendBuilder := ingress.NewDefaultEnhancedBackendBuilder(k8sClient, annotationParser, authConfigBuilder, controllerConfig.IngressConfig.TolerateNonExistentBackendService, controllerConfig.IngressConfig.TolerateNonExistentBackendAction)
5555
referenceIndexer := ingress.NewDefaultReferenceIndexer(enhancedBackendBuilder, authConfigBuilder, logger)
5656
trackingProvider := tracking.NewDefaultProvider(ingressTagPrefix, controllerConfig.ClusterName)
5757
elbv2TaggingManager := elbv2deploy.NewDefaultTaggingManager(cloud.ELBV2(), cloud.VpcID(), controllerConfig.FeatureGates, cloud.RGT(), logger)

docs/deploy/configurations.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ Currently, you can set only 1 namespace to watch in this flag. See [this Kuberne
6969
|aws-api-endpoints | AWS API Endpoints Config | | AWS API endpoints mapping, format: serviceID1=URL1,serviceID2=URL2 |
7070
|aws-api-throttle | AWS Throttle Config | [default value](#default-throttle-config ) | throttle settings for AWS APIs, format: serviceID1:operationRegex1=rate:burst,serviceID2:operationRegex2=rate:burst |
7171
|aws-max-retries | int | 10 | Maximum retries for AWS APIs |
72-
|aws-region | string | [instance metadata](#instance-metadata) | AWS Region for the kubernetes cluster |
73-
|aws-vpc-id | string | [instance metadata](#instance-metadata) | AWS VPC ID for the Kubernetes cluster |
72+
|aws-region | string | [instance metadata](#instance-metadata) | AWS Region for the kubernetes cluster |
73+
|aws-vpc-id | string | [instance metadata](#instance-metadata) | AWS VPC ID for the Kubernetes cluster |
7474
|backend-security-group | string | | Backend security group id to use for the ingress rules on the worker node SG|
7575
|cluster-name | string | | Kubernetes cluster name|
7676
|default-ssl-policy | string | ELBSecurityPolicy-2016-08 | Default SSL Policy that will be applied to all Ingresses or Services that do not have the SSL Policy annotation |
7777
|default-tags | stringMap | | AWS Tags that will be applied to all AWS resources managed by this controller. Specified Tags takes highest priority |
7878
|default-target-type | string | instance | Default target type for Ingresses and Services - ip, instance |
7979
|[disable-ingress-class-annotation](#disable-ingress-class-annotation) | boolean | false | Disable new usage of the `kubernetes.io/ingress.class` annotation |
8080
|[disable-ingress-group-name-annotation](#disable-ingress-group-name-annotation) | boolean | false | Disallow new use of the `alb.ingress.kubernetes.io/group.name` annotation |
81-
|disable-restricted-sg-rules | boolean | false | Disable the usage of restricted security group rules |
81+
|disable-restricted-sg-rules | boolean | false | Disable the usage of restricted security group rules |
8282
|enable-backend-security-group | boolean | true | Enable sharing of security groups for backend traffic |
8383
|enable-endpoint-slices | boolean | false | Use EndpointSlices instead of Endpoints for pod endpoint and TargetGroupBinding resolution for load balancers with IP targets. |
8484
|enable-leader-election | boolean | true | Enable leader election for the load balancer controller manager. Enabling this will ensure there is only one active controller manager |
@@ -98,9 +98,11 @@ Currently, you can set only 1 namespace to watch in this flag. See [this Kuberne
9898
|log-level | string | info | Set the controller log level - info, debug |
9999
|metrics-bind-addr | string | :8080 | The address the metric endpoint binds to |
100100
|service-max-concurrent-reconciles | int | 3 | Maximum number of concurrently running reconcile loops for service |
101-
|[sync-period](#sync-period) | duration | 10h0m0s | Period at which the controller forces the repopulation of its local object stores|
101+
|[sync-period](#sync-period) | duration | 10h0m0s | Period at which the controller forces the repopulation of its local object stores|
102102
|targetgroupbinding-max-concurrent-reconciles | int | 3 | Maximum number of concurrently running reconcile loops for targetGroupBinding |
103103
|targetgroupbinding-max-exponential-backoff-delay | duration | 16m40s | Maximum duration of exponential backoff for targetGroupBinding reconcile failures |
104+
|tolerate-non-existent-backend-service | boolean | true | Whether to allow rules which refer to backend services that do not exist |
105+
|tolerate-non-existent-backend-action | boolean | true | Whether to allow rules which refer to backend actions that do not exist |
104106
|watch-namespace | string | | Namespace the controller watches for updates to Kubernetes objects, If empty, all namespaces are watched. |
105107
|webhook-bind-port | int | 9443 | The TCP port the Webhook server binds to |
106108
|webhook-cert-dir | string | /tmp/k8s-webhook-server/serving-certs | The directory that contains the server key and certificate |

helm/aws-load-balancer-controller/templates/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ spec:
122122
{{- if kindIs "bool" .Values.disableIngressGroupNameAnnotation }}
123123
- --disable-ingress-group-name-annotation={{ .Values.disableIngressGroupNameAnnotation }}
124124
{{- end }}
125+
{{- if kindIs "bool" .Values.tolerateNonExistentBackendService }}
126+
- --tolerate-non-existent-backend-service={{ .Values.tolerateNonExistentBackendService }}
127+
{{- end }}
128+
{{- if kindIs "bool" .Values.tolerateNonExistentBackendAction }}
129+
- --tolerate-non-existent-backend-action={{ .Values.tolerateNonExistentBackendAction }}
130+
{{- end }}
125131
{{- if .Values.defaultSSLPolicy }}
126132
- --default-ssl-policy={{ .Values.defaultSSLPolicy }}
127133
{{- end }}

helm/aws-load-balancer-controller/test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ disableIngressClassAnnotation:
209209
# disableIngressGroupNameAnnotation disables the usage of alb.ingress.kubernetes.io/group.name annotation, false by default
210210
disableIngressGroupNameAnnotation:
211211

212+
# tolerateNonExistentBackendService permits rules which specify backend services that don't exist, true by default
213+
tolerateNonExistentBackendService:
214+
215+
# tolerateNonExistentBackendAction permits rules which specify backend actions that don't exist, true by default
216+
tolerateNonExistentBackendAction:
217+
212218
# defaultSSLPolicy specifies the default SSL policy to use for TLS/HTTPS listeners
213219
defaultSSLPolicy:
214220

helm/aws-load-balancer-controller/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ disableIngressClassAnnotation:
227227
# disableIngressGroupNameAnnotation disables the usage of alb.ingress.kubernetes.io/group.name annotation, false by default
228228
disableIngressGroupNameAnnotation:
229229

230+
# tolerateNonExistentBackendService permits rules which specify backend services that don't exist, true by default
231+
tolerateNonExistentBackendService:
232+
233+
# tolerateNonExistentBackendAction permits rules which specify backend actions that don't exist, true by default
234+
tolerateNonExistentBackendAction:
235+
230236
# defaultSSLPolicy specifies the default SSL policy to use for TLS/HTTPS listeners
231237
defaultSSLPolicy:
232238

pkg/config/ingress_config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ const (
77
flagDisableIngressClassAnnotation = "disable-ingress-class-annotation"
88
flagDisableIngressGroupNameAnnotation = "disable-ingress-group-name-annotation"
99
flagIngressMaxConcurrentReconciles = "ingress-max-concurrent-reconciles"
10+
flagTolerateNonExistentBackendService = "tolerate-non-existent-backend-service"
11+
flagTolerateNonExistentBackendAction = "tolerate-non-existent-backend-action"
1012
defaultIngressClass = "alb"
1113
defaultDisableIngressClassAnnotation = false
1214
defaultDisableIngressGroupNameAnnotation = false
1315
defaultMaxIngressConcurrentReconciles = 3
16+
defaultTolerateNonExistentBackendService = true
17+
defaultTolerateNonExistentBackendAction = true
1418
)
1519

1620
// IngressConfig contains the configurations for the Ingress controller
@@ -30,6 +34,14 @@ type IngressConfig struct {
3034

3135
// Max concurrent reconcile loops for Ingress objects
3236
MaxConcurrentReconciles int
37+
38+
// TolerateNonExistentBackendService specifies whether to allow rules that reference a backend service that does not
39+
// exist. In this case, requests to that rule will result in a 503 error.
40+
TolerateNonExistentBackendService bool
41+
42+
// TolerateNonExistentBackendAction specifies whether to allow rules that reference a backend action that does not
43+
// exist. In this case, requests to that rule will result in a 503 error.
44+
TolerateNonExistentBackendAction bool
3345
}
3446

3547
// BindFlags binds the command line flags to the fields in the config object
@@ -42,4 +54,8 @@ func (cfg *IngressConfig) BindFlags(fs *pflag.FlagSet) {
4254
"Disable new usage of alb.ingress.kubernetes.io/group.name annotation")
4355
fs.IntVar(&cfg.MaxConcurrentReconciles, flagIngressMaxConcurrentReconciles, defaultMaxIngressConcurrentReconciles,
4456
"Maximum number of concurrently running reconcile loops for ingress")
57+
fs.BoolVar(&cfg.TolerateNonExistentBackendService, flagTolerateNonExistentBackendService, defaultTolerateNonExistentBackendService,
58+
"Tolerate rules that specify a non-existent backend service")
59+
fs.BoolVar(&cfg.TolerateNonExistentBackendAction, flagTolerateNonExistentBackendAction, defaultTolerateNonExistentBackendAction,
60+
"Tolerate rules that specify a non-existent backend action")
4561
}

pkg/ingress/enhanced_backend_builder.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ const (
2424
nonExistentBackendServiceMessageBody = "Backend service does not exist"
2525
// the message body of fixed 503 response used when referencing a non-existent annotation Action as backend.
2626
nonExistentBackendActionMessageBody = "Backend action does not exist"
27-
// by default, we tolerate a missing backend service, and use a fixed 503 response instead.
28-
defaultTolerateNonExistentBackendService = true
29-
// by default, we tolerate a missing backend action, and use a fixed 503 response instead.
30-
defaultTolerateNonExistentBackendAction = true
3127
)
3228

3329
// EnhancedBackend is an enhanced version of Ingress backend.
@@ -80,14 +76,13 @@ type EnhancedBackendBuilder interface {
8076
}
8177

8278
// NewDefaultEnhancedBackendBuilder constructs new defaultEnhancedBackendBuilder.
83-
func NewDefaultEnhancedBackendBuilder(k8sClient client.Client, annotationParser annotations.Parser, authConfigBuilder AuthConfigBuilder) *defaultEnhancedBackendBuilder {
79+
func NewDefaultEnhancedBackendBuilder(k8sClient client.Client, annotationParser annotations.Parser, authConfigBuilder AuthConfigBuilder, tolerateNonExistentBackendService bool, tolerateNonExistentBackendAction bool) *defaultEnhancedBackendBuilder {
8480
return &defaultEnhancedBackendBuilder{
85-
k8sClient: k8sClient,
86-
annotationParser: annotationParser,
87-
authConfigBuilder: authConfigBuilder,
88-
89-
tolerateNonExistentBackendService: defaultTolerateNonExistentBackendAction,
90-
tolerateNonExistentBackendAction: defaultTolerateNonExistentBackendService,
81+
k8sClient: k8sClient,
82+
annotationParser: annotationParser,
83+
authConfigBuilder: authConfigBuilder,
84+
tolerateNonExistentBackendService: tolerateNonExistentBackendService,
85+
tolerateNonExistentBackendAction: tolerateNonExistentBackendAction,
9186
}
9287
}
9388

pkg/ingress/model_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
29152915
certDiscovery := NewMockCertDiscovery(ctrl)
29162916
annotationParser := annotations.NewSuffixAnnotationParser("alb.ingress.kubernetes.io")
29172917
authConfigBuilder := NewDefaultAuthConfigBuilder(annotationParser)
2918-
enhancedBackendBuilder := NewDefaultEnhancedBackendBuilder(k8sClient, annotationParser, authConfigBuilder)
2918+
enhancedBackendBuilder := NewDefaultEnhancedBackendBuilder(k8sClient, annotationParser, authConfigBuilder, true, true)
29192919
ruleOptimizer := NewDefaultRuleOptimizer(logr.New(&log.NullLogSink{}))
29202920
trackingProvider := tracking.NewDefaultProvider("ingress.k8s.aws", clusterName)
29212921
stackMarshaller := deploy.NewDefaultStackMarshaller()

pkg/ingress/reference_indexer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func Test_defaultReferenceIndexer_BuildServiceRefIndexes(t *testing.T) {
314314
t.Run(tt.name, func(t *testing.T) {
315315
annotationParser := annotations.NewSuffixAnnotationParser("alb.ingress.kubernetes.io")
316316
authConfigBuilder := NewDefaultAuthConfigBuilder(annotationParser)
317-
enhancedBackendBuilder := NewDefaultEnhancedBackendBuilder(nil, annotationParser, nil)
317+
enhancedBackendBuilder := NewDefaultEnhancedBackendBuilder(nil, annotationParser, nil, true, true)
318318
i := &defaultReferenceIndexer{
319319
enhancedBackendBuilder: enhancedBackendBuilder,
320320
authConfigBuilder: authConfigBuilder,
@@ -365,7 +365,7 @@ func Test_defaultReferenceIndexer_BuildSecretRefIndexes(t *testing.T) {
365365
t.Run(tt.name, func(t *testing.T) {
366366
annotationParser := annotations.NewSuffixAnnotationParser("alb.ingress.kubernetes.io")
367367
authConfigBuilder := NewDefaultAuthConfigBuilder(annotationParser)
368-
enhancedBackendBuilder := NewDefaultEnhancedBackendBuilder(nil, annotationParser, nil)
368+
enhancedBackendBuilder := NewDefaultEnhancedBackendBuilder(nil, annotationParser, nil, true, true)
369369
i := &defaultReferenceIndexer{
370370
enhancedBackendBuilder: enhancedBackendBuilder,
371371
authConfigBuilder: authConfigBuilder,

0 commit comments

Comments
 (0)