Add config options for class name and class name required (#99)

This commit is contained in:
Nila 2022-08-22 11:50:00 +02:00 committed by GitHub
parent 1ba3f761ec
commit f7739a6837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 20 deletions

View File

@ -76,6 +76,12 @@ spec:
{{- if .Values.ingressController.verbose }} {{- if .Values.ingressController.verbose }}
- -v - -v
{{- end }} {{- end }}
{{- if .Values.ingressController.className }}
- -class-name={{ .Values.ingressController.className }}
{{- end }}
{{- if .Values.ingressController.classNameRequired }}
- -class-name-required={{ .Values.ingressController.classNameRequired }}
{{- end }}
readinessProbe: readinessProbe:
initialDelaySeconds: 3 initialDelaySeconds: 3
periodSeconds: 10 periodSeconds: 10

View File

@ -21,7 +21,8 @@ ingressController:
verbose: false verbose: false
rbac: rbac:
create: true create: true
className: "caddy"
classNameRequired: false
leaseId: "" leaseId: ""
config: config:
# -- Acme Server URL # -- Acme Server URL
@ -47,7 +48,8 @@ serviceAccount:
podAnnotations: {} podAnnotations: {}
podSecurityContext: {} podSecurityContext:
{}
# fsGroup: 2000 # fsGroup: 2000
podDisruptionBudget: podDisruptionBudget:
@ -64,7 +66,8 @@ securityContext:
runAsUser: 0 runAsUser: 0
runAsGroup: 0 runAsGroup: 0
resources: {} resources:
{}
# We usually recommend not to specify default resources and to leave this as a conscious # 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 # 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 # resources, such as Minikube. If you do want to specify resources, uncomment the following

View File

@ -2,14 +2,21 @@ package main
import ( import (
"flag" "flag"
"github.com/caddyserver/ingress/pkg/store"
"strings" "strings"
"github.com/caddyserver/ingress/pkg/store"
) )
func parseFlags() store.Options { func parseFlags() store.Options {
var namespace string var namespace string
flag.StringVar(&namespace, "namespace", "", "the namespace that you would like to observe kubernetes ingress resources in.") 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 var configMapName string
flag.StringVar(&configMapName, "config-map", "", "defines the config map name from where to load global options") 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() flag.Parse()
return store.Options{ return store.Options{
WatchNamespace: namespace, WatchNamespace: namespace,
ConfigMapName: configMapName, ClassName: className,
Verbose: verbose, ClassNameRequired: classNameRequired,
LeaseId: leaseId, ConfigMapName: configMapName,
PluginsOrder: strings.Split(pluginsOrder, ","), Verbose: verbose,
LeaseId: leaseId,
PluginsOrder: strings.Split(pluginsOrder, ","),
} }
} }

View File

@ -5,6 +5,9 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"time"
"github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2"
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
"github.com/caddyserver/ingress/internal/k8s" "github.com/caddyserver/ingress/internal/k8s"
@ -18,8 +21,6 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"os"
"time"
// load required caddy plugins // load required caddy plugins
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy" _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy"
@ -123,10 +124,9 @@ func NewCaddyController(
// Watch ingress resources in selected namespaces // Watch ingress resources in selected namespaces
ingressParams := k8s.IngressParams{ ingressParams := k8s.IngressParams{
InformerFactory: controller.factories.WatchedNamespace, InformerFactory: controller.factories.WatchedNamespace,
// TODO Add configuration for that ClassName: opts.ClassName,
ClassName: "caddy", ClassNameRequired: opts.ClassNameRequired,
ClassNameRequired: false,
} }
controller.informers.Ingress = k8s.WatchIngresses(ingressParams, k8s.IngressHandlers{ controller.informers.Ingress = k8s.WatchIngresses(ingressParams, k8s.IngressHandlers{
AddFunc: controller.onIngressAdded, AddFunc: controller.onIngressAdded,

View File

@ -2,9 +2,11 @@ package store
// Options represents ingress controller config received through cli arguments. // Options represents ingress controller config received through cli arguments.
type Options struct { type Options struct {
WatchNamespace string WatchNamespace string
ConfigMapName string ConfigMapName string
Verbose bool ClassName string
LeaseId string ClassNameRequired bool
PluginsOrder []string Verbose bool
LeaseId string
PluginsOrder []string
} }