@@ -1083,64 +1083,70 @@ func (r *NamespaceScopeReconciler) CSVReconcile(req ctrl.Request) (ctrl.Result,
1083
1083
continue
1084
1084
}
1085
1085
patchedCSVList = append (patchedCSVList , packageName .(string ))
1086
- csv := csvList .Items [0 ]
1087
- csvOriginal := csv .DeepCopy ()
1088
- if csv .Spec .InstallStrategy .StrategyName != "deployment" {
1089
- continue
1090
- }
1091
- deploymentSpecs := csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs
1092
- for _ , deploy := range deploymentSpecs {
1093
- podTemplate := deploy .Spec .Template
1094
- // Insert restartlabel into operator pods
1095
- if podTemplate .Labels == nil {
1096
- podTemplate .Labels = make (map [string ]string )
1097
- }
1098
- for k , v := range instance .Spec .RestartLabels {
1099
- podTemplate .Labels [k ] = v
1086
+
1087
+ for _ , c := range csvList .Items {
1088
+ // avoid Implicit memory aliasing in for loop
1089
+ csv := c
1090
+ klog .V (2 ).Infof ("Found CSV %s for packageManifest %s" , csv .Name , packageName .(string ))
1091
+ csvOriginal := csv .DeepCopy ()
1092
+ if csv .Spec .InstallStrategy .StrategyName != "deployment" {
1093
+ continue
1100
1094
}
1101
- // Insert WATCH_NAMESPACE into operator pod environment variables
1102
- for containerIndex , container := range podTemplate .Spec .Containers {
1103
- var found bool
1104
- optional := true
1105
- configmapEnv := corev1.EnvVar {
1106
- Name : "WATCH_NAMESPACE" ,
1107
- ValueFrom : & corev1.EnvVarSource {
1108
- ConfigMapKeyRef : & corev1.ConfigMapKeySelector {
1109
- Optional : & optional ,
1110
- Key : "namespaces" ,
1111
- LocalObjectReference : corev1.LocalObjectReference {
1112
- Name : configmapName ,
1095
+ deploymentSpecs := csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs
1096
+ for _ , deploy := range deploymentSpecs {
1097
+ podTemplate := deploy .Spec .Template
1098
+ // Insert restartlabel into operator pods
1099
+ if podTemplate .Labels == nil {
1100
+ podTemplate .Labels = make (map [string ]string )
1101
+ }
1102
+ for k , v := range instance .Spec .RestartLabels {
1103
+ podTemplate .Labels [k ] = v
1104
+ }
1105
+ // Insert WATCH_NAMESPACE into operator pod environment variables
1106
+ for containerIndex , container := range podTemplate .Spec .Containers {
1107
+ var found bool
1108
+ optional := true
1109
+ configmapEnv := corev1.EnvVar {
1110
+ Name : "WATCH_NAMESPACE" ,
1111
+ ValueFrom : & corev1.EnvVarSource {
1112
+ ConfigMapKeyRef : & corev1.ConfigMapKeySelector {
1113
+ Optional : & optional ,
1114
+ Key : "namespaces" ,
1115
+ LocalObjectReference : corev1.LocalObjectReference {
1116
+ Name : configmapName ,
1117
+ },
1113
1118
},
1114
1119
},
1115
- },
1116
- }
1117
- for index , env := range container .Env {
1118
- if env .Name == "WATCH_NAMESPACE" {
1119
- found = true
1120
- if env .ValueFrom .ConfigMapKeyRef != nil && env .ValueFrom .ConfigMapKeyRef .Key == "namespaces" && env .ValueFrom .ConfigMapKeyRef .LocalObjectReference .Name == configmapName {
1121
- continue
1120
+ }
1121
+ for index , env := range container .Env {
1122
+ if env .Name == "WATCH_NAMESPACE" {
1123
+ found = true
1124
+ if env .ValueFrom .ConfigMapKeyRef != nil && env .ValueFrom .ConfigMapKeyRef .Key == "namespaces" && env .ValueFrom .ConfigMapKeyRef .LocalObjectReference .Name == configmapName {
1125
+ klog .V (2 ).Infof ("WATCH_NAMESPACE ENV variable is found in CSV %s, and match the configmap %s, skip it" , csv .Name , configmapName )
1126
+ continue
1127
+ }
1128
+ klog .V (2 ).Infof ("WATCH_NAMESPACE ENV variable is found in CSV %s, but not match the configmap %s, replace it" , csv .Name , configmapName )
1129
+ container .Env [index ] = configmapEnv
1122
1130
}
1123
- container .Env [index ] = configmapEnv
1124
1131
}
1132
+ if ! found {
1133
+ klog .V (2 ).Infof ("WATCH_NAMESPACE ENV variable is not found in CSV %s, insert it" , csv .Name )
1134
+ container .Env = append (container .Env , configmapEnv )
1135
+ }
1136
+ podTemplate .Spec .Containers [containerIndex ] = container
1125
1137
}
1126
- if ! found {
1127
- container .Env = append (container .Env , configmapEnv )
1128
- }
1129
- podTemplate .Spec .Containers [containerIndex ] = container
1130
1138
}
1131
- }
1132
-
1133
- if equality .Semantic .DeepDerivative (csvOriginal .Spec .InstallStrategy .StrategySpec .DeploymentSpecs , csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs ) {
1134
- klog .V (3 ).Infof ("No updates in the CSV, skip patching the CSV %s " , csv .Name )
1135
- continue
1136
- }
1139
+ if equality .Semantic .DeepEqual (csvOriginal .Spec .InstallStrategy .StrategySpec .DeploymentSpecs , csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs ) {
1140
+ klog .V (3 ).Infof ("No updates in the CSV, skip patching the CSV %s " , csv .Name )
1141
+ continue
1142
+ }
1137
1143
1138
- if err := r .Client .Patch (ctx , & csv , client .MergeFrom (csvOriginal )); err != nil {
1139
- klog .Error (err )
1140
- return ctrl.Result {}, err
1144
+ if err := r .Client .Patch (ctx , & csv , client .MergeFrom (csvOriginal )); err != nil {
1145
+ klog .Error (err )
1146
+ return ctrl.Result {}, err
1147
+ }
1148
+ klog .V (1 ).Infof ("WATCH_NAMESPACE and restart labels are inserted into CSV %s " , csv .Name )
1141
1149
}
1142
- klog .V (1 ).Infof ("WATCH_NAMESPACE and restart labels are inserted into CSV %s " , csv .Name )
1143
-
1144
1150
}
1145
1151
1146
1152
if util .CheckListDifference (instance .Status .ManagedCSVList , managedCSVList ) {
0 commit comments