Skip to content

Commit d0ff121

Browse files
committed
adding a customizable calue for controller class
1 parent 8ba34e2 commit d0ff121

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
@@ -52,7 +52,7 @@ func NewGroupReconciler(cloud aws.Cloud, k8sClient client.Client, eventRecorder
5252
annotationParser := annotations.NewSuffixAnnotationParser(annotations.AnnotationPrefixIngress)
5353
authConfigBuilder := ingress.NewDefaultAuthConfigBuilder(annotationParser)
5454
enhancedBackendBuilder := ingress.NewDefaultEnhancedBackendBuilder(k8sClient, annotationParser, authConfigBuilder, controllerConfig.IngressConfig.TolerateNonExistentBackendService, controllerConfig.IngressConfig.TolerateNonExistentBackendAction)
55-
referenceIndexer := ingress.NewDefaultReferenceIndexer(enhancedBackendBuilder, authConfigBuilder, logger)
55+
referenceIndexer := ingress.NewDefaultReferenceIndexer(enhancedBackendBuilder, authConfigBuilder, logger, controllerConfig.IngressConfig.ControllerClass)
5656
trackingProvider := tracking.NewDefaultProvider(ingressTagPrefix, controllerConfig.ClusterName)
5757
modelBuilder := ingress.NewDefaultModelBuilder(k8sClient, eventRecorder,
5858
cloud.EC2(), cloud.ELBV2(), cloud.ACM(),
@@ -64,10 +64,10 @@ func NewGroupReconciler(cloud aws.Cloud, k8sClient client.Client, eventRecorder
6464
stackMarshaller := deploy.NewDefaultStackMarshaller()
6565
stackDeployer := deploy.NewDefaultStackDeployer(cloud, k8sClient, networkingSGManager, networkingSGReconciler, elbv2TaggingManager,
6666
controllerConfig, ingressTagPrefix, logger)
67-
classLoader := ingress.NewDefaultClassLoader(k8sClient, true)
67+
classLoader := ingress.NewDefaultClassLoader(k8sClient, true, controllerConfig.IngressConfig.ControllerClass)
6868
classAnnotationMatcher := ingress.NewDefaultClassAnnotationMatcher(controllerConfig.IngressConfig.IngressClass)
6969
manageIngressesWithoutIngressClass := controllerConfig.IngressConfig.IngressClass == ""
70-
groupLoader := ingress.NewDefaultGroupLoader(k8sClient, eventRecorder, annotationParser, classLoader, classAnnotationMatcher, manageIngressesWithoutIngressClass)
70+
groupLoader := ingress.NewDefaultGroupLoader(k8sClient, eventRecorder, annotationParser, classLoader, classAnnotationMatcher, manageIngressesWithoutIngressClass, controllerConfig.IngressConfig.ControllerClass)
7171
groupFinalizerManager := ingress.NewDefaultFinalizerManager(finalizerManager)
7272

7373
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
@@ -45,7 +45,7 @@ type GroupLoader interface {
4545
}
4646

4747
// NewDefaultGroupLoader constructs new GroupLoader instance.
48-
func NewDefaultGroupLoader(client client.Client, eventRecorder record.EventRecorder, annotationParser annotations.Parser, classLoader ClassLoader, classAnnotationMatcher ClassAnnotationMatcher, manageIngressesWithoutIngressClass bool) *defaultGroupLoader {
48+
func NewDefaultGroupLoader(client client.Client, eventRecorder record.EventRecorder, annotationParser annotations.Parser, classLoader ClassLoader, classAnnotationMatcher ClassAnnotationMatcher, manageIngressesWithoutIngressClass bool, controllerClass string) *defaultGroupLoader {
4949
return &defaultGroupLoader{
5050
client: client,
5151
eventRecorder: eventRecorder,
@@ -54,6 +54,7 @@ func NewDefaultGroupLoader(client client.Client, eventRecorder record.EventRecor
5454
classLoader: classLoader,
5555
classAnnotationMatcher: classAnnotationMatcher,
5656
manageIngressesWithoutIngressClass: manageIngressesWithoutIngressClass,
57+
controllerClass: controllerClass,
5758
}
5859
}
5960

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

7981
func (m *defaultGroupLoader) Load(ctx context.Context, groupID GroupID) (Group, error) {
@@ -219,7 +221,7 @@ func (m *defaultGroupLoader) classifyIngress(ctx context.Context, ing *networkin
219221
return ClassifiedIngress{
220222
Ing: ing,
221223
IngClassConfig: ingClassConfig,
222-
}, ingClassConfig.IngClass.Spec.Controller == IngressClassControllerALB, nil
224+
}, ingClassConfig.IngClass.Spec.Controller == m.controllerClass, nil
223225
}
224226

225227
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
@@ -27,11 +27,12 @@ func NewIngressValidator(client client.Client, ingConfig config.IngressConfig, l
2727
return &ingressValidator{
2828
annotationParser: annotations.NewSuffixAnnotationParser(annotations.AnnotationPrefixIngress),
2929
classAnnotationMatcher: ingress.NewDefaultClassAnnotationMatcher(ingConfig.IngressClass),
30-
classLoader: ingress.NewDefaultClassLoader(client, false),
30+
classLoader: ingress.NewDefaultClassLoader(client, false, ingConfig.ControllerClass),
3131
disableIngressClassAnnotation: ingConfig.DisableIngressClassAnnotation,
3232
disableIngressGroupAnnotation: ingConfig.DisableIngressGroupNameAnnotation,
3333
manageIngressesWithoutIngressClass: ingConfig.IngressClass == "",
3434
logger: logger,
35+
controllerClass: ingConfig.ControllerClass,
3536
}
3637
}
3738

@@ -47,6 +48,7 @@ type ingressValidator struct {
4748
// and "spec.ingressClassName" should be managed or not.
4849
manageIngressesWithoutIngressClass bool
4950
logger logr.Logger
51+
controllerClass string
5052
}
5153

5254
func (v *ingressValidator) Prototype(req admission.Request) (runtime.Object, error) {
@@ -108,7 +110,7 @@ func (v *ingressValidator) checkIngressClass(ctx context.Context, ing *networkin
108110
return false, err
109111
}
110112
if classConfiguration.IngClass != nil {
111-
return classConfiguration.IngClass.Spec.Controller != ingress.IngressClassControllerALB, nil
113+
return classConfiguration.IngClass.Spec.Controller != v.controllerClass, nil
112114
}
113115
return !v.manageIngressesWithoutIngressClass, nil
114116
}

0 commit comments

Comments
 (0)