Skip to content

Commit a4f6ffc

Browse files
committed
Add TargetType field to IngressClassParams
1 parent d0df42b commit a4f6ffc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
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"`

docs/guide/ingress/ingress_class.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/inboun
188188

189189
#### spec.certificateArn
190190
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-
191+
192192
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/certificate-arn` annotation.
193193

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

238+
#### spec.targetType
239+
240+
`targetType` is an optional setting. The available options are `instance` or `ip`.
241+
242+
This defines the target type of target groups for all Ingresses that belong to IngressClass with this IngressClassParams.
243+
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/target-type` annotation.
244+
238245
#### spec.loadBalancerAttributes
239246

240247
`loadBalancerAttributes` is an optional setting.

pkg/ingress/model_build_target_group.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"crypto/sha256"
66
"encoding/hex"
77
"fmt"
8-
awssdk "github.com/aws/aws-sdk-go-v2/aws"
98
"regexp"
109
"strconv"
1110

11+
awssdk "github.com/aws/aws-sdk-go-v2/aws"
12+
1213
"github.com/pkg/errors"
1314
corev1 "k8s.io/api/core/v1"
1415
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -153,7 +154,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingNetworking(ctx context.Co
153154
func (t *defaultModelBuildTask) buildTargetGroupSpec(ctx context.Context,
154155
ing ClassifiedIngress, svc *corev1.Service, port intstr.IntOrString, svcPort corev1.ServicePort) (elbv2model.TargetGroupSpec, error) {
155156
svcAndIngAnnotations := algorithm.MergeStringMap(svc.Annotations, ing.Ing.Annotations)
156-
targetType, err := t.buildTargetGroupTargetType(ctx, svcAndIngAnnotations)
157+
targetType, err := t.buildTargetGroupTargetType(ctx, svcAndIngAnnotations, ing.IngClassConfig)
157158
if err != nil {
158159
return elbv2model.TargetGroupSpec{}, err
159160
}
@@ -220,9 +221,12 @@ func (t *defaultModelBuildTask) buildTargetGroupName(_ context.Context,
220221
return fmt.Sprintf("k8s-%.8s-%.8s-%.10s", sanitizedNamespace, sanitizedName, uuid)
221222
}
222223

223-
func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string) (elbv2model.TargetType, error) {
224+
func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string, classCfg ClassConfiguration) (elbv2model.TargetType, error) {
224225
rawTargetType := string(t.defaultTargetType)
225226
_ = t.annotationParser.ParseStringAnnotation(annotations.IngressSuffixTargetType, &rawTargetType, svcAndIngAnnotations)
227+
if classCfg.IngClassParams != nil && classCfg.IngClassParams.Spec.TargetType != "" {
228+
rawTargetType = string(classCfg.IngClassParams.Spec.TargetType)
229+
}
226230
switch rawTargetType {
227231
case string(elbv2model.TargetTypeInstance):
228232
return elbv2model.TargetTypeInstance, nil

0 commit comments

Comments
 (0)