Add pod-annotations CLI flag to the install command (#1626)

* allow users to specify additional Velero/restic pod annotations on the command line with the pod-annotations flag

Signed-off-by: Traci Kamp <traci.kamp@gmail.com>
This commit is contained in:
Traci Kamp
2019-07-03 15:22:34 -07:00
committed by KubeKween
parent eec5cc687e
commit f829dabcf4
5 changed files with 29 additions and 4 deletions
+1
View File
@@ -61,6 +61,7 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
"name": "restic",
"component": "velero",
},
Annotations: c.annotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: "velero",
+8 -1
View File
@@ -31,6 +31,7 @@ type podTemplateConfig struct {
withoutCredentialsVolume bool
envVars []corev1.EnvVar
restoreOnly bool
annotations map[string]string
}
func WithImage(image string) podTemplateOption {
@@ -39,6 +40,12 @@ func WithImage(image string) podTemplateOption {
}
}
func WithAnnotations(annotations map[string]string) podTemplateOption {
return func(c *podTemplateConfig) {
c.annotations = annotations
}
}
func WithoutCredentialsVolume() podTemplateOption {
return func(c *podTemplateConfig) {
c.withoutCredentialsVolume = true
@@ -98,7 +105,7 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1beta1.Deploy
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: containerLabels,
Annotations: podAnnotations(),
Annotations: podAnnotations(c.annotations),
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyAlways,
+14 -2
View File
@@ -45,12 +45,20 @@ func labels() map[string]string {
}
}
func podAnnotations() map[string]string {
return map[string]string{
func podAnnotations(userAnnotations map[string]string) map[string]string {
// Use the default annotations as a starting point
base := map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": "8085",
"prometheus.io/path": "/metrics",
}
// Merge base annotations with user annotations to enforce CLI precedence
for k, v := range userAnnotations {
base[k] = v
}
return base
}
func containerPorts() []corev1.ContainerPort {
@@ -180,6 +188,7 @@ type VeleroOptions struct {
ProviderName string
Bucket string
Prefix string
PodAnnotations map[string]string
SecretData []byte
RestoreOnly bool
UseRestic bool
@@ -221,10 +230,12 @@ func AllResources(o *VeleroOptions) (*unstructured.UnstructuredList, error) {
}
deploy := Deployment(o.Namespace,
WithAnnotations(o.PodAnnotations),
WithImage(o.Image),
)
if o.RestoreOnly {
deploy = Deployment(o.Namespace,
WithAnnotations(o.PodAnnotations),
WithImage(o.Image),
WithRestoreOnly(),
)
@@ -233,6 +244,7 @@ func AllResources(o *VeleroOptions) (*unstructured.UnstructuredList, error) {
if o.UseRestic {
ds := DaemonSet(o.Namespace,
WithAnnotations(o.PodAnnotations),
WithImage(o.Image),
)
appendUnstructured(resources, ds)