Skip to content

Commit cf87246

Browse files
committed
Fix node-disruption-types containing empty strings
Split was containing empty string. Now we filter them out to avoid rejecting maintenances.
1 parent bf78b8e commit cf87246

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

cmd/main.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
nodedisruptionv1alpha1 "github.com/criteo/node-disruption-controller/api/v1alpha1"
3737
"github.com/criteo/node-disruption-controller/internal/controller"
38+
"github.com/criteo/node-disruption-controller/pkg/utils"
3839
//+kubebuilder:scaffold:imports
3940
)
4041

@@ -57,7 +58,7 @@ func main() {
5758
var rejectEmptyNodeDisruption bool
5859
var retryInterval time.Duration
5960
var rejectOverlappingDisruption bool
60-
var nodeDisruptionTypes string
61+
var nodeDisruptionTypesRaw string
6162
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6263
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6364
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
@@ -66,7 +67,7 @@ func main() {
6667
flag.BoolVar(&rejectEmptyNodeDisruption, "reject-empty-node-disruption", false, "Reject NodeDisruption matching no actual node.")
6768
flag.DurationVar(&retryInterval, "retry-interval", controller.DefaultRetryInterval, "How long to wait between each retry (Default 60s)")
6869
flag.BoolVar(&rejectOverlappingDisruption, "reject-overlapping-disruption", false, "Automatically reject any overlapping NodeDisruption (based on node selector), preserving the oldest one")
69-
flag.StringVar(&nodeDisruptionTypes, "node-disruption-types", "", "The list of types allowed for a node disruption separated by a comma.")
70+
flag.StringVar(&nodeDisruptionTypesRaw, "node-disruption-types", "", "The list of types allowed for a node disruption separated by a comma.")
7071

7172
opts := zap.Options{
7273
Development: true,
@@ -100,14 +101,16 @@ func main() {
100101
os.Exit(1)
101102
}
102103

104+
nodeDisruptionTypes := utils.FilterEmptyString(strings.Split(nodeDisruptionTypesRaw, ","))
105+
103106
if err = (&controller.NodeDisruptionReconciler{
104107
Client: mgr.GetClient(),
105108
Scheme: mgr.GetScheme(),
106109
Config: controller.NodeDisruptionReconcilerConfig{
107110
RejectEmptyNodeDisruption: rejectEmptyNodeDisruption,
108111
RetryInterval: retryInterval,
109112
RejectOverlappingDisruption: rejectOverlappingDisruption,
110-
NodeDisruptionTypes: strings.Split(nodeDisruptionTypes, ","),
113+
NodeDisruptionTypes: nodeDisruptionTypes,
111114
},
112115
}).SetupWithManager(mgr); err != nil {
113116
setupLog.Error(err, "unable to create controller", "controller", "NodeDisruption")

pkg/utils/utils.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package utils
2+
3+
func FilterEmptyString(source []string) (filtered []string) {
4+
for _, element := range source {
5+
if element != "" {
6+
filtered = append(filtered, element)
7+
}
8+
}
9+
return filtered
10+
}

pkg/utils/utils_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package utils
2+
3+
import (
4+
"reflect"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestFilterEmptyString(t *testing.T) {
10+
result := FilterEmptyString(strings.Split(",,foo,,bar,,", ","))
11+
expected := []string{"foo", "bar"}
12+
if !reflect.DeepEqual(result, expected) {
13+
t.Fatalf("Mismatching strings: %s != %s", result, expected)
14+
}
15+
}

0 commit comments

Comments
 (0)