@@ -113,14 +113,26 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
113
113
pullPolicy = corev1 .PullAlways
114
114
}
115
115
116
+ // make a copy of the labels and annotations to avoid mutating the input parameters
117
+ podLabels := make (map [string ]string )
118
+ podAnnotations := make (map [string ]string )
119
+
120
+ for key , value := range labels {
121
+ podLabels [key ] = value
122
+ }
123
+
124
+ for key , value := range annotations {
125
+ podAnnotations [key ] = value
126
+ }
127
+
116
128
readOnlyRootFilesystem := false
117
129
118
130
pod := & corev1.Pod {
119
131
ObjectMeta : metav1.ObjectMeta {
120
132
GenerateName : source .GetName () + "-" ,
121
133
Namespace : source .GetNamespace (),
122
- Labels : labels ,
123
- Annotations : annotations ,
134
+ Labels : podLabels ,
135
+ Annotations : podAnnotations ,
124
136
},
125
137
Spec : corev1.PodSpec {
126
138
Containers : []corev1.Container {
@@ -207,25 +219,17 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
207
219
}
208
220
209
221
// Set priorityclass if its annotation exists
210
- if prio , ok := annotations [CatalogPriorityClassKey ]; ok && prio != "" {
222
+ if prio , ok := podAnnotations [CatalogPriorityClassKey ]; ok && prio != "" {
211
223
pod .Spec .PriorityClassName = prio
212
224
}
213
225
214
226
// Add PodSpec hash
215
227
// This hash info will be used to detect PodSpec changes
216
- if labels == nil {
217
- labels = make (map [string ]string )
218
- }
219
- labels [PodHashLabelKey ] = hashPodSpec (pod .Spec )
220
- pod .SetLabels (labels )
228
+ podLabels [PodHashLabelKey ] = hashPodSpec (pod .Spec )
221
229
222
230
// add eviction annotation to enable the cluster autoscaler to evict the pod in order to drain the node
223
231
// since catalog pods are not backed by a controller, they cannot be evicted by default
224
- if annotations == nil {
225
- annotations = make (map [string ]string )
226
- }
227
- annotations [ClusterAutoscalingAnnotationKey ] = "true"
228
- pod .SetAnnotations (annotations )
232
+ podAnnotations [ClusterAutoscalingAnnotationKey ] = "true"
229
233
230
234
return pod
231
235
}
0 commit comments