Skip to content

Commit d0aedac

Browse files
authored
Allow to ignore only specific integrations (#35)
1 parent 3cf0c30 commit d0aedac

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ also disable processing for individual ingress routes by setting an additional a
163163

164164
```yaml
165165
metadata:
166-
annoations:
167-
switchboard.borchero.com/ignore: "true"
166+
annotations:
167+
switchboard.borchero.com/ignore: "all"
168168
```
169169

170+
By setting the `ignore` annotation to `all` (or `true`), Switchboard does not process the ingress
171+
route at all. For more fine-grained control, the value of this annotation can also be set to a
172+
comma-separated list of integrations (possible values `cert-manager`, `external-dns`).
173+
170174
## License
171175

172176
Switchboard is licensed under the [MIT License](./LICENSE).

internal/controllers/ingressroute.go

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func (r *IngressRouteReconciler) Reconcile(
8080

8181
// Then, we can run the integrations
8282
for _, itg := range r.integrations {
83+
if !r.selector.MatchesIntegration(ingressRoute.Annotations, itg.Name()) {
84+
// If integration is ignored, skip it
85+
logger.Debug("ignoring integration", zap.String("integration", itg.Name()))
86+
continue
87+
}
8388
if err := itg.UpdateResource(ctx, &ingressRoute, info); err != nil {
8489
logger.Error("failed to upsert resource",
8590
zap.String("integration", itg.Name()), zap.Error(err),

internal/switchboard/selector.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package switchboard
22

3+
import "strings"
4+
35
const (
46
ingressAnnotationKey = "kubernetes.io/ingress.class"
57
ignoreAnnotationKey = "switchboard.borchero.com/ignore"
@@ -21,7 +23,7 @@ func NewSelector(ingressClass *string) Selector {
2123
func (s Selector) Matches(annotations map[string]string) bool {
2224
// If the ignore annotation is set, selector never matches
2325
if ignore, ok := annotations[ignoreAnnotationKey]; ok {
24-
if ignore == "true" {
26+
if ignore == "true" || ignore == "all" {
2527
return false
2628
}
2729
}
@@ -38,3 +40,20 @@ func (s Selector) Matches(annotations map[string]string) bool {
3840
// Otherwise, any ingress class is fine
3941
return true
4042
}
43+
44+
// MatchesIntegration returns whether the provided set of annotations match the provided
45+
// integration.
46+
func (s Selector) MatchesIntegration(annotations map[string]string, integration string) bool {
47+
if ignore, ok := annotations[ignoreAnnotationKey]; ok {
48+
if ignore == "true" || ignore == "all" {
49+
return false
50+
}
51+
// Iterate over list of values set for `ignore` annotation
52+
for _, ignored := range strings.Split(ignore, ",") {
53+
if strings.TrimSpace(ignored) == integration {
54+
return false
55+
}
56+
}
57+
}
58+
return true
59+
}

internal/switchboard/selector_test.go

+61
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ func TestMatchesNoIngressClass(t *testing.T) {
1919
"kubernetes.io/ingress.class": "test",
2020
"switchboard.borchero.com/ignore": "true",
2121
}))
22+
assert.False(t, selector.Matches(map[string]string{
23+
"switchboard.borchero.com/ignore": "all",
24+
}))
25+
assert.False(t, selector.Matches(map[string]string{
26+
"kubernetes.io/ingress.class": "test",
27+
"switchboard.borchero.com/ignore": "all",
28+
}))
2229
}
2330

2431
func TestMatchesIngressClass(t *testing.T) {
@@ -42,4 +49,58 @@ func TestMatchesIngressClass(t *testing.T) {
4249
"kubernetes.io/ingress.class": "ingress",
4350
"switchboard.borchero.com/ignore": "true",
4451
}))
52+
assert.False(t, selector.Matches(map[string]string{
53+
"switchboard.borchero.com/ignore": "all",
54+
}))
55+
assert.False(t, selector.Matches(map[string]string{
56+
"kubernetes.io/ingress.class": "test",
57+
"switchboard.borchero.com/ignore": "all",
58+
}))
59+
assert.False(t, selector.Matches(map[string]string{
60+
"kubernetes.io/ingress.class": "ingress",
61+
"switchboard.borchero.com/ignore": "all",
62+
}))
63+
}
64+
65+
func TestMatchesIntegration(t *testing.T) {
66+
cls := "ingress"
67+
selector := NewSelector(&cls)
68+
69+
// Ignore all
70+
assert.False(t, selector.MatchesIntegration(map[string]string{
71+
"switchboard.borchero.com/ignore": "true",
72+
}, "external-dns"))
73+
assert.False(t, selector.MatchesIntegration(map[string]string{
74+
"switchboard.borchero.com/ignore": "all",
75+
}, "external-dns"))
76+
77+
// Ignore only one
78+
assert.False(t, selector.MatchesIntegration(map[string]string{
79+
"switchboard.borchero.com/ignore": "external-dns",
80+
}, "external-dns"))
81+
assert.True(t, selector.MatchesIntegration(map[string]string{
82+
"switchboard.borchero.com/ignore": "cert-manager",
83+
}, "external-dns"))
84+
85+
// Ignore multiple
86+
assert.False(t, selector.MatchesIntegration(map[string]string{
87+
"switchboard.borchero.com/ignore": "external-dns,cert-manager",
88+
}, "external-dns"))
89+
assert.False(t, selector.MatchesIntegration(map[string]string{
90+
"switchboard.borchero.com/ignore": "external-dns,cert-manager",
91+
}, "cert-manager"))
92+
assert.True(t, selector.MatchesIntegration(map[string]string{
93+
"switchboard.borchero.com/ignore": "external-dns,cert-manager",
94+
}, "unknown"))
95+
96+
// Ignore with space in between
97+
assert.False(t, selector.MatchesIntegration(map[string]string{
98+
"switchboard.borchero.com/ignore": "external-dns, cert-manager",
99+
}, "external-dns"))
100+
assert.False(t, selector.MatchesIntegration(map[string]string{
101+
"switchboard.borchero.com/ignore": "external-dns, cert-manager",
102+
}, "cert-manager"))
103+
assert.True(t, selector.MatchesIntegration(map[string]string{
104+
"switchboard.borchero.com/ignore": "external-dns, cert-manager",
105+
}, "unknown"))
45106
}

0 commit comments

Comments
 (0)