-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support watching objects given a specific label and/or field selector (…
…#34) Co-authored-by: Mariano Uvalle <[email protected]>
- Loading branch information
Showing
2 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package manager | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type Options struct { | ||
Rest *rest.Config | ||
Namespace string | ||
FieldSelector string | ||
LabelSelector string | ||
HealthProbeAddr string | ||
MetricsAddr string | ||
qps float64 // flags don't support float32, bind to this value and copy over to Rest.QPS during initialization | ||
} | ||
|
||
func (o *Options) Bind(set *flag.FlagSet) { | ||
set.StringVar(&o.Namespace, "namespace", "", "Only reconcile resources in a particular namespace") | ||
set.StringVar(&o.HealthProbeAddr, "health-probe-addr", ":8081", "Address to serve health probes on") | ||
set.StringVar(&o.MetricsAddr, "metrics-addr", ":8080", "Address to serve Prometheus metrics on") | ||
set.IntVar(&o.Rest.Burst, "burst", 50, "apiserver client rate limiter burst configuration") | ||
set.Float64Var(&o.qps, "qps", 20, "Max requests per second to apiserver") | ||
set.StringVar(&o.FieldSelector, "watch-field-selector", "", "Only reconcile resources that match the given field selector") | ||
set.StringVar(&o.LabelSelector, "watch-label-selector", "", "Only reconcile resiurces that match the given label selector") | ||
} | ||
|
||
func (o *Options) getDefaultLabelSelector() (labels.Selector, error) { | ||
if o.LabelSelector == "" { | ||
return labels.Everything(), nil | ||
} | ||
s, err := labels.Parse(o.LabelSelector) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not parse watch-label-selector flag: %w", err) | ||
} | ||
return s, nil | ||
} | ||
|
||
func (o *Options) getDefaultFieldSelector() (fields.Selector, error) { | ||
if o.FieldSelector == "" { | ||
return fields.Everything(), nil | ||
} | ||
f, err := fields.ParseSelector(o.FieldSelector) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not parse watch-field-selector flag: %w", err) | ||
} | ||
return f, nil | ||
} |