From e9018c983ea5f1900b1ff8e4e661069d71c497c4 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 2 Feb 2024 16:30:50 +0200 Subject: [PATCH] allow setting traefik versions --- cmd/rollouts-controller/main.go | 6 ++++++ rollout/trafficrouting/traefik/traefik.go | 6 +++--- utils/defaults/defaults.go | 18 ++++++++++++++++++ utils/defaults/defaults_test.go | 10 ++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/cmd/rollouts-controller/main.go b/cmd/rollouts-controller/main.go index ad7190c585..79b2698611 100644 --- a/cmd/rollouts-controller/main.go +++ b/cmd/rollouts-controller/main.go @@ -63,6 +63,8 @@ func newCommand() *cobra.Command { ingressThreads int istioVersion string trafficSplitVersion string + traefikAPIGroup string + traefikVersion string ambassadorVersion string ingressVersion string appmeshCRDVersion string @@ -98,6 +100,8 @@ func newCommand() *cobra.Command { defaults.SetAmbassadorAPIVersion(ambassadorVersion) defaults.SetSMIAPIVersion(trafficSplitVersion) defaults.SetAppMeshCRDVersion(appmeshCRDVersion) + defaults.SetTraefikAPIGroup(traefikAPIGroup) + defaults.SetTraefikVersion(traefikVersion) config, err := clientConfig.ClientConfig() checkError(err) @@ -249,6 +253,8 @@ func newCommand() *cobra.Command { command.Flags().StringVar(&istioVersion, "istio-api-version", defaults.DefaultIstioVersion, "Set the default Istio apiVersion that controller should look when manipulating VirtualServices.") command.Flags().StringVar(&ambassadorVersion, "ambassador-api-version", defaults.DefaultAmbassadorVersion, "Set the Ambassador apiVersion that controller should look when manipulating Ambassador Mappings.") command.Flags().StringVar(&trafficSplitVersion, "traffic-split-api-version", defaults.DefaultSMITrafficSplitVersion, "Set the default TrafficSplit apiVersion that controller uses when creating TrafficSplits.") + command.Flags().StringVar(&traefikAPIGroup, "traefik-api-group", defaults.DefaultTraefikAPIGroup, "Set the default Traerfik apiGroup that controller uses.") + command.Flags().StringVar(&traefikVersion, "traefik-api-version", defaults.DefaultTraefikVersion, "Set the default Traerfik apiVersion that controller uses.") command.Flags().StringVar(&ingressVersion, "ingress-api-version", "", "Set the Ingress apiVersion that the controller should use.") command.Flags().StringVar(&appmeshCRDVersion, "appmesh-crd-version", defaults.DefaultAppMeshCRDVersion, "Set the default AppMesh CRD Version that controller uses when manipulating resources.") command.Flags().StringArrayVar(&albIngressClasses, "alb-ingress-classes", defaultALBIngressClass, "Defines all the ingress class annotations that the alb ingress controller operates on. Defaults to alb") diff --git a/rollout/trafficrouting/traefik/traefik.go b/rollout/trafficrouting/traefik/traefik.go index 5840bf4a42..8b5cfb7312 100644 --- a/rollout/trafficrouting/traefik/traefik.go +++ b/rollout/trafficrouting/traefik/traefik.go @@ -25,7 +25,7 @@ const TraefikServiceUpdateError = "TraefikServiceUpdateError" var ( apiGroupToResource = map[string]string{ - defaults.DefaultTraefikAPIGroup: traefikServices, + defaults.GetTraefikAPIGroup(): traefikServices, } ) @@ -68,8 +68,8 @@ func NewDynamicClient(di dynamic.Interface, namespace string) dynamic.ResourceIn } func GetMappingGVR() schema.GroupVersionResource { - group := defaults.DefaultTraefikAPIGroup - parts := strings.Split(defaults.DefaultTraefikVersion, "/") + group := defaults.GetTraefikAPIGroup() + parts := strings.Split(defaults.GetTraefikVersion(), "/") version := parts[len(parts)-1] resourceName := apiGroupToResource[group] return schema.GroupVersionResource{ diff --git a/utils/defaults/defaults.go b/utils/defaults/defaults.go index 8c1c171219..f1c38dcef1 100644 --- a/utils/defaults/defaults.go +++ b/utils/defaults/defaults.go @@ -67,6 +67,8 @@ const ( var ( defaultVerifyTargetGroup = false + traefikAPIGroup = DefaultTraefikAPIGroup + traefikVersion = DefaultTraefikVersion istioAPIVersion = DefaultIstioVersion ambassadorAPIVersion = DefaultAmbassadorVersion smiAPIVersion = DefaultSMITrafficSplitVersion @@ -305,6 +307,22 @@ func GetSMIAPIVersion() string { return smiAPIVersion } +func SetTraefikVersion(apiVersion string) { + traefikVersion = apiVersion +} + +func GetTraefikVersion() string { + return traefikVersion +} + +func SetTraefikAPIGroup(apiGroup string) { + traefikAPIGroup = apiGroup +} + +func GetTraefikAPIGroup() string { + return traefikAPIGroup +} + func SetTargetGroupBindingAPIVersion(apiVersion string) { targetGroupBindingAPIVersion = apiVersion } diff --git a/utils/defaults/defaults_test.go b/utils/defaults/defaults_test.go index 1d981731c2..edd144d1f7 100644 --- a/utils/defaults/defaults_test.go +++ b/utils/defaults/defaults_test.go @@ -398,6 +398,16 @@ func TestSetDefaults(t *testing.T) { SetSMIAPIVersion(DefaultSMITrafficSplitVersion) assert.Equal(t, DefaultSMITrafficSplitVersion, GetSMIAPIVersion()) + SetTraefikAPIGroup("traefik.containo.us") + assert.Equal(t, "traefik.containo.us", GetTraefikAPIGroup()) + SetTraefikAPIGroup(DefaultTraefikAPIGroup) + assert.Equal(t, DefaultTraefikAPIGroup, GetTraefikAPIGroup()) + + SetTraefikVersion("traefik.containo.us/v1alpha1") + assert.Equal(t, "traefik.containo.us/v1alpha1", GetTraefikVersion()) + SetTraefikVersion(DefaultTraefikVersion) + assert.Equal(t, DefaultTraefikVersion, GetTraefikVersion()) + SetTargetGroupBindingAPIVersion("v1alpha9") assert.Equal(t, "v1alpha9", GetTargetGroupBindingAPIVersion()) SetTargetGroupBindingAPIVersion(DefaultTargetGroupBindingAPIVersion)