diff --git a/.circleci/config.yml b/.circleci/config.yml index f9164539d..9d79a90bf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,6 +9,15 @@ jobs: - run: test/e2e-build.sh - run: test/e2e-tests.sh + e2e-smi-istio-testing: + machine: true + steps: + - checkout + - run: test/e2e-kind.sh + - run: test/e2e-istio.sh + - run: test/e2e-smi-istio-build.sh + - run: test/e2e-tests.sh canary + e2e-supergloo-testing: machine: true steps: @@ -38,6 +47,13 @@ workflows: - /gh-pages.*/ - /docs-.*/ - /release-.*/ + - e2e-smi-istio-testing: + filters: + branches: + ignore: + - /gh-pages.*/ + - /docs-.*/ + - /release-.*/ - e2e-supergloo-testing: filters: branches: diff --git a/Makefile b/Makefile index 262f98b9d..15771dccd 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,12 @@ run-nginx: -slack-url=https://hooks.slack.com/services/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 \ -slack-channel="devops-alerts" +run-smi: + go run cmd/flagger/* -kubeconfig=$$HOME/.kube/config -log-level=info -mesh-provider=smi:istio -namespace=smi \ + -metrics-server=https://prometheus.istio.weavedx.com \ + -slack-url=https://hooks.slack.com/services/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 \ + -slack-channel="devops-alerts" + build: docker build -t weaveworks/flagger:$(TAG) . -f Dockerfile diff --git a/README.md b/README.md index 60e382c8f..9e20ec4a5 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,6 @@ spec: # Istio gateways (optional) gateways: - public-gateway.istio-system.svc.cluster.local - - mesh # Istio virtual service host names (optional) hosts: - podinfo.example.com @@ -93,17 +92,12 @@ spec: # HTTP rewrite (optional) rewrite: uri: / - # Envoy timeout and retry policy (optional) - headers: - request: - add: - x-envoy-upstream-rq-timeout-ms: "15000" - x-envoy-max-retries: "10" - x-envoy-retry-on: "gateway-error,connect-failure,refused-stream" # cross-origin resource sharing policy (optional) corsPolicy: allowOrigin: - example.com + # request timeout (optional) + timeout: 5s # promote the canary without analysing it (default false) skipAnalysis: false # define the canary analysis timing and KPIs diff --git a/artifacts/flagger/account.yaml b/artifacts/flagger/account.yaml index 0fac89ad3..d31e75687 100644 --- a/artifacts/flagger/account.yaml +++ b/artifacts/flagger/account.yaml @@ -59,6 +59,11 @@ rules: - virtualservices - virtualservices/status verbs: ["*"] + - apiGroups: + - split.smi-spec.io + resources: + - trafficsplits + verbs: ["*"] - nonResourceURLs: - /version verbs: diff --git a/artifacts/smi/istio-adapter.yaml b/artifacts/smi/istio-adapter.yaml new file mode 100644 index 000000000..eaebdcb8e --- /dev/null +++ b/artifacts/smi/istio-adapter.yaml @@ -0,0 +1,131 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: trafficsplits.split.smi-spec.io +spec: + additionalPrinterColumns: + - JSONPath: .spec.service + description: The service + name: Service + type: string + group: split.smi-spec.io + names: + kind: TrafficSplit + listKind: TrafficSplitList + plural: trafficsplits + singular: trafficsplit + scope: Namespaced + subresources: + status: {} + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: smi-adapter-istio + namespace: istio-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: smi-adapter-istio +rules: + - apiGroups: + - "" + resources: + - pods + - services + - endpoints + - persistentvolumeclaims + - events + - configmaps + - secrets + verbs: + - '*' + - apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - '*' + - apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + verbs: + - get + - create + - apiGroups: + - apps + resourceNames: + - smi-adapter-istio + resources: + - deployments/finalizers + verbs: + - update + - apiGroups: + - split.smi-spec.io + resources: + - '*' + verbs: + - '*' + - apiGroups: + - networking.istio.io + resources: + - '*' + verbs: + - '*' +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: smi-adapter-istio +subjects: + - kind: ServiceAccount + name: smi-adapter-istio + namespace: istio-system +roleRef: + kind: ClusterRole + name: smi-adapter-istio + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: smi-adapter-istio + namespace: istio-system +spec: + replicas: 1 + selector: + matchLabels: + name: smi-adapter-istio + template: + metadata: + labels: + name: smi-adapter-istio + annotations: + sidecar.istio.io/inject: "false" + spec: + serviceAccountName: smi-adapter-istio + containers: + - name: smi-adapter-istio + image: docker.io/stefanprodan/smi-adapter-istio:0.0.2-beta.1 + command: + - smi-adapter-istio + imagePullPolicy: Always + env: + - name: WATCH_NAMESPACE + value: "" + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: OPERATOR_NAME + value: "smi-adapter-istio" diff --git a/charts/flagger/templates/rbac.yaml b/charts/flagger/templates/rbac.yaml index e03755c08..782e1df14 100644 --- a/charts/flagger/templates/rbac.yaml +++ b/charts/flagger/templates/rbac.yaml @@ -55,6 +55,11 @@ rules: - virtualservices - virtualservices/status verbs: ["*"] + - apiGroups: + - split.smi-spec.io + resources: + - trafficsplits + verbs: ["*"] - nonResourceURLs: - /version verbs: diff --git a/docs/gitbook/how-it-works.md b/docs/gitbook/how-it-works.md index d5c9160fb..3a08f8ebe 100644 --- a/docs/gitbook/how-it-works.md +++ b/docs/gitbook/how-it-works.md @@ -38,7 +38,6 @@ spec: # Istio gateways (optional) gateways: - public-gateway.istio-system.svc.cluster.local - - mesh # Istio virtual service host names (optional) hosts: - podinfo.example.com diff --git a/docs/gitbook/usage/ab-testing.md b/docs/gitbook/usage/ab-testing.md index 3014a7949..32bdc9e36 100644 --- a/docs/gitbook/usage/ab-testing.md +++ b/docs/gitbook/usage/ab-testing.md @@ -60,7 +60,6 @@ spec: # Istio gateways (optional) gateways: - public-gateway.istio-system.svc.cluster.local - - mesh # Istio virtual service host names (optional) hosts: - app.example.com diff --git a/docs/gitbook/usage/progressive-delivery.md b/docs/gitbook/usage/progressive-delivery.md index 2bb25dcff..0c6936577 100644 --- a/docs/gitbook/usage/progressive-delivery.md +++ b/docs/gitbook/usage/progressive-delivery.md @@ -54,7 +54,6 @@ spec: # Istio gateways (optional) gateways: - public-gateway.istio-system.svc.cluster.local - - mesh # Istio virtual service host names (optional) hosts: - app.example.com diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 4cdcbb363..5ca27f136 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -23,5 +23,5 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-ge ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/weaveworks/flagger/pkg/client github.com/weaveworks/flagger/pkg/apis \ - "appmesh:v1beta1 istio:v1alpha3 flagger:v1alpha3" \ + "appmesh:v1beta1 istio:v1alpha3 flagger:v1alpha3 smi:v1alpha1" \ --go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt diff --git a/pkg/apis/smi/register.go b/pkg/apis/smi/register.go new file mode 100644 index 000000000..67cbbf793 --- /dev/null +++ b/pkg/apis/smi/register.go @@ -0,0 +1,5 @@ +package smi + +const ( + GroupName = "split.smi-spec.io" +) diff --git a/pkg/apis/smi/v1alpha1/doc.go b/pkg/apis/smi/v1alpha1/doc.go new file mode 100644 index 000000000..7792b7f6b --- /dev/null +++ b/pkg/apis/smi/v1alpha1/doc.go @@ -0,0 +1,4 @@ +// +k8s:deepcopy-gen=package +// +groupName=split.smi-spec.io + +package v1alpha1 diff --git a/pkg/apis/smi/v1alpha1/register.go b/pkg/apis/smi/v1alpha1/register.go new file mode 100644 index 000000000..c9868ec52 --- /dev/null +++ b/pkg/apis/smi/v1alpha1/register.go @@ -0,0 +1,48 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + ts "github.com/weaveworks/flagger/pkg/apis/smi" +) + +// SchemeGroupVersion is the identifier for the API which includes +// the name of the group and the version of the API +var SchemeGroupVersion = schema.GroupVersion{ + Group: ts.GroupName, + Version: "v1alpha1", +} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder collects functions that add things to a scheme. It's to allow + // code to compile without explicitly referencing generated types. You should + // declare one in each package that will have generated deep copy or conversion + // functions. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + + // AddToScheme applies all the stored functions to the scheme. A non-nil error + // indicates that one function failed and the attempt was abandoned. + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TrafficSplit{}, + &TrafficSplitList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/smi/v1alpha1/traffic_split.go b/pkg/apis/smi/v1alpha1/traffic_split.go new file mode 100644 index 000000000..725748324 --- /dev/null +++ b/pkg/apis/smi/v1alpha1/traffic_split.go @@ -0,0 +1,56 @@ +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TrafficSplit allows users to incrementally direct percentages of traffic +// between various services. It will be used by clients such as ingress +// controllers or service mesh sidecars to split the outgoing traffic to +// different destinations. +type TrafficSplit struct { + metav1.TypeMeta `json:",inline"` + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // Specification of the desired behavior of the traffic split. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status + // +optional + Spec TrafficSplitSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` + + // Most recently observed status of the pod. + // This data may not be up to date. + // Populated by the system. + // Read-only. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status + // +optional + //Status Status `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` +} + +// TrafficSplitSpec is the specification for a TrafficSplit +type TrafficSplitSpec struct { + Service string `json:"service,omitempty"` + Backends []TrafficSplitBackend `json:"backends,omitempty"` +} + +// TrafficSplitBackend defines a backend +type TrafficSplitBackend struct { + Service string `json:"service,omitempty"` + Weight *resource.Quantity `json:"weight,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type TrafficSplitList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []TrafficSplit `json:"items"` +} diff --git a/pkg/apis/smi/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/smi/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..96694d48e --- /dev/null +++ b/pkg/apis/smi/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,129 @@ +// +build !ignore_autogenerated + +/* +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 deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrafficSplit) DeepCopyInto(out *TrafficSplit) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficSplit. +func (in *TrafficSplit) DeepCopy() *TrafficSplit { + if in == nil { + return nil + } + out := new(TrafficSplit) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TrafficSplit) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrafficSplitBackend) DeepCopyInto(out *TrafficSplitBackend) { + *out = *in + if in.Weight != nil { + in, out := &in.Weight, &out.Weight + x := (*in).DeepCopy() + *out = &x + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficSplitBackend. +func (in *TrafficSplitBackend) DeepCopy() *TrafficSplitBackend { + if in == nil { + return nil + } + out := new(TrafficSplitBackend) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrafficSplitList) DeepCopyInto(out *TrafficSplitList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TrafficSplit, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficSplitList. +func (in *TrafficSplitList) DeepCopy() *TrafficSplitList { + if in == nil { + return nil + } + out := new(TrafficSplitList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TrafficSplitList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrafficSplitSpec) DeepCopyInto(out *TrafficSplitSpec) { + *out = *in + if in.Backends != nil { + in, out := &in.Backends, &out.Backends + *out = make([]TrafficSplitBackend, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficSplitSpec. +func (in *TrafficSplitSpec) DeepCopy() *TrafficSplitSpec { + if in == nil { + return nil + } + out := new(TrafficSplitSpec) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index c6039c8f1..1a3e17bcf 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -22,6 +22,7 @@ import ( appmeshv1beta1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/appmesh/v1beta1" flaggerv1alpha3 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/flagger/v1alpha3" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/istio/v1alpha3" + splitv1alpha1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/smi/v1alpha1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -38,6 +39,9 @@ type Interface interface { NetworkingV1alpha3() networkingv1alpha3.NetworkingV1alpha3Interface // Deprecated: please explicitly pick a version if possible. Networking() networkingv1alpha3.NetworkingV1alpha3Interface + SplitV1alpha1() splitv1alpha1.SplitV1alpha1Interface + // Deprecated: please explicitly pick a version if possible. + Split() splitv1alpha1.SplitV1alpha1Interface } // Clientset contains the clients for groups. Each group has exactly one @@ -47,6 +51,7 @@ type Clientset struct { appmeshV1beta1 *appmeshv1beta1.AppmeshV1beta1Client flaggerV1alpha3 *flaggerv1alpha3.FlaggerV1alpha3Client networkingV1alpha3 *networkingv1alpha3.NetworkingV1alpha3Client + splitV1alpha1 *splitv1alpha1.SplitV1alpha1Client } // AppmeshV1beta1 retrieves the AppmeshV1beta1Client @@ -82,6 +87,17 @@ func (c *Clientset) Networking() networkingv1alpha3.NetworkingV1alpha3Interface return c.networkingV1alpha3 } +// SplitV1alpha1 retrieves the SplitV1alpha1Client +func (c *Clientset) SplitV1alpha1() splitv1alpha1.SplitV1alpha1Interface { + return c.splitV1alpha1 +} + +// Deprecated: Split retrieves the default version of SplitClient. +// Please explicitly pick a version. +func (c *Clientset) Split() splitv1alpha1.SplitV1alpha1Interface { + return c.splitV1alpha1 +} + // Discovery retrieves the DiscoveryClient func (c *Clientset) Discovery() discovery.DiscoveryInterface { if c == nil { @@ -110,6 +126,10 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } + cs.splitV1alpha1, err = splitv1alpha1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) if err != nil { @@ -125,6 +145,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { cs.appmeshV1beta1 = appmeshv1beta1.NewForConfigOrDie(c) cs.flaggerV1alpha3 = flaggerv1alpha3.NewForConfigOrDie(c) cs.networkingV1alpha3 = networkingv1alpha3.NewForConfigOrDie(c) + cs.splitV1alpha1 = splitv1alpha1.NewForConfigOrDie(c) cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) return &cs @@ -136,6 +157,7 @@ func New(c rest.Interface) *Clientset { cs.appmeshV1beta1 = appmeshv1beta1.New(c) cs.flaggerV1alpha3 = flaggerv1alpha3.New(c) cs.networkingV1alpha3 = networkingv1alpha3.New(c) + cs.splitV1alpha1 = splitv1alpha1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index abb769814..57e467ca0 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -26,6 +26,8 @@ import ( fakeflaggerv1alpha3 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/flagger/v1alpha3/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" + splitv1alpha1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/smi/v1alpha1" + fakesplitv1alpha1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" @@ -104,3 +106,13 @@ func (c *Clientset) NetworkingV1alpha3() networkingv1alpha3.NetworkingV1alpha3In func (c *Clientset) Networking() networkingv1alpha3.NetworkingV1alpha3Interface { return &fakenetworkingv1alpha3.FakeNetworkingV1alpha3{Fake: &c.Fake} } + +// SplitV1alpha1 retrieves the SplitV1alpha1Client +func (c *Clientset) SplitV1alpha1() splitv1alpha1.SplitV1alpha1Interface { + return &fakesplitv1alpha1.FakeSplitV1alpha1{Fake: &c.Fake} +} + +// Split retrieves the SplitV1alpha1Client +func (c *Clientset) Split() splitv1alpha1.SplitV1alpha1Interface { + return &fakesplitv1alpha1.FakeSplitV1alpha1{Fake: &c.Fake} +} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 29214ba66..b5910b2e2 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -22,6 +22,7 @@ import ( appmeshv1beta1 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta1" flaggerv1alpha3 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3" + splitv1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -36,6 +37,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ appmeshv1beta1.AddToScheme, flaggerv1alpha3.AddToScheme, networkingv1alpha3.AddToScheme, + splitv1alpha1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index c1e0adcc0..7337f87a8 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -22,6 +22,7 @@ import ( appmeshv1beta1 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta1" flaggerv1alpha3 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" networkingv1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3" + splitv1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -36,6 +37,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ appmeshv1beta1.AddToScheme, flaggerv1alpha3.AddToScheme, networkingv1alpha3.AddToScheme, + splitv1alpha1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/doc.go new file mode 100644 index 000000000..20b3d7fd1 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* +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. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/doc.go new file mode 100644 index 000000000..7a3b19cb7 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* +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 has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/fake_smi_client.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/fake_smi_client.go new file mode 100644 index 000000000..e3cf89ede --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/fake_smi_client.go @@ -0,0 +1,40 @@ +/* +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 ( + v1alpha1 "github.com/weaveworks/flagger/pkg/client/clientset/versioned/typed/smi/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeSplitV1alpha1 struct { + *testing.Fake +} + +func (c *FakeSplitV1alpha1) TrafficSplits(namespace string) v1alpha1.TrafficSplitInterface { + return &FakeTrafficSplits{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSplitV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/fake_trafficsplit.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/fake_trafficsplit.go new file mode 100644 index 000000000..ac6b67ccd --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/fake/fake_trafficsplit.go @@ -0,0 +1,128 @@ +/* +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 ( + v1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" + 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" +) + +// FakeTrafficSplits implements TrafficSplitInterface +type FakeTrafficSplits struct { + Fake *FakeSplitV1alpha1 + ns string +} + +var trafficsplitsResource = schema.GroupVersionResource{Group: "split.smi-spec.io", Version: "v1alpha1", Resource: "trafficsplits"} + +var trafficsplitsKind = schema.GroupVersionKind{Group: "split.smi-spec.io", Version: "v1alpha1", Kind: "TrafficSplit"} + +// Get takes name of the trafficSplit, and returns the corresponding trafficSplit object, and an error if there is any. +func (c *FakeTrafficSplits) Get(name string, options v1.GetOptions) (result *v1alpha1.TrafficSplit, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(trafficsplitsResource, c.ns, name), &v1alpha1.TrafficSplit{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrafficSplit), err +} + +// List takes label and field selectors, and returns the list of TrafficSplits that match those selectors. +func (c *FakeTrafficSplits) List(opts v1.ListOptions) (result *v1alpha1.TrafficSplitList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(trafficsplitsResource, trafficsplitsKind, c.ns, opts), &v1alpha1.TrafficSplitList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.TrafficSplitList{ListMeta: obj.(*v1alpha1.TrafficSplitList).ListMeta} + for _, item := range obj.(*v1alpha1.TrafficSplitList).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 trafficSplits. +func (c *FakeTrafficSplits) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(trafficsplitsResource, c.ns, opts)) + +} + +// Create takes the representation of a trafficSplit and creates it. Returns the server's representation of the trafficSplit, and an error, if there is any. +func (c *FakeTrafficSplits) Create(trafficSplit *v1alpha1.TrafficSplit) (result *v1alpha1.TrafficSplit, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(trafficsplitsResource, c.ns, trafficSplit), &v1alpha1.TrafficSplit{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrafficSplit), err +} + +// Update takes the representation of a trafficSplit and updates it. Returns the server's representation of the trafficSplit, and an error, if there is any. +func (c *FakeTrafficSplits) Update(trafficSplit *v1alpha1.TrafficSplit) (result *v1alpha1.TrafficSplit, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(trafficsplitsResource, c.ns, trafficSplit), &v1alpha1.TrafficSplit{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrafficSplit), err +} + +// Delete takes name of the trafficSplit and deletes it. Returns an error if one occurs. +func (c *FakeTrafficSplits) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(trafficsplitsResource, c.ns, name), &v1alpha1.TrafficSplit{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTrafficSplits) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(trafficsplitsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.TrafficSplitList{}) + return err +} + +// Patch applies the patch and returns the patched trafficSplit. +func (c *FakeTrafficSplits) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.TrafficSplit, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(trafficsplitsResource, c.ns, name, pt, data, subresources...), &v1alpha1.TrafficSplit{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrafficSplit), err +} diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/generated_expansion.go new file mode 100644 index 000000000..4cc5c42a8 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/generated_expansion.go @@ -0,0 +1,21 @@ +/* +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 v1alpha1 + +type TrafficSplitExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/smi_client.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/smi_client.go new file mode 100644 index 000000000..745325bdf --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/smi_client.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 client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" + "github.com/weaveworks/flagger/pkg/client/clientset/versioned/scheme" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" +) + +type SplitV1alpha1Interface interface { + RESTClient() rest.Interface + TrafficSplitsGetter +} + +// SplitV1alpha1Client is used to interact with features provided by the split.smi-spec.io group. +type SplitV1alpha1Client struct { + restClient rest.Interface +} + +func (c *SplitV1alpha1Client) TrafficSplits(namespace string) TrafficSplitInterface { + return newTrafficSplits(c, namespace) +} + +// NewForConfig creates a new SplitV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*SplitV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &SplitV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new SplitV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *SplitV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new SplitV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *SplitV1alpha1Client { + return &SplitV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SplitV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/smi/v1alpha1/trafficsplit.go b/pkg/client/clientset/versioned/typed/smi/v1alpha1/trafficsplit.go new file mode 100644 index 000000000..18f7bdc64 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/smi/v1alpha1/trafficsplit.go @@ -0,0 +1,174 @@ +/* +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 v1alpha1 + +import ( + "time" + + v1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" + scheme "github.com/weaveworks/flagger/pkg/client/clientset/versioned/scheme" + v1 "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" +) + +// TrafficSplitsGetter has a method to return a TrafficSplitInterface. +// A group's client should implement this interface. +type TrafficSplitsGetter interface { + TrafficSplits(namespace string) TrafficSplitInterface +} + +// TrafficSplitInterface has methods to work with TrafficSplit resources. +type TrafficSplitInterface interface { + Create(*v1alpha1.TrafficSplit) (*v1alpha1.TrafficSplit, error) + Update(*v1alpha1.TrafficSplit) (*v1alpha1.TrafficSplit, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.TrafficSplit, error) + List(opts v1.ListOptions) (*v1alpha1.TrafficSplitList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.TrafficSplit, err error) + TrafficSplitExpansion +} + +// trafficSplits implements TrafficSplitInterface +type trafficSplits struct { + client rest.Interface + ns string +} + +// newTrafficSplits returns a TrafficSplits +func newTrafficSplits(c *SplitV1alpha1Client, namespace string) *trafficSplits { + return &trafficSplits{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the trafficSplit, and returns the corresponding trafficSplit object, and an error if there is any. +func (c *trafficSplits) Get(name string, options v1.GetOptions) (result *v1alpha1.TrafficSplit, err error) { + result = &v1alpha1.TrafficSplit{} + err = c.client.Get(). + Namespace(c.ns). + Resource("trafficsplits"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of TrafficSplits that match those selectors. +func (c *trafficSplits) List(opts v1.ListOptions) (result *v1alpha1.TrafficSplitList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.TrafficSplitList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("trafficsplits"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested trafficSplits. +func (c *trafficSplits) Watch(opts v1.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("trafficsplits"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a trafficSplit and creates it. Returns the server's representation of the trafficSplit, and an error, if there is any. +func (c *trafficSplits) Create(trafficSplit *v1alpha1.TrafficSplit) (result *v1alpha1.TrafficSplit, err error) { + result = &v1alpha1.TrafficSplit{} + err = c.client.Post(). + Namespace(c.ns). + Resource("trafficsplits"). + Body(trafficSplit). + Do(). + Into(result) + return +} + +// Update takes the representation of a trafficSplit and updates it. Returns the server's representation of the trafficSplit, and an error, if there is any. +func (c *trafficSplits) Update(trafficSplit *v1alpha1.TrafficSplit) (result *v1alpha1.TrafficSplit, err error) { + result = &v1alpha1.TrafficSplit{} + err = c.client.Put(). + Namespace(c.ns). + Resource("trafficsplits"). + Name(trafficSplit.Name). + Body(trafficSplit). + Do(). + Into(result) + return +} + +// Delete takes name of the trafficSplit and deletes it. Returns an error if one occurs. +func (c *trafficSplits) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("trafficsplits"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *trafficSplits) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("trafficsplits"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched trafficSplit. +func (c *trafficSplits) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.TrafficSplit, err error) { + result = &v1alpha1.TrafficSplit{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("trafficsplits"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 62626dd95..c19c5ca26 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -28,6 +28,7 @@ import ( flagger "github.com/weaveworks/flagger/pkg/client/informers/externalversions/flagger" internalinterfaces "github.com/weaveworks/flagger/pkg/client/informers/externalversions/internalinterfaces" istio "github.com/weaveworks/flagger/pkg/client/informers/externalversions/istio" + smi "github.com/weaveworks/flagger/pkg/client/informers/externalversions/smi" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -177,6 +178,7 @@ type SharedInformerFactory interface { Appmesh() appmesh.Interface Flagger() flagger.Interface Networking() istio.Interface + Split() smi.Interface } func (f *sharedInformerFactory) Appmesh() appmesh.Interface { @@ -190,3 +192,7 @@ func (f *sharedInformerFactory) Flagger() flagger.Interface { func (f *sharedInformerFactory) Networking() istio.Interface { return istio.New(f, f.namespace, f.tweakListOptions) } + +func (f *sharedInformerFactory) Split() smi.Interface { + return smi.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index f938d50b7..b374b9be7 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -24,6 +24,7 @@ import ( v1beta1 "github.com/weaveworks/flagger/pkg/apis/appmesh/v1beta1" v1alpha3 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" istiov1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3" + v1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) @@ -70,6 +71,10 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case istiov1alpha3.SchemeGroupVersion.WithResource("virtualservices"): return &genericInformer{resource: resource.GroupResource(), informer: f.Networking().V1alpha3().VirtualServices().Informer()}, nil + // Group=split.smi-spec.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("trafficsplits"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Split().V1alpha1().TrafficSplits().Informer()}, nil + } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/pkg/client/informers/externalversions/smi/interface.go b/pkg/client/informers/externalversions/smi/interface.go new file mode 100644 index 000000000..cfc8f7193 --- /dev/null +++ b/pkg/client/informers/externalversions/smi/interface.go @@ -0,0 +1,46 @@ +/* +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 split + +import ( + internalinterfaces "github.com/weaveworks/flagger/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/weaveworks/flagger/pkg/client/informers/externalversions/smi/v1alpha1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/smi/v1alpha1/interface.go b/pkg/client/informers/externalversions/smi/v1alpha1/interface.go new file mode 100644 index 000000000..dabfa5487 --- /dev/null +++ b/pkg/client/informers/externalversions/smi/v1alpha1/interface.go @@ -0,0 +1,45 @@ +/* +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 v1alpha1 + +import ( + internalinterfaces "github.com/weaveworks/flagger/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // TrafficSplits returns a TrafficSplitInformer. + TrafficSplits() TrafficSplitInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// TrafficSplits returns a TrafficSplitInformer. +func (v *version) TrafficSplits() TrafficSplitInformer { + return &trafficSplitInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/smi/v1alpha1/trafficsplit.go b/pkg/client/informers/externalversions/smi/v1alpha1/trafficsplit.go new file mode 100644 index 000000000..feb6b703a --- /dev/null +++ b/pkg/client/informers/externalversions/smi/v1alpha1/trafficsplit.go @@ -0,0 +1,89 @@ +/* +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 v1alpha1 + +import ( + time "time" + + smiv1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" + versioned "github.com/weaveworks/flagger/pkg/client/clientset/versioned" + internalinterfaces "github.com/weaveworks/flagger/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/weaveworks/flagger/pkg/client/listers/smi/v1alpha1" + v1 "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" +) + +// TrafficSplitInformer provides access to a shared informer and lister for +// TrafficSplits. +type TrafficSplitInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.TrafficSplitLister +} + +type trafficSplitInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTrafficSplitInformer constructs a new informer for TrafficSplit 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 NewTrafficSplitInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTrafficSplitInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTrafficSplitInformer constructs a new informer for TrafficSplit 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 NewFilteredTrafficSplitInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SplitV1alpha1().TrafficSplits(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SplitV1alpha1().TrafficSplits(namespace).Watch(options) + }, + }, + &smiv1alpha1.TrafficSplit{}, + resyncPeriod, + indexers, + ) +} + +func (f *trafficSplitInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTrafficSplitInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *trafficSplitInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&smiv1alpha1.TrafficSplit{}, f.defaultInformer) +} + +func (f *trafficSplitInformer) Lister() v1alpha1.TrafficSplitLister { + return v1alpha1.NewTrafficSplitLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/listers/smi/v1alpha1/expansion_generated.go b/pkg/client/listers/smi/v1alpha1/expansion_generated.go new file mode 100644 index 000000000..271ee2430 --- /dev/null +++ b/pkg/client/listers/smi/v1alpha1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +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 v1alpha1 + +// TrafficSplitListerExpansion allows custom methods to be added to +// TrafficSplitLister. +type TrafficSplitListerExpansion interface{} + +// TrafficSplitNamespaceListerExpansion allows custom methods to be added to +// TrafficSplitNamespaceLister. +type TrafficSplitNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/smi/v1alpha1/trafficsplit.go b/pkg/client/listers/smi/v1alpha1/trafficsplit.go new file mode 100644 index 000000000..23c52eba1 --- /dev/null +++ b/pkg/client/listers/smi/v1alpha1/trafficsplit.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 v1alpha1 + +import ( + v1alpha1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// TrafficSplitLister helps list TrafficSplits. +type TrafficSplitLister interface { + // List lists all TrafficSplits in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.TrafficSplit, err error) + // TrafficSplits returns an object that can list and get TrafficSplits. + TrafficSplits(namespace string) TrafficSplitNamespaceLister + TrafficSplitListerExpansion +} + +// trafficSplitLister implements the TrafficSplitLister interface. +type trafficSplitLister struct { + indexer cache.Indexer +} + +// NewTrafficSplitLister returns a new TrafficSplitLister. +func NewTrafficSplitLister(indexer cache.Indexer) TrafficSplitLister { + return &trafficSplitLister{indexer: indexer} +} + +// List lists all TrafficSplits in the indexer. +func (s *trafficSplitLister) List(selector labels.Selector) (ret []*v1alpha1.TrafficSplit, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.TrafficSplit)) + }) + return ret, err +} + +// TrafficSplits returns an object that can list and get TrafficSplits. +func (s *trafficSplitLister) TrafficSplits(namespace string) TrafficSplitNamespaceLister { + return trafficSplitNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// TrafficSplitNamespaceLister helps list and get TrafficSplits. +type TrafficSplitNamespaceLister interface { + // List lists all TrafficSplits in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.TrafficSplit, err error) + // Get retrieves the TrafficSplit from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.TrafficSplit, error) + TrafficSplitNamespaceListerExpansion +} + +// trafficSplitNamespaceLister implements the TrafficSplitNamespaceLister +// interface. +type trafficSplitNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TrafficSplits in the indexer for a given namespace. +func (s trafficSplitNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.TrafficSplit, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.TrafficSplit)) + }) + return ret, err +} + +// Get retrieves the TrafficSplit from the indexer for a given namespace and name. +func (s trafficSplitNamespaceLister) Get(name string) (*v1alpha1.TrafficSplit, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("trafficsplit"), name) + } + return obj.(*v1alpha1.TrafficSplit), nil +} diff --git a/pkg/router/factory.go b/pkg/router/factory.go index ab836d318..09ed940b8 100644 --- a/pkg/router/factory.go +++ b/pkg/router/factory.go @@ -56,6 +56,15 @@ func (factory *Factory) MeshRouter(provider string) Interface { kubeClient: factory.kubeClient, appmeshClient: factory.meshClient, } + case strings.HasPrefix(provider, "smi:"): + mesh := strings.TrimPrefix(provider, "smi:") + return &SmiRouter{ + logger: factory.logger, + flaggerClient: factory.flaggerClient, + kubeClient: factory.kubeClient, + smiClient: factory.meshClient, + targetMesh: mesh, + } case strings.HasPrefix(provider, "supergloo"): supergloo, err := NewSuperglooRouter(context.TODO(), provider, factory.flaggerClient, factory.logger, factory.kubeConfig) if err != nil { diff --git a/pkg/router/smi.go b/pkg/router/smi.go new file mode 100644 index 000000000..4bdb2fbd2 --- /dev/null +++ b/pkg/router/smi.go @@ -0,0 +1,190 @@ +package router + +import ( + "encoding/json" + "fmt" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" + smiv1 "github.com/weaveworks/flagger/pkg/apis/smi/v1alpha1" + clientset "github.com/weaveworks/flagger/pkg/client/clientset/versioned" + "go.uber.org/zap" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/kubernetes" +) + +type SmiRouter struct { + kubeClient kubernetes.Interface + flaggerClient clientset.Interface + smiClient clientset.Interface + logger *zap.SugaredLogger + targetMesh string +} + +// Reconcile creates or updates the SMI traffic split +func (sr *SmiRouter) Reconcile(canary *flaggerv1.Canary) error { + targetName := canary.Spec.TargetRef.Name + canaryName := fmt.Sprintf("%s-canary", targetName) + primaryName := fmt.Sprintf("%s-primary", targetName) + + var host string + if len(canary.Spec.Service.Hosts) > 0 { + host = canary.Spec.Service.Hosts[0] + } else { + host = targetName + } + + tsSpec := smiv1.TrafficSplitSpec{ + Service: host, + Backends: []smiv1.TrafficSplitBackend{ + { + Service: canaryName, + Weight: resource.NewQuantity(0, resource.DecimalExponent), + }, + { + Service: primaryName, + Weight: resource.NewQuantity(100, resource.DecimalExponent), + }, + }, + } + + ts, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Get(targetName, metav1.GetOptions{}) + // create traffic split + if errors.IsNotFound(err) { + t := &smiv1.TrafficSplit{ + ObjectMeta: metav1.ObjectMeta{ + Name: targetName, + Namespace: canary.Namespace, + OwnerReferences: []metav1.OwnerReference{ + *metav1.NewControllerRef(canary, schema.GroupVersionKind{ + Group: flaggerv1.SchemeGroupVersion.Group, + Version: flaggerv1.SchemeGroupVersion.Version, + Kind: flaggerv1.CanaryKind, + }), + }, + Annotations: sr.makeAnnotations(canary.Spec.Service.Gateways), + }, + Spec: tsSpec, + } + + _, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Create(t) + if err != nil { + return err + } + + sr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). + Infof("TrafficSplit %s.%s created", t.GetName(), canary.Namespace) + return nil + } + + if err != nil { + return fmt.Errorf("traffic split %s query error %v", targetName, err) + } + + // update traffic split + if diff := cmp.Diff(tsSpec, ts.Spec, cmpopts.IgnoreTypes(resource.Quantity{})); diff != "" { + tsClone := ts.DeepCopy() + tsClone.Spec = tsSpec + + _, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Update(tsClone) + if err != nil { + return fmt.Errorf("TrafficSplit %s update error %v", targetName, err) + } + + sr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). + Infof("TrafficSplit %s.%s updated", targetName, canary.Namespace) + return nil + } + + return nil +} + +// GetRoutes returns the destinations weight for primary and canary +func (sr *SmiRouter) GetRoutes(canary *flaggerv1.Canary) ( + primaryWeight int, + canaryWeight int, + err error, +) { + targetName := canary.Spec.TargetRef.Name + canaryName := fmt.Sprintf("%s-canary", targetName) + primaryName := fmt.Sprintf("%s-primary", targetName) + ts, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Get(targetName, metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + err = fmt.Errorf("TrafficSplit %s.%s not found", targetName, canary.Namespace) + return + } + err = fmt.Errorf("TrafficSplit %s.%s query error %v", targetName, canary.Namespace, err) + return + } + + for _, r := range ts.Spec.Backends { + w, _ := r.Weight.AsInt64() + if r.Service == primaryName { + primaryWeight = int(w) + } + if r.Service == canaryName { + canaryWeight = int(w) + } + } + + if primaryWeight == 0 && canaryWeight == 0 { + err = fmt.Errorf("TrafficSplit %s.%s does not contain routes for %s and %s", + targetName, canary.Namespace, primaryName, canaryName) + } + + return +} + +// SetRoutes updates the destinations weight for primary and canary +func (sr *SmiRouter) SetRoutes( + canary *flaggerv1.Canary, + primaryWeight int, + canaryWeight int, +) error { + targetName := canary.Spec.TargetRef.Name + canaryName := fmt.Sprintf("%s-canary", targetName) + primaryName := fmt.Sprintf("%s-primary", targetName) + ts, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Get(targetName, metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + return fmt.Errorf("TrafficSplit %s.%s not found", targetName, canary.Namespace) + + } + return fmt.Errorf("TrafficSplit %s.%s query error %v", targetName, canary.Namespace, err) + } + + backends := []smiv1.TrafficSplitBackend{ + { + Service: canaryName, + Weight: resource.NewQuantity(int64(canaryWeight), resource.DecimalExponent), + }, + { + Service: primaryName, + Weight: resource.NewQuantity(int64(primaryWeight), resource.DecimalExponent), + }, + } + + tsClone := ts.DeepCopy() + tsClone.Spec.Backends = backends + + _, err = sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Update(tsClone) + if err != nil { + return fmt.Errorf("TrafficSplit %s update error %v", targetName, err) + } + + return nil +} + +func (sr *SmiRouter) makeAnnotations(gateways []string) map[string]string { + res := make(map[string]string) + if sr.targetMesh == "istio" && len(gateways) > 0 { + g, _ := json.Marshal(gateways) + res["VirtualService.v1alpha3.networking.istio.io/spec.gateways"] = string(g) + } + return res +} diff --git a/test/e2e-smi-istio-build.sh b/test/e2e-smi-istio-build.sh new file mode 100755 index 000000000..06b28ff15 --- /dev/null +++ b/test/e2e-smi-istio-build.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -o errexit + +REPO_ROOT=$(git rev-parse --show-toplevel) +export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" + +echo '>>> Building Flagger' +cd ${REPO_ROOT} && docker build -t test/flagger:latest . -f Dockerfile + +kind load docker-image test/flagger:latest + +echo '>>> Installing Flagger' +helm upgrade -i flagger ${REPO_ROOT}/charts/flagger \ +--wait \ +--namespace istio-system \ +--set meshProvider=smi:istio + +kubectl -n istio-system set image deployment/flagger flagger=test/flagger:latest + +kubectl -n istio-system rollout status deployment/flagger + +echo '>>> Installing the SMI Istio adapter' +kubectl apply -f ${REPO_ROOT}/artifacts/smi/istio-adapter.yaml + +kubectl -n istio-system rollout status deployment/smi-adapter-istio \ No newline at end of file