Skip to content

Commit 9c318d2

Browse files
committed
adding a customizable calue for controller class
1 parent 31ec9f0 commit 9c318d2

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

controllers/ingress/group_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewGroupReconciler(cloud services.Cloud, k8sClient client.Client, eventReco
5757
annotationParser := annotations.NewSuffixAnnotationParser(annotations.AnnotationPrefixIngress)
5858
authConfigBuilder := ingress.NewDefaultAuthConfigBuilder(annotationParser)
5959
enhancedBackendBuilder := ingress.NewDefaultEnhancedBackendBuilder(k8sClient, annotationParser, authConfigBuilder, controllerConfig.IngressConfig.TolerateNonExistentBackendService, controllerConfig.IngressConfig.TolerateNonExistentBackendAction)
60-
referenceIndexer := ingress.NewDefaultReferenceIndexer(enhancedBackendBuilder, authConfigBuilder, logger)
60+
referenceIndexer := ingress.NewDefaultReferenceIndexer(enhancedBackendBuilder, authConfigBuilder, logger, controllerConfig.IngressConfig.ControllerClass)
6161
trackingProvider := tracking.NewDefaultProvider(ingressTagPrefix, controllerConfig.ClusterName)
6262
modelBuilder := ingress.NewDefaultModelBuilder(k8sClient, eventRecorder,
6363
cloud.EC2(), cloud.ELBV2(), cloud.ACM(),
@@ -69,10 +69,10 @@ func NewGroupReconciler(cloud services.Cloud, k8sClient client.Client, eventReco
6969
stackMarshaller := deploy.NewDefaultStackMarshaller()
7070
stackDeployer := deploy.NewDefaultStackDeployer(cloud, k8sClient, networkingManager, networkingSGManager, networkingSGReconciler, elbv2TaggingManager,
7171
controllerConfig, ingressTagPrefix, logger, metricsCollector, controllerName)
72-
classLoader := ingress.NewDefaultClassLoader(k8sClient, true)
72+
classLoader := ingress.NewDefaultClassLoader(k8sClient, true, controllerConfig.IngressConfig.ControllerClass)
7373
classAnnotationMatcher := ingress.NewDefaultClassAnnotationMatcher(controllerConfig.IngressConfig.IngressClass)
7474
manageIngressesWithoutIngressClass := controllerConfig.IngressConfig.IngressClass == ""
75-
groupLoader := ingress.NewDefaultGroupLoader(k8sClient, eventRecorder, annotationParser, classLoader, classAnnotationMatcher, manageIngressesWithoutIngressClass)
75+
groupLoader := ingress.NewDefaultGroupLoader(k8sClient, eventRecorder, annotationParser, classLoader, classAnnotationMatcher, manageIngressesWithoutIngressClass, controllerConfig.IngressConfig.ControllerClass)
7676
groupFinalizerManager := ingress.NewDefaultFinalizerManager(finalizerManager)
7777

7878
return &groupReconciler{

pkg/config/ingress_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ const (
1010
flagTolerateNonExistentBackendService = "tolerate-non-existent-backend-service"
1111
flagTolerateNonExistentBackendAction = "tolerate-non-existent-backend-action"
1212
flagAllowedCAArns = "allowed-certificate-authority-arns"
13+
flagControllerClass = "controller-class"
1314
defaultIngressClass = "alb"
1415
defaultDisableIngressClassAnnotation = false
1516
defaultDisableIngressGroupNameAnnotation = false
1617
defaultMaxIngressConcurrentReconciles = 3
1718
defaultTolerateNonExistentBackendService = true
1819
defaultTolerateNonExistentBackendAction = true
20+
defaultControllerClass = "ingress.k8s.aws/alb"
1921
)
2022

2123
// IngressConfig contains the configurations for the Ingress controller
@@ -46,6 +48,9 @@ type IngressConfig struct {
4648

4749
// AllowedCertificateAuthoritiyARNs contains a list of all CAs to consider when discovering certificates for ingress resources
4850
AllowedCertificateAuthorityARNs []string
51+
52+
// ControllerClass is the class for the ingress controller
53+
ControllerClass string
4954
}
5055

5156
// BindFlags binds the command line flags to the fields in the config object
@@ -63,4 +68,5 @@ func (cfg *IngressConfig) BindFlags(fs *pflag.FlagSet) {
6368
fs.BoolVar(&cfg.TolerateNonExistentBackendAction, flagTolerateNonExistentBackendAction, defaultTolerateNonExistentBackendAction,
6469
"Tolerate rules that specify a non-existent backend action")
6570
fs.StringSliceVar(&cfg.AllowedCertificateAuthorityARNs, flagAllowedCAArns, []string{}, "Specify an optional list of CA ARNs to filter on in cert discovery")
71+
fs.StringVar(&cfg.ControllerClass, flagControllerClass, defaultControllerClass, "ControllerClass is the class for the ingress controller, the default value is \"ingress.k8s.aws/alb\".")
6672
}

pkg/ingress/class_loader.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
const (
2020
// the controller name used in IngressClass for ALB.
21-
IngressClassControllerALB = "ingress.k8s.aws/alb"
2221
// the Kind for IngressClassParams CRD.
2322
ingressClassParamsKind = "IngressClassParams"
2423
// default class from ingressClass
@@ -35,17 +34,19 @@ type ClassLoader interface {
3534
}
3635

3736
// NewDefaultClassLoader constructs new defaultClassLoader instance.
38-
func NewDefaultClassLoader(client client.Client, loadParams bool) ClassLoader {
37+
func NewDefaultClassLoader(client client.Client, loadParams bool, controllerClass string) ClassLoader {
3938
return &defaultClassLoader{
40-
client: client,
41-
loadParams: loadParams,
39+
client: client,
40+
loadParams: loadParams,
41+
controllerClass: controllerClass,
4242
}
4343
}
4444

4545
// default implementation for ClassLoader
4646
type defaultClassLoader struct {
47-
client client.Client
48-
loadParams bool
47+
client client.Client
48+
loadParams bool
49+
controllerClass string
4950
}
5051

5152
// GetDefaultIngressClass returns the default IngressClass from the list of IngressClasses.
@@ -93,7 +94,7 @@ func (l *defaultClassLoader) Load(ctx context.Context, ing *networking.Ingress)
9394
}
9495
return ClassConfiguration{}, err
9596
}
96-
if ingClass.Spec.Controller != IngressClassControllerALB || ingClass.Spec.Parameters == nil || !l.loadParams {
97+
if ingClass.Spec.Controller != l.controllerClass || ingClass.Spec.Parameters == nil || !l.loadParams {
9798
return ClassConfiguration{
9899
IngClass: ingClass,
99100
}, nil

pkg/ingress/group_loader.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type GroupLoader interface {
4646
}
4747

4848
// NewDefaultGroupLoader constructs new GroupLoader instance.
49-
func NewDefaultGroupLoader(client client.Client, eventRecorder record.EventRecorder, annotationParser annotations.Parser, classLoader ClassLoader, classAnnotationMatcher ClassAnnotationMatcher, manageIngressesWithoutIngressClass bool) *defaultGroupLoader {
49+
func NewDefaultGroupLoader(client client.Client, eventRecorder record.EventRecorder, annotationParser annotations.Parser, classLoader ClassLoader, classAnnotationMatcher ClassAnnotationMatcher, manageIngressesWithoutIngressClass bool, controllerClass string) *defaultGroupLoader {
5050
return &defaultGroupLoader{
5151
client: client,
5252
eventRecorder: eventRecorder,
@@ -55,6 +55,7 @@ func NewDefaultGroupLoader(client client.Client, eventRecorder record.EventRecor
5555
classLoader: classLoader,
5656
classAnnotationMatcher: classAnnotationMatcher,
5757
manageIngressesWithoutIngressClass: manageIngressesWithoutIngressClass,
58+
controllerClass: controllerClass,
5859
}
5960
}
6061

@@ -75,6 +76,7 @@ type defaultGroupLoader struct {
7576
// manageIngressesWithoutIngressClass specifies whether ingresses without "kubernetes.io/ingress.class" annotation
7677
// and "spec.ingressClassName" should be managed or not.
7778
manageIngressesWithoutIngressClass bool
79+
controllerClass string
7880
}
7981

8082
func (m *defaultGroupLoader) Load(ctx context.Context, groupID GroupID) (Group, error) {
@@ -220,7 +222,7 @@ func (m *defaultGroupLoader) classifyIngress(ctx context.Context, ing *networkin
220222
return ClassifiedIngress{
221223
Ing: ing,
222224
IngClassConfig: ingClassConfig,
223-
}, ingClassConfig.IngClass.Spec.Controller == IngressClassControllerALB, nil
225+
}, ingClassConfig.IngClass.Spec.Controller == m.controllerClass, nil
224226
}
225227

226228
return ClassifiedIngress{

pkg/ingress/reference_indexer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ type ReferenceIndexer interface {
3535
}
3636

3737
// NewDefaultReferenceIndexer constructs new defaultReferenceIndexer.
38-
func NewDefaultReferenceIndexer(enhancedBackendBuilder EnhancedBackendBuilder, authConfigBuilder AuthConfigBuilder, logger logr.Logger) *defaultReferenceIndexer {
38+
func NewDefaultReferenceIndexer(enhancedBackendBuilder EnhancedBackendBuilder, authConfigBuilder AuthConfigBuilder, logger logr.Logger, controllerClass string) *defaultReferenceIndexer {
3939
return &defaultReferenceIndexer{
4040
enhancedBackendBuilder: enhancedBackendBuilder,
4141
authConfigBuilder: authConfigBuilder,
4242
logger: logger,
43+
controllerClass: controllerClass,
4344
}
4445
}
4546

@@ -50,6 +51,7 @@ type defaultReferenceIndexer struct {
5051
enhancedBackendBuilder EnhancedBackendBuilder
5152
authConfigBuilder AuthConfigBuilder
5253
logger logr.Logger
54+
controllerClass string
5355
}
5456

5557
func (i *defaultReferenceIndexer) BuildServiceRefIndexes(ctx context.Context, ing *networking.Ingress) []string {
@@ -103,7 +105,7 @@ func (i *defaultReferenceIndexer) BuildIngressClassRefIndexes(_ context.Context,
103105
}
104106

105107
func (i *defaultReferenceIndexer) BuildIngressClassParamsRefIndexes(_ context.Context, ingClass *networking.IngressClass) []string {
106-
if ingClass.Spec.Controller != IngressClassControllerALB || ingClass.Spec.Parameters == nil {
108+
if ingClass.Spec.Controller != i.controllerClass || ingClass.Spec.Parameters == nil {
107109
return nil
108110
}
109111
if ingClass.Spec.Parameters.APIGroup == nil ||

webhooks/networking/ingress_validator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ func NewIngressValidator(client client.Client, ingConfig config.IngressConfig, l
2828
return &ingressValidator{
2929
annotationParser: annotations.NewSuffixAnnotationParser(annotations.AnnotationPrefixIngress),
3030
classAnnotationMatcher: ingress.NewDefaultClassAnnotationMatcher(ingConfig.IngressClass),
31-
classLoader: ingress.NewDefaultClassLoader(client, false),
31+
classLoader: ingress.NewDefaultClassLoader(client, false, ingConfig.ControllerClass),
3232
disableIngressClassAnnotation: ingConfig.DisableIngressClassAnnotation,
3333
disableIngressGroupAnnotation: ingConfig.DisableIngressGroupNameAnnotation,
3434
manageIngressesWithoutIngressClass: ingConfig.IngressClass == "",
3535
logger: logger,
3636
metricsCollector: metricsCollector,
37+
controllerClass: ingConfig.ControllerClass,
3738
}
3839
}
3940

@@ -50,6 +51,7 @@ type ingressValidator struct {
5051
manageIngressesWithoutIngressClass bool
5152
logger logr.Logger
5253
metricsCollector lbcmetrics.MetricCollector
54+
controllerClass string
5355
}
5456

5557
func (v *ingressValidator) Prototype(req admission.Request) (runtime.Object, error) {
@@ -121,7 +123,7 @@ func (v *ingressValidator) checkIngressClass(ctx context.Context, ing *networkin
121123
return false, err
122124
}
123125
if classConfiguration.IngClass != nil {
124-
return classConfiguration.IngClass.Spec.Controller != ingress.IngressClassControllerALB, nil
126+
return classConfiguration.IngClass.Spec.Controller != v.controllerClass, nil
125127
}
126128
return !v.manageIngressesWithoutIngressClass, nil
127129
}

0 commit comments

Comments
 (0)