Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ Available Commands:

Flags:
-s, --api-server string Kubernetes api-server url
-j, --check-interval int Check interval in seconds (default 10)
-c, --config string Configuration file (default "/etc/katafygio/katafygio.yaml")
-q, --context string Kubernetes configuration context
-d, --dry-run Dry-run mode: don't store anything
-m, --dump-only Dump mode: dump everything once and exit
-x, --exclude-kind strings Ressource kind to exclude. Eg. 'deployment'
-y, --exclude-object strings Object to exclude. Eg. 'configmap:kube-system/kube-dns'
-l, --filter string Label filter. Select only objects matching the label
-b, --git-author string Author for git commits (default "Katafygio")
-f, --git-email string Email address for git commits (default "katafygio@localhost")
-t, --git-timeout duration Git operations timeout (default 5m0s)
-g, --git-url string Git repository URL
-p, --healthcheck-port int Port for answering healthchecks on /health url
Expand Down
2 changes: 1 addition & 1 deletion assets/helm-chart/katafygio/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: katafygio
home: https://github.com/bpineau/katafygio
sources:
- https://github.com/bpineau/katafygio
version: 0.4.3
version: 0.4.4
keywords:
- backup
- dump
Expand Down
9 changes: 9 additions & 0 deletions assets/helm-chart/katafygio/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ spec:
- --exclude-object={{ . }}
{{- end }}
{{- end }}
{{- if .Values.gitAuthor }}
- --git-author={{ .Values.gitAuthor }}
{{- end }}
{{- if .Values.gitEmail }}
- --git-email={{ .Values.gitEmail }}
{{- end }}
{{- if .Values.checkInterval }}
- --check-interval={{ .Values.checkInterval }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.healthcheckPort }}
Expand Down
9 changes: 9 additions & 0 deletions assets/helm-chart/katafygio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ gitSshConfig: |
StrictHostKeyChecking no
UserKnownHostsFile /dev/null

# gitAuthor (optional) The author name used for git commits
gitAuthor: "Katafygio"

# gitEmail (optional) The email address used for git commits
gitEmail: "katafygio@localhost"

# checkInterval (optional) How long in seconds at minimum between git commits
checkInterval: 10

# healthcheckPort is the TCP port Katafygio will listen for health check requests.
healthcheckPort: 8080

Expand Down
3 changes: 2 additions & 1 deletion cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/signal"
"path/filepath"
"syscall"
"time"

"github.com/spf13/afero"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -63,7 +64,7 @@ func runE(cmd *cobra.Command, args []string) (err error) {

var repo *git.Store
if !noGit {
repo, err = git.New(logger, dryRun, localDir, gitURL, gitTimeout).Start()
repo, err = git.New(logger, dryRun, localDir, gitURL, gitAuthor, gitEmail, gitTimeout, time.Duration(checkInt)*time.Second).Start()
}
if err != nil {
return fmt.Errorf("failed to start git repo handler: %v", err)
Expand Down
15 changes: 15 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ var (
gitTimeout time.Duration
healthP int
resyncInt int
checkInt int
exclkind []string
exclobj []string
noGit bool
gitAuthor string
gitEmail string
)

func bindPFlag(key string, cmd string) {
Expand Down Expand Up @@ -94,8 +97,17 @@ func init() {
RootCmd.PersistentFlags().IntVarP(&resyncInt, "resync-interval", "i", 900, "Full resync interval in seconds (0 to disable)")
bindPFlag("resync-interval", "resync-interval")

RootCmd.PersistentFlags().IntVarP(&checkInt, "check-interval", "j", 10, "Check interval in seconds")
bindPFlag("check-interval", "check-interval")

RootCmd.PersistentFlags().BoolVarP(&noGit, "no-git", "n", false, "Don't version with git")
bindPFlag("no-git", "no-git")

RootCmd.PersistentFlags().StringVarP(&gitAuthor, "git-author", "b", "Katafygio", "Author for git commits")
bindPFlag("git-author", "git-author")

RootCmd.PersistentFlags().StringVarP(&gitEmail, "git-email", "f", "katafygio@localhost", "Email address for git commits")
bindPFlag("git-email", "git-email")
}

// for whatever the reason, viper don't auto bind values from config file so we have to tell him
Expand All @@ -115,7 +127,10 @@ func bindConf(cmd *cobra.Command, args []string) {
gitTimeout = viper.GetDuration("git-timeout")
healthP = viper.GetInt("healthcheck-port")
resyncInt = viper.GetInt("resync-interval")
checkInt = viper.GetInt("check-interval")
exclkind = viper.GetStringSlice("exclude-kind")
exclobj = viper.GetStringSlice("exclude-object")
noGit = viper.GetBool("no-git")
gitAuthor = viper.GetString("git-author")
gitEmail = viper.GetString("git-email")
}
53 changes: 23 additions & 30 deletions pkg/store/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ import (
)

var (
// CheckInterval defines the interval between local directory checks
CheckInterval = 10 * time.Second

// GitAuthor is the name of the commiter
GitAuthor = "Katafygio"

// GitEmail is the email of the commiter
GitEmail = "katafygio@localhost"

// GitMsg is the commit message we'll use
GitMsg = "Kubernetes cluster change"
)
Expand All @@ -34,35 +25,37 @@ type logger interface {

// Store will maintain a git repository off dumped kube objects
type Store struct {
Logger logger
LocalDir string
URL string
Timeout time.Duration
Author string
Email string
Msg string
DryRun bool
stopch chan struct{}
donech chan struct{}
Logger logger
LocalDir string
URL string
Timeout time.Duration
CheckInterval time.Duration
Author string
Email string
Msg string
DryRun bool
stopch chan struct{}
donech chan struct{}
}

// New instantiate a new git Store. url is optional.
func New(log logger, dryRun bool, dir, url string, timeout time.Duration) *Store {
func New(log logger, dryRun bool, dir, url string, author string, email string, timeout time.Duration, checkInterval time.Duration) *Store {
return &Store{
Logger: log,
LocalDir: dir,
URL: url,
Timeout: timeout,
Author: GitAuthor,
Email: GitEmail,
Msg: GitMsg,
DryRun: dryRun,
Logger: log,
LocalDir: dir,
URL: url,
Timeout: timeout,
CheckInterval: checkInterval,
Author: author,
Email: email,
Msg: GitMsg,
DryRun: dryRun,
}
}

// Start maintains a directory content committed
func (s *Store) Start() (*Store, error) {
s.Logger.Infof("Starting git repository synchronizer")
s.Logger.Infof(fmt.Sprintf("Starting git repository synchronizer every %s", s.CheckInterval.String()))
s.stopch = make(chan struct{})
s.donech = make(chan struct{})

Expand All @@ -72,7 +65,7 @@ func (s *Store) Start() (*Store, error) {
}

go func() {
checkTick := time.NewTicker(CheckInterval)
checkTick := time.NewTicker(s.CheckInterval)
defer checkTick.Stop()
defer close(s.donech)

Expand Down
4 changes: 2 additions & 2 deletions pkg/store/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGitDryRun(t *testing.T) {

appFs = afero.NewMemMapFs()

repo, err := New(new(mockLog), true, "/tmp/ktest", "", timeout).Start()
repo, err := New(new(mockLog), true, "/tmp/ktest", "", "test", "test@test", timeout, 10*time.Second).Start()
if err != nil {
t.Errorf("failed to start git: %v", err)
}
Expand All @@ -62,7 +62,7 @@ func TestGit(t *testing.T) {

defer os.RemoveAll(dir)

repo, err := New(new(mockLog), false, dir, "", timeout).Start()
repo, err := New(new(mockLog), false, dir, "", "test", "test@test", timeout, 10*time.Second).Start()
if err != nil {
t.Errorf("failed to start git: %v", err)
}
Expand Down