Skip to content

Commit 9b158f5

Browse files
authored
Merge pull request #4029 from mikutas/3518
Add `targetType` field to IngressClassParams
2 parents 6413d24 + 20277e7 commit 9b158f5

File tree

6 files changed

+347
-3
lines changed

6 files changed

+347
-3
lines changed

apis/elbv2/v1beta1/ingressclassparams_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ type IngressClassParamsSpec struct {
152152
// Tags defines list of Tags on AWS resources provisioned for Ingresses that belong to IngressClass with this IngressClassParams.
153153
Tags []Tag `json:"tags,omitempty"`
154154

155+
// TargetType defines the target type of target groups for all Ingresses that belong to IngressClass with this IngressClassParams.
156+
// +optional
157+
TargetType TargetType `json:"targetType,omitempty"`
158+
155159
// LoadBalancerAttributes define the custom attributes to LoadBalancers for all Ingress that that belong to IngressClass with this IngressClassParams.
156160
// +optional
157161
LoadBalancerAttributes []Attribute `json:"loadBalancerAttributes,omitempty"`

config/crd/bases/elbv2.k8s.aws_ingressclassparams.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ spec:
261261
- value
262262
type: object
263263
type: array
264+
targetType:
265+
description: TargetType defines the target type of target groups for
266+
all Ingresses that belong to IngressClass with this IngressClassParams.
267+
enum:
268+
- instance
269+
- ip
270+
type: string
264271
type: object
265272
type: object
266273
served: true

docs/guide/ingress/ingress_class.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ You can use IngressClassParams to enforce settings for a set of Ingresses.
150150
minimumLoadBalancerCapacity:
151151
capacityUnits: 1000
152152
```
153+
- with targetType
154+
```
155+
apiVersion: elbv2.k8s.aws/v1beta1
156+
kind: IngressClassParams
157+
metadata:
158+
name: class2048-config
159+
spec:
160+
targetType: ip
161+
```
153162

154163
### IngressClassParams specification
155164

@@ -188,7 +197,7 @@ If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/inboun
188197

189198
#### spec.certificateArn
190199
Cluster administrators can use the optional `certificateARN` field to specify the ARN of the certificates for all Ingresses that belong to IngressClass with this IngressClassParams.
191-
200+
192201
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/certificate-arn` annotation.
193202

194203
#### spec.sslPolicy
@@ -235,6 +244,13 @@ Cluster administrators can use `tags` field to specify the custom tags for AWS r
235244
2. `spec.tags` in IngressClassParams will have the middle priority.
236245
3. `alb.ingress.kubernetes.io/tags` annotation will have the lowest priority.
237246

247+
#### spec.targetType
248+
249+
`targetType` is an optional setting. The available options are `instance` or `ip`.
250+
251+
This defines the target type of target groups for all Ingresses that belong to IngressClass with this IngressClassParams.
252+
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/target-type` annotation.
253+
238254
#### spec.loadBalancerAttributes
239255

240256
`loadBalancerAttributes` is an optional setting.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ spec:
260260
- value
261261
type: object
262262
type: array
263+
targetType:
264+
description: TargetType defines the target type of target groups for
265+
all Ingresses that belong to IngressClass with this IngressClassParams.
266+
enum:
267+
- instance
268+
- ip
269+
type: string
263270
type: object
264271
type: object
265272
served: true

pkg/ingress/model_build_target_group.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingNetworking(_ context.Cont
151151
func (t *defaultModelBuildTask) buildTargetGroupSpec(ctx context.Context,
152152
ing ClassifiedIngress, svc *corev1.Service, port intstr.IntOrString, svcPort corev1.ServicePort) (elbv2model.TargetGroupSpec, error) {
153153
svcAndIngAnnotations := algorithm.MergeStringMap(svc.Annotations, ing.Ing.Annotations)
154-
targetType, err := t.buildTargetGroupTargetType(ctx, svcAndIngAnnotations)
154+
targetType, err := t.buildTargetGroupTargetType(ctx, svcAndIngAnnotations, ing.IngClassConfig)
155155
if err != nil {
156156
return elbv2model.TargetGroupSpec{}, err
157157
}
@@ -218,9 +218,12 @@ func (t *defaultModelBuildTask) buildTargetGroupName(_ context.Context,
218218
return fmt.Sprintf("k8s-%.8s-%.8s-%.10s", sanitizedNamespace, sanitizedName, uuid)
219219
}
220220

221-
func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string) (elbv2model.TargetType, error) {
221+
func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string, classCfg ClassConfiguration) (elbv2model.TargetType, error) {
222222
rawTargetType := string(t.defaultTargetType)
223223
_ = t.annotationParser.ParseStringAnnotation(annotations.IngressSuffixTargetType, &rawTargetType, svcAndIngAnnotations)
224+
if classCfg.IngClassParams != nil && classCfg.IngClassParams.Spec.TargetType != "" {
225+
rawTargetType = string(classCfg.IngClassParams.Spec.TargetType)
226+
}
224227
switch rawTargetType {
225228
case string(elbv2model.TargetTypeInstance):
226229
return elbv2model.TargetTypeInstance, nil

0 commit comments

Comments
 (0)