Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: argo rollout compatibility with emissary and edge stack v2.0 #1330

Merged
merged 2 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/getting-started/ambassador/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ This tutorial will walk you through the process of configuring Argo Rollouts to
- Kubernetes cluster
- Argo-Rollouts installed in the cluster

---
**Note**
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.
---

## 1. Install and configure Ambassador Edge Stack

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/).
Expand Down
11 changes: 11 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12778,6 +12778,17 @@ rules:
- update
- list
- delete
- apiGroups:
- x.getambassador.io
resources:
- ambassadormappings
verbs:
- create
- watch
- get
- update
- list
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
11 changes: 11 additions & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12694,6 +12694,17 @@ rules:
- update
- list
- delete
- apiGroups:
- x.getambassador.io
resources:
- ambassadormappings
verbs:
- create
- watch
- get
- update
- list
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
11 changes: 11 additions & 0 deletions manifests/role/argo-rollouts-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,14 @@ rules:
- update
- list
- delete
- apiGroups:
- x.getambassador.io
resources:
- ambassadormappings
verbs:
- create
- watch
- get
- update
- list
- delete
16 changes: 14 additions & 2 deletions rollout/trafficrouting/ambassador/ambassador.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const (

var (
ambassadorAPIVersion = defaults.DefaultAmbassadorVersion
apiGroupToResource = map[string]string{
"getambassador.io": "mappings",
"x.getambassador.io": "ambassadormappings",
}
)

func SetAPIVersion(apiVersion string) {
Expand Down Expand Up @@ -300,11 +304,19 @@ func GetMappingGVR() schema.GroupVersionResource {

func toMappingGVR(apiVersion string) schema.GroupVersionResource {
parts := strings.Split(apiVersion, "/")
group := defaults.DefaultAmbassadorAPIGroup
if len(parts) > 1 {
group = parts[0]
}
resourcename, known := apiGroupToResource[group]
if !known {
resourcename = apiGroupToResource[defaults.DefaultAmbassadorAPIGroup]
}
version := parts[len(parts)-1]
return schema.GroupVersionResource{
Group: "getambassador.io",
Group: group,
Version: version,
Resource: "mappings",
Resource: resourcename,
}
}

Expand Down
56 changes: 55 additions & 1 deletion rollout/trafficrouting/ambassador/ambassador_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ spec:
service: myapp:8080
weight: 20`

baseV3Mapping = `
apiVersion: x.getambassador.io/v3alpha1
kind: AmbassadorMapping
metadata:
name: myapp-mapping
namespace: default
spec:
hostname: 'example.com'
prefix: /myapp/
rewrite: /myapp/
service: myapp:8080`

canaryMapping = `
apiVersion: getambassador.io/v2
kind: Mapping
Expand Down Expand Up @@ -237,6 +249,34 @@ func TestReconciler_SetWeight(t *testing.T) {
assert.Equal(t, 0, len(f.fakeClient.updateInvokations))
assert.Equal(t, 0, len(f.fakeClient.deleteInvokations))
})
t.Run("will create canary ambassadormapping and set weight successfully", func(t *testing.T) {
// given
t.Parallel()
f := setup()
getReturns := []*getReturn{
{err: k8serrors.NewNotFound(schema.GroupResource{}, "canary-mapping")},
{obj: toUnstructured(t, baseV3Mapping)},
}
createReturns := []*createReturn{
{nil, nil},
}
f.fakeClient.getReturns = getReturns
f.fakeClient.createReturns = createReturns

// when
err := f.reconciler.SetWeight(13)

// then
assert.NoError(t, err)
assert.Equal(t, 2, len(f.fakeClient.getInvokations))
assert.Equal(t, "myapp-mapping-canary", f.fakeClient.getInvokations[0].name)
assert.Equal(t, "myapp-mapping", f.fakeClient.getInvokations[1].name)
assert.Equal(t, 1, len(f.fakeClient.createInvokations))
assert.Equal(t, int64(13), ambassador.GetMappingWeight(f.fakeClient.createInvokations[0].obj))
assert.Equal(t, "canary-service:8080", ambassador.GetMappingService(f.fakeClient.createInvokations[0].obj))
assert.Equal(t, 0, len(f.fakeClient.updateInvokations))
assert.Equal(t, 0, len(f.fakeClient.deleteInvokations))
})
t.Run("will create canary mapping with no service port", func(t *testing.T) {
// given
t.Parallel()
Expand Down Expand Up @@ -522,11 +562,25 @@ func TestGetMappingGVR(t *testing.T) {
gvr := ambassador.GetMappingGVR()

// then
assert.Equal(t, "getambassador.io", gvr.Group)
assert.Equal(t, "invalid.com", gvr.Group)
assert.Equal(t, "v1alpha1", gvr.Version)
assert.Equal(t, "mappings", gvr.Resource)
assert.Equal(t, apiVersion, ambassador.GetAPIVersion())
})
t.Run("will get correct gvr for x.getambassador.io api group", func(t *testing.T) {
// given
apiVersion := "x.getambassador.io/v3alpha1"
ambassador.SetAPIVersion(apiVersion)

// when
gvr := ambassador.GetMappingGVR()

// then
assert.Equal(t, "x.getambassador.io", gvr.Group)
assert.Equal(t, "v3alpha1", gvr.Version)
assert.Equal(t, "ambassadormappings", gvr.Resource)
assert.Equal(t, apiVersion, ambassador.GetAPIVersion())
})
}

func toUnstructured(t *testing.T, manifest string) *unstructured.Unstructured {
Expand Down
3 changes: 2 additions & 1 deletion utils/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const (
)

const (
DefaultAmbassadorVersion = "v2"
DefaultAmbassadorAPIGroup = "getambassador.io"
DefaultAmbassadorVersion = "getambassador.io/v2"
DefaultIstioVersion = "v1alpha3"
DefaultSMITrafficSplitVersion = "v1alpha1"
)
Expand Down