Skip to content

Commit 4e0451f

Browse files
committed
Update doc, eg config file and filter on kind too
* Viper way to pass slices (arrays) through env isn't obvious, let's provide an example * Update the example configuration file to reflect available options * Some resources defs don't have a singular form, outside of the Kind name * Support multiple kube-config (via KUBECONFIG=/path1:/path2)
1 parent 6e9c7a0 commit 4e0451f

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To create a local git repository and continuously save the cluster content:
2020
katafygio --local-dir /tmp/kfdump
2121
```
2222

23-
Same, but also continuously push to a remote repository:
23+
To continuously push changes to a remote git repository:
2424
```bash
2525
katafygio --git-url https://user:[email protected]/myorg/myrepos.git --local-dir /tmp/kfdump
2626
```
@@ -47,7 +47,8 @@ You can also use the [docker image](https://hub.docker.com/r/bpineau/katafygio/)
4747

4848
```
4949
Backup Kubernetes cluster as yaml files in a git repository.
50-
--exclude-kind (-x) and --exclude-object (-y) may be specified several times.
50+
--exclude-kind (-x) and --exclude-object (-y) may be specified several times,
51+
or once with several comma separated values.
5152
5253
Usage:
5354
katafygio [flags]
@@ -70,7 +71,7 @@ Flags:
7071
-g, --git-url string Git repository URL
7172
-p, --healthcheck-port int Port for answering healthchecks on /health url
7273
-h, --help help for katafygio
73-
-k, --kube-config string Kubernetes config path
74+
-k, --kube-config string Kubernetes configuration path
7475
-e, --local-dir string Where to dump yaml files (default "./kubernetes-backup")
7576
-v, --log-level string Log level (default "info")
7677
-o, --log-output string Log output (default "stderr")
@@ -79,7 +80,7 @@ Flags:
7980
-i, --resync-interval int Full resync interval in seconds (0 to disable) (default 900)
8081
```
8182

82-
## Config file and env variables
83+
## Configuration file and env variables
8384

8485
All settings can be passed by command line options, or environment variable, or in
8586
[a yaml configuration file](https://github.com/bpineau/katafygio/blob/master/assets/katafygio.yaml)
@@ -90,8 +91,9 @@ in uppercase, prefixed by "KF", and with underscore instead of dashs. ie.:
9091
export KF_GIT_URL=https://user:[email protected]/myorg/myrepos.git
9192
export KF_LOCAL_DIR=/tmp/kfdump
9293
export KF_LOG_LEVEL=info
94+
export KF_EXCLUDE_KIND="pod ep rs clusterrole"
9395
94-
# exception, for kubectl compatibility:
96+
# non-prefixed KUBECONFIG works the same as for kubectl
9597
export KUBECONFIG=/tmp/kconfig
9698
```
9799

assets/katafygio.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# To provide alternate api-server URL or config to reach the cluster:
44
#api-server: http://127.0.0.1:8080
55
#kube-config: /etc/kubernetes/config
6+
#context: default
67

78
log-level: "info"
89
log-output: "stderr"
@@ -18,7 +19,7 @@ local-dir: /var/cache/katafygio
1819
#git-timeout: 300s
1920

2021
# Port to listen for http health check probes. 0 to disable.
21-
healthcheck-port: 0
22+
healthcheck-port: 8080
2223

2324
# How often should Katafygio full resync. Only needed to catch possibly
2425
# missed events: events are handled in real-time. 0 to disable.
@@ -44,3 +45,11 @@ resync-interval: 900
4445
# - configmap:kube-system/datadog-leader-elector
4546
# - deployment:default/testdeploy
4647

48+
# Set to true o dump once and exit (instead of continuously dumping new changes)
49+
dump-only: false
50+
51+
# Set to true to disable git versionning
52+
no-git: false
53+
54+
# Set to true to simulate operations (not dumping or versionning anything)
55+
dry-run: false

cmd/flags.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ func init() {
5050

5151
RootCmd.PersistentFlags().StringVarP(&kubeConf, "kube-config", "k", "", "Kubernetes configuration path")
5252
bindPFlag("kube-config", "kube-config")
53-
if err := viper.BindEnv("kube-config", "KUBECONFIG"); err != nil {
54-
log.Fatal("Failed to bind cli argument:", err)
55-
}
5653

5754
RootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "Dry-run mode: don't store anything")
5855
bindPFlag("dry-run", "dry-run")
@@ -100,6 +97,7 @@ func init() {
10097
// for whatever the reason, viper don't auto bind values from config file so we have to tell him
10198
func bindConf(cmd *cobra.Command, args []string) {
10299
apiServer = viper.GetString("api-server")
100+
context = viper.GetString("context")
103101
kubeConf = viper.GetString("kube-config")
104102
dryRun = viper.GetBool("dry-run")
105103
dumpMode = viper.GetBool("dump-only")

pkg/observer/observer.go

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ func (c *Observer) expandAndFilterAPIResources(groups []*metav1.APIResourceList)
212212

213213
func isExcluded(excluded []string, ar metav1.APIResource) bool {
214214
lname := strings.ToLower(ar.Name)
215+
lkind := strings.ToLower(ar.Kind)
215216
singular := strings.ToLower(ar.SingularName)
216217

217218
for _, ctl := range excluded {
@@ -221,6 +222,10 @@ func isExcluded(excluded []string, ar metav1.APIResource) bool {
221222
return true
222223
}
223224

225+
if strings.Compare(lkind, excl) == 0 {
226+
return true
227+
}
228+
224229
if strings.Compare(singular, excl) == 0 {
225230
return true
226231
}

pkg/observer/observer_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestObserverRecoverFromDicoveryFailure(t *testing.T) {
264264
}
265265

266266
func TestExclusion(t *testing.T) {
267-
excluded := []string{"rs", "poD", "endpoints"} // short, singular, plural forms
267+
excluded := []string{"rs", "pods", "node", "Endpoint"} // short, singular, plural forms
268268

269269
if isExcluded(excluded,
270270
metav1.APIResource{Name: "Foos", Kind: "Foo", SingularName: "Foo", ShortNames: []string{}}) {
@@ -277,7 +277,12 @@ func TestExclusion(t *testing.T) {
277277
}
278278

279279
if !isExcluded(excluded,
280-
metav1.APIResource{Name: "Pods", Kind: "Pod", SingularName: "Pod", ShortNames: []string{"po"}}) {
280+
metav1.APIResource{Name: "Pods", Kind: "Pod", ShortNames: []string{"po"}}) {
281+
t.Error("exclusions should consider kind's name")
282+
}
283+
284+
if !isExcluded(excluded,
285+
metav1.APIResource{Name: "Node", Kind: "Node", SingularName: "Node", ShortNames: []string{""}}) {
281286
t.Error("exclusions should ignore objects case")
282287
}
283288

0 commit comments

Comments
 (0)