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