diff --git a/charts/caddy-ingress-controller/templates/deployment.yaml b/charts/caddy-ingress-controller/templates/deployment.yaml index 579832f..988ffbf 100644 --- a/charts/caddy-ingress-controller/templates/deployment.yaml +++ b/charts/caddy-ingress-controller/templates/deployment.yaml @@ -76,6 +76,12 @@ spec: {{- if .Values.ingressController.verbose }} - -v {{- end }} + {{- if .Values.ingressController.className }} + - -class-name={{ .Values.ingressController.className }} + {{- end }} + {{- if .Values.ingressController.classNameRequired }} + - -class-name-required={{ .Values.ingressController.classNameRequired }} + {{- end }} readinessProbe: initialDelaySeconds: 3 periodSeconds: 10 diff --git a/charts/caddy-ingress-controller/values.yaml b/charts/caddy-ingress-controller/values.yaml index 90a15b8..e187760 100644 --- a/charts/caddy-ingress-controller/values.yaml +++ b/charts/caddy-ingress-controller/values.yaml @@ -21,7 +21,8 @@ ingressController: verbose: false rbac: create: true - + className: "caddy" + classNameRequired: false leaseId: "" config: # -- Acme Server URL @@ -47,7 +48,8 @@ serviceAccount: podAnnotations: {} -podSecurityContext: {} +podSecurityContext: + {} # fsGroup: 2000 podDisruptionBudget: @@ -64,7 +66,8 @@ securityContext: runAsUser: 0 runAsGroup: 0 -resources: {} +resources: + {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little # resources, such as Minikube. If you do want to specify resources, uncomment the following diff --git a/cmd/caddy/flag.go b/cmd/caddy/flag.go index af9da7f..b259ef2 100644 --- a/cmd/caddy/flag.go +++ b/cmd/caddy/flag.go @@ -2,14 +2,21 @@ package main import ( "flag" - "github.com/caddyserver/ingress/pkg/store" "strings" + + "github.com/caddyserver/ingress/pkg/store" ) func parseFlags() store.Options { var namespace string flag.StringVar(&namespace, "namespace", "", "the namespace that you would like to observe kubernetes ingress resources in.") + var className string + flag.StringVar(&className, "class-name", "caddy", "class name of the ingress controller") + + var classNameRequired bool + flag.BoolVar(&classNameRequired, "class-name-required", false, "only allow ingress resources with a matching ingress class name") + var configMapName string flag.StringVar(&configMapName, "config-map", "", "defines the config map name from where to load global options") @@ -25,10 +32,12 @@ func parseFlags() store.Options { flag.Parse() return store.Options{ - WatchNamespace: namespace, - ConfigMapName: configMapName, - Verbose: verbose, - LeaseId: leaseId, - PluginsOrder: strings.Split(pluginsOrder, ","), + WatchNamespace: namespace, + ClassName: className, + ClassNameRequired: classNameRequired, + ConfigMapName: configMapName, + Verbose: verbose, + LeaseId: leaseId, + PluginsOrder: strings.Split(pluginsOrder, ","), } } diff --git a/internal/controller/controller.go b/internal/controller/controller.go index ef503c2..3ecfbaa 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -5,6 +5,9 @@ import ( "context" "encoding/json" "fmt" + "os" + "time" + "github.com/caddyserver/caddy/v2" "github.com/caddyserver/certmagic" "github.com/caddyserver/ingress/internal/k8s" @@ -18,8 +21,6 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" - "os" - "time" // load required caddy plugins _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy" @@ -123,10 +124,9 @@ func NewCaddyController( // Watch ingress resources in selected namespaces ingressParams := k8s.IngressParams{ - InformerFactory: controller.factories.WatchedNamespace, - // TODO Add configuration for that - ClassName: "caddy", - ClassNameRequired: false, + InformerFactory: controller.factories.WatchedNamespace, + ClassName: opts.ClassName, + ClassNameRequired: opts.ClassNameRequired, } controller.informers.Ingress = k8s.WatchIngresses(ingressParams, k8s.IngressHandlers{ AddFunc: controller.onIngressAdded, diff --git a/pkg/store/options.go b/pkg/store/options.go index 114eac6..d389f3d 100644 --- a/pkg/store/options.go +++ b/pkg/store/options.go @@ -2,9 +2,11 @@ package store // Options represents ingress controller config received through cli arguments. type Options struct { - WatchNamespace string - ConfigMapName string - Verbose bool - LeaseId string - PluginsOrder []string + WatchNamespace string + ConfigMapName string + ClassName string + ClassNameRequired bool + Verbose bool + LeaseId string + PluginsOrder []string }