add --maintenance-frequency flag to ark restic repo init

Signed-off-by: Steve Kriss <steve@heptio.com>
pull/532/head
Steve Kriss 2018-06-13 15:23:23 -07:00
parent 6e9e653f76
commit a927906e52
2 changed files with 22 additions and 10 deletions

View File

@ -14,10 +14,11 @@ ark restic repo init NAMESPACE [flags]
### Options
```
-h, --help help for init
--key-data string Encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.
--key-file string Path to file containing the encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.
--key-size int Size of the generated key for the restic repository (default 1024)
-h, --help help for init
--key-data string Encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.
--key-file string Path to file containing the encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.
--key-size int Size of the generated key for the restic repository (default 1024)
--maintenance-frequency duration How often maintenance (i.e. restic prune & check) is run on the repository (default 24h0m0s)
```
### Options inherited from parent commands

View File

@ -18,6 +18,7 @@ package repo
import (
"crypto/rand"
"time"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -55,10 +56,11 @@ func NewInitCommand(f client.Factory) *cobra.Command {
}
type InitRepositoryOptions struct {
Namespace string
KeyFile string
KeyData string
KeySize int
Namespace string
KeyFile string
KeyData string
KeySize int
MaintenanceFrequency time.Duration
fileSystem filesystem.Interface
kubeClient kclientset.Interface
@ -68,8 +70,9 @@ type InitRepositoryOptions struct {
func NewInitRepositoryOptions() *InitRepositoryOptions {
return &InitRepositoryOptions{
KeySize: 1024,
fileSystem: filesystem.NewFileSystem(),
KeySize: 1024,
MaintenanceFrequency: restic.DefaultMaintenanceFrequency,
fileSystem: filesystem.NewFileSystem(),
}
}
@ -82,6 +85,7 @@ func (o *InitRepositoryOptions) BindFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.KeyFile, "key-file", o.KeyFile, "Path to file containing the encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.")
flags.StringVar(&o.KeyData, "key-data", o.KeyData, "Encryption key for the restic repository. Optional; if unset, Ark will generate a random key for you.")
flags.IntVar(&o.KeySize, "key-size", o.KeySize, "Size of the generated key for the restic repository")
flags.DurationVar(&o.MaintenanceFrequency, "maintenance-frequency", o.MaintenanceFrequency, "How often maintenance (i.e. restic prune & check) is run on the repository")
}
func (o *InitRepositoryOptions) Complete(f client.Factory, args []string) error {
@ -118,6 +122,10 @@ func (o *InitRepositoryOptions) Validate(f client.Factory) error {
return errors.Errorf("keyBytes is required")
}
if o.MaintenanceFrequency <= 0 {
return errors.Errorf("--maintenance-frequency must be greater than zero")
}
kubeClient, err := f.KubeClient()
if err != nil {
return err
@ -147,6 +155,9 @@ func (o *InitRepositoryOptions) Run(f client.Factory) error {
Namespace: f.Namespace(),
Name: o.Namespace,
},
Spec: v1.ResticRepositorySpec{
MaintenanceFrequency: metav1.Duration{Duration: o.MaintenanceFrequency},
},
}
_, err := o.arkClient.ArkV1().ResticRepositories(f.Namespace()).Create(repo)