Skip to content

Commit

Permalink
add e2e TestAlbHeaderRouteMultiIngress
Browse files Browse the repository at this point in the history
Signed-off-by: n888 <[email protected]>
  • Loading branch information
n888 committed Apr 18, 2023
1 parent 4585d60 commit 77ea4d2
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/e2e/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,48 @@ func (s *AWSSuite) TestAlbHeaderRoute() {
})
}

func (s *AWSSuite) TestAlbHeaderRouteMultiIngress() {
s.Given().
RolloutObjects("@header-routing/alb-header-route-multi-ingress.yaml").
When().
ApplyManifests().
WaitForRolloutStatus("Healthy").
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionDoesNotExistMultiIngress(t, s, "header-route")
assertAlbActionServiceWeightMultiIngress(t, s, "action1", "canary-service", 0)
assertAlbActionServiceWeightMultiIngress(t, s, "action1", "stable-service", 100)
}).
When().
UpdateSpec().
WaitForRolloutStatus("Paused").
Sleep(5 * time.Second).
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionDoesNotExistMultiIngress(t, s, "header-route")
assertAlbActionServiceWeightMultiIngress(t, s, "action1", "canary-service", 20)
assertAlbActionServiceWeightMultiIngress(t, s, "action1", "stable-service", 80)
}).
When().
PromoteRollout().
WaitForRolloutStatus("Paused").
Sleep(5 * time.Second).
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionServiceWeightMultiIngress(t, s, "header-route", "canary-service", 100)
assertAlbActionServiceWeightMultiIngress(t, s, "action1", "canary-service", 20)
assertAlbActionServiceWeightMultiIngress(t, s, "action1", "stable-service", 80)
}).
When().
PromoteRollout().
WaitForRolloutStatus("Paused").
Sleep(5 * time.Second).
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionDoesNotExistMultiIngress(t, s, "header-route")
})
}

func assertAlbActionServiceWeight(t *fixtures.Then, s *AWSSuite, actionName, serviceName string, expectedWeight int64) {
ingress := t.GetALBIngress()
key := "alb.ingress.kubernetes.io/actions." + actionName
Expand All @@ -370,9 +412,42 @@ func assertAlbActionServiceWeight(t *fixtures.Then, s *AWSSuite, actionName, ser
assert.True(s.T(), found, "Service %s was not found", serviceName)
}

func assertAlbActionServiceWeightMultiIngress(t *fixtures.Then, s *AWSSuite, actionName, serviceName string, expectedWeight int64) {
ingresses := t.GetALBIngresses()
for _, ingress := range ingresses {
key := "alb.ingress.kubernetes.io/actions." + actionName
actionStr, ok := ingress.Annotations[key]
assert.True(s.T(), ok, "Annotation for action was not found: %s", key)

var albAction ingress2.ALBAction
err := json.Unmarshal([]byte(actionStr), &albAction)
if err != nil {
panic(err)
}

found := false
for _, group := range albAction.ForwardConfig.TargetGroups {
if group.ServiceName == serviceName {
assert.Equal(s.T(), pointer.Int64(expectedWeight), group.Weight)
found = true
}
}
assert.True(s.T(), found, "Service %s was not found", serviceName)
}
}

func assertAlbActionDoesNotExist(t *fixtures.Then, s *AWSSuite, actionName string) {
ingress := t.GetALBIngress()
key := "alb.ingress.kubernetes.io/actions." + actionName
_, ok := ingress.Annotations[key]
assert.False(s.T(), ok, "Annotation for action should not exist: %s", key)
}

func assertAlbActionDoesNotExistMultiIngress(t *fixtures.Then, s *AWSSuite, actionName string) {
ingresses := t.GetALBIngresses()
for _, ingress := range ingresses {
key := "alb.ingress.kubernetes.io/actions." + actionName
_, ok := ingress.Annotations[key]
assert.False(s.T(), ok, "Annotation for action should not exist: %s", key)
}
}
112 changes: 112 additions & 0 deletions test/e2e/header-routing/alb-header-route-multi-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
apiVersion: v1
kind: Service
metadata:
name: canary-service
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: http
selector:
app: alb-rollout
---
apiVersion: v1
kind: Service
metadata:
name: stable-service
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: http
selector:
app: alb-rollout
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: alb-rollout-multi-ingress-1
annotations:
kubernetes.io/ingress.class: alb
spec:
rules:
- http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: action1
port:
name: use-annotation
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: alb-rollout-multi-ingress-2
annotations:
kubernetes.io/ingress.class: alb
spec:
rules:
- http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: action1
port:
name: use-annotation
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollouts-demo
spec:
replicas: 5
selector:
matchLabels:
app: alb-rollout
template:
metadata:
labels:
app: alb-rollout
spec:
containers:
- name: alb-rollout
image: "argoproj/rollouts-demo:yellow"
ports:
- name: http
containerPort: 8080
protocol: TCP
strategy:
canary:
scaleDownDelaySeconds: 5
stableService: stable-service
canaryService: canary-service
trafficRouting:
managedRoutes:
- name: header-route
alb:
ingresses:
- alb-rollout-multi-ingress-1
- alb-rollout-multi-ingress-2
rootService: action1
servicePort: 8080
steps:
- setWeight: 20
- pause: {}
- setHeaderRoute:
name: header-route
match:
- headerName: Custom-Header
headerValue:
exact: Mozilla*
- pause: {}
- setHeaderRoute:
name: header-route
- pause: {}

0 comments on commit 77ea4d2

Please sign in to comment.