From 4cf057bb7060f157c25abfbf621af2d80fc0b063 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Thu, 10 Dec 2020 16:13:24 -0500 Subject: [PATCH 01/16] Small docs fixes Signed-off-by: Kevin Dorosh --- test/README.md | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/README.md b/test/README.md index 80d880ca4..5e0f21711 100644 --- a/test/README.md +++ b/test/README.md @@ -1,5 +1,6 @@ # Flagger end-to-end testing +<<<<<<< HEAD The e2e testing infrastructure is powered by GitHub Actions and [Kubernetes Kind](https://github.com/kubernetes-sigs/kind). ### e2e workflow @@ -12,3 +13,88 @@ The e2e testing infrastructure is powered by GitHub Actions and [Kubernetes Kind * test the canary initialization (port discovery and metadata) * test the canary release (progressive traffic shifting, headers routing, mirroring, analysis, promotion, rollback) * test webhooks (conformance, load testing, pre/post rollout) +======= +The e2e testing infrastructure is powered by CircleCI and [Kubernetes Kind](https://github.com/kubernetes-sigs/kind). + +### CircleCI e2e Istio workflow + +* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) +* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) +* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) +* install latest stable Helm CLI [e2e-istio.sh](e2e-istio.sh) +* deploy Tiller on the local cluster [e2e-istio.sh](e2e-istio.sh) +* install Istio CRDs with Helm [e2e-istio.sh](e2e-istio.sh) +* install Istio control plane and Prometheus with Helm [e2e-istio.sh](e2e-istio.sh) +* load Flagger image onto the local cluster [e2e-istio.sh](e2e-istio.sh) +* deploy Flagger in the istio-system namespace [e2e-istio.sh](e2e-istio.sh) +* create a test namespace with Istio injection enabled [e2e-tests.sh](e2e-tests.sh) +* deploy the load tester in the test namespace [e2e-tests.sh](e2e-tests.sh) +* deploy a demo workload (podinfo) in the test namespace [e2e-tests.sh](e2e-tests.sh) +* test the canary initialization [e2e-tests.sh](e2e-tests.sh) +* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-tests.sh](e2e-tests.sh) +* test the A/B testing analysis and promotion using cookies filters and pre/post rollout webhooks [e2e-tests.sh](e2e-tests.sh) + +### CircleCI e2e Linkerd workflow + +* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) +* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) +* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) +* install Linkerd [e2e-linkerd.sh](e2e-linkerd.sh) +* load Flagger image onto the local cluster [e2e-linkerd.sh](e2e-linkerd.sh) +* deploy Flagger in the linkerd namespace with Kustomize [e2e-linkerd.sh](e2e-linkerd.sh) +* create a test namespace with Linkerd injection enabled [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) +* deploy the load tester in the test namespace [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) +* deploy a demo workload (podinfo) in the test namespace [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) +* test the canary initialization with port discovery enabled and service target port [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) +* test the canary analysis and promotion using gRPC acceptance tests and HTTP load tests [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) +* test the canary rollback on HTTP 500 errors [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) + +### CircleCI e2e NGINX ingress workflow + +* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) +* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) +* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) +* install latest stable Helm CLI [e2e-nginx.sh](e2e-nginx.sh) +* deploy Tiller on the local cluster [e2e-nginx.sh](e2e-nginx.sh) +* install NGINX ingress with Helm [e2e-nginx.sh](e2e-nginx.sh) +* load Flagger image onto the local cluster [e2e-nginx.sh](e2e-nginx.sh) +* install Flagger and Prometheus in the ingress-nginx namespace [e2e-nginx.sh](e2e-nginx.sh) +* create a test namespace [e2e-nginx-tests.sh](e2e-nginx-tests.sh) +* deploy the load tester in the test namespace [e2e-nginx-tests.sh](e2e-nginx-tests.sh) +* deploy the demo workload (podinfo) and ingress in the test namespace [e2e-nginx-tests.sh](e2e-nginx-tests.sh) +* test the canary initialization [e2e-nginx-tests.sh](e2e-nginx-tests.sh) +* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-nginx-tests.sh](e2e-nginx-tests.sh) +* test the A/B testing analysis and promotion using header filters and pre/post rollout webhooks [e2e-nginx-tests.sh](e2e-nginx-tests.sh) +* cleanup test environment [e2e-nginx-cleanup.sh](e2e-nginx-cleanup.sh) +* install NGINX Ingress and Flagger with custom ingress annotations prefix [e2e-nginx-custom-annotations.sh](e2e-nginx-custom-annotations.sh) +* repeat the canary and A/B testing workflow [e2e-nginx-tests.sh](e2e-nginx-tests.sh) + +### CircleCI e2e Skipper ingress workflow + +* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) +* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) +* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) +* install Skipper ingress with Kustomize [e2e-skipper.sh](e2e-skipper.sh) +* load Flagger image onto the local cluster [e2e-skipper.sh](e2e-skipper.sh) +* install Flagger and Prometheus in the flagger-system namespace [e2e-skipper.sh](e2e-skipper.sh) +* create a test namespace [e2e-skipper-tests.sh](e2e-skipper-tests.sh) +* deploy the load tester in the test namespace [e2e-skipper-tests.sh](e2e-skipper-tests.sh) +* deploy the demo workload (podinfo) and ingress in the test namespace [e2e-skipper-tests.sh](e2e-skipper-tests.sh) +* test the canary initialization [e2e-skipper-tests.sh](e2e-skipper-tests.sh) +* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-skipper-tests.sh](e2e-skipper-tests.sh) +* cleanup test environment [e2e-skipper-cleanup.sh](e2e-skipper-cleanup.sh) + +### CircleCI e2e Traefik workflow + +* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) +* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) +* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) +* install Traeik with Helm [e2e-traefik.sh](e2e-traefik.sh) +* load Flagger image onto the local cluster [e2e-traefik.sh](e2e-traefik.sh) +* install Flagger and Prometheus in the traefik namespace [e2e-traefik.sh](e2e-traefik.sh) +* create a test namespace [e2e-traefik-tests.sh](e2e-traefik-tests.sh) +* deploy the load tester in the test namespace [e2e-traefik-tests.sh](e2e-traefik-tests.sh) +* deploy the demo workload (podinfo) and ingress in the test namespace [e2e-traefik-tests.sh](e2e-traefik-tests.sh) +* test the canary initialization [e2e-traefik-tests.sh](e2e-traefik-tests.sh) +* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-traefik-tests.sh](e2e-traefik-tests.sh) +>>>>>>> Small docs fixes From ffc1442891e19d2ae41a536a8380dc1267e663c1 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Thu, 10 Dec 2020 16:33:41 -0500 Subject: [PATCH 02/16] Initial commit Signed-off-by: Kevin Dorosh --- pkg/router/gloo.go | 4 ++-- test/gloo/install.sh | 2 +- test/gloo/test-canary.sh | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/router/gloo.go b/pkg/router/gloo.go index 5d0aa53d3..99434991f 100644 --- a/pkg/router/gloo.go +++ b/pkg/router/gloo.go @@ -17,7 +17,7 @@ import ( clientset "github.com/weaveworks/flagger/pkg/client/clientset/versioned" ) -// GlooRouter is managing Istio virtual services +// GlooRouter is managing Gloo route tables type GlooRouter struct { kubeClient kubernetes.Interface glooClient clientset.Interface @@ -26,7 +26,7 @@ type GlooRouter struct { upstreamDiscoveryNs string } -// Reconcile creates or updates the Istio virtual service +// Reconcile creates or updates the Gloo Edge route table func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error { apexName, _, _ := canary.GetServiceNames() canaryName := fmt.Sprintf("%s-%s-canary-%v", canary.Namespace, apexName, canary.Spec.Service.Port) diff --git a/test/gloo/install.sh b/test/gloo/install.sh index b68a60790..89a2f73a7 100755 --- a/test/gloo/install.sh +++ b/test/gloo/install.sh @@ -2,7 +2,7 @@ set -o errexit -GLOO_VER="1.3.28" +GLOO_VER="1.5.13" REPO_ROOT=$(git rev-parse --show-toplevel) mkdir -p ${REPO_ROOT}/bin diff --git a/test/gloo/test-canary.sh b/test/gloo/test-canary.sh index 72ea019ac..0410a55c2 100755 --- a/test/gloo/test-canary.sh +++ b/test/gloo/test-canary.sh @@ -1,11 +1,28 @@ #!/usr/bin/env bash # This script runs e2e tests for Canary initialization, analysis and promotion +<<<<<<< HEAD:test/gloo/test-canary.sh +======= +# Prerequisites: Kubernetes Kind, Helm and Gloo Edge ingress controller +>>>>>>> Initial commit:test/e2e-gloo-tests.sh set -o errexit REPO_ROOT=$(git rev-parse --show-toplevel) +<<<<<<< HEAD:test/gloo/test-canary.sh +======= +echo '>>> Creating test namespace' +kubectl create namespace test + +echo '>>> Installing load tester' +kubectl apply -k ${REPO_ROOT}/kustomize/tester +kubectl -n test rollout status deployment/flagger-loadtester + +echo '>>> Initializing canary' +kubectl apply -f ${REPO_ROOT}/test/e2e-workload.yaml + +>>>>>>> Initial commit:test/e2e-gloo-tests.sh cat < Date: Mon, 14 Dec 2020 15:53:11 -0500 Subject: [PATCH 03/16] Add route table codegen Signed-off-by: Kevin Dorosh --- pkg/apis/gloo/v1/doc.go | 2 +- pkg/apis/gloo/v1/types.go | 35 +++- pkg/apis/gloo/v1/zz_generated.deepcopy.go | 112 +++++++++-- pkg/client/clientset/versioned/clientset.go | 18 +- .../versioned/fake/clientset_generated.go | 10 +- .../clientset/versioned/fake/register.go | 4 +- .../clientset/versioned/scheme/register.go | 4 +- .../typed/gloo/v1/fake/fake_gloo_client.go | 8 +- .../typed/gloo/v1/fake/fake_routetable.go | 130 +++++++++++++ .../typed/gloo/v1/generated_expansion.go | 2 +- .../versioned/typed/gloo/v1/gloo_client.go | 30 +-- .../versioned/typed/gloo/v1/routetable.go | 178 ++++++++++++++++++ .../informers/externalversions/factory.go | 4 +- .../informers/externalversions/generic.go | 6 +- .../externalversions/gloo/v1/interface.go | 10 +- .../externalversions/gloo/v1/routetable.go | 90 +++++++++ .../listers/gloo/v1/expansion_generated.go | 12 +- pkg/client/listers/gloo/v1/routetable.go | 94 +++++++++ 18 files changed, 667 insertions(+), 82 deletions(-) create mode 100644 pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_routetable.go create mode 100644 pkg/client/clientset/versioned/typed/gloo/v1/routetable.go create mode 100644 pkg/client/informers/externalversions/gloo/v1/routetable.go create mode 100644 pkg/client/listers/gloo/v1/routetable.go diff --git a/pkg/apis/gloo/v1/doc.go b/pkg/apis/gloo/v1/doc.go index 0c6413321..75ed100f7 100644 --- a/pkg/apis/gloo/v1/doc.go +++ b/pkg/apis/gloo/v1/doc.go @@ -1,5 +1,5 @@ // +k8s:deepcopy-gen=package // Package v1 is the v1 version of the API. -// +groupName=gloo.solo.io +// +groupName=gateway.solo.io package v1 diff --git a/pkg/apis/gloo/v1/types.go b/pkg/apis/gloo/v1/types.go index 5209206c6..cf4dc7adb 100644 --- a/pkg/apis/gloo/v1/types.go +++ b/pkg/apis/gloo/v1/types.go @@ -7,16 +7,35 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// UpstreamGroup is a specification for a Gloo UpstreamGroup resource -type UpstreamGroup struct { +// RouteTable is a specification for a Gloo RouteTable resource +type RouteTable struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec UpstreamGroupSpec `json:"spec"` + Spec RouteTableSpec `json:"spec"` } -type UpstreamGroupSpec struct { - Destinations []WeightedDestination `json:"destinations,omitempty"` +type RouteTableSpec struct { + Routes []Route `json:"destinations,omitempty"` +} + +type Route struct { + Matchers []Matcher `json:"destinations,omitempty"` + Action RouteAction `json:"action,omitempty"` +} + +type Matcher struct { + PathSpecifier Matcher_Prefix `json:"path_specifier,omitempty"` +} + +type Matcher_Prefix struct { + // If specified, the route is a prefix rule meaning that the prefix must + // match the beginning of the *:path* header. + Prefix string `prefix:"path_specifier,omitempty"` +} + +type RouteAction struct { + Destination WeightedDestination `json:"destination,omitempty"` } // WeightedDestination attaches a weight to a single destination. @@ -40,10 +59,10 @@ type ResourceRef struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// UpstreamGroupList is a list of UpstreamGroup resources -type UpstreamGroupList struct { +// RouteTableList is a list of RouteTable resources +type RouteTableList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata"` - Items []UpstreamGroup `json:"items"` + Items []RouteTable `json:"items"` } diff --git a/pkg/apis/gloo/v1/zz_generated.deepcopy.go b/pkg/apis/gloo/v1/zz_generated.deepcopy.go index 909575ed5..a4b860faa 100644 --- a/pkg/apis/gloo/v1/zz_generated.deepcopy.go +++ b/pkg/apis/gloo/v1/zz_generated.deepcopy.go @@ -41,6 +41,39 @@ func (in *Destination) DeepCopy() *Destination { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Matcher) DeepCopyInto(out *Matcher) { + *out = *in + out.PathSpecifier = in.PathSpecifier + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matcher. +func (in *Matcher) DeepCopy() *Matcher { + if in == nil { + return nil + } + out := new(Matcher) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Matcher_Prefix) DeepCopyInto(out *Matcher_Prefix) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matcher_Prefix. +func (in *Matcher_Prefix) DeepCopy() *Matcher_Prefix { + if in == nil { + return nil + } + out := new(Matcher_Prefix) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceRef) DeepCopyInto(out *ResourceRef) { *out = *in @@ -58,7 +91,46 @@ func (in *ResourceRef) DeepCopy() *ResourceRef { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UpstreamGroup) DeepCopyInto(out *UpstreamGroup) { +func (in *Route) DeepCopyInto(out *Route) { + *out = *in + if in.Matchers != nil { + in, out := &in.Matchers, &out.Matchers + *out = make([]Matcher, len(*in)) + copy(*out, *in) + } + out.Action = in.Action + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Route. +func (in *Route) DeepCopy() *Route { + if in == nil { + return nil + } + out := new(Route) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RouteAction) DeepCopyInto(out *RouteAction) { + *out = *in + out.Destination = in.Destination + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteAction. +func (in *RouteAction) DeepCopy() *RouteAction { + if in == nil { + return nil + } + out := new(RouteAction) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RouteTable) DeepCopyInto(out *RouteTable) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -66,18 +138,18 @@ func (in *UpstreamGroup) DeepCopyInto(out *UpstreamGroup) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpstreamGroup. -func (in *UpstreamGroup) DeepCopy() *UpstreamGroup { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteTable. +func (in *RouteTable) DeepCopy() *RouteTable { if in == nil { return nil } - out := new(UpstreamGroup) + out := new(RouteTable) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UpstreamGroup) DeepCopyObject() runtime.Object { +func (in *RouteTable) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -85,13 +157,13 @@ func (in *UpstreamGroup) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UpstreamGroupList) DeepCopyInto(out *UpstreamGroupList) { +func (in *RouteTableList) DeepCopyInto(out *RouteTableList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]UpstreamGroup, len(*in)) + *out = make([]RouteTable, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -99,18 +171,18 @@ func (in *UpstreamGroupList) DeepCopyInto(out *UpstreamGroupList) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpstreamGroupList. -func (in *UpstreamGroupList) DeepCopy() *UpstreamGroupList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteTableList. +func (in *RouteTableList) DeepCopy() *RouteTableList { if in == nil { return nil } - out := new(UpstreamGroupList) + out := new(RouteTableList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UpstreamGroupList) DeepCopyObject() runtime.Object { +func (in *RouteTableList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -118,22 +190,24 @@ func (in *UpstreamGroupList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UpstreamGroupSpec) DeepCopyInto(out *UpstreamGroupSpec) { +func (in *RouteTableSpec) DeepCopyInto(out *RouteTableSpec) { *out = *in - if in.Destinations != nil { - in, out := &in.Destinations, &out.Destinations - *out = make([]WeightedDestination, len(*in)) - copy(*out, *in) + if in.Routes != nil { + in, out := &in.Routes, &out.Routes + *out = make([]Route, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpstreamGroupSpec. -func (in *UpstreamGroupSpec) DeepCopy() *UpstreamGroupSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouteTableSpec. +func (in *RouteTableSpec) DeepCopy() *RouteTableSpec { if in == nil { return nil } - out := new(UpstreamGroupSpec) + out := new(RouteTableSpec) in.DeepCopyInto(out) return out } diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index 81853527b..03d3e9f82 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -24,7 +24,7 @@ import ( appmeshv1beta1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/appmesh/v1beta1" appmeshv1beta2 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/appmesh/v1beta2" flaggerv1beta1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/flagger/v1beta1" - gloov1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/gloo/v1" + gatewayv1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/gloo/v1" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/istio/v1alpha3" projectcontourv1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/projectcontour/v1" splitv1alpha1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/smi/v1alpha1" @@ -40,7 +40,7 @@ type Interface interface { AppmeshV1beta2() appmeshv1beta2.AppmeshV1beta2Interface AppmeshV1beta1() appmeshv1beta1.AppmeshV1beta1Interface FlaggerV1beta1() flaggerv1beta1.FlaggerV1beta1Interface - GlooV1() gloov1.GlooV1Interface + GatewayV1() gatewayv1.GatewayV1Interface NetworkingV1alpha3() networkingv1alpha3.NetworkingV1alpha3Interface ProjectcontourV1() projectcontourv1.ProjectcontourV1Interface SplitV1alpha1() splitv1alpha1.SplitV1alpha1Interface @@ -55,7 +55,7 @@ type Clientset struct { appmeshV1beta2 *appmeshv1beta2.AppmeshV1beta2Client appmeshV1beta1 *appmeshv1beta1.AppmeshV1beta1Client flaggerV1beta1 *flaggerv1beta1.FlaggerV1beta1Client - glooV1 *gloov1.GlooV1Client + gatewayV1 *gatewayv1.GatewayV1Client networkingV1alpha3 *networkingv1alpha3.NetworkingV1alpha3Client projectcontourV1 *projectcontourv1.ProjectcontourV1Client splitV1alpha1 *splitv1alpha1.SplitV1alpha1Client @@ -78,9 +78,9 @@ func (c *Clientset) FlaggerV1beta1() flaggerv1beta1.FlaggerV1beta1Interface { return c.flaggerV1beta1 } -// GlooV1 retrieves the GlooV1Client -func (c *Clientset) GlooV1() gloov1.GlooV1Interface { - return c.glooV1 +// GatewayV1 retrieves the GatewayV1Client +func (c *Clientset) GatewayV1() gatewayv1.GatewayV1Interface { + return c.gatewayV1 } // NetworkingV1alpha3 retrieves the NetworkingV1alpha3Client @@ -141,7 +141,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } - cs.glooV1, err = gloov1.NewForConfig(&configShallowCopy) + cs.gatewayV1, err = gatewayv1.NewForConfig(&configShallowCopy) if err != nil { return nil, err } @@ -180,7 +180,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { cs.appmeshV1beta2 = appmeshv1beta2.NewForConfigOrDie(c) cs.appmeshV1beta1 = appmeshv1beta1.NewForConfigOrDie(c) cs.flaggerV1beta1 = flaggerv1beta1.NewForConfigOrDie(c) - cs.glooV1 = gloov1.NewForConfigOrDie(c) + cs.gatewayV1 = gatewayv1.NewForConfigOrDie(c) cs.networkingV1alpha3 = networkingv1alpha3.NewForConfigOrDie(c) cs.projectcontourV1 = projectcontourv1.NewForConfigOrDie(c) cs.splitV1alpha1 = splitv1alpha1.NewForConfigOrDie(c) @@ -197,7 +197,7 @@ func New(c rest.Interface) *Clientset { cs.appmeshV1beta2 = appmeshv1beta2.New(c) cs.appmeshV1beta1 = appmeshv1beta1.New(c) cs.flaggerV1beta1 = flaggerv1beta1.New(c) - cs.glooV1 = gloov1.New(c) + cs.gatewayV1 = gatewayv1.New(c) cs.networkingV1alpha3 = networkingv1alpha3.New(c) cs.projectcontourV1 = projectcontourv1.New(c) cs.splitV1alpha1 = splitv1alpha1.New(c) diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index dcb551b9f..7af643575 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -26,8 +26,8 @@ import ( fakeappmeshv1beta2 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/appmesh/v1beta2/fake" flaggerv1beta1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/flagger/v1beta1" fakeflaggerv1beta1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/flagger/v1beta1/fake" - gloov1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/gloo/v1" - fakegloov1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/gloo/v1/fake" + gatewayv1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/gloo/v1" + fakegatewayv1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/gloo/v1/fake" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/istio/v1alpha3" fakenetworkingv1alpha3 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/istio/v1alpha3/fake" projectcontourv1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/projectcontour/v1" @@ -107,9 +107,9 @@ func (c *Clientset) FlaggerV1beta1() flaggerv1beta1.FlaggerV1beta1Interface { return &fakeflaggerv1beta1.FakeFlaggerV1beta1{Fake: &c.Fake} } -// GlooV1 retrieves the GlooV1Client -func (c *Clientset) GlooV1() gloov1.GlooV1Interface { - return &fakegloov1.FakeGlooV1{Fake: &c.Fake} +// GatewayV1 retrieves the GatewayV1Client +func (c *Clientset) GatewayV1() gatewayv1.GatewayV1Interface { + return &fakegatewayv1.FakeGatewayV1{Fake: &c.Fake} } // NetworkingV1alpha3 retrieves the NetworkingV1alpha3Client diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index b7feb7ce5..1a0cd77fc 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -22,7 +22,7 @@ import ( appmeshv1beta1 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta1" appmeshv1beta2 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta2" flaggerv1beta1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1beta1" - gloov1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" + gatewayv1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3" projectcontourv1 "github.com/weaveworks/flagger/pkg/apis/projectcontour/v1" splitv1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" @@ -42,7 +42,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ appmeshv1beta2.AddToScheme, appmeshv1beta1.AddToScheme, flaggerv1beta1.AddToScheme, - gloov1.AddToScheme, + gatewayv1.AddToScheme, networkingv1alpha3.AddToScheme, projectcontourv1.AddToScheme, splitv1alpha1.AddToScheme, diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 3623b9775..77d971cc3 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -22,7 +22,7 @@ import ( appmeshv1beta1 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta1" appmeshv1beta2 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta2" flaggerv1beta1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1beta1" - gloov1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" + gatewayv1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3" projectcontourv1 "github.com/weaveworks/flagger/pkg/apis/projectcontour/v1" splitv1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" @@ -42,7 +42,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ appmeshv1beta2.AddToScheme, appmeshv1beta1.AddToScheme, flaggerv1beta1.AddToScheme, - gloov1.AddToScheme, + gatewayv1.AddToScheme, networkingv1alpha3.AddToScheme, projectcontourv1.AddToScheme, splitv1alpha1.AddToScheme, diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_gloo_client.go b/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_gloo_client.go index 21e3167dd..c82fb83b5 100644 --- a/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_gloo_client.go +++ b/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_gloo_client.go @@ -24,17 +24,17 @@ import ( testing "k8s.io/client-go/testing" ) -type FakeGlooV1 struct { +type FakeGatewayV1 struct { *testing.Fake } -func (c *FakeGlooV1) UpstreamGroups(namespace string) v1.UpstreamGroupInterface { - return &FakeUpstreamGroups{c, namespace} +func (c *FakeGatewayV1) RouteTables(namespace string) v1.RouteTableInterface { + return &FakeRouteTables{c, namespace} } // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. -func (c *FakeGlooV1) RESTClient() rest.Interface { +func (c *FakeGatewayV1) RESTClient() rest.Interface { var ret *rest.RESTClient return ret } diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_routetable.go b/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_routetable.go new file mode 100644 index 000000000..6302a1bb3 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_routetable.go @@ -0,0 +1,130 @@ +/* +Copyright The Flagger Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + gloov1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeRouteTables implements RouteTableInterface +type FakeRouteTables struct { + Fake *FakeGatewayV1 + ns string +} + +var routetablesResource = schema.GroupVersionResource{Group: "gateway.solo.io", Version: "v1", Resource: "routetables"} + +var routetablesKind = schema.GroupVersionKind{Group: "gateway.solo.io", Version: "v1", Kind: "RouteTable"} + +// Get takes name of the routeTable, and returns the corresponding routeTable object, and an error if there is any. +func (c *FakeRouteTables) Get(ctx context.Context, name string, options v1.GetOptions) (result *gloov1.RouteTable, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(routetablesResource, c.ns, name), &gloov1.RouteTable{}) + + if obj == nil { + return nil, err + } + return obj.(*gloov1.RouteTable), err +} + +// List takes label and field selectors, and returns the list of RouteTables that match those selectors. +func (c *FakeRouteTables) List(ctx context.Context, opts v1.ListOptions) (result *gloov1.RouteTableList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(routetablesResource, routetablesKind, c.ns, opts), &gloov1.RouteTableList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &gloov1.RouteTableList{ListMeta: obj.(*gloov1.RouteTableList).ListMeta} + for _, item := range obj.(*gloov1.RouteTableList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested routeTables. +func (c *FakeRouteTables) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(routetablesResource, c.ns, opts)) + +} + +// Create takes the representation of a routeTable and creates it. Returns the server's representation of the routeTable, and an error, if there is any. +func (c *FakeRouteTables) Create(ctx context.Context, routeTable *gloov1.RouteTable, opts v1.CreateOptions) (result *gloov1.RouteTable, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(routetablesResource, c.ns, routeTable), &gloov1.RouteTable{}) + + if obj == nil { + return nil, err + } + return obj.(*gloov1.RouteTable), err +} + +// Update takes the representation of a routeTable and updates it. Returns the server's representation of the routeTable, and an error, if there is any. +func (c *FakeRouteTables) Update(ctx context.Context, routeTable *gloov1.RouteTable, opts v1.UpdateOptions) (result *gloov1.RouteTable, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(routetablesResource, c.ns, routeTable), &gloov1.RouteTable{}) + + if obj == nil { + return nil, err + } + return obj.(*gloov1.RouteTable), err +} + +// Delete takes name of the routeTable and deletes it. Returns an error if one occurs. +func (c *FakeRouteTables) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(routetablesResource, c.ns, name), &gloov1.RouteTable{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeRouteTables) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(routetablesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &gloov1.RouteTableList{}) + return err +} + +// Patch applies the patch and returns the patched routeTable. +func (c *FakeRouteTables) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *gloov1.RouteTable, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(routetablesResource, c.ns, name, pt, data, subresources...), &gloov1.RouteTable{}) + + if obj == nil { + return nil, err + } + return obj.(*gloov1.RouteTable), err +} diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/generated_expansion.go b/pkg/client/clientset/versioned/typed/gloo/v1/generated_expansion.go index a727e4520..d32c97665 100644 --- a/pkg/client/clientset/versioned/typed/gloo/v1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/gloo/v1/generated_expansion.go @@ -18,4 +18,4 @@ limitations under the License. package v1 -type UpstreamGroupExpansion interface{} +type RouteTableExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/gloo_client.go b/pkg/client/clientset/versioned/typed/gloo/v1/gloo_client.go index 143d844cb..ab0209d75 100644 --- a/pkg/client/clientset/versioned/typed/gloo/v1/gloo_client.go +++ b/pkg/client/clientset/versioned/typed/gloo/v1/gloo_client.go @@ -24,22 +24,22 @@ import ( rest "k8s.io/client-go/rest" ) -type GlooV1Interface interface { +type GatewayV1Interface interface { RESTClient() rest.Interface - UpstreamGroupsGetter + RouteTablesGetter } -// GlooV1Client is used to interact with features provided by the gloo.solo.io group. -type GlooV1Client struct { +// GatewayV1Client is used to interact with features provided by the gateway.solo.io group. +type GatewayV1Client struct { restClient rest.Interface } -func (c *GlooV1Client) UpstreamGroups(namespace string) UpstreamGroupInterface { - return newUpstreamGroups(c, namespace) +func (c *GatewayV1Client) RouteTables(namespace string) RouteTableInterface { + return newRouteTables(c, namespace) } -// NewForConfig creates a new GlooV1Client for the given config. -func NewForConfig(c *rest.Config) (*GlooV1Client, error) { +// NewForConfig creates a new GatewayV1Client for the given config. +func NewForConfig(c *rest.Config) (*GatewayV1Client, error) { config := *c if err := setConfigDefaults(&config); err != nil { return nil, err @@ -48,12 +48,12 @@ func NewForConfig(c *rest.Config) (*GlooV1Client, error) { if err != nil { return nil, err } - return &GlooV1Client{client}, nil + return &GatewayV1Client{client}, nil } -// NewForConfigOrDie creates a new GlooV1Client for the given config and +// NewForConfigOrDie creates a new GatewayV1Client for the given config and // panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *GlooV1Client { +func NewForConfigOrDie(c *rest.Config) *GatewayV1Client { client, err := NewForConfig(c) if err != nil { panic(err) @@ -61,9 +61,9 @@ func NewForConfigOrDie(c *rest.Config) *GlooV1Client { return client } -// New creates a new GlooV1Client for the given RESTClient. -func New(c rest.Interface) *GlooV1Client { - return &GlooV1Client{c} +// New creates a new GatewayV1Client for the given RESTClient. +func New(c rest.Interface) *GatewayV1Client { + return &GatewayV1Client{c} } func setConfigDefaults(config *rest.Config) error { @@ -81,7 +81,7 @@ func setConfigDefaults(config *rest.Config) error { // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. -func (c *GlooV1Client) RESTClient() rest.Interface { +func (c *GatewayV1Client) RESTClient() rest.Interface { if c == nil { return nil } diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/routetable.go b/pkg/client/clientset/versioned/typed/gloo/v1/routetable.go new file mode 100644 index 000000000..fb66451ea --- /dev/null +++ b/pkg/client/clientset/versioned/typed/gloo/v1/routetable.go @@ -0,0 +1,178 @@ +/* +Copyright The Flagger Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + "time" + + v1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" + scheme "github.com/weaveworks/flagger/pkg/client/clientset/versioned/scheme" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// RouteTablesGetter has a method to return a RouteTableInterface. +// A group's client should implement this interface. +type RouteTablesGetter interface { + RouteTables(namespace string) RouteTableInterface +} + +// RouteTableInterface has methods to work with RouteTable resources. +type RouteTableInterface interface { + Create(ctx context.Context, routeTable *v1.RouteTable, opts metav1.CreateOptions) (*v1.RouteTable, error) + Update(ctx context.Context, routeTable *v1.RouteTable, opts metav1.UpdateOptions) (*v1.RouteTable, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.RouteTable, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.RouteTableList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.RouteTable, err error) + RouteTableExpansion +} + +// routeTables implements RouteTableInterface +type routeTables struct { + client rest.Interface + ns string +} + +// newRouteTables returns a RouteTables +func newRouteTables(c *GatewayV1Client, namespace string) *routeTables { + return &routeTables{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the routeTable, and returns the corresponding routeTable object, and an error if there is any. +func (c *routeTables) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.RouteTable, err error) { + result = &v1.RouteTable{} + err = c.client.Get(). + Namespace(c.ns). + Resource("routetables"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of RouteTables that match those selectors. +func (c *routeTables) List(ctx context.Context, opts metav1.ListOptions) (result *v1.RouteTableList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.RouteTableList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("routetables"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested routeTables. +func (c *routeTables) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("routetables"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a routeTable and creates it. Returns the server's representation of the routeTable, and an error, if there is any. +func (c *routeTables) Create(ctx context.Context, routeTable *v1.RouteTable, opts metav1.CreateOptions) (result *v1.RouteTable, err error) { + result = &v1.RouteTable{} + err = c.client.Post(). + Namespace(c.ns). + Resource("routetables"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(routeTable). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a routeTable and updates it. Returns the server's representation of the routeTable, and an error, if there is any. +func (c *routeTables) Update(ctx context.Context, routeTable *v1.RouteTable, opts metav1.UpdateOptions) (result *v1.RouteTable, err error) { + result = &v1.RouteTable{} + err = c.client.Put(). + Namespace(c.ns). + Resource("routetables"). + Name(routeTable.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(routeTable). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the routeTable and deletes it. Returns an error if one occurs. +func (c *routeTables) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("routetables"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *routeTables) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("routetables"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched routeTable. +func (c *routeTables) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.RouteTable, err error) { + result = &v1.RouteTable{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("routetables"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 91ed5fc81..8c3de27d3 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -180,7 +180,7 @@ type SharedInformerFactory interface { Appmesh() appmesh.Interface Flagger() flagger.Interface - Gloo() gloo.Interface + Gateway() gloo.Interface Networking() istio.Interface Projectcontour() projectcontour.Interface Split() smi.Interface @@ -195,7 +195,7 @@ func (f *sharedInformerFactory) Flagger() flagger.Interface { return flagger.New(f, f.namespace, f.tweakListOptions) } -func (f *sharedInformerFactory) Gloo() gloo.Interface { +func (f *sharedInformerFactory) Gateway() gloo.Interface { return gloo.New(f, f.namespace, f.tweakListOptions) } diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 849d78815..c9bed5fac 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -84,9 +84,9 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case flaggerv1beta1.SchemeGroupVersion.WithResource("metrictemplates"): return &genericInformer{resource: resource.GroupResource(), informer: f.Flagger().V1beta1().MetricTemplates().Informer()}, nil - // Group=gloo.solo.io, Version=v1 - case v1.SchemeGroupVersion.WithResource("upstreamgroups"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Gloo().V1().UpstreamGroups().Informer()}, nil + // Group=gateway.solo.io, Version=v1 + case v1.SchemeGroupVersion.WithResource("routetables"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Gateway().V1().RouteTables().Informer()}, nil // Group=networking.istio.io, Version=v1alpha3 case v1alpha3.SchemeGroupVersion.WithResource("destinationrules"): diff --git a/pkg/client/informers/externalversions/gloo/v1/interface.go b/pkg/client/informers/externalversions/gloo/v1/interface.go index b86cea539..d7fc8e2ea 100644 --- a/pkg/client/informers/externalversions/gloo/v1/interface.go +++ b/pkg/client/informers/externalversions/gloo/v1/interface.go @@ -24,8 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { - // UpstreamGroups returns a UpstreamGroupInformer. - UpstreamGroups() UpstreamGroupInformer + // RouteTables returns a RouteTableInformer. + RouteTables() RouteTableInformer } type version struct { @@ -39,7 +39,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// UpstreamGroups returns a UpstreamGroupInformer. -func (v *version) UpstreamGroups() UpstreamGroupInformer { - return &upstreamGroupInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +// RouteTables returns a RouteTableInformer. +func (v *version) RouteTables() RouteTableInformer { + return &routeTableInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } diff --git a/pkg/client/informers/externalversions/gloo/v1/routetable.go b/pkg/client/informers/externalversions/gloo/v1/routetable.go new file mode 100644 index 000000000..582a33be2 --- /dev/null +++ b/pkg/client/informers/externalversions/gloo/v1/routetable.go @@ -0,0 +1,90 @@ +/* +Copyright The Flagger Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + gloov1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" + versioned "github.com/weaveworks/flagger/pkg/client/clientset/versioned" + internalinterfaces "github.com/weaveworks/flagger/pkg/client/informers/externalversions/internalinterfaces" + v1 "github.com/weaveworks/flagger/pkg/client/listers/gloo/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// RouteTableInformer provides access to a shared informer and lister for +// RouteTables. +type RouteTableInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.RouteTableLister +} + +type routeTableInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewRouteTableInformer constructs a new informer for RouteTable type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewRouteTableInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredRouteTableInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredRouteTableInformer constructs a new informer for RouteTable type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredRouteTableInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.GatewayV1().RouteTables(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.GatewayV1().RouteTables(namespace).Watch(context.TODO(), options) + }, + }, + &gloov1.RouteTable{}, + resyncPeriod, + indexers, + ) +} + +func (f *routeTableInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredRouteTableInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *routeTableInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&gloov1.RouteTable{}, f.defaultInformer) +} + +func (f *routeTableInformer) Lister() v1.RouteTableLister { + return v1.NewRouteTableLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/listers/gloo/v1/expansion_generated.go b/pkg/client/listers/gloo/v1/expansion_generated.go index aee9e4646..57595b08f 100644 --- a/pkg/client/listers/gloo/v1/expansion_generated.go +++ b/pkg/client/listers/gloo/v1/expansion_generated.go @@ -18,10 +18,10 @@ limitations under the License. package v1 -// UpstreamGroupListerExpansion allows custom methods to be added to -// UpstreamGroupLister. -type UpstreamGroupListerExpansion interface{} +// RouteTableListerExpansion allows custom methods to be added to +// RouteTableLister. +type RouteTableListerExpansion interface{} -// UpstreamGroupNamespaceListerExpansion allows custom methods to be added to -// UpstreamGroupNamespaceLister. -type UpstreamGroupNamespaceListerExpansion interface{} +// RouteTableNamespaceListerExpansion allows custom methods to be added to +// RouteTableNamespaceLister. +type RouteTableNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/gloo/v1/routetable.go b/pkg/client/listers/gloo/v1/routetable.go new file mode 100644 index 000000000..aa2aa7b1d --- /dev/null +++ b/pkg/client/listers/gloo/v1/routetable.go @@ -0,0 +1,94 @@ +/* +Copyright The Flagger Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// RouteTableLister helps list RouteTables. +type RouteTableLister interface { + // List lists all RouteTables in the indexer. + List(selector labels.Selector) (ret []*v1.RouteTable, err error) + // RouteTables returns an object that can list and get RouteTables. + RouteTables(namespace string) RouteTableNamespaceLister + RouteTableListerExpansion +} + +// routeTableLister implements the RouteTableLister interface. +type routeTableLister struct { + indexer cache.Indexer +} + +// NewRouteTableLister returns a new RouteTableLister. +func NewRouteTableLister(indexer cache.Indexer) RouteTableLister { + return &routeTableLister{indexer: indexer} +} + +// List lists all RouteTables in the indexer. +func (s *routeTableLister) List(selector labels.Selector) (ret []*v1.RouteTable, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.RouteTable)) + }) + return ret, err +} + +// RouteTables returns an object that can list and get RouteTables. +func (s *routeTableLister) RouteTables(namespace string) RouteTableNamespaceLister { + return routeTableNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// RouteTableNamespaceLister helps list and get RouteTables. +type RouteTableNamespaceLister interface { + // List lists all RouteTables in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1.RouteTable, err error) + // Get retrieves the RouteTable from the indexer for a given namespace and name. + Get(name string) (*v1.RouteTable, error) + RouteTableNamespaceListerExpansion +} + +// routeTableNamespaceLister implements the RouteTableNamespaceLister +// interface. +type routeTableNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all RouteTables in the indexer for a given namespace. +func (s routeTableNamespaceLister) List(selector labels.Selector) (ret []*v1.RouteTable, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.RouteTable)) + }) + return ret, err +} + +// Get retrieves the RouteTable from the indexer for a given namespace and name. +func (s routeTableNamespaceLister) Get(name string) (*v1.RouteTable, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("routetable"), name) + } + return obj.(*v1.RouteTable), nil +} From c6bc21b46851dcafa6a403e50ce239684eac586f Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 14 Dec 2020 15:57:59 -0500 Subject: [PATCH 04/16] Update gloo logic to use route tables, cleanup Signed-off-by: Kevin Dorosh --- pkg/apis/gloo/v1/register.go | 4 +- pkg/apis/gloo/v1/types.go | 10 +- pkg/apis/gloo/v1/zz_generated.deepcopy.go | 25 ++- .../typed/gloo/v1/fake/fake_upstreamgroup.go | 130 ------------- .../versioned/typed/gloo/v1/upstreamgroup.go | 178 ------------------ .../externalversions/gloo/v1/upstreamgroup.go | 90 --------- pkg/client/listers/gloo/v1/upstreamgroup.go | 94 --------- pkg/router/gloo.go | 133 ++++++++----- test/gloo/test-canary.sh | 4 +- 9 files changed, 117 insertions(+), 551 deletions(-) delete mode 100644 pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_upstreamgroup.go delete mode 100644 pkg/client/clientset/versioned/typed/gloo/v1/upstreamgroup.go delete mode 100644 pkg/client/informers/externalversions/gloo/v1/upstreamgroup.go delete mode 100644 pkg/client/listers/gloo/v1/upstreamgroup.go diff --git a/pkg/apis/gloo/v1/register.go b/pkg/apis/gloo/v1/register.go index f9ce797e9..0d746552a 100755 --- a/pkg/apis/gloo/v1/register.go +++ b/pkg/apis/gloo/v1/register.go @@ -28,8 +28,8 @@ var ( // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, - &UpstreamGroup{}, - &UpstreamGroupList{}, + &RouteTable{}, + &RouteTableList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/gloo/v1/types.go b/pkg/apis/gloo/v1/types.go index cf4dc7adb..89e64bfd0 100644 --- a/pkg/apis/gloo/v1/types.go +++ b/pkg/apis/gloo/v1/types.go @@ -20,8 +20,8 @@ type RouteTableSpec struct { } type Route struct { - Matchers []Matcher `json:"destinations,omitempty"` - Action RouteAction `json:"action,omitempty"` + Matchers []Matcher `json:"destinations,omitempty"` + Action RouteAction `json:"action,omitempty"` } type Matcher struct { @@ -35,7 +35,11 @@ type Matcher_Prefix struct { } type RouteAction struct { - Destination WeightedDestination `json:"destination,omitempty"` + Destination MultiDestination `json:"destination,omitempty"` +} + +type MultiDestination struct { + Destinations []WeightedDestination `json:"destinations,omitempty"` } // WeightedDestination attaches a weight to a single destination. diff --git a/pkg/apis/gloo/v1/zz_generated.deepcopy.go b/pkg/apis/gloo/v1/zz_generated.deepcopy.go index a4b860faa..b15c516c9 100644 --- a/pkg/apis/gloo/v1/zz_generated.deepcopy.go +++ b/pkg/apis/gloo/v1/zz_generated.deepcopy.go @@ -74,6 +74,27 @@ func (in *Matcher_Prefix) DeepCopy() *Matcher_Prefix { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MultiDestination) DeepCopyInto(out *MultiDestination) { + *out = *in + if in.Destinations != nil { + in, out := &in.Destinations, &out.Destinations + *out = make([]WeightedDestination, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiDestination. +func (in *MultiDestination) DeepCopy() *MultiDestination { + if in == nil { + return nil + } + out := new(MultiDestination) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceRef) DeepCopyInto(out *ResourceRef) { *out = *in @@ -98,7 +119,7 @@ func (in *Route) DeepCopyInto(out *Route) { *out = make([]Matcher, len(*in)) copy(*out, *in) } - out.Action = in.Action + in.Action.DeepCopyInto(&out.Action) return } @@ -115,7 +136,7 @@ func (in *Route) DeepCopy() *Route { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RouteAction) DeepCopyInto(out *RouteAction) { *out = *in - out.Destination = in.Destination + in.Destination.DeepCopyInto(&out.Destination) return } diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_upstreamgroup.go b/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_upstreamgroup.go deleted file mode 100644 index 61aab3f8b..000000000 --- a/pkg/client/clientset/versioned/typed/gloo/v1/fake/fake_upstreamgroup.go +++ /dev/null @@ -1,130 +0,0 @@ -/* -Copyright The Flagger Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - gloov1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeUpstreamGroups implements UpstreamGroupInterface -type FakeUpstreamGroups struct { - Fake *FakeGlooV1 - ns string -} - -var upstreamgroupsResource = schema.GroupVersionResource{Group: "gloo.solo.io", Version: "v1", Resource: "upstreamgroups"} - -var upstreamgroupsKind = schema.GroupVersionKind{Group: "gloo.solo.io", Version: "v1", Kind: "UpstreamGroup"} - -// Get takes name of the upstreamGroup, and returns the corresponding upstreamGroup object, and an error if there is any. -func (c *FakeUpstreamGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *gloov1.UpstreamGroup, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(upstreamgroupsResource, c.ns, name), &gloov1.UpstreamGroup{}) - - if obj == nil { - return nil, err - } - return obj.(*gloov1.UpstreamGroup), err -} - -// List takes label and field selectors, and returns the list of UpstreamGroups that match those selectors. -func (c *FakeUpstreamGroups) List(ctx context.Context, opts v1.ListOptions) (result *gloov1.UpstreamGroupList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(upstreamgroupsResource, upstreamgroupsKind, c.ns, opts), &gloov1.UpstreamGroupList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &gloov1.UpstreamGroupList{ListMeta: obj.(*gloov1.UpstreamGroupList).ListMeta} - for _, item := range obj.(*gloov1.UpstreamGroupList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested upstreamGroups. -func (c *FakeUpstreamGroups) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(upstreamgroupsResource, c.ns, opts)) - -} - -// Create takes the representation of a upstreamGroup and creates it. Returns the server's representation of the upstreamGroup, and an error, if there is any. -func (c *FakeUpstreamGroups) Create(ctx context.Context, upstreamGroup *gloov1.UpstreamGroup, opts v1.CreateOptions) (result *gloov1.UpstreamGroup, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(upstreamgroupsResource, c.ns, upstreamGroup), &gloov1.UpstreamGroup{}) - - if obj == nil { - return nil, err - } - return obj.(*gloov1.UpstreamGroup), err -} - -// Update takes the representation of a upstreamGroup and updates it. Returns the server's representation of the upstreamGroup, and an error, if there is any. -func (c *FakeUpstreamGroups) Update(ctx context.Context, upstreamGroup *gloov1.UpstreamGroup, opts v1.UpdateOptions) (result *gloov1.UpstreamGroup, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(upstreamgroupsResource, c.ns, upstreamGroup), &gloov1.UpstreamGroup{}) - - if obj == nil { - return nil, err - } - return obj.(*gloov1.UpstreamGroup), err -} - -// Delete takes name of the upstreamGroup and deletes it. Returns an error if one occurs. -func (c *FakeUpstreamGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(upstreamgroupsResource, c.ns, name), &gloov1.UpstreamGroup{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeUpstreamGroups) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(upstreamgroupsResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &gloov1.UpstreamGroupList{}) - return err -} - -// Patch applies the patch and returns the patched upstreamGroup. -func (c *FakeUpstreamGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *gloov1.UpstreamGroup, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(upstreamgroupsResource, c.ns, name, pt, data, subresources...), &gloov1.UpstreamGroup{}) - - if obj == nil { - return nil, err - } - return obj.(*gloov1.UpstreamGroup), err -} diff --git a/pkg/client/clientset/versioned/typed/gloo/v1/upstreamgroup.go b/pkg/client/clientset/versioned/typed/gloo/v1/upstreamgroup.go deleted file mode 100644 index 3ee89217a..000000000 --- a/pkg/client/clientset/versioned/typed/gloo/v1/upstreamgroup.go +++ /dev/null @@ -1,178 +0,0 @@ -/* -Copyright The Flagger Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - v1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" - scheme "github.com/weaveworks/flagger/pkg/client/clientset/versioned/scheme" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" -) - -// UpstreamGroupsGetter has a method to return a UpstreamGroupInterface. -// A group's client should implement this interface. -type UpstreamGroupsGetter interface { - UpstreamGroups(namespace string) UpstreamGroupInterface -} - -// UpstreamGroupInterface has methods to work with UpstreamGroup resources. -type UpstreamGroupInterface interface { - Create(ctx context.Context, upstreamGroup *v1.UpstreamGroup, opts metav1.CreateOptions) (*v1.UpstreamGroup, error) - Update(ctx context.Context, upstreamGroup *v1.UpstreamGroup, opts metav1.UpdateOptions) (*v1.UpstreamGroup, error) - Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.UpstreamGroup, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.UpstreamGroupList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.UpstreamGroup, err error) - UpstreamGroupExpansion -} - -// upstreamGroups implements UpstreamGroupInterface -type upstreamGroups struct { - client rest.Interface - ns string -} - -// newUpstreamGroups returns a UpstreamGroups -func newUpstreamGroups(c *GlooV1Client, namespace string) *upstreamGroups { - return &upstreamGroups{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the upstreamGroup, and returns the corresponding upstreamGroup object, and an error if there is any. -func (c *upstreamGroups) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.UpstreamGroup, err error) { - result = &v1.UpstreamGroup{} - err = c.client.Get(). - Namespace(c.ns). - Resource("upstreamgroups"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of UpstreamGroups that match those selectors. -func (c *upstreamGroups) List(ctx context.Context, opts metav1.ListOptions) (result *v1.UpstreamGroupList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.UpstreamGroupList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("upstreamgroups"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested upstreamGroups. -func (c *upstreamGroups) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("upstreamgroups"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a upstreamGroup and creates it. Returns the server's representation of the upstreamGroup, and an error, if there is any. -func (c *upstreamGroups) Create(ctx context.Context, upstreamGroup *v1.UpstreamGroup, opts metav1.CreateOptions) (result *v1.UpstreamGroup, err error) { - result = &v1.UpstreamGroup{} - err = c.client.Post(). - Namespace(c.ns). - Resource("upstreamgroups"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(upstreamGroup). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a upstreamGroup and updates it. Returns the server's representation of the upstreamGroup, and an error, if there is any. -func (c *upstreamGroups) Update(ctx context.Context, upstreamGroup *v1.UpstreamGroup, opts metav1.UpdateOptions) (result *v1.UpstreamGroup, err error) { - result = &v1.UpstreamGroup{} - err = c.client.Put(). - Namespace(c.ns). - Resource("upstreamgroups"). - Name(upstreamGroup.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(upstreamGroup). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the upstreamGroup and deletes it. Returns an error if one occurs. -func (c *upstreamGroups) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("upstreamgroups"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *upstreamGroups) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("upstreamgroups"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched upstreamGroup. -func (c *upstreamGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.UpstreamGroup, err error) { - result = &v1.UpstreamGroup{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("upstreamgroups"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/gloo/v1/upstreamgroup.go b/pkg/client/informers/externalversions/gloo/v1/upstreamgroup.go deleted file mode 100644 index 7932e0045..000000000 --- a/pkg/client/informers/externalversions/gloo/v1/upstreamgroup.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright The Flagger Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1 - -import ( - "context" - time "time" - - gloov1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" - versioned "github.com/weaveworks/flagger/pkg/client/clientset/versioned" - internalinterfaces "github.com/weaveworks/flagger/pkg/client/informers/externalversions/internalinterfaces" - v1 "github.com/weaveworks/flagger/pkg/client/listers/gloo/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// UpstreamGroupInformer provides access to a shared informer and lister for -// UpstreamGroups. -type UpstreamGroupInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1.UpstreamGroupLister -} - -type upstreamGroupInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewUpstreamGroupInformer constructs a new informer for UpstreamGroup type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewUpstreamGroupInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredUpstreamGroupInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredUpstreamGroupInformer constructs a new informer for UpstreamGroup type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredUpstreamGroupInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.GlooV1().UpstreamGroups(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.GlooV1().UpstreamGroups(namespace).Watch(context.TODO(), options) - }, - }, - &gloov1.UpstreamGroup{}, - resyncPeriod, - indexers, - ) -} - -func (f *upstreamGroupInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredUpstreamGroupInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *upstreamGroupInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&gloov1.UpstreamGroup{}, f.defaultInformer) -} - -func (f *upstreamGroupInformer) Lister() v1.UpstreamGroupLister { - return v1.NewUpstreamGroupLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/listers/gloo/v1/upstreamgroup.go b/pkg/client/listers/gloo/v1/upstreamgroup.go deleted file mode 100644 index 52b8be193..000000000 --- a/pkg/client/listers/gloo/v1/upstreamgroup.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright The Flagger Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1 - -import ( - v1 "github.com/weaveworks/flagger/pkg/apis/gloo/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// UpstreamGroupLister helps list UpstreamGroups. -type UpstreamGroupLister interface { - // List lists all UpstreamGroups in the indexer. - List(selector labels.Selector) (ret []*v1.UpstreamGroup, err error) - // UpstreamGroups returns an object that can list and get UpstreamGroups. - UpstreamGroups(namespace string) UpstreamGroupNamespaceLister - UpstreamGroupListerExpansion -} - -// upstreamGroupLister implements the UpstreamGroupLister interface. -type upstreamGroupLister struct { - indexer cache.Indexer -} - -// NewUpstreamGroupLister returns a new UpstreamGroupLister. -func NewUpstreamGroupLister(indexer cache.Indexer) UpstreamGroupLister { - return &upstreamGroupLister{indexer: indexer} -} - -// List lists all UpstreamGroups in the indexer. -func (s *upstreamGroupLister) List(selector labels.Selector) (ret []*v1.UpstreamGroup, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.UpstreamGroup)) - }) - return ret, err -} - -// UpstreamGroups returns an object that can list and get UpstreamGroups. -func (s *upstreamGroupLister) UpstreamGroups(namespace string) UpstreamGroupNamespaceLister { - return upstreamGroupNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// UpstreamGroupNamespaceLister helps list and get UpstreamGroups. -type UpstreamGroupNamespaceLister interface { - // List lists all UpstreamGroups in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1.UpstreamGroup, err error) - // Get retrieves the UpstreamGroup from the indexer for a given namespace and name. - Get(name string) (*v1.UpstreamGroup, error) - UpstreamGroupNamespaceListerExpansion -} - -// upstreamGroupNamespaceLister implements the UpstreamGroupNamespaceLister -// interface. -type upstreamGroupNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all UpstreamGroups in the indexer for a given namespace. -func (s upstreamGroupNamespaceLister) List(selector labels.Selector) (ret []*v1.UpstreamGroup, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.UpstreamGroup)) - }) - return ret, err -} - -// Get retrieves the UpstreamGroup from the indexer for a given namespace and name. -func (s upstreamGroupNamespaceLister) Get(name string) (*v1.UpstreamGroup, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("upstreamgroup"), name) - } - return obj.(*v1.UpstreamGroup), nil -} diff --git a/pkg/router/gloo.go b/pkg/router/gloo.go index 99434991f..6180ace35 100644 --- a/pkg/router/gloo.go +++ b/pkg/router/gloo.go @@ -32,32 +32,49 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error { canaryName := fmt.Sprintf("%s-%s-canary-%v", canary.Namespace, apexName, canary.Spec.Service.Port) primaryName := fmt.Sprintf("%s-%s-primary-%v", canary.Namespace, apexName, canary.Spec.Service.Port) - newSpec := gloov1.UpstreamGroupSpec{ - Destinations: []gloov1.WeightedDestination{ + newSpec := gloov1.RouteTableSpec{ + Routes: []gloov1.Route{ { - Destination: gloov1.Destination{ - Upstream: gloov1.ResourceRef{ - Name: primaryName, - Namespace: gr.upstreamDiscoveryNs, + // eventually inherit from parent, used for A/B rollouts too? + Matchers: []gloov1.Matcher{ + { + PathSpecifier: gloov1.Matcher_Prefix{ + Prefix: "/", + }, }, }, - Weight: 100, - }, - { - Destination: gloov1.Destination{ - Upstream: gloov1.ResourceRef{ - Name: canaryName, - Namespace: gr.upstreamDiscoveryNs, + Action: gloov1.RouteAction{ + Destination: gloov1.MultiDestination{ + Destinations: []gloov1.WeightedDestination{ + { + Destination: gloov1.Destination{ + Upstream: gloov1.ResourceRef{ + Name: primaryName, + Namespace: gr.upstreamDiscoveryNs, + }, + }, + Weight: 100, + }, + { + Destination: gloov1.Destination{ + Upstream: gloov1.ResourceRef{ + Name: canaryName, + Namespace: gr.upstreamDiscoveryNs, + }, + }, + Weight: 0, + }, + }, }, }, - Weight: 0, }, }, } - upstreamGroup, err := gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) + routeTable, err := gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) if errors.IsNotFound(err) { - upstreamGroup = &gloov1.UpstreamGroup{ + + routeTable = &gloov1.RouteTable{ ObjectMeta: metav1.ObjectMeta{ Name: apexName, Namespace: canary.Namespace, @@ -72,33 +89,33 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error { Spec: newSpec, } - _, err = gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Create(context.TODO(), upstreamGroup, metav1.CreateOptions{}) + _, err = gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Create(context.TODO(), routeTable, metav1.CreateOptions{}) if err != nil { - return fmt.Errorf("UpstreamGroup %s.%s create error: %w", apexName, canary.Namespace, err) + return fmt.Errorf("RouteTable %s.%s create error: %w", apexName, canary.Namespace, err) } gr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). - Infof("UpstreamGroup %s.%s created", upstreamGroup.GetName(), canary.Namespace) + Infof("RouteTable %s.%s created", routeTable.GetName(), canary.Namespace) return nil } else if err != nil { - return fmt.Errorf("UpstreamGroup %s.%s get query error: %w", apexName, canary.Namespace, err) + return fmt.Errorf("RouteTable %s.%s get query error: %w", apexName, canary.Namespace, err) } - // update upstreamGroup but keep the original destination weights - if upstreamGroup != nil { + // update routeTable but keep the original destination weights + if routeTable != nil { if diff := cmp.Diff( newSpec, - upstreamGroup.Spec, + routeTable.Spec, cmpopts.IgnoreFields(gloov1.WeightedDestination{}, "Weight"), ); diff != "" { - clone := upstreamGroup.DeepCopy() + clone := routeTable.DeepCopy() clone.Spec = newSpec - _, err = gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Update(context.TODO(), clone, metav1.UpdateOptions{}) + _, err = gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Update(context.TODO(), clone, metav1.UpdateOptions{}) if err != nil { - return fmt.Errorf("UpstreamGroup %s.%s update error: %w", apexName, canary.Namespace, err) + return fmt.Errorf("RouteTable %s.%s update error: %w", apexName, canary.Namespace, err) } gr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). - Infof("UpstreamGroup %s.%s updated", upstreamGroup.GetName(), canary.Namespace) + Infof("RouteTable %s.%s updated", routeTable.GetName(), canary.Namespace) } } @@ -115,18 +132,18 @@ func (gr *GlooRouter) GetRoutes(canary *flaggerv1.Canary) ( apexName := canary.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-%s-primary-%v", canary.Namespace, canary.Spec.TargetRef.Name, canary.Spec.Service.Port) - upstreamGroup, err := gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) + routeTable, err := gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) if err != nil { - err = fmt.Errorf("UpstreamGroup %s.%s get query error: %w", apexName, canary.Namespace, err) + err = fmt.Errorf("RouteTable %s.%s get query error: %w", apexName, canary.Namespace, err) return } - if len(upstreamGroup.Spec.Destinations) < 2 { - err = fmt.Errorf("UpstreamGroup %s.%s destinations not found", apexName, canary.Namespace) + if len(routeTable.Spec.Routes[0].Action.Destination.Destinations) < 2 { + err = fmt.Errorf("RouteTable %s.%s destinations not found", apexName, canary.Namespace) return } - for _, dst := range upstreamGroup.Spec.Destinations { + for _, dst := range routeTable.Spec.Routes[0].Action.Destination.Destinations { if dst.Destination.Upstream.Name == primaryName { primaryWeight = int(dst.Weight) canaryWeight = 100 - primaryWeight @@ -152,37 +169,53 @@ func (gr *GlooRouter) SetRoutes( return fmt.Errorf("RoutingRule %s.%s update failed: no valid weights", apexName, canary.Namespace) } - upstreamGroup, err := gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) + routeTable, err := gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{}) if err != nil { - return fmt.Errorf("UpstreamGroup %s.%s query error: %w", apexName, canary.Namespace, err) + return fmt.Errorf("RouteTable %s.%s query error: %w", apexName, canary.Namespace, err) } - upstreamGroup.Spec = gloov1.UpstreamGroupSpec{ - Destinations: []gloov1.WeightedDestination{ + routeTable.Spec = gloov1.RouteTableSpec{ + Routes: []gloov1.Route{ { - Destination: gloov1.Destination{ - Upstream: gloov1.ResourceRef{ - Name: primaryName, - Namespace: gr.upstreamDiscoveryNs, + // eventually inherit from parent, used for A/B rollouts too? + Matchers: []gloov1.Matcher{ + { + PathSpecifier: gloov1.Matcher_Prefix{ + Prefix: "/", + }, }, }, - Weight: uint32(primaryWeight), - }, - { - Destination: gloov1.Destination{ - Upstream: gloov1.ResourceRef{ - Name: canaryName, - Namespace: gr.upstreamDiscoveryNs, + Action: gloov1.RouteAction{ + Destination: gloov1.MultiDestination{ + Destinations: []gloov1.WeightedDestination{ + { + Destination: gloov1.Destination{ + Upstream: gloov1.ResourceRef{ + Name: primaryName, + Namespace: gr.upstreamDiscoveryNs, + }, + }, + Weight: uint32(primaryWeight), + }, + { + Destination: gloov1.Destination{ + Upstream: gloov1.ResourceRef{ + Name: canaryName, + Namespace: gr.upstreamDiscoveryNs, + }, + }, + Weight: uint32(canaryWeight), + }, + }, }, }, - Weight: uint32(canaryWeight), }, }, } - _, err = gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Update(context.TODO(), upstreamGroup, metav1.UpdateOptions{}) + _, err = gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Update(context.TODO(), routeTable, metav1.UpdateOptions{}) if err != nil { - return fmt.Errorf("UpstreamGroup %s.%s update error: %w", apexName, canary.Namespace, err) + return fmt.Errorf("RouteTable %s.%s update error: %w", apexName, canary.Namespace, err) } return nil } diff --git a/test/gloo/test-canary.sh b/test/gloo/test-canary.sh index 0410a55c2..6a64b8537 100755 --- a/test/gloo/test-canary.sh +++ b/test/gloo/test-canary.sh @@ -36,8 +36,8 @@ spec: routes: - matchers: - prefix: / - routeAction: - upstreamGroup: + delegateAction: + ref: name: podinfo namespace: test EOF From f187d86427088fc05b4fd0b83cb3d43a5ef8c488 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 14 Dec 2020 17:26:55 -0500 Subject: [PATCH 05/16] Add permissions Signed-off-by: Kevin Dorosh --- artifacts/flagger/account.yaml | 15 +++++++++++++-- charts/flagger/templates/rbac.yaml | 15 +++++++++++++-- kustomize/base/flagger/rbac.yaml | 15 +++++++++++++-- pkg/apis/gloo/register.go | 2 +- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/artifacts/flagger/account.yaml b/artifacts/flagger/account.yaml index 22c304474..c8ed98336 100644 --- a/artifacts/flagger/account.yaml +++ b/artifacts/flagger/account.yaml @@ -153,8 +153,19 @@ rules: resources: - upstreams - upstreams/finalizers - - upstreamgroups - - upstreamgroups/finalizers + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - gateway.solo.io + resources: + - routetables + - routetables/finalizers verbs: - get - list diff --git a/charts/flagger/templates/rbac.yaml b/charts/flagger/templates/rbac.yaml index 16a9151f7..afd0d6118 100644 --- a/charts/flagger/templates/rbac.yaml +++ b/charts/flagger/templates/rbac.yaml @@ -149,8 +149,19 @@ rules: resources: - upstreams - upstreams/finalizers - - upstreamgroups - - upstreamgroups/finalizers + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - gateway.solo.io + resources: + - routetables + - routetables/finalizers verbs: - get - list diff --git a/kustomize/base/flagger/rbac.yaml b/kustomize/base/flagger/rbac.yaml index e2a6b48d7..f4db1403a 100644 --- a/kustomize/base/flagger/rbac.yaml +++ b/kustomize/base/flagger/rbac.yaml @@ -143,8 +143,19 @@ rules: resources: - upstreams - upstreams/finalizers - - upstreamgroups - - upstreamgroups/finalizers + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - gateway.solo.io + resources: + - routetables + - routetables/finalizers verbs: - get - list diff --git a/pkg/apis/gloo/register.go b/pkg/apis/gloo/register.go index 1e6e90165..0d7175074 100644 --- a/pkg/apis/gloo/register.go +++ b/pkg/apis/gloo/register.go @@ -1,5 +1,5 @@ package gloo const ( - GroupName = "gloo.solo.io" + GroupName = "gateway.solo.io" ) From 87c57fef2c0be95ea35d6d508f2959b9479eb973 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 14 Dec 2020 18:11:33 -0500 Subject: [PATCH 06/16] Fix api mistakes Signed-off-by: Kevin Dorosh --- pkg/apis/gloo/v1/types.go | 16 +++++----------- pkg/apis/gloo/v1/zz_generated.deepcopy.go | 17 ----------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/pkg/apis/gloo/v1/types.go b/pkg/apis/gloo/v1/types.go index 89e64bfd0..00351f889 100644 --- a/pkg/apis/gloo/v1/types.go +++ b/pkg/apis/gloo/v1/types.go @@ -16,26 +16,20 @@ type RouteTable struct { } type RouteTableSpec struct { - Routes []Route `json:"destinations,omitempty"` + Routes []Route `json:"routes,omitempty"` } type Route struct { - Matchers []Matcher `json:"destinations,omitempty"` - Action RouteAction `json:"action,omitempty"` + Matchers []Matcher `json:"matchers,omitempty"` + Action RouteAction `json:"route_action,omitempty"` } type Matcher struct { - PathSpecifier Matcher_Prefix `json:"path_specifier,omitempty"` -} - -type Matcher_Prefix struct { - // If specified, the route is a prefix rule meaning that the prefix must - // match the beginning of the *:path* header. - Prefix string `prefix:"path_specifier,omitempty"` + Prefix string `json:"prefix,omitempty"` } type RouteAction struct { - Destination MultiDestination `json:"destination,omitempty"` + Destination MultiDestination `json:"multi,omitempty"` } type MultiDestination struct { diff --git a/pkg/apis/gloo/v1/zz_generated.deepcopy.go b/pkg/apis/gloo/v1/zz_generated.deepcopy.go index b15c516c9..6c3ba44ef 100644 --- a/pkg/apis/gloo/v1/zz_generated.deepcopy.go +++ b/pkg/apis/gloo/v1/zz_generated.deepcopy.go @@ -44,7 +44,6 @@ func (in *Destination) DeepCopy() *Destination { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Matcher) DeepCopyInto(out *Matcher) { *out = *in - out.PathSpecifier = in.PathSpecifier return } @@ -58,22 +57,6 @@ func (in *Matcher) DeepCopy() *Matcher { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Matcher_Prefix) DeepCopyInto(out *Matcher_Prefix) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Matcher_Prefix. -func (in *Matcher_Prefix) DeepCopy() *Matcher_Prefix { - if in == nil { - return nil - } - out := new(Matcher_Prefix) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MultiDestination) DeepCopyInto(out *MultiDestination) { *out = *in From a88f4ae90de5a4ca588f66b85e3027f375136158 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 14 Dec 2020 18:12:49 -0500 Subject: [PATCH 07/16] Fix compile error Signed-off-by: Kevin Dorosh --- pkg/router/gloo.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/router/gloo.go b/pkg/router/gloo.go index 6180ace35..6d778ef7e 100644 --- a/pkg/router/gloo.go +++ b/pkg/router/gloo.go @@ -38,9 +38,7 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error { // eventually inherit from parent, used for A/B rollouts too? Matchers: []gloov1.Matcher{ { - PathSpecifier: gloov1.Matcher_Prefix{ - Prefix: "/", - }, + Prefix: "/", }, }, Action: gloov1.RouteAction{ @@ -180,9 +178,7 @@ func (gr *GlooRouter) SetRoutes( // eventually inherit from parent, used for A/B rollouts too? Matchers: []gloov1.Matcher{ { - PathSpecifier: gloov1.Matcher_Prefix{ - Prefix: "/", - }, + Prefix: "/", }, }, Action: gloov1.RouteAction{ From 107113f2c7ab899e981f11ddbc9c513ab1b8fda5 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 14 Dec 2020 20:29:42 -0500 Subject: [PATCH 08/16] Fix test Signed-off-by: Kevin Dorosh --- pkg/router/gloo_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/router/gloo_test.go b/pkg/router/gloo_test.go index 20493ed39..f6958f6bf 100644 --- a/pkg/router/gloo_test.go +++ b/pkg/router/gloo_test.go @@ -25,9 +25,9 @@ func TestGlooRouter_Sync(t *testing.T) { require.NoError(t, err) // test insert - ug, err := router.glooClient.GlooV1().UpstreamGroups("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) + rt, err := router.glooClient.GatewayV1().RouteTables("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) require.NoError(t, err) - dests := ug.Spec.Destinations + dests := rt.Spec.Routes[0].Action.Destination.Destinations assert.Len(t, dests, 2) assert.Equal(t, uint32(100), dests[0].Weight) assert.Equal(t, uint32(0), dests[1].Weight) @@ -55,7 +55,7 @@ func TestGlooRouter_SetRoutes(t *testing.T) { err = router.SetRoutes(mocks.canary, p, c, m) require.NoError(t, err) - ug, err := router.glooClient.GlooV1().UpstreamGroups("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) + rt, err := router.glooClient.GatewayV1().RouteTables("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) require.NoError(t, err) var pRoute gloov1.WeightedDestination @@ -63,7 +63,7 @@ func TestGlooRouter_SetRoutes(t *testing.T) { canaryName := fmt.Sprintf("%s-%s-canary-%v", mocks.canary.Namespace, mocks.canary.Spec.TargetRef.Name, mocks.canary.Spec.Service.Port) primaryName := fmt.Sprintf("%s-%s-primary-%v", mocks.canary.Namespace, mocks.canary.Spec.TargetRef.Name, mocks.canary.Spec.Service.Port) - for _, dest := range ug.Spec.Destinations { + for _, dest := range rt.Spec.Routes[0].Action.Destination.Destinations { if dest.Destination.Upstream.Name == primaryName { pRoute = dest } From 250df0e499a7b78d07074eb658f9eb1cbb56e93c Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Wed, 16 Dec 2020 13:32:00 -0500 Subject: [PATCH 09/16] Fix json naming Signed-off-by: Kevin Dorosh --- pkg/apis/gloo/v1/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/gloo/v1/types.go b/pkg/apis/gloo/v1/types.go index 00351f889..54dfb5728 100644 --- a/pkg/apis/gloo/v1/types.go +++ b/pkg/apis/gloo/v1/types.go @@ -21,7 +21,7 @@ type RouteTableSpec struct { type Route struct { Matchers []Matcher `json:"matchers,omitempty"` - Action RouteAction `json:"route_action,omitempty"` + Action RouteAction `json:"routeAction,omitempty"` } type Matcher struct { From d063db6d4a5fc4e775cbd9f34fcc45cdf95f60e0 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Wed, 16 Dec 2020 13:49:51 -0500 Subject: [PATCH 10/16] Update documented flow Signed-off-by: Kevin Dorosh --- README.md | 2 +- .../tutorials/gloo-progressive-delivery.md | 21 +++++++++++-------- docs/gitbook/usage/deployment-strategies.md | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8aeafee79..f5289a648 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ For more details on how the canary analysis and promotion works please [read the | Feature | Contour | Gloo | NGINX | Skipper | Traefik | | ------------------------------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | | Canary deployments (weighted traffic) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| A/B testing (headers and cookies routing) | :heavy_check_mark: | :heavy_minus_sign: | :heavy_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: | +| A/B testing (headers and cookies routing) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: | | Blue/Green deployments (traffic switch) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Webhooks (acceptance/load testing) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Manual gating (approve/pause/resume) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | diff --git a/docs/gitbook/tutorials/gloo-progressive-delivery.md b/docs/gitbook/tutorials/gloo-progressive-delivery.md index 6ac14abff..abc4e20a3 100644 --- a/docs/gitbook/tutorials/gloo-progressive-delivery.md +++ b/docs/gitbook/tutorials/gloo-progressive-delivery.md @@ -1,12 +1,15 @@ # Gloo Canary Deployments -This guide shows you how to use the [Gloo](https://gloo.solo.io/) ingress controller and Flagger to automate canary deployments. +This guide shows you how to use the [Gloo Edge](https://gloo.solo.io/) ingress controller and Flagger to automate canary deployments. ![Flagger Gloo Ingress Controller](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-gloo-overview.png) ## Prerequisites -Flagger requires a Kubernetes cluster **v1.11** or newer and Gloo ingress **1.3.5** or newer. +This guide was written for Flagger version **1.5.0** or higher. Prior versions of Flagger used Gloo upstream groups to handle +canaries, but newer versions of Flagger use Gloo route tables to handle canaries as well as A/B testing. + +Flagger requires a Kubernetes cluster **v1.11** or newer and Gloo Edge ingress **1.6.0** or newer. Install Gloo with Helm v3: @@ -31,7 +34,7 @@ helm upgrade -i flagger flagger/flagger \ ## Bootstrap Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), -then creates a series of objects (Kubernetes deployments, ClusterIP services and Gloo upstream groups). +then creates a series of objects (Kubernetes deployments, ClusterIP services and Gloo route tables). These objects expose the application outside the cluster and drive the canary analysis and promotion. Create a test namespace: @@ -52,7 +55,7 @@ Deploy the load testing service to generate traffic during the canary analysis: kubectl -n test apply -k github.com/weaveworks/flagger//kustomize/tester ``` -Create an virtual service definition that references an upstream group that will be generated by Flagger +Create an virtual service definition that references an route table that will be generated by Flagger (replace `app.example.com` with your own domain): ```yaml @@ -68,8 +71,8 @@ spec: routes: - matchers: - prefix: / - routeAction: - upstreamGroup: + delegateAction: + ref: name: podinfo namespace: test ``` @@ -168,7 +171,7 @@ horizontalpodautoscaler.autoscaling/podinfo-primary service/podinfo service/podinfo-canary service/podinfo-primary -upstreamgroups.gloo.solo.io/podinfo +routetables.gateway.solo.io/podinfo ``` When the bootstrap finishes Flagger will set the canary status to initialized: @@ -252,13 +255,13 @@ podinfod=stefanprodan/podinfo:3.1.2 Generate HTTP 500 errors: ```bash -watch curl -H 'Host: app.example.com' http://gateway-proxy-v2.gloo-system/status/500 +watch curl -H 'Host: app.example.com' http://gateway-proxy.gloo-system/status/500 ``` Generate high latency: ```bash -watch curl -H 'Host: app.example.com' http://gateway-proxy-v2.gloo-system/delay/2 +watch curl -H 'Host: app.example.com' http://gateway-proxy.gloo-system/delay/2 ``` When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, diff --git a/docs/gitbook/usage/deployment-strategies.md b/docs/gitbook/usage/deployment-strategies.md index e96a12e67..903c98373 100644 --- a/docs/gitbook/usage/deployment-strategies.md +++ b/docs/gitbook/usage/deployment-strategies.md @@ -2,11 +2,11 @@ Flagger can run automated application analysis, promotion and rollback for the following deployment strategies: * **Canary Release** (progressive traffic shifting) - * Istio, Linkerd, App Mesh, NGINX, Skipper, Contour, Gloo, Traefik + * Istio, Linkerd, App Mesh, NGINX, Skipper, Contour, Gloo Edge, Traefik * **A/B Testing** (HTTP headers and cookies traffic routing) - * Istio, App Mesh, NGINX, Contour + * Istio, App Mesh, NGINX, Contour, Gloo Edge * **Blue/Green** (traffic switching) - * Kubernetes CNI, Istio, Linkerd, App Mesh, NGINX, Contour, Gloo + * Kubernetes CNI, Istio, Linkerd, App Mesh, NGINX, Contour, Gloo Edge * **Blue/Green Mirroring** (traffic shadowing) * Istio From ea53160db440be9395a51a0ffbd11478ebceb2b0 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Wed, 16 Dec 2020 16:57:59 -0500 Subject: [PATCH 11/16] First pass A/B testing Signed-off-by: Kevin Dorosh --- pkg/apis/gloo/v1/types.go | 20 ++++++ pkg/apis/gloo/v1/zz_generated.deepcopy.go | 51 +++++++++++++- pkg/router/gloo.go | 40 ++++++++++- pkg/router/gloo_test.go | 39 +++++++++++ test/gloo/test-canary.sh | 83 ++++++++++++++++++++++- 5 files changed, 228 insertions(+), 5 deletions(-) diff --git a/pkg/apis/gloo/v1/types.go b/pkg/apis/gloo/v1/types.go index 54dfb5728..f372284a9 100644 --- a/pkg/apis/gloo/v1/types.go +++ b/pkg/apis/gloo/v1/types.go @@ -25,7 +25,27 @@ type Route struct { } type Matcher struct { + // only one of Prefix, Exact, Regex may be nonempty Prefix string `json:"prefix,omitempty"` + Exact string `json:"exact,omitempty"` + Regex string `json:"regex,omitempty"` + + Headers []HeaderMatcher `json:"headers,omitempty"` + QueryParameterMatchers []QueryParameterMatcher `json:"queryParameters,omitempty"` + Methods []string `json:"methods,omitempty"` +} + +type HeaderMatcher struct { + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` + Regex bool `json:"regex,omitempty"` + InvertMatch bool `json:"invertMatch,omitempty"` +} + +type QueryParameterMatcher struct { + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` + Regex bool `json:"regex,omitempty"` } type RouteAction struct { diff --git a/pkg/apis/gloo/v1/zz_generated.deepcopy.go b/pkg/apis/gloo/v1/zz_generated.deepcopy.go index 6c3ba44ef..04ec6741d 100644 --- a/pkg/apis/gloo/v1/zz_generated.deepcopy.go +++ b/pkg/apis/gloo/v1/zz_generated.deepcopy.go @@ -41,9 +41,40 @@ func (in *Destination) DeepCopy() *Destination { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HeaderMatcher) DeepCopyInto(out *HeaderMatcher) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HeaderMatcher. +func (in *HeaderMatcher) DeepCopy() *HeaderMatcher { + if in == nil { + return nil + } + out := new(HeaderMatcher) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Matcher) DeepCopyInto(out *Matcher) { *out = *in + if in.Headers != nil { + in, out := &in.Headers, &out.Headers + *out = make([]HeaderMatcher, len(*in)) + copy(*out, *in) + } + if in.QueryParameterMatchers != nil { + in, out := &in.QueryParameterMatchers, &out.QueryParameterMatchers + *out = make([]QueryParameterMatcher, len(*in)) + copy(*out, *in) + } + if in.Methods != nil { + in, out := &in.Methods, &out.Methods + *out = make([]string, len(*in)) + copy(*out, *in) + } return } @@ -78,6 +109,22 @@ func (in *MultiDestination) DeepCopy() *MultiDestination { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *QueryParameterMatcher) DeepCopyInto(out *QueryParameterMatcher) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QueryParameterMatcher. +func (in *QueryParameterMatcher) DeepCopy() *QueryParameterMatcher { + if in == nil { + return nil + } + out := new(QueryParameterMatcher) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceRef) DeepCopyInto(out *ResourceRef) { *out = *in @@ -100,7 +147,9 @@ func (in *Route) DeepCopyInto(out *Route) { if in.Matchers != nil { in, out := &in.Matchers, &out.Matchers *out = make([]Matcher, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } in.Action.DeepCopyInto(&out.Action) return diff --git a/pkg/router/gloo.go b/pkg/router/gloo.go index 6d778ef7e..63094583a 100644 --- a/pkg/router/gloo.go +++ b/pkg/router/gloo.go @@ -35,10 +35,11 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error { newSpec := gloov1.RouteTableSpec{ Routes: []gloov1.Route{ { - // eventually inherit from parent, used for A/B rollouts too? Matchers: []gloov1.Matcher{ { - Prefix: "/", + Prefix: "/", + Headers: getHeaderMatchers(canary), + Methods: getMethods(canary), }, }, Action: gloov1.RouteAction{ @@ -178,7 +179,9 @@ func (gr *GlooRouter) SetRoutes( // eventually inherit from parent, used for A/B rollouts too? Matchers: []gloov1.Matcher{ { - Prefix: "/", + Prefix: "/", + Headers: getHeaderMatchers(canary), + Methods: getMethods(canary), }, }, Action: gloov1.RouteAction{ @@ -219,3 +222,34 @@ func (gr *GlooRouter) SetRoutes( func (gr *GlooRouter) Finalize(_ *flaggerv1.Canary) error { return nil } + +func getHeaderMatchers(canary *flaggerv1.Canary) []gloov1.HeaderMatcher { + var headerMatchers []gloov1.HeaderMatcher + for _, match := range canary.GetAnalysis().Match { + for s, stringMatch := range match.Headers { + h := gloov1.HeaderMatcher{ + Name: s, + Value: stringMatch.Exact, + } + if stringMatch.Regex != "" { + h = gloov1.HeaderMatcher{ + Name: s, + Value: stringMatch.Regex, + Regex: true, + } + } + headerMatchers = append(headerMatchers, h) + } + } + return headerMatchers +} + +func getMethods(canary *flaggerv1.Canary) []string { + var methods []string + for _, match := range canary.GetAnalysis().Match { + if stringMatch := match.Method; stringMatch != nil { + methods = append(methods, stringMatch.Exact) + } + } + return methods +} diff --git a/pkg/router/gloo_test.go b/pkg/router/gloo_test.go index f6958f6bf..32773c117 100644 --- a/pkg/router/gloo_test.go +++ b/pkg/router/gloo_test.go @@ -21,6 +21,7 @@ func TestGlooRouter_Sync(t *testing.T) { kubeClient: mocks.kubeClient, } + // init err := router.Reconcile(mocks.canary) require.NoError(t, err) @@ -31,6 +32,25 @@ func TestGlooRouter_Sync(t *testing.T) { assert.Len(t, dests, 2) assert.Equal(t, uint32(100), dests[0].Weight) assert.Equal(t, uint32(0), dests[1].Weight) + + // test headers update + cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) + require.NoError(t, err) + + cdClone := cd.DeepCopy() + cdClone.Spec.Analysis.Iterations = 5 + cdClone.Spec.Analysis.Match = newTestABTest().Spec.Analysis.Match + canary, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Update(context.TODO(), cdClone, metav1.UpdateOptions{}) + require.NoError(t, err) + + // apply change + err = router.Reconcile(canary) + require.NoError(t, err) + + rt, err = router.glooClient.GatewayV1().RouteTables("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) + require.NoError(t, err) + assert.Equal(t, "x-user-type", rt.Spec.Routes[0].Matchers[0].Headers[0].Name) + assert.Equal(t, "test", rt.Spec.Routes[0].Matchers[0].Headers[0].Value) } func TestGlooRouter_SetRoutes(t *testing.T) { @@ -74,6 +94,25 @@ func TestGlooRouter_SetRoutes(t *testing.T) { assert.Equal(t, uint32(p), pRoute.Weight) assert.Equal(t, uint32(c), cRoute.Weight) + + cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) + require.NoError(t, err) + + // test update to A/B + cdClone := cd.DeepCopy() + cdClone.Spec.Analysis.Iterations = 5 + cdClone.Spec.Analysis.Match = newTestABTest().Spec.Analysis.Match + canary, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Update(context.TODO(), cdClone, metav1.UpdateOptions{}) + require.NoError(t, err) + + // test set routes for A/B + err = router.SetRoutes(canary, 0, 100, false) + require.NoError(t, err) + + rt, err = router.glooClient.GatewayV1().RouteTables("default").Get(context.TODO(), "podinfo", metav1.GetOptions{}) + require.NoError(t, err) + assert.Equal(t, "x-user-type", rt.Spec.Routes[0].Matchers[0].Headers[0].Name) + assert.Equal(t, "test", rt.Spec.Routes[0].Matchers[0].Headers[0].Value) } func TestGlooRouter_GetRoutes(t *testing.T) { diff --git a/test/gloo/test-canary.sh b/test/gloo/test-canary.sh index 6a64b8537..f14e79d58 100755 --- a/test/gloo/test-canary.sh +++ b/test/gloo/test-canary.sh @@ -19,7 +19,7 @@ echo '>>> Installing load tester' kubectl apply -k ${REPO_ROOT}/kustomize/tester kubectl -n test rollout status deployment/flagger-loadtester -echo '>>> Initializing canary' +echo '>>> Initialising canary' kubectl apply -f ${REPO_ROOT}/test/e2e-workload.yaml >>>>>>> Initial commit:test/e2e-gloo-tests.sh @@ -127,4 +127,85 @@ until ${ok}; do fi done +echo '>>> Waiting for canary finalization' +retries=50 +count=0 +ok=false +until ${ok}; do + kubectl -n test get canary/podinfo | grep 'Succeeded' && ok=true || ok=false + sleep 5 + count=$(($count + 1)) + if [[ ${count} -eq ${retries} ]]; then + kubectl -n ingress-nginx logs deployment/flagger + echo "No more retries left" + exit 1 + fi +done + echo '✔ Canary promotion test passed' + +cat <>> Triggering A/B testing' +kubectl -n test set image deployment/podinfo podinfod=stefanprodan/podinfo:3.1.2 + +echo '>>> Waiting for A/B testing promotion' +retries=50 +count=0 +ok=false +until ${ok}; do + kubectl -n test describe deployment/podinfo-primary | grep '3.1.2' && ok=true || ok=false + sleep 10 + kubectl -n gloo-system logs deployment/flagger --tail 1 + count=$(($count + 1)) + if [[ ${count} -eq ${retries} ]]; then + kubectl -n gloo-system logs deployment/flagger + echo "No more retries left" + exit 1 + fi +done + +echo '✔ A/B testing promotion test passed' + +kubectl -n gloo-system logs deployment/flagger + +echo '✔ All tests passed' \ No newline at end of file From 657e2ef0f5bc1a36bbfc366da8f70653e841e683 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Sun, 20 Dec 2020 22:54:50 -0500 Subject: [PATCH 12/16] Update to use new Gloo Edge 1.6 API Signed-off-by: Kevin Dorosh --- pkg/apis/gloo/v1/types.go | 10 +++------- pkg/router/gloo.go | 35 +++++++++++++++++++++-------------- test/gloo/install.sh | 2 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pkg/apis/gloo/v1/types.go b/pkg/apis/gloo/v1/types.go index f372284a9..c9f54abcf 100644 --- a/pkg/apis/gloo/v1/types.go +++ b/pkg/apis/gloo/v1/types.go @@ -20,16 +20,12 @@ type RouteTableSpec struct { } type Route struct { - Matchers []Matcher `json:"matchers,omitempty"` - Action RouteAction `json:"routeAction,omitempty"` + Matchers []Matcher `json:"matchers,omitempty"` + Action RouteAction `json:"routeAction,omitempty"` + InheritablePathMatchers bool `json:"inheritablePathMatchers,omitempty"` } type Matcher struct { - // only one of Prefix, Exact, Regex may be nonempty - Prefix string `json:"prefix,omitempty"` - Exact string `json:"exact,omitempty"` - Regex string `json:"regex,omitempty"` - Headers []HeaderMatcher `json:"headers,omitempty"` QueryParameterMatchers []QueryParameterMatcher `json:"queryParameters,omitempty"` Methods []string `json:"methods,omitempty"` diff --git a/pkg/router/gloo.go b/pkg/router/gloo.go index 63094583a..589dd88f5 100644 --- a/pkg/router/gloo.go +++ b/pkg/router/gloo.go @@ -35,13 +35,8 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error { newSpec := gloov1.RouteTableSpec{ Routes: []gloov1.Route{ { - Matchers: []gloov1.Matcher{ - { - Prefix: "/", - Headers: getHeaderMatchers(canary), - Methods: getMethods(canary), - }, - }, + InheritablePathMatchers: true, + Matchers: getMatchers(canary), Action: gloov1.RouteAction{ Destination: gloov1.MultiDestination{ Destinations: []gloov1.WeightedDestination{ @@ -176,14 +171,9 @@ func (gr *GlooRouter) SetRoutes( routeTable.Spec = gloov1.RouteTableSpec{ Routes: []gloov1.Route{ { + InheritablePathMatchers: true, // eventually inherit from parent, used for A/B rollouts too? - Matchers: []gloov1.Matcher{ - { - Prefix: "/", - Headers: getHeaderMatchers(canary), - Methods: getMethods(canary), - }, - }, + Matchers: getMatchers(canary), Action: gloov1.RouteAction{ Destination: gloov1.MultiDestination{ Destinations: []gloov1.WeightedDestination{ @@ -223,6 +213,23 @@ func (gr *GlooRouter) Finalize(_ *flaggerv1.Canary) error { return nil } +func getMatchers(canary *flaggerv1.Canary) []gloov1.Matcher { + + headerMatchers := getHeaderMatchers(canary) + methods := getMethods(canary) + + if len(headerMatchers) == 0 && len(methods) == 0 { + return nil + } + + return []gloov1.Matcher{ + { + Headers: headerMatchers, + Methods: methods, + }, + } +} + func getHeaderMatchers(canary *flaggerv1.Canary) []gloov1.HeaderMatcher { var headerMatchers []gloov1.HeaderMatcher for _, match := range canary.GetAnalysis().Match { diff --git a/test/gloo/install.sh b/test/gloo/install.sh index 89a2f73a7..3b09f90be 100755 --- a/test/gloo/install.sh +++ b/test/gloo/install.sh @@ -2,7 +2,7 @@ set -o errexit -GLOO_VER="1.5.13" +GLOO_VER="1.6.0-beta22" # this can be replaced with 1.6.0 when it's released in two weeks REPO_ROOT=$(git rev-parse --show-toplevel) mkdir -p ${REPO_ROOT}/bin From 0085ccfa0c979c161b1ecd2c0bf8df4dc8e2b93f Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 21 Dec 2020 15:40:28 -0500 Subject: [PATCH 13/16] Remove dated comment Signed-off-by: Kevin Dorosh --- pkg/router/gloo.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/router/gloo.go b/pkg/router/gloo.go index 589dd88f5..a57558f7e 100644 --- a/pkg/router/gloo.go +++ b/pkg/router/gloo.go @@ -172,8 +172,7 @@ func (gr *GlooRouter) SetRoutes( Routes: []gloov1.Route{ { InheritablePathMatchers: true, - // eventually inherit from parent, used for A/B rollouts too? - Matchers: getMatchers(canary), + Matchers: getMatchers(canary), Action: gloov1.RouteAction{ Destination: gloov1.MultiDestination{ Destinations: []gloov1.WeightedDestination{ From f3b0581d9bd3ecee53273cab03da07954fd2d802 Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 21 Dec 2020 17:58:09 -0500 Subject: [PATCH 14/16] Fix rebase Signed-off-by: Kevin Dorosh --- test/README.md | 86 ---------------------------------------- test/gloo/test-canary.sh | 17 -------- 2 files changed, 103 deletions(-) diff --git a/test/README.md b/test/README.md index 5e0f21711..80d880ca4 100644 --- a/test/README.md +++ b/test/README.md @@ -1,6 +1,5 @@ # Flagger end-to-end testing -<<<<<<< HEAD The e2e testing infrastructure is powered by GitHub Actions and [Kubernetes Kind](https://github.com/kubernetes-sigs/kind). ### e2e workflow @@ -13,88 +12,3 @@ The e2e testing infrastructure is powered by GitHub Actions and [Kubernetes Kind * test the canary initialization (port discovery and metadata) * test the canary release (progressive traffic shifting, headers routing, mirroring, analysis, promotion, rollback) * test webhooks (conformance, load testing, pre/post rollout) -======= -The e2e testing infrastructure is powered by CircleCI and [Kubernetes Kind](https://github.com/kubernetes-sigs/kind). - -### CircleCI e2e Istio workflow - -* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) -* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) -* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) -* install latest stable Helm CLI [e2e-istio.sh](e2e-istio.sh) -* deploy Tiller on the local cluster [e2e-istio.sh](e2e-istio.sh) -* install Istio CRDs with Helm [e2e-istio.sh](e2e-istio.sh) -* install Istio control plane and Prometheus with Helm [e2e-istio.sh](e2e-istio.sh) -* load Flagger image onto the local cluster [e2e-istio.sh](e2e-istio.sh) -* deploy Flagger in the istio-system namespace [e2e-istio.sh](e2e-istio.sh) -* create a test namespace with Istio injection enabled [e2e-tests.sh](e2e-tests.sh) -* deploy the load tester in the test namespace [e2e-tests.sh](e2e-tests.sh) -* deploy a demo workload (podinfo) in the test namespace [e2e-tests.sh](e2e-tests.sh) -* test the canary initialization [e2e-tests.sh](e2e-tests.sh) -* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-tests.sh](e2e-tests.sh) -* test the A/B testing analysis and promotion using cookies filters and pre/post rollout webhooks [e2e-tests.sh](e2e-tests.sh) - -### CircleCI e2e Linkerd workflow - -* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) -* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) -* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) -* install Linkerd [e2e-linkerd.sh](e2e-linkerd.sh) -* load Flagger image onto the local cluster [e2e-linkerd.sh](e2e-linkerd.sh) -* deploy Flagger in the linkerd namespace with Kustomize [e2e-linkerd.sh](e2e-linkerd.sh) -* create a test namespace with Linkerd injection enabled [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) -* deploy the load tester in the test namespace [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) -* deploy a demo workload (podinfo) in the test namespace [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) -* test the canary initialization with port discovery enabled and service target port [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) -* test the canary analysis and promotion using gRPC acceptance tests and HTTP load tests [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) -* test the canary rollback on HTTP 500 errors [e2e-linkerd-tests.sh](e2e-linkerd-tests.sh) - -### CircleCI e2e NGINX ingress workflow - -* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) -* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) -* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) -* install latest stable Helm CLI [e2e-nginx.sh](e2e-nginx.sh) -* deploy Tiller on the local cluster [e2e-nginx.sh](e2e-nginx.sh) -* install NGINX ingress with Helm [e2e-nginx.sh](e2e-nginx.sh) -* load Flagger image onto the local cluster [e2e-nginx.sh](e2e-nginx.sh) -* install Flagger and Prometheus in the ingress-nginx namespace [e2e-nginx.sh](e2e-nginx.sh) -* create a test namespace [e2e-nginx-tests.sh](e2e-nginx-tests.sh) -* deploy the load tester in the test namespace [e2e-nginx-tests.sh](e2e-nginx-tests.sh) -* deploy the demo workload (podinfo) and ingress in the test namespace [e2e-nginx-tests.sh](e2e-nginx-tests.sh) -* test the canary initialization [e2e-nginx-tests.sh](e2e-nginx-tests.sh) -* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-nginx-tests.sh](e2e-nginx-tests.sh) -* test the A/B testing analysis and promotion using header filters and pre/post rollout webhooks [e2e-nginx-tests.sh](e2e-nginx-tests.sh) -* cleanup test environment [e2e-nginx-cleanup.sh](e2e-nginx-cleanup.sh) -* install NGINX Ingress and Flagger with custom ingress annotations prefix [e2e-nginx-custom-annotations.sh](e2e-nginx-custom-annotations.sh) -* repeat the canary and A/B testing workflow [e2e-nginx-tests.sh](e2e-nginx-tests.sh) - -### CircleCI e2e Skipper ingress workflow - -* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) -* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) -* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) -* install Skipper ingress with Kustomize [e2e-skipper.sh](e2e-skipper.sh) -* load Flagger image onto the local cluster [e2e-skipper.sh](e2e-skipper.sh) -* install Flagger and Prometheus in the flagger-system namespace [e2e-skipper.sh](e2e-skipper.sh) -* create a test namespace [e2e-skipper-tests.sh](e2e-skipper-tests.sh) -* deploy the load tester in the test namespace [e2e-skipper-tests.sh](e2e-skipper-tests.sh) -* deploy the demo workload (podinfo) and ingress in the test namespace [e2e-skipper-tests.sh](e2e-skipper-tests.sh) -* test the canary initialization [e2e-skipper-tests.sh](e2e-skipper-tests.sh) -* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-skipper-tests.sh](e2e-skipper-tests.sh) -* cleanup test environment [e2e-skipper-cleanup.sh](e2e-skipper-cleanup.sh) - -### CircleCI e2e Traefik workflow - -* install latest stable kubectl [e2e-kind.sh](e2e-kind.sh) -* install Kubernetes Kind [e2e-kind.sh](e2e-kind.sh) -* create local Kubernetes cluster with kind [e2e-kind.sh](e2e-kind.sh) -* install Traeik with Helm [e2e-traefik.sh](e2e-traefik.sh) -* load Flagger image onto the local cluster [e2e-traefik.sh](e2e-traefik.sh) -* install Flagger and Prometheus in the traefik namespace [e2e-traefik.sh](e2e-traefik.sh) -* create a test namespace [e2e-traefik-tests.sh](e2e-traefik-tests.sh) -* deploy the load tester in the test namespace [e2e-traefik-tests.sh](e2e-traefik-tests.sh) -* deploy the demo workload (podinfo) and ingress in the test namespace [e2e-traefik-tests.sh](e2e-traefik-tests.sh) -* test the canary initialization [e2e-traefik-tests.sh](e2e-traefik-tests.sh) -* test the canary analysis and promotion using weighted traffic and the load testing webhook [e2e-traefik-tests.sh](e2e-traefik-tests.sh) ->>>>>>> Small docs fixes diff --git a/test/gloo/test-canary.sh b/test/gloo/test-canary.sh index f14e79d58..95932b48b 100755 --- a/test/gloo/test-canary.sh +++ b/test/gloo/test-canary.sh @@ -1,28 +1,11 @@ #!/usr/bin/env bash # This script runs e2e tests for Canary initialization, analysis and promotion -<<<<<<< HEAD:test/gloo/test-canary.sh -======= -# Prerequisites: Kubernetes Kind, Helm and Gloo Edge ingress controller ->>>>>>> Initial commit:test/e2e-gloo-tests.sh set -o errexit REPO_ROOT=$(git rev-parse --show-toplevel) -<<<<<<< HEAD:test/gloo/test-canary.sh -======= -echo '>>> Creating test namespace' -kubectl create namespace test - -echo '>>> Installing load tester' -kubectl apply -k ${REPO_ROOT}/kustomize/tester -kubectl -n test rollout status deployment/flagger-loadtester - -echo '>>> Initialising canary' -kubectl apply -f ${REPO_ROOT}/test/e2e-workload.yaml - ->>>>>>> Initial commit:test/e2e-gloo-tests.sh cat < Date: Mon, 21 Dec 2020 16:37:16 -0500 Subject: [PATCH 15/16] Guide is working Signed-off-by: Kevin Dorosh --- docs/gitbook/tutorials/gloo-progressive-delivery.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gitbook/tutorials/gloo-progressive-delivery.md b/docs/gitbook/tutorials/gloo-progressive-delivery.md index abc4e20a3..16c684f3e 100644 --- a/docs/gitbook/tutorials/gloo-progressive-delivery.md +++ b/docs/gitbook/tutorials/gloo-progressive-delivery.md @@ -55,7 +55,7 @@ Deploy the load testing service to generate traffic during the canary analysis: kubectl -n test apply -k github.com/weaveworks/flagger//kustomize/tester ``` -Create an virtual service definition that references an route table that will be generated by Flagger +Create a virtual service definition that references a route table that will be generated by Flagger (replace `app.example.com` with your own domain): ```yaml From 3bc8a0280d5c8889e149f8a8a833b20705a0764d Mon Sep 17 00:00:00 2001 From: Kevin Dorosh Date: Mon, 21 Dec 2020 16:43:44 -0500 Subject: [PATCH 16/16] We are generating 404s not 400s Signed-off-by: Kevin Dorosh --- docs/gitbook/tutorials/gloo-progressive-delivery.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gitbook/tutorials/gloo-progressive-delivery.md b/docs/gitbook/tutorials/gloo-progressive-delivery.md index 16c684f3e..10884943e 100644 --- a/docs/gitbook/tutorials/gloo-progressive-delivery.md +++ b/docs/gitbook/tutorials/gloo-progressive-delivery.md @@ -356,7 +356,7 @@ podinfod=stefanprodan/podinfo:3.1.3 Generate 404s: ```bash -watch curl -H 'Host: app.example.com' http://gateway-proxy.gloo-system/status/400 +watch curl -H 'Host: app.example.com' http://gateway-proxy.gloo-system/status/404 ``` Watch Flagger logs: