Skip to content

Commit da5e875

Browse files
authored
Merge pull request #801 from gigi-at-zymergen/797
#797 Add a forward actions annotation to allow forwarding to external target groups
2 parents 63e5be0 + c37d7e5 commit da5e875

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Migrating From Legacy Apps with Manually Configured Target Groups
2+
3+
Many organizations are decomposing old legacy apps into smaller services and components.
4+
5+
During the transition they may be running a hybrid ecosystem with some parts of the app running in ec2 instances,
6+
some in Kubernetes microservices, and possibly even some in serverless environments like Lambda.
7+
8+
The existing clients of the application expect all endpoints under one DNS entry and it's desirable to be able
9+
to route traffic at the ALB to services running outside the Kubernetes cluster.
10+
11+
The actions annotation allows the definition of a forward rule to a previously configured target group.
12+
Learn more about the actions annotation at
13+
[`alb.ingress.kubernetes.io/actions.${action-name}`](../ingress/annotation.md#actions)
14+
15+
## Example Ingress Manifest
16+
```yaml
17+
apiVersion: extensions/v1beta1
18+
kind: Ingress
19+
metadata:
20+
namespace: testcase
21+
name: echoserver
22+
annotations:
23+
kubernetes.io/ingress.class: alb
24+
alb.ingress.kubernetes.io/actions.legacy-app: '{"Type": "forward", "TargetGroupArn": "legacy-tg-arn"}'
25+
spec:
26+
rules:
27+
- http:
28+
paths:
29+
- path: /v1/endpoints
30+
backend:
31+
serviceName: legacy-app
32+
servicePort: use-annotation
33+
- path: /normal-path
34+
backend:
35+
serviceName: echoserver
36+
servicePort: 80
37+
```
38+
39+
!!!note
40+
The `TargetGroupArn` must be set and the user is responsible for configuring the Target group in AWS before applying
41+
the forward rule.
42+

internal/ingress/annotations/action/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (a action) Parse(ing parser.AnnotationInterface) (interface{}, error) {
6161
if data.RedirectConfig == nil {
6262
return nil, fmt.Errorf("%v is type redirect but did not include a valid RedirectConfig configuration", serviceName)
6363
}
64+
case "forward":
65+
if data.TargetGroupArn == nil {
66+
return nil, fmt.Errorf("%v is type forward but did not include a valid TargetGroupArn configuration", serviceName)
67+
}
6468
default:
6569
return nil, fmt.Errorf("an invalid action type %v was configured in %v", *data.Type, serviceName)
6670
}
@@ -158,6 +162,10 @@ func Dummy() *Config {
158162
MessageBody: aws.String("message body"),
159163
},
160164
}),
165+
"forward": setDefaults(&elbv2.Action{
166+
Type: aws.String(elbv2.ActionTypeEnumForward),
167+
TargetGroupArn: aws.String("legacy-tg-arn"),
168+
}),
161169
},
162170
}
163171
}

internal/ingress/annotations/action/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestIngressActions(t *testing.T) {
2222
"StatusCode":"503", "MessageBody":"message body"}}`
2323
data[parser.GetAnnotationWithPrefix("actions.redirect-action")] = `{"Type": "redirect", "RedirectConfig": {"Protocol":"HTTPS",
2424
"Port":"443", "Host":"#{host}", "Path": "/#{path}", "Query": "#{query}", "StatusCode": "HTTP_301"}}`
25+
data[parser.GetAnnotationWithPrefix("actions.forward")] = `{"Type": "forward", "TargetGroupArn": "legacy-tg-arn"}`
2526
ing.SetAnnotations(data)
2627

2728
ai, err := NewParser(mockBackend{}).Parse(ing)

0 commit comments

Comments
 (0)