Skip to content

Commit cd54596

Browse files
ivanmatmatioktalz
authored andcommitted
MINOR: add experimental flag
1 parent 8967b95 commit cd54596

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

main.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ func logInfo(logger utils.Logger, osArgs utils.OSArgs) bool {
197197
fmt.Printf("Ingress class: %s\n", osArgs.IngressClass)
198198
fmt.Printf("Empty Ingress class: %t\n", osArgs.EmptyIngressClass)
199199
}
200+
if osArgs.Experimental.UseIngressMerge {
201+
fmt.Println("Ingress Management: merge implementation")
202+
} else {
203+
fmt.Println("Ingress Management: default implementation")
204+
}
200205
return true
201206
}
202207

@@ -253,8 +258,12 @@ func logInfo(logger utils.Logger, osArgs utils.OSArgs) bool {
253258
}
254259
logger.Debugf("Kubernetes Informers resync period: %s", osArgs.CacheResyncPeriod.String())
255260
logger.Printf("Controller initial sync period: %s", osArgs.InitialSyncPeriod.String())
261+
if osArgs.Experimental.UseIngressMerge {
262+
logger.Print("Ingress Management: merge implementation")
263+
} else {
264+
logger.Print("Ingress Management: default implementation")
265+
}
256266
logger.Printf("Controller sync period: %s\n", osArgs.SyncPeriod.String())
257-
258267
hostname, err := os.Hostname()
259268
logger.Error(err)
260269
logger.Printf("Running on %s", hostname)

pkg/controller/builder.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (builder *Builder) Build() *HAProxyController {
183183
if podIP == "" {
184184
podIP = "127.0.0.1"
185185
}
186-
return &HAProxyController{
186+
haproxyController := &HAProxyController{
187187
osArgs: builder.osArgs,
188188
haproxy: haproxy,
189189
podNamespace: os.Getenv("POD_NAMESPACE"),
@@ -199,6 +199,11 @@ func (builder *Builder) Build() *HAProxyController {
199199
PodIP: podIP,
200200
Hostname: hostname,
201201
}
202+
haproxyController.processIngress = haproxyController.processIngressesDefaultImplementation
203+
if builder.osArgs.Experimental.UseIngressMerge {
204+
haproxyController.processIngress = haproxyController.processIngressesWithMerge
205+
}
206+
return haproxyController
202207
}
203208

204209
func addControllerMetricData(builder *Builder, chShutdown chan struct{}) {

pkg/controller/controller.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type HAProxyController struct {
6262
osArgs utils.OSArgs
6363
auxCfgModTime int64
6464
ready bool
65+
processIngress func()
6566
}
6667

6768
// Wrapping a Native-Client transaction and commit it.
@@ -152,7 +153,7 @@ func (c *HAProxyController) updateHAProxy() {
152153
logger.Error(err)
153154
}
154155

155-
c.processIngressesWithMerge()
156+
c.processIngress()
156157

157158
updated := deep.Equal(route.CurentCustomRoutes, route.CustomRoutes, deep.FLAG_IGNORE_SLICE_ORDER)
158159
if len(updated) != 0 {
@@ -423,3 +424,18 @@ func (c *HAProxyController) processIngressesWithMerge() {
423424
}
424425
}
425426
}
427+
428+
func (c *HAProxyController) processIngressesDefaultImplementation() {
429+
for _, namespace := range c.store.Namespaces {
430+
c.store.SecretsProcessed = map[string]struct{}{}
431+
for _, ingResource := range namespace.Ingresses {
432+
if !namespace.Relevant && !ingResource.Faked {
433+
// As we watch only for white-listed namespaces, we should not worry about iterating over
434+
// many ingresses in irrelevant namespaces.
435+
// There should only be fake ingresses in irrelevant namespaces so loop should be whithin small amount of ingresses (Prometheus)
436+
continue
437+
}
438+
c.manageIngress(ingResource)
439+
}
440+
}
441+
}

pkg/utils/flags-experimental.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package utils
16+
17+
import (
18+
"strings"
19+
)
20+
21+
type Experimental struct {
22+
UseIngressMerge bool
23+
}
24+
25+
const (
26+
flagSeparator = ","
27+
// Experimental flags
28+
flagUseIngressMerge = "use-ingress-merge"
29+
)
30+
31+
// UnmarshalFlag Unmarshal flag
32+
func (e *Experimental) UnmarshalFlag(value string) error {
33+
var errors Errors
34+
flags := strings.Split(value, flagSeparator)
35+
36+
// Then parse
37+
for _, flag := range flags {
38+
if flag == flagUseIngressMerge {
39+
e.UseIngressMerge = true
40+
continue
41+
}
42+
}
43+
44+
return errors.Result()
45+
}
46+
47+
// MarshalFlag Marshals flag
48+
func (e Experimental) MarshalFlag() (string, error) {
49+
flags := []string{}
50+
if e.UseIngressMerge {
51+
flags = append(flags, flagUseIngressMerge)
52+
}
53+
return strings.Join(flags, flagSeparator), nil
54+
}

pkg/utils/flags.go

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type OSArgs struct {
117117
DisableIPV6 bool `long:"disable-ipv6" description:"toggle to disable the IPv6 protocol from all frontends"`
118118
UseWithPebble bool `long:"with-pebble" description:"use pebble to start/stop/reload HAProxy"`
119119
JobCheckCRD bool `long:"job-check-crd" description:"does not execute IC, but adds/updates CRDs"`
120+
Experimental Experimental `long:"experimental" description:"comma separated list of experimental features to activate"`
120121
DisableQuic bool `long:"disable-quic" description:"disable quic protocol in http frontend bindings"`
121122
DisableDelayedWritingOnlyIfReload bool `long:"disable-writing-only-if-reload" description:"disable the delayed writing of files to disk only in case of haproxy reload (=write files to disk even if no reload)"`
122123
CRDInputFile string `long:"input-file" description:"The file path of a CRD manifest to convert"`

0 commit comments

Comments
 (0)