Skip to content

Commit 4392301

Browse files
committed
MINOR: CR: enable config-snippets even with CR usage
No need to make custom resources and config-snippet mutually exclusive
1 parent ab56e15 commit 4392301

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

controller/annotations/annotations.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ type Annotation interface {
2020
Process(k store.K8s, annotations ...map[string]string) error
2121
}
2222

23-
func Global(g *models.Global, l *models.LogTargets) []Annotation {
23+
func GlobalCfgSnipp() []Annotation {
2424
return []Annotation{
2525
NewGlobalCfgSnippet("global-config-snippet"),
2626
NewFrontendCfgSnippet("frontend-config-snippet", "http"),
2727
NewFrontendCfgSnippet("frontend-config-snippet", "https"),
2828
NewFrontendCfgSnippet("stats-config-snippet", "stats"),
29+
}
30+
}
31+
32+
func Global(g *models.Global, l *models.LogTargets) []Annotation {
33+
return []Annotation{
2934
global.NewSyslogServers("syslog-server", l),
3035
global.NewNbthread("nbthread", g),
3136
global.NewMaxconn("maxconn", g),
@@ -92,7 +97,6 @@ func Frontend(i store.Ingress, r *haproxy.Rules, m haproxy.Maps) []Annotation {
9297

9398
func Backend(b *models.Backend, s store.K8s, certs *haproxy.Certificates) []Annotation {
9499
annotations := []Annotation{
95-
NewBackendCfgSnippet("backend-config-snippet", b.Name),
96100
service.NewAbortOnClose("abortonclose", b),
97101
service.NewTimeoutCheck("timeout-check", b),
98102
service.NewLoadBalance("load-balance", b),

controller/global.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ func (c *HAProxyController) globalCfg() (reload, restart bool) {
7979
logger.Debugf("Global log targets updated: %s\nRestart required", updated)
8080
restart = true
8181
}
82+
reload, res := c.globalCfgSnipp()
83+
restart = restart || res
84+
return
85+
}
86+
87+
func (c *HAProxyController) globalCfgSnipp() (reload, restart bool) {
88+
var err error
89+
for _, a := range annotations.GlobalCfgSnipp() {
90+
err = a.Process(c.Store, c.Store.ConfigMaps.Main.Annotations)
91+
if err != nil {
92+
logger.Errorf("annotation %s: %s", a.GetName(), err)
93+
}
94+
}
8295
updatedSnipp, errSnipp := annotations.UpdateGlobalCfgSnippet(c.Client)
8396
logger.Error(errSnipp)
8497
if len(updatedSnipp) != 0 {

controller/service/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func (s *SvcContext) HandleBackend(client api.HAProxyClient, store store.K8s) (r
134134
logger.Debugf("Ingress '%s/%s': new backend '%s', reload required", s.ingress.Namespace, s.ingress.Name, newBackend.Name)
135135
}
136136
// config-snippet
137+
logger.Error(annotations.NewBackendCfgSnippet("backend-config-snippet", newBackend.Name).Process(store, s.service.Annotations, s.ingress.Annotations, store.ConfigMaps.Main.Annotations))
137138
change, errSnipp := annotations.UpdateBackendCfgSnippet(client, newBackend.Name)
138139
logger.Error(errSnipp)
139140
if len(change) != 0 {

0 commit comments

Comments
 (0)