@@ -31,6 +31,7 @@ const (
31
31
32
32
var (
33
33
resticPvHostPath string = getResticPvHostPath ()
34
+ emptyString = ""
34
35
35
36
// v1.MountPropagationHostToContainer is a const. Const cannot be pointed to.
36
37
// we need to declare mountPropagationToHostContainer so that we have an address to point to
@@ -107,7 +108,6 @@ func (r *DPAReconciler) ReconcileResticDaemonset(log logr.Logger) (bool, error)
107
108
if err := controllerutil .SetControllerReference (& dpa , ds , r .Scheme ); err != nil {
108
109
return err
109
110
}
110
-
111
111
if _ , err := r .buildResticDaemonset (& dpa , ds ); err != nil {
112
112
return err
113
113
}
@@ -144,21 +144,17 @@ func (r *DPAReconciler) buildResticDaemonset(dpa *oadpv1alpha1.DataProtectionApp
144
144
return nil , fmt .Errorf ("ds cannot be nil" )
145
145
}
146
146
147
- resticDaemonSetName := ds .Name
148
- ownerRefs := ds .OwnerReferences
149
-
150
- * ds = * install .DaemonSet (ds .Namespace ,
147
+ prevDs := ds .DeepCopy ()
148
+ ds .Spec = install .DaemonSet (ds .Namespace ,
151
149
install .WithResources (r .getResticResourceReqs (dpa )),
152
150
install .WithImage (getVeleroImage (dpa )),
153
151
install .WithAnnotations (dpa .Spec .PodAnnotations ),
154
- install .WithSecret (false ))
152
+ install .WithSecret (false )). Spec
155
153
156
- ds .Name = resticDaemonSetName
157
- ds .OwnerReferences = ownerRefs
158
- return r .customizeResticDaemonset (dpa , ds )
154
+ return r .customizeResticDaemonset (dpa , ds , prevDs )
159
155
}
160
156
161
- func (r * DPAReconciler ) customizeResticDaemonset (dpa * oadpv1alpha1.DataProtectionApplication , ds * appsv1.DaemonSet ) (* appsv1.DaemonSet , error ) {
157
+ func (r * DPAReconciler ) customizeResticDaemonset (dpa * oadpv1alpha1.DataProtectionApplication , ds * appsv1.DaemonSet , prevDs * appsv1. DaemonSet ) (* appsv1.DaemonSet , error ) {
162
158
163
159
// customize specs
164
160
ds .Spec .Selector = resticLabelSelector
@@ -234,6 +230,49 @@ func (r *DPAReconciler) customizeResticDaemonset(dpa *oadpv1alpha1.DataProtectio
234
230
if err := credentials .AppendCloudProviderVolumes (dpa , ds , providerNeedsDefaultCreds , hasCloudStorage ); err != nil {
235
231
return nil , err
236
232
}
233
+
234
+ // Define defaults to avoid update events
235
+ // replace volumeSource HostPath Type if nil with empty string
236
+ for i , vol := range ds .Spec .Template .Spec .Volumes {
237
+ if vol .VolumeSource .HostPath != nil && vol .VolumeSource .HostPath .Type == nil {
238
+ ds .Spec .Template .Spec .Volumes [i ].VolumeSource .HostPath .Type = (* corev1 .HostPathType )(& emptyString )
239
+ }
240
+ }
241
+ for i , container := range ds .Spec .Template .Spec .Containers {
242
+ for j , env := range container .Env {
243
+ if env .ValueFrom != nil && env .ValueFrom .FieldRef != nil && ds .Spec .Template .Spec .Containers [i ].Env [j ].ValueFrom .FieldRef .APIVersion == "" {
244
+ ds .Spec .Template .Spec .Containers [i ].Env [j ].ValueFrom .FieldRef .APIVersion = "v1"
245
+ }
246
+ }
247
+ if container .TerminationMessagePath == "" {
248
+ ds .Spec .Template .Spec .Containers [i ].TerminationMessagePath = corev1 .TerminationMessagePathDefault
249
+ }
250
+ if container .TerminationMessagePolicy == "" {
251
+ ds .Spec .Template .Spec .Containers [i ].TerminationMessagePolicy = corev1 .TerminationMessageReadFile
252
+ }
253
+ }
254
+ if ds .Spec .Template .Spec .RestartPolicy == "" {
255
+ ds .Spec .Template .Spec .RestartPolicy = prevDs .Spec .Template .Spec .RestartPolicy
256
+ }
257
+ if ds .Spec .Template .Spec .DNSPolicy == "" {
258
+ ds .Spec .Template .Spec .DNSPolicy = prevDs .Spec .Template .Spec .DNSPolicy
259
+ }
260
+ if ds .Spec .Template .Spec .SchedulerName == "" {
261
+ ds .Spec .Template .Spec .SchedulerName = prevDs .Spec .Template .Spec .SchedulerName
262
+ }
263
+ if ds .Spec .Template .Spec .DeprecatedServiceAccount == "" {
264
+ ds .Spec .Template .Spec .DeprecatedServiceAccount = prevDs .Spec .Template .Spec .DeprecatedServiceAccount
265
+ }
266
+ if ds .Spec .Template .Spec .TerminationGracePeriodSeconds == nil {
267
+ ds .Spec .Template .Spec .TerminationGracePeriodSeconds = prevDs .Spec .Template .Spec .TerminationGracePeriodSeconds
268
+ }
269
+ if ds .Spec .UpdateStrategy .RollingUpdate == nil {
270
+ ds .Spec .UpdateStrategy .RollingUpdate = prevDs .Spec .UpdateStrategy .RollingUpdate
271
+ }
272
+ if ds .Spec .RevisionHistoryLimit == nil {
273
+ ds .Spec .RevisionHistoryLimit = prevDs .Spec .RevisionHistoryLimit
274
+ }
275
+
237
276
return ds , nil
238
277
}
239
278
0 commit comments