@@ -113,14 +113,26 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
113113 pullPolicy = corev1 .PullAlways
114114 }
115115
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+
116128 readOnlyRootFilesystem := false
117129
118130 pod := & corev1.Pod {
119131 ObjectMeta : metav1.ObjectMeta {
120132 GenerateName : source .GetName () + "-" ,
121133 Namespace : source .GetNamespace (),
122- Labels : labels ,
123- Annotations : annotations ,
134+ Labels : podLabels ,
135+ Annotations : podAnnotations ,
124136 },
125137 Spec : corev1.PodSpec {
126138 Containers : []corev1.Container {
@@ -207,25 +219,17 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
207219 }
208220
209221 // Set priorityclass if its annotation exists
210- if prio , ok := annotations [CatalogPriorityClassKey ]; ok && prio != "" {
222+ if prio , ok := podAnnotations [CatalogPriorityClassKey ]; ok && prio != "" {
211223 pod .Spec .PriorityClassName = prio
212224 }
213225
214226 // Add PodSpec hash
215227 // 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 )
221229
222230 // add eviction annotation to enable the cluster autoscaler to evict the pod in order to drain the node
223231 // 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"
229233
230234 return pod
231235}
0 commit comments