Skip to content

Commit 3763739

Browse files
committed
operator: fix controllers indicating changes when there are none
Signed-off-by: Tuomas Katila <[email protected]>
1 parent 025937d commit 3763739

File tree

5 files changed

+61
-21
lines changed

5 files changed

+61
-21
lines changed

pkg/controllers/dlb/controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (
118118
updated = true
119119
}
120120
} else {
121-
setInitContainer(&ds.Spec.Template.Spec, dp.Spec)
122-
updated = true
121+
containers := ds.Spec.Template.Spec.InitContainers
122+
if len(containers) != 1 || containers[0].Image != dp.Spec.InitImage {
123+
setInitContainer(&ds.Spec.Template.Spec, dp.Spec)
124+
updated = true
125+
}
123126
}
124127

125128
if len(dp.Spec.NodeSelector) > 0 {

pkg/controllers/dsa/controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ func provisioningUpdate(ds *apps.DaemonSet, dp *devicepluginv1.DsaDevicePlugin)
218218
found := false
219219

220220
for _, container := range ds.Spec.Template.Spec.InitContainers {
221-
if container.Name == inicontainerName && container.Image != dp.Spec.InitImage {
221+
if container.Name == inicontainerName {
222+
if container.Image != dp.Spec.InitImage {
223+
update = true
224+
}
225+
222226
found = true
223-
update = true
224227

225228
break
226229
}

pkg/controllers/gpu/controller.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,32 +242,54 @@ func removeVolumeMount(volumeMounts []v1.VolumeMount, name string) []v1.VolumeMo
242242
return newVolumeMounts
243243
}
244244

245-
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
246-
dp := rawObj.(*devicepluginv1.GpuDevicePlugin)
247-
248-
if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {
249-
ds.Spec.Template.Spec.Containers[0].Image = dp.Spec.Image
250-
updated = true
251-
}
245+
func processInitcontainer(ds *apps.DaemonSet, dp *devicepluginv1.GpuDevicePlugin) bool {
246+
initContainers := ds.Spec.Template.Spec.InitContainers
252247

253248
if dp.Spec.InitImage == "" {
254-
if ds.Spec.Template.Spec.InitContainers != nil {
249+
if initContainers != nil {
255250
ds.Spec.Template.Spec.InitContainers = nil
256251
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, "nfd-features")
257-
updated = true
252+
253+
return true
258254
}
259-
} else {
255+
} else if len(initContainers) != 1 || initContainers[0].Image != dp.Spec.InitImage {
260256
setInitContainer(&ds.Spec.Template.Spec, dp.Spec.InitImage)
261-
updated = true
257+
258+
return true
262259
}
263260

261+
return false
262+
}
263+
264+
func processNodeSelector(ds *apps.DaemonSet, dp *devicepluginv1.GpuDevicePlugin) bool {
264265
if len(dp.Spec.NodeSelector) > 0 {
265266
if !reflect.DeepEqual(ds.Spec.Template.Spec.NodeSelector, dp.Spec.NodeSelector) {
266267
ds.Spec.Template.Spec.NodeSelector = dp.Spec.NodeSelector
267-
updated = true
268+
269+
return true
268270
}
269271
} else if !reflect.DeepEqual(ds.Spec.Template.Spec.NodeSelector, defaultNodeSelector) {
270272
ds.Spec.Template.Spec.NodeSelector = defaultNodeSelector
273+
274+
return true
275+
}
276+
277+
return false
278+
}
279+
280+
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
281+
dp := rawObj.(*devicepluginv1.GpuDevicePlugin)
282+
283+
if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {
284+
ds.Spec.Template.Spec.Containers[0].Image = dp.Spec.Image
285+
updated = true
286+
}
287+
288+
if processInitcontainer(ds, dp) {
289+
updated = true
290+
}
291+
292+
if processNodeSelector(ds, dp) {
271293
updated = true
272294
}
273295

pkg/controllers/iaa/controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,12 @@ func provisioningUpdate(ds *apps.DaemonSet, dp *devicepluginv1.IaaDevicePlugin)
219219
found := false
220220

221221
for _, container := range ds.Spec.Template.Spec.InitContainers {
222-
if container.Name == "intel-iaa-initcontainer" && container.Image != dp.Spec.InitImage {
222+
if container.Name == "intel-iaa-initcontainer" {
223+
if container.Image != dp.Spec.InitImage {
224+
update = true
225+
}
226+
223227
found = true
224-
update = true
225228

226229
break
227230
}

pkg/controllers/qat/controller.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
111111
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
112112
dp := rawObj.(*devicepluginv1.QatDevicePlugin)
113113

114-
if !reflect.DeepEqual(ds.ObjectMeta.Annotations, dp.ObjectMeta.Annotations) {
114+
// Remove always incrementing annotation so it doesn't cause the next DeepEqual
115+
// to return false every time.
116+
dsAnnotations := ds.ObjectMeta.DeepCopy().Annotations
117+
delete(dsAnnotations, "deprecated.daemonset.template.generation")
118+
119+
if !reflect.DeepEqual(dsAnnotations, dp.ObjectMeta.Annotations) {
115120
pluginAnnotations := dp.ObjectMeta.DeepCopy().Annotations
116121
ds.ObjectMeta.Annotations = pluginAnnotations
117122
ds.Spec.Template.Annotations = pluginAnnotations
@@ -131,8 +136,12 @@ func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (
131136
updated = true
132137
}
133138
} else {
134-
setInitContainer(&ds.Spec.Template.Spec, dp.Spec)
135-
updated = true
139+
containers := ds.Spec.Template.Spec.InitContainers
140+
if len(containers) != 1 || containers[0].Image != dp.Spec.InitImage {
141+
setInitContainer(&ds.Spec.Template.Spec, dp.Spec)
142+
143+
updated = true
144+
}
136145
}
137146

138147
if len(dp.Spec.NodeSelector) > 0 {

0 commit comments

Comments
 (0)