Skip to content

Commit e6bae87

Browse files
author
Alix Cook
authored
feat: argo rollout compatibility with emissary and edge stack v2.0 (argoproj#1330)
Signed-off-by: Alix Cook <[email protected]>
1 parent f628aa6 commit e6bae87

File tree

7 files changed

+109
-4
lines changed

7 files changed

+109
-4
lines changed

docs/getting-started/ambassador/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ This tutorial will walk you through the process of configuring Argo Rollouts to
77
- Kubernetes cluster
88
- Argo-Rollouts installed in the cluster
99

10+
---
11+
**Note**
12+
If using Ambassador Edge Stack or Emissary-ingress 2.0+, you will need to install Argo-Rollouts version v1.1+, and you will need to supply `--ambassador-api-version x.getambassador.io/v3alpha1` to your `argo-rollouts` deployment.
13+
---
14+
1015
## 1. Install and configure Ambassador Edge Stack
1116

1217
If you don't have Ambassador in your cluster you can install it following the [Edge Stack documentation](https://www.getambassador.io/docs/latest/topics/install/).

manifests/install.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12778,6 +12778,17 @@ rules:
1277812778
- update
1277912779
- list
1278012780
- delete
12781+
- apiGroups:
12782+
- x.getambassador.io
12783+
resources:
12784+
- ambassadormappings
12785+
verbs:
12786+
- create
12787+
- watch
12788+
- get
12789+
- update
12790+
- list
12791+
- delete
1278112792
---
1278212793
apiVersion: rbac.authorization.k8s.io/v1
1278312794
kind: ClusterRoleBinding

manifests/namespace-install.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12694,6 +12694,17 @@ rules:
1269412694
- update
1269512695
- list
1269612696
- delete
12697+
- apiGroups:
12698+
- x.getambassador.io
12699+
resources:
12700+
- ambassadormappings
12701+
verbs:
12702+
- create
12703+
- watch
12704+
- get
12705+
- update
12706+
- list
12707+
- delete
1269712708
---
1269812709
apiVersion: rbac.authorization.k8s.io/v1
1269912710
kind: ClusterRole

manifests/role/argo-rollouts-clusterrole.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,14 @@ rules:
170170
- update
171171
- list
172172
- delete
173+
- apiGroups:
174+
- x.getambassador.io
175+
resources:
176+
- ambassadormappings
177+
verbs:
178+
- create
179+
- watch
180+
- get
181+
- update
182+
- list
183+
- delete

rollout/trafficrouting/ambassador/ambassador.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const (
3636

3737
var (
3838
ambassadorAPIVersion = defaults.DefaultAmbassadorVersion
39+
apiGroupToResource = map[string]string{
40+
"getambassador.io": "mappings",
41+
"x.getambassador.io": "ambassadormappings",
42+
}
3943
)
4044

4145
func SetAPIVersion(apiVersion string) {
@@ -300,11 +304,19 @@ func GetMappingGVR() schema.GroupVersionResource {
300304

301305
func toMappingGVR(apiVersion string) schema.GroupVersionResource {
302306
parts := strings.Split(apiVersion, "/")
307+
group := defaults.DefaultAmbassadorAPIGroup
308+
if len(parts) > 1 {
309+
group = parts[0]
310+
}
311+
resourcename, known := apiGroupToResource[group]
312+
if !known {
313+
resourcename = apiGroupToResource[defaults.DefaultAmbassadorAPIGroup]
314+
}
303315
version := parts[len(parts)-1]
304316
return schema.GroupVersionResource{
305-
Group: "getambassador.io",
317+
Group: group,
306318
Version: version,
307-
Resource: "mappings",
319+
Resource: resourcename,
308320
}
309321
}
310322

rollout/trafficrouting/ambassador/ambassador_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ spec:
5454
service: myapp:8080
5555
weight: 20`
5656

57+
baseV3Mapping = `
58+
apiVersion: x.getambassador.io/v3alpha1
59+
kind: AmbassadorMapping
60+
metadata:
61+
name: myapp-mapping
62+
namespace: default
63+
spec:
64+
hostname: 'example.com'
65+
prefix: /myapp/
66+
rewrite: /myapp/
67+
service: myapp:8080`
68+
5769
canaryMapping = `
5870
apiVersion: getambassador.io/v2
5971
kind: Mapping
@@ -237,6 +249,34 @@ func TestReconciler_SetWeight(t *testing.T) {
237249
assert.Equal(t, 0, len(f.fakeClient.updateInvokations))
238250
assert.Equal(t, 0, len(f.fakeClient.deleteInvokations))
239251
})
252+
t.Run("will create canary ambassadormapping and set weight successfully", func(t *testing.T) {
253+
// given
254+
t.Parallel()
255+
f := setup()
256+
getReturns := []*getReturn{
257+
{err: k8serrors.NewNotFound(schema.GroupResource{}, "canary-mapping")},
258+
{obj: toUnstructured(t, baseV3Mapping)},
259+
}
260+
createReturns := []*createReturn{
261+
{nil, nil},
262+
}
263+
f.fakeClient.getReturns = getReturns
264+
f.fakeClient.createReturns = createReturns
265+
266+
// when
267+
err := f.reconciler.SetWeight(13)
268+
269+
// then
270+
assert.NoError(t, err)
271+
assert.Equal(t, 2, len(f.fakeClient.getInvokations))
272+
assert.Equal(t, "myapp-mapping-canary", f.fakeClient.getInvokations[0].name)
273+
assert.Equal(t, "myapp-mapping", f.fakeClient.getInvokations[1].name)
274+
assert.Equal(t, 1, len(f.fakeClient.createInvokations))
275+
assert.Equal(t, int64(13), ambassador.GetMappingWeight(f.fakeClient.createInvokations[0].obj))
276+
assert.Equal(t, "canary-service:8080", ambassador.GetMappingService(f.fakeClient.createInvokations[0].obj))
277+
assert.Equal(t, 0, len(f.fakeClient.updateInvokations))
278+
assert.Equal(t, 0, len(f.fakeClient.deleteInvokations))
279+
})
240280
t.Run("will create canary mapping with no service port", func(t *testing.T) {
241281
// given
242282
t.Parallel()
@@ -522,11 +562,25 @@ func TestGetMappingGVR(t *testing.T) {
522562
gvr := ambassador.GetMappingGVR()
523563

524564
// then
525-
assert.Equal(t, "getambassador.io", gvr.Group)
565+
assert.Equal(t, "invalid.com", gvr.Group)
526566
assert.Equal(t, "v1alpha1", gvr.Version)
527567
assert.Equal(t, "mappings", gvr.Resource)
528568
assert.Equal(t, apiVersion, ambassador.GetAPIVersion())
529569
})
570+
t.Run("will get correct gvr for x.getambassador.io api group", func(t *testing.T) {
571+
// given
572+
apiVersion := "x.getambassador.io/v3alpha1"
573+
ambassador.SetAPIVersion(apiVersion)
574+
575+
// when
576+
gvr := ambassador.GetMappingGVR()
577+
578+
// then
579+
assert.Equal(t, "x.getambassador.io", gvr.Group)
580+
assert.Equal(t, "v3alpha1", gvr.Version)
581+
assert.Equal(t, "ambassadormappings", gvr.Resource)
582+
assert.Equal(t, apiVersion, ambassador.GetAPIVersion())
583+
})
530584
}
531585

532586
func toUnstructured(t *testing.T, manifest string) *unstructured.Unstructured {

utils/defaults/defaults.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const (
3131
)
3232

3333
const (
34-
DefaultAmbassadorVersion = "v2"
34+
DefaultAmbassadorAPIGroup = "getambassador.io"
35+
DefaultAmbassadorVersion = "getambassador.io/v2"
3536
DefaultIstioVersion = "v1alpha3"
3637
DefaultSMITrafficSplitVersion = "v1alpha1"
3738
)

0 commit comments

Comments
 (0)