Skip to content

Commit 73d0ca7

Browse files
committed
Use proper labels selector terminology
Now we have several ways to filter out un-wanted objects (by name, by kind, by namespace, by namespace regexp, or having an ownership ref), the "filter" workd becomes a bit overloaded. Use the proper "selector" name (instead of "filter") for label selectors. Internal only (keep `--filter` cli option name, so we don't break backward compat).
1 parent 201d150 commit 73d0ca7

File tree

5 files changed

+29
-36
lines changed

5 files changed

+29
-36
lines changed

README.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ katafygio --no-git --dump-only --local-dir /tmp/clusterdump/
1717

1818
To create a local git repository and continuously save the cluster content:
1919
```bash
20-
katafygio --local-dir /tmp/kfdump
20+
katafygio --local-dir /tmp/clusterdump/
2121
```
2222

2323
To continuously push changes to a remote git repository:
2424
```bash
25-
katafygio --git-url https://user:[email protected]/myorg/myrepos.git --local-dir /tmp/kfdump
25+
katafygio --git-url https://user:[email protected]/myorg/myrepos.git --local-dir /tmp/clusterdump/
2626
```
2727

2828
Filtering out irrelevant objects (esp. ReplicaSets and Pods) with `-w`, `-x`, `-y`
@@ -31,15 +31,16 @@ and `-z` is useful to keep a concise git history.
3131
```bash
3232
# Filtering out objects having an owner reference (eg. managed pods or replicasets,
3333
# from Deployments, Daemonsets etc that we already archive), secrets (confidential),
34-
# events and nodes (irrelevant), and a configmap named "leader-elector" that has
35-
# low value and is causing commits churn:
34+
# events and nodes (irrelevant), helm secrets/configmap releases, and a configmap
35+
# named "leader-elector" that has low value and is causing commits churn:
3636

3737
katafygio \
38-
--local-dir /tmp/kfdump \
38+
--local-dir /tmp/clusterdump/ \
3939
--git-url https://user:[email protected]/myorg/myrepos.git \
4040
--exclude-having-owner-ref \
4141
--exclude-kind secrets,events,nodes,endpoints \
42-
--exclude-object configmap:kube-system/leader-elector
42+
--exclude-object configmap:kube-system/leader-elector \
43+
--filter 'owner!=helm'
4344
```
4445

4546
You can also use the [docker image](https://hub.docker.com/r/bpineau/katafygio/).
@@ -69,7 +70,7 @@ Flags:
6970
-x, --exclude-kind strings Ressource kind to exclude. Eg. 'deployment'
7071
-z, --exclude-namespaces strings Namespaces to exclude. Eg. 'temp.*' as regexes. This collects all namespaces and then filters them. Don't use it with the namespace flag.
7172
-y, --exclude-object strings Object to exclude. Eg. 'configmap:kube-system/kube-dns'
72-
-l, --filter string Label filter. Select only objects matching the label
73+
-l, --filter string Label selector. Select only objects matching the label
7374
-t, --git-timeout duration Git operations timeout (default 5m0s)
7475
-g, --git-url string Git repository URL
7576
-p, --healthcheck-port int Port for answering healthchecks on /health url
@@ -92,7 +93,7 @@ The environment are the same as command line options, in uppercase, prefixed by
9293

9394
```
9495
export KF_GIT_URL=https://user:[email protected]/myorg/myrepos.git
95-
export KF_LOCAL_DIR=/tmp/kfdump
96+
export KF_LOCAL_DIR=/tmp/clusterdump
9697
export KF_LOG_LEVEL=info
9798
export KF_EXCLUDE_KIND="pod ep rs clusterrole"
9899
@@ -105,7 +106,8 @@ export KUBECONFIG=/tmp/kconfig
105106
You can find pre-built binaries in the [releases](https://github.com/bpineau/katafygio/releases) page,
106107
ready to run on your desktop or in a Kubernetes cluster.
107108

108-
We also provide a [docker image](https://hub.docker.com/r/bpineau/katafygio/).
109+
We also provide a docker image on [docker hub](https://hub.docker.com/r/bpineau/katafygio/)
110+
and on [quay.io](https://quay.io/bpineau/katafygio).
109111

110112
On MacOS, you can use the brew formula:
111113
```bash
@@ -121,5 +123,5 @@ helm install --name kf-backups assets/helm-chart/katafygio/
121123

122124
* [Heptio Velero](https://github.com/heptio/velero) does sophisticated clusters backups, including volumes
123125
* [Stash](https://github.com/appscode/stash) backups volumes
124-
* [etcd backup operator](https://github.com/coreos/etcd-operator)
126+
* [etcd backup operator](https://github.com/coreos/etcd-operator) save etcd dumps (archived project)
125127

cmd/execute.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func runE(cmd *cobra.Command, args []string) (err error) {
8282
}
8383

8484
evts := event.New()
85-
fact := controller.NewFactory(logger, filter, resyncInt, exclusions)
85+
fact := controller.NewFactory(logger, selector, resyncInt, exclusions)
8686
reco := recorder.New(logger, evts, localDir, resyncInt*2, dryRun).Start()
8787
obsv := observer.New(logger, restcfg, evts, fact, exclkind, namespace).Start()
8888

cmd/flags.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
logLevel string
2121
logOutput string
2222
logServer string
23-
filter string
23+
selector string
2424
localDir string
2525
gitURL string
2626
gitTimeout time.Duration
@@ -93,8 +93,8 @@ func init() {
9393
RootCmd.PersistentFlags().BoolVarP(&noOwnerRef, "exclude-having-owner-ref", "w", false, "Exclude all objects having an Owner Reference")
9494
bindPFlag("exclude-having-owner-ref", "exclude-having-owner-ref")
9595

96-
RootCmd.PersistentFlags().StringVarP(&filter, "filter", "l", "", "Label filter. Select only objects matching the label")
97-
bindPFlag("filter", "filter")
96+
RootCmd.PersistentFlags().StringVarP(&selector, "filter", "l", "", "Label selector. Select only objects matching the label")
97+
bindPFlag("selector", "selector")
9898

9999
RootCmd.PersistentFlags().IntVarP(&healthP, "healthcheck-port", "p", 0, "Port for answering healthchecks on /health url")
100100
bindPFlag("healthcheck-port", "healthcheck-port")
@@ -118,7 +118,7 @@ func bindConf(cmd *cobra.Command, args []string) {
118118
logLevel = viper.GetString("log-level")
119119
logOutput = viper.GetString("log-output")
120120
logServer = viper.GetString("log-server")
121-
filter = viper.GetString("filter")
121+
selector = viper.GetString("filter")
122122
localDir = viper.GetString("local-dir")
123123
gitURL = viper.GetString("git-url")
124124
gitTimeout = viper.GetDuration("git-timeout")

pkg/controller/controller.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Exclusions struct {
5252
// Factory generate controllers
5353
type Factory struct {
5454
logger logger
55-
filter string
55+
selector string
5656
resyncIntv time.Duration
5757
exclusions *Exclusions
5858
}
@@ -76,18 +76,18 @@ func New(client cache.ListerWatcher,
7676
notifier event.Notifier,
7777
log logger,
7878
name string,
79-
filter string,
79+
selector string,
8080
resync time.Duration,
8181
exclusions *Exclusions,
8282
) *Controller {
8383

84-
selector := metav1.ListOptions{LabelSelector: filter, ResourceVersion: "0", AllowWatchBookmarks: true}
84+
lopts := metav1.ListOptions{LabelSelector: selector, ResourceVersion: "0", AllowWatchBookmarks: true}
8585
lw := &cache.ListWatch{
8686
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
87-
return client.List(selector)
87+
return client.List(lopts)
8888
},
8989
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
90-
return client.Watch(selector)
90+
return client.Watch(lopts)
9191
},
9292
}
9393

@@ -256,16 +256,16 @@ func (c *Controller) enqueue(notif *event.Notification) {
256256
}
257257

258258
// NewFactory create a controller factory
259-
func NewFactory(logger logger, filter string, resync int, exclusions *Exclusions) *Factory {
259+
func NewFactory(logger logger, selector string, resync int, exclusions *Exclusions) *Factory {
260260
return &Factory{
261261
logger: logger,
262-
filter: filter,
262+
selector: selector,
263263
resyncIntv: time.Duration(resync) * time.Second,
264264
exclusions: exclusions,
265265
}
266266
}
267267

268268
// NewController create a controller.Controller
269269
func (f *Factory) NewController(client cache.ListerWatcher, notifier event.Notifier, name string) Interface {
270-
return New(client, notifier, f.logger, name, f.filter, f.resyncIntv, f.exclusions)
270+
return New(client, notifier, f.logger, name, f.selector, f.resyncIntv, f.exclusions)
271271
}

pkg/controller/controller_test.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,18 @@ func TestController(t *testing.T) {
186186
}
187187
ctrl.Stop()
188188

189-
gotFoo2 := false
190189
for _, ev := range evt.evts {
191-
// ensure cleanup filters works as expected
192-
if strings.Contains(string(ev.Object), "shouldnotbethere") {
193-
t.Error("object cleanup filters didn't work")
194-
}
195-
196190
// ensure deletion notifications pops up as expected
197191
if strings.Compare(ev.Key, "ns1/Bar1") == 0 && ev.Action != event.Delete {
198192
t.Error("deletion notification failed")
199193
}
200194

201-
if strings.Compare(ev.Key, "ns2/Bar2") == 0 {
202-
gotFoo2 = true
195+
// ensure cleanup label selectors filter works as expected
196+
if strings.Contains(string(ev.Object), "shouldnotbethere") {
197+
t.Error("labels selectors filters didn't work")
203198
}
204199

205-
// ensure objet filter works as expected
200+
// ensure objet name filter works as expected
206201
if strings.Compare(ev.Key, "ns3/Bar3") == 0 {
207202
t.Error("execludedobject filter failed")
208203
}
@@ -222,8 +217,4 @@ func TestController(t *testing.T) {
222217
t.Error("update didn't propagate")
223218
}
224219
}
225-
226-
if !gotFoo2 {
227-
t.Errorf("we should have notified obj2")
228-
}
229220
}

0 commit comments

Comments
 (0)