Skip to content

Commit

Permalink
feat: Allow Traffic shaping through header based routing ALB. e2e tes…
Browse files Browse the repository at this point in the history
…ts for header route

Signed-off-by: Andrii Perenesenko <andrii.perenesenko@gmail.com>
  • Loading branch information
perenesenko committed May 31, 2022
1 parent b31015b commit b9e4021
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/e2e/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (

"github.com/stretchr/testify/suite"
"github.com/tj/assert"
"k8s.io/utils/pointer"

"github.com/argoproj/argo-rollouts/rollout/trafficrouting/istio"
"github.com/argoproj/argo-rollouts/test/fixtures"
ingress2 "github.com/argoproj/argo-rollouts/utils/ingress"
)
Expand Down Expand Up @@ -171,3 +173,74 @@ func (s *AWSSuite) TestALBExperimentStepNoSetWeight() {
Then().
Assert(assertWeights(s, "alb-rollout-canary", "alb-rollout-stable", 0, 100))
}

func (s *AWSSuite) TestAlbHeaderRoute() {
s.Given().
RolloutObjects("@header-routing/alb-header-route.yaml").
When().
ApplyManifests().
WaitForRolloutStatus("Healthy").
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionDoesNotExist(t, s, istio.HeaderRouteName)
assertAlbActionServiceWeight(t, s, "action1", "canary-service", 0)
assertAlbActionServiceWeight(t, s, "action1", "stable-service", 100)
}).
When().
UpdateSpec().
WaitForRolloutStatus("Paused").
Sleep(1 * time.Second).
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionDoesNotExist(t, s, istio.HeaderRouteName)
assertAlbActionServiceWeight(t, s, "action1", "canary-service", 20)
assertAlbActionServiceWeight(t, s, "action1", "stable-service", 80)
}).
When().
PromoteRollout().
WaitForRolloutStatus("Paused").
Sleep(1 * time.Second).
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionServiceWeight(t, s, istio.HeaderRouteName, "canary-service", 100)
assertAlbActionServiceWeight(t, s, "action1", "canary-service", 20)
assertAlbActionServiceWeight(t, s, "action1", "stable-service", 80)
}).
When().
PromoteRollout().
WaitForRolloutStatus("Paused").
Sleep(1 * time.Second).
Then().
Assert(func(t *fixtures.Then) {
assertAlbActionDoesNotExist(t, s, istio.HeaderRouteName)
})
}

func assertAlbActionServiceWeight(t *fixtures.Then, s *AWSSuite, actionName, serviceName string, expectedWeight int64) {
ingress := t.GetALBIngress()
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)
}
103 changes: 103 additions & 0 deletions test/e2e/header-routing/alb-header-route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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-ingress
annotations:
alb.ingress.kubernetes.io/security-groups: 'iks-intuit-cidr-ingress-tcp-443'
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-2:795188202216:certificate/27d920c5-a8a6-4210-9f31-bd4a2d439039
alb.ingress.kubernetes.io/load-balancer-attributes: access_logs.s3.enabled=false
alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-2-2017-01
kubernetes.io/ingress.class: aws-alb
alb.ingress.kubernetes.io/load-balancer-name: rollouts-sample
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
alb.ingress.kubernetes.io/healthcheck-path: /color
alb.ingress.kubernetes.io/backend-protocol: HTTP
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS": 443}]'
alb.ingress.kubernetes.io/ssl-redirect: '443'
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/subnets: IngressSubnetAz1, IngressSubnetAz2, IngressSubnetAz3
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:
alb:
ingress: alb-rollout-ingress
rootService: action1
servicePort: 8080
steps:
- setWeight: 20
- pause: {}
- setHeaderRouting:
match:
- headerName: Custom-Header
headerValue:
exact: Mozilla*
- pause: {}
- setHeaderRouting: {}
- pause: {}

0 comments on commit b9e4021

Please sign in to comment.