mirror of
https://github.com/kubereboot/kured.git
synced 2026-08-23 21:36:33 +00:00
Use RegexpValue in plags
This will remove double pointers, and be explicit about the type we are using. Signed-off-by: Jean-Philippe Evrard <open-source@a.spamming.party>
This commit is contained in:
+3
-4
@@ -12,7 +12,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -60,7 +59,7 @@ var (
|
||||
lockReleaseDelay time.Duration
|
||||
prometheusURL string
|
||||
preferNoScheduleTaintName string
|
||||
alertFilter *regexp.Regexp
|
||||
alertFilter regexpValue
|
||||
alertFilterMatchOnly bool
|
||||
alertFiringOnly bool
|
||||
rebootSentinelFile string
|
||||
@@ -150,7 +149,7 @@ func main() {
|
||||
"delay lock release for this duration (default: 0, disabled)")
|
||||
flag.StringVar(&prometheusURL, "prometheus-url", "",
|
||||
"Prometheus instance to probe for active alerts")
|
||||
flag.Var(®expValue{&alertFilter}, "alert-filter-regexp",
|
||||
flag.Var(&alertFilter, "alert-filter-regexp",
|
||||
"alert names to ignore when checking for active alerts")
|
||||
flag.BoolVar(&alertFilterMatchOnly, "alert-filter-match-only", false,
|
||||
"Only block if the alert-filter-regexp matches active alerts")
|
||||
@@ -655,7 +654,7 @@ func rebootAsRequired(nodeID string, rebooter reboot.Rebooter, checker checkers.
|
||||
|
||||
var blockCheckers []blockers.RebootBlocker
|
||||
if prometheusURL != "" {
|
||||
blockCheckers = append(blockCheckers, blockers.PrometheusBlockingChecker{PromClient: promClient, Filter: alertFilter, FiringOnly: alertFiringOnly, FilterMatchOnly: alertFilterMatchOnly})
|
||||
blockCheckers = append(blockCheckers, blockers.PrometheusBlockingChecker{PromClient: promClient, Filter: alertFilter.Regexp, FiringOnly: alertFiringOnly, FilterMatchOnly: alertFilterMatchOnly})
|
||||
}
|
||||
if podSelectors != nil {
|
||||
blockCheckers = append(blockCheckers, blockers.KubernetesBlockingChecker{Client: client, Nodename: nodeID, Filter: podSelectors})
|
||||
|
||||
+7
-11
@@ -1,30 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// Custom flag type to handle *regexp.Regexp with pflag
|
||||
type regexpValue struct {
|
||||
value **regexp.Regexp
|
||||
*regexp.Regexp
|
||||
}
|
||||
|
||||
// String method to return the string representation of the value
|
||||
func (rev *regexpValue) String() string {
|
||||
if *rev.value != nil {
|
||||
return (*rev.value).String()
|
||||
if rev.Regexp == nil {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
return rev.Regexp.String()
|
||||
}
|
||||
|
||||
// Set method to parse the input string and set the regexp value
|
||||
func (rev *regexpValue) Set(s string) error {
|
||||
compiledRegexp, err := regexp.Compile(s)
|
||||
value, err := regexp.Compile(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid regular expression: %w", err)
|
||||
return err
|
||||
}
|
||||
*rev.value = compiledRegexp
|
||||
rev.Regexp = value
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user