Skip to content

Commit 344896f

Browse files
authored
add unit tests and fix annotation-based forward (kubernetes-sigs#1507)
1 parent 1343015 commit 344896f

File tree

11 files changed

+2039
-11
lines changed

11 files changed

+2039
-11
lines changed

controllers/ingress/group_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (r *groupReconciler) buildAndDeployModel(ctx context.Context, ingGroup ingr
148148
if err := r.stackDeployer.Deploy(ctx, stack); err != nil {
149149
return nil, nil, err
150150
}
151-
r.logger.Info("successfully deployed model")
151+
r.logger.Info("successfully deployed model", "ingressGroup", ingGroup.ID)
152152
return stack, lb, err
153153
}
154154

controllers/service/service_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (r *serviceReconciler) buildAndDeployModel(ctx context.Context, svc *corev1
9999
if err = r.stackDeployer.Deploy(ctx, stack); err != nil {
100100
return nil, nil, err
101101
}
102-
r.logger.Info("successfully deployed model")
102+
r.logger.Info("successfully deployed model", "service", k8s.NamespacedName(svc))
103103

104104
return stack, lb, nil
105105
}

docs/guide/ingress/annotations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Traffic Routing can be controlled with following annotations:
199199
alb.ingress.kubernetes.io/actions.forward-single-tg: >
200200
{"type":"forward","targetGroupARN": "arn-of-your-target-group"}
201201
alb.ingress.kubernetes.io/actions.forward-multiple-tg: >
202-
{"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"service-1","servicePort":"80","weight":20},{"serviceName":"service-2","servicePort":"80","weight":20},{"targetGroupARN":"arn-of-your-non-k8s-target-group","weight":60}],"targetGroupStickinessConfig":{"enabled":true,"durationSeconds":200}}}
202+
{"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"service-1","servicePort":"http","weight":20},{"serviceName":"service-2","servicePort":80,"weight":20},{"targetGroupARN":"arn-of-your-non-k8s-target-group","weight":60}],"targetGroupStickinessConfig":{"enabled":true,"durationSeconds":200}}}
203203
spec:
204204
rules:
205205
- http:

mocks/ingress/mock_cert_discovery.go

+49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/networking/mock_subnet_resolver.go

+51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ingress/config_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (c *QueryStringKeyValuePair) validate() error {
276276
// Information about a query string condition.
277277
type QueryStringConditionConfig struct {
278278
// One or more key/value pairs or values to find in the query string.
279-
Values []*QueryStringKeyValuePair `json:"values"`
279+
Values []QueryStringKeyValuePair `json:"values"`
280280
}
281281

282282
func (c *QueryStringConditionConfig) validate() error {

pkg/ingress/enhanced_backend_builder.go

+12
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ func (b *defaultEnhancedBackendBuilder) buildActionViaAnnotation(_ context.Conte
102102
}
103103
action.TargetGroupARN = nil
104104
}
105+
106+
// normalize servicePort to be int type if possible.
107+
// this is for backwards-compatibility with old AWSALBIngressController, where ServicePort is defined as Type string.
108+
if action.Type == ActionTypeForward && action.ForwardConfig != nil {
109+
for _, tgt := range action.ForwardConfig.TargetGroups {
110+
if tgt.ServicePort != nil {
111+
normalizedSVCPort := intstr.Parse(tgt.ServicePort.String())
112+
*tgt.ServicePort = normalizedSVCPort
113+
}
114+
}
115+
}
116+
105117
return action, nil
106118
}
107119

0 commit comments

Comments
 (0)