Skip to content

Commit

Permalink
allow setting traefik versions
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Feb 2, 2024
1 parent 8405f2e commit e9018c9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func newCommand() *cobra.Command {
ingressThreads int
istioVersion string
trafficSplitVersion string
traefikAPIGroup string
traefikVersion string
ambassadorVersion string
ingressVersion string
appmeshCRDVersion string
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions rollout/trafficrouting/traefik/traefik.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TraefikServiceUpdateError = "TraefikServiceUpdateError"

var (
apiGroupToResource = map[string]string{
defaults.DefaultTraefikAPIGroup: traefikServices,
defaults.GetTraefikAPIGroup(): traefikServices,
}
)

Expand Down Expand Up @@ -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{
Expand Down
18 changes: 18 additions & 0 deletions utils/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const (

var (
defaultVerifyTargetGroup = false
traefikAPIGroup = DefaultTraefikAPIGroup
traefikVersion = DefaultTraefikVersion
istioAPIVersion = DefaultIstioVersion
ambassadorAPIVersion = DefaultAmbassadorVersion
smiAPIVersion = DefaultSMITrafficSplitVersion
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions utils/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e9018c9

Please sign in to comment.