Skip to content

Commit 4796f39

Browse files
committed
MEDIUM: add custom-validation-rules flag to dedicate correct custom resource for validation rules
1 parent 2654780 commit 4796f39

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
lines changed

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ func logInfo(logger utils.Logger, osArgs utils.OSArgs) bool {
265265
} else {
266266
logger.Print("Ingress Management: default implementation")
267267
}
268+
if osArgs.CustomValidationRules.Name != "" {
269+
logger.Printf("Custom validation rules provided in '%s'", osArgs.CustomValidationRules)
270+
}
271+
268272
logger.Printf("Controller sync period: %s\n", osArgs.SyncPeriod.String())
269273
hostname, err := os.Hostname()
270274
logger.Error(err)

pkg/controller/monitor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ func (c *HAProxyController) SyncData() {
8686
change = c.store.EventTCPRoute(ns, job.Data.(*store.TCPRoute))
8787
case k8ssync.REFERENCEGRANT:
8888
change = c.store.EventReferenceGrant(ns, job.Data.(*store.ReferenceGrant))
89+
case k8ssync.CUSTOM_RESOURCE:
90+
change = true
8991
case k8ssync.CR_TCP:
9092
var data *store.TCPs
9193
if job.Data != nil {

pkg/k8s/cr-validation-rules.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func (c ValidationCR) GetInformerV3(eventChan chan k8ssync.SyncDataEvent, factor
4848
return
4949
}
5050

51+
if data.ObjectMeta.Namespace != osArgs.CustomValidationRules.Namespace {
52+
return
53+
}
54+
if data.ObjectMeta.Name != osArgs.CustomValidationRules.Name {
55+
return
56+
}
57+
5158
validator, err := validators.Get()
5259
if err != nil {
5360
logger.Error("Failed to get validator: %s", err)
@@ -59,8 +66,11 @@ func (c ValidationCR) GetInformerV3(eventChan chan k8ssync.SyncDataEvent, factor
5966
return
6067
}
6168
logger.Infof("ValidationRules %s/%s accepted and set [%s]", data.Namespace, data.Name, data.Spec.Prefix)
69+
// eventChan <- k8ssync.SyncDataEvent{
70+
// SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.Namespace, Name: data.Name, Data: data,
71+
// }
6272
eventChan <- k8ssync.SyncDataEvent{
63-
SyncType: k8ssync.SyncType(c.GetKind()), Namespace: data.Namespace, Name: data.Name, Data: data,
73+
SyncType: k8ssync.CUSTOM_RESOURCE, Namespace: data.Namespace, Name: data.Name, Data: data,
6474
}
6575
}
6676

pkg/k8s/crs-monitor.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (k k8s) RunCRSCreationMonitoring(eventChan chan k8ssync.SyncDataEvent, stop
112112
}
113113
logger.Info("Custom resource definition created, adding CR watcher for " + crsV1[groupKind.Kind].GetKind())
114114
case "ingress.v3.haproxy.org":
115+
ok := true
115116
switch groupKind.Kind {
116117
case "Backend":
117118
crsV3[groupKind.Kind] = NewBackendCRV3()
@@ -122,9 +123,15 @@ func (k k8s) RunCRSCreationMonitoring(eventChan chan k8ssync.SyncDataEvent, stop
122123
case "TCP":
123124
crsV3[groupKind.Kind] = NewTCPCRV3()
124125
case "ValidationRules":
125-
crsV3[groupKind.Kind] = NewValidationCRV3()
126+
if osArgs.CustomValidationRules.Name != "" {
127+
crsV3[groupKind.Kind] = NewValidationCRV3()
128+
} else {
129+
ok = false
130+
}
131+
}
132+
if ok {
133+
logger.Info("Custom resource definition created, adding CR watcher for " + crsV3[groupKind.Kind].GetKind())
126134
}
127-
logger.Info("Custom resource definition created, adding CR watcher for " + crsV3[groupKind.Kind].GetKind())
128135
}
129136

130137
k.runCRInformers(eventChan, stop, namespace, informersSyncedEvent, crsV1, crsV3, osArgs)

pkg/k8s/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ func New(osArgs utils.OSArgs, whitelist map[string]struct{}, publishSvc *utils.N
160160
k.registerCoreCRV3(NewDefaultsCRV3())
161161
k.registerCoreCRV3(NewBackendCRV3())
162162
k.registerCoreCRV3(NewTCPCRV3())
163-
k.registerCoreCRV3(NewValidationCRV3())
163+
if osArgs.CustomValidationRules.Name != "" {
164+
k.registerCoreCRV3(NewValidationCRV3())
165+
}
164166
return k
165167
}
166168

pkg/k8s/sync/sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ const (
5252
GATEWAY SyncType = "GATEWAY"
5353
TCPROUTE SyncType = "TCPROUTE"
5454
REFERENCEGRANT SyncType = "REFERENCEGRANT"
55+
CUSTOM_RESOURCE SyncType = "CUSTOM_RESOURCE"
5556
)

pkg/utils/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ type OSArgs struct {
124124
CRDOutputFile string `long:"output-file" description:"The file path of the converted (to the most recent version) CRD manifest"`
125125
DisableIngressStatusUpdate bool `long:"disable-ingress-status-update" description:"If true, disables updating the status field of Ingress resources"`
126126
EnableCustomAnnotationsOnIngress bool `long:"enable-custom-annotations-on-ingress" description:"allow custom user annotations on ingress"`
127+
CustomValidationRules NamespaceValue `long:"custom-validation-rules" description:"custom validation rules object" default:""`
127128
}

0 commit comments

Comments
 (0)