add default-volumes-to-restic flag to velero installation

Signed-off-by: Ashish Amarnath <ashisham@vmware.com>
This commit is contained in:
Ashish Amarnath
2020-06-16 12:31:50 -07:00
parent 63f7690f44
commit 6a8dca6b84
3 changed files with 24 additions and 0 deletions

View File

@@ -70,6 +70,7 @@ type InstallOptions struct {
CRDsOnly bool
CACertFile string
Features string
DefaultVolumesToRestic bool
}
// BindFlags adds command line values to the options struct.
@@ -103,6 +104,7 @@ func (o *InstallOptions) BindFlags(flags *pflag.FlagSet) {
flags.BoolVar(&o.CRDsOnly, "crds-only", o.CRDsOnly, "only generate CustomResourceDefinition resources. Useful for updating CRDs for an existing Velero install.")
flags.StringVar(&o.CACertFile, "cacert", o.CACertFile, "file containing a certificate bundle to use when verifying TLS connections to the object store. Optional.")
flags.StringVar(&o.Features, "features", o.Features, "comma separated list of Velero feature flags to be set on the Velero deployment and the restic daemonset, if restic is enabled")
flags.BoolVar(&o.DefaultVolumesToRestic, "default-volumes-to-restic", o.DefaultVolumesToRestic, "bool flag to configure Velero server to use restic by default to backup all pod volumes on all backups. Optional.")
}
// NewInstallOptions instantiates a new, default InstallOptions struct.
@@ -126,6 +128,7 @@ func NewInstallOptions() *InstallOptions {
UseVolumeSnapshots: true,
NoDefaultBackupLocation: false,
CRDsOnly: false,
DefaultVolumesToRestic: false,
}
}
@@ -183,6 +186,7 @@ func (o *InstallOptions) AsVeleroOptions() (*install.VeleroOptions, error) {
NoDefaultBackupLocation: o.NoDefaultBackupLocation,
CACertData: caCertData,
Features: strings.Split(o.Features, ","),
DefaultVolumesToRestic: o.DefaultVolumesToRestic,
}, nil
}
@@ -374,6 +378,10 @@ func (o *InstallOptions) Validate(c *cobra.Command, args []string, f client.Fact
}
}
if o.DefaultVolumesToRestic && !o.UseRestic {
return errors.New("--use-restic is required when using --default-volumes-to-restic")
}
switch {
case o.SecretFile == "" && !o.NoSecret:
return errors.New("One of --secret-file or --no-secret is required")

View File

@@ -40,6 +40,7 @@ type podTemplateConfig struct {
defaultResticMaintenanceFrequency time.Duration
plugins []string
features []string
defaultVolumesToRestic bool
}
func WithImage(image string) podTemplateOption {
@@ -107,6 +108,12 @@ func WithFeatures(features []string) podTemplateOption {
}
}
func WithDefaultVolumesToRestic() podTemplateOption {
return func(c *podTemplateConfig) {
c.defaultVolumesToRestic = true
}
}
func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment {
// TODO: Add support for server args
c := &podTemplateConfig{
@@ -129,6 +136,10 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
args = append(args, fmt.Sprintf("--features=%s", strings.Join(c.features, ",")))
}
if c.defaultVolumesToRestic {
args = append(args, "--default-volumes-to-restic=true")
}
containerLabels := labels()
containerLabels["deploy"] = "velero"

View File

@@ -220,6 +220,7 @@ type VeleroOptions struct {
NoDefaultBackupLocation bool
CACertData []byte
Features []string
DefaultVolumesToRestic bool
}
func AllCRDs() *unstructured.UnstructuredList {
@@ -287,6 +288,10 @@ func AllResources(o *VeleroOptions) (*unstructured.UnstructuredList, error) {
deployOpts = append(deployOpts, WithPlugins(o.Plugins))
}
if o.DefaultVolumesToRestic {
deployOpts = append(deployOpts, WithDefaultVolumesToRestic())
}
deploy := Deployment(o.Namespace, deployOpts...)
appendUnstructured(resources, deploy)