Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add targetType field to IngressClassParams #4029

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/elbv2/v1beta1/ingressclassparams_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ type IngressClassParamsSpec struct {
// Tags defines list of Tags on AWS resources provisioned for Ingresses that belong to IngressClass with this IngressClassParams.
Tags []Tag `json:"tags,omitempty"`

// TargetType defines the target type of target groups for all Ingresses that belong to IngressClass with this IngressClassParams.
// +optional
TargetType TargetType `json:"targetType,omitempty"`

// LoadBalancerAttributes define the custom attributes to LoadBalancers for all Ingress that that belong to IngressClass with this IngressClassParams.
// +optional
LoadBalancerAttributes []Attribute `json:"loadBalancerAttributes,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/elbv2.k8s.aws_ingressclassparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ spec:
- value
type: object
type: array
targetType:
description: TargetType defines the target type of target groups for
all Ingresses that belong to IngressClass with this IngressClassParams.
enum:
- instance
- ip
type: string
type: object
type: object
served: true
Expand Down
1 change: 0 additions & 1 deletion config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
Expand Down
9 changes: 8 additions & 1 deletion docs/guide/ingress/ingress_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/inboun

#### spec.certificateArn
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.

If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/certificate-arn` annotation.

#### spec.sslPolicy
Expand Down Expand Up @@ -225,6 +225,13 @@ Cluster administrators can use `tags` field to specify the custom tags for AWS r
2. `spec.tags` in IngressClassParams will have the middle priority.
3. `alb.ingress.kubernetes.io/tags` annotation will have the lowest priority.

#### spec.targetType

`targetType` is an optional setting. The available options are `instance` or `ip`.

This defines the target type of target groups for all Ingresses that belong to IngressClass with this IngressClassParams.
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/target-type` annotation.

#### spec.loadBalancerAttributes

`loadBalancerAttributes` is an optional setting.
Expand Down
7 changes: 7 additions & 0 deletions helm/aws-load-balancer-controller/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ spec:
- value
type: object
type: array
targetType:
description: TargetType defines the target type of target groups for
all Ingresses that belong to IngressClass with this IngressClassParams.
enum:
- instance
- ip
type: string
type: object
type: object
served: true
Expand Down
10 changes: 7 additions & 3 deletions pkg/ingress/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
awssdk "github.com/aws/aws-sdk-go-v2/aws"
"regexp"
"strconv"

awssdk "github.com/aws/aws-sdk-go-v2/aws"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -153,7 +154,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingNetworking(ctx context.Co
func (t *defaultModelBuildTask) buildTargetGroupSpec(ctx context.Context,
ing ClassifiedIngress, svc *corev1.Service, port intstr.IntOrString, svcPort corev1.ServicePort) (elbv2model.TargetGroupSpec, error) {
svcAndIngAnnotations := algorithm.MergeStringMap(svc.Annotations, ing.Ing.Annotations)
targetType, err := t.buildTargetGroupTargetType(ctx, svcAndIngAnnotations)
targetType, err := t.buildTargetGroupTargetType(ctx, svcAndIngAnnotations, ing.IngClassConfig)
if err != nil {
return elbv2model.TargetGroupSpec{}, err
}
Expand Down Expand Up @@ -220,9 +221,12 @@ func (t *defaultModelBuildTask) buildTargetGroupName(_ context.Context,
return fmt.Sprintf("k8s-%.8s-%.8s-%.10s", sanitizedNamespace, sanitizedName, uuid)
}

func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string) (elbv2model.TargetType, error) {
func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string, classCfg ClassConfiguration) (elbv2model.TargetType, error) {
rawTargetType := string(t.defaultTargetType)
_ = t.annotationParser.ParseStringAnnotation(annotations.IngressSuffixTargetType, &rawTargetType, svcAndIngAnnotations)
if classCfg.IngClassParams != nil && classCfg.IngClassParams.Spec.TargetType != "" {
rawTargetType = string(classCfg.IngClassParams.Spec.TargetType)
}
switch rawTargetType {
case string(elbv2model.TargetTypeInstance):
return elbv2model.TargetTypeInstance, nil
Expand Down
Loading