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 1 commit
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
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
1 change: 1 addition & 0 deletions utils/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
)

const (
DefaultAmbassadorAPIGroup = "getambassador.io"
DefaultAmbassadorVersion = "v2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it seems this change now accepts API version with or without the group in it. e.g.:

rollouts-controller --ambassador-api-version v2
rollouts-controller --ambassador-api-version getambassador.io/v2
rollouts-controller --ambassador-api-version x.getambassador.io/v3alpha1

Now that we support supplying a different group, can we change DefaultAmbassadorVersion to be getambassador.io/v2 so that when users see the --help of the rollout controller, they know that this is possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense.

DefaultIstioVersion = "v1alpha3"
DefaultSMITrafficSplitVersion = "v1alpha1"
Expand Down