Add --plugins flag to velero install (#1930)

* Add plugins flag to install

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
This commit is contained in:
Nolan Brubaker
2019-10-03 16:44:52 -07:00
committed by KubeKween
parent db59d8d4bc
commit f009fe9bd1
7 changed files with 63 additions and 34 deletions
+17
View File
@@ -24,6 +24,8 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/vmware-tanzu/velero/pkg/builder"
)
type podTemplateOption func(*podTemplateConfig)
@@ -36,6 +38,7 @@ type podTemplateConfig struct {
resources corev1.ResourceRequirements
withSecret bool
defaultResticMaintenanceFrequency time.Duration
plugins []string
}
func WithImage(image string) podTemplateOption {
@@ -91,6 +94,12 @@ func WithDefaultResticMaintenanceFrequency(val time.Duration) podTemplateOption
}
}
func WithPlugins(plugins []string) podTemplateOption {
return func(c *podTemplateConfig) {
c.plugins = plugins
}
}
func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment {
// TODO: Add support for server args
c := &podTemplateConfig{
@@ -236,5 +245,13 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
deployment.Spec.Template.Spec.Containers[0].Args = append(deployment.Spec.Template.Spec.Containers[0].Args, fmt.Sprintf("--default-restic-prune-frequency=%v", c.defaultResticMaintenanceFrequency))
}
if len(c.plugins) > 0 {
for _, image := range c.plugins {
container := *builder.ForPluginContainer(image, pullPolicy).Result()
deployment.Spec.Template.Spec.InitContainers = append(deployment.Spec.Template.Spec.InitContainers, container)
}
}
return deployment
}
+5 -1
View File
@@ -215,6 +215,7 @@ type VeleroOptions struct {
BSLConfig map[string]string
VSLConfig map[string]string
DefaultResticMaintenanceFrequency time.Duration
Plugins []string
}
// AllResources returns a list of all resources necessary to install Velero, in the appropriate order, into a Kubernetes cluster.
@@ -266,13 +267,16 @@ func AllResources(o *VeleroOptions) (*unstructured.UnstructuredList, error) {
deployOpts = append(deployOpts, WithRestoreOnly())
}
if len(o.Plugins) > 0 {
deployOpts = append(deployOpts, WithPlugins(o.Plugins))
}
deploy := Deployment(o.Namespace, deployOpts...)
appendUnstructured(resources, deploy)
if o.UseRestic {
ds := DaemonSet(o.Namespace,
WithAnnotations(o.PodAnnotations),
WithImage(o.Image),
WithResources(o.ResticPodResources),