@@ -151,12 +151,17 @@ func (n *NutanixCSI) handleHelmAddonApply(
151
151
)
152
152
}
153
153
154
- helmChart , err := n .helmChartInfoGetter .For (ctx , log , config .NutanixStorageCSI )
154
+ storageChart , err := n .helmChartInfoGetter .For (ctx , log , config .NutanixStorageCSI )
155
155
if err != nil {
156
- return fmt .Errorf ("failed to get values for nutanix-csi-config %w" , err )
156
+ return fmt .Errorf ("failed to get helm chart %q: %w" , config . NutanixStorageCSI , err )
157
157
}
158
158
159
- hcp := & caaphv1.HelmChartProxy {
159
+ snapshotHelmChart , err := n .helmChartInfoGetter .For (ctx , log , config .NutanixSnapshotCSI )
160
+ if err != nil {
161
+ return fmt .Errorf ("failed to get helm chart %q: %w" , config .NutanixSnapshotCSI , err )
162
+ }
163
+
164
+ storageChartProxy := & caaphv1.HelmChartProxy {
160
165
TypeMeta : metav1.TypeMeta {
161
166
APIVersion : caaphv1 .GroupVersion .String (),
162
167
Kind : "HelmChartProxy" ,
@@ -166,35 +171,19 @@ func (n *NutanixCSI) handleHelmAddonApply(
166
171
Name : "nutanix-csi-" + req .Cluster .Name ,
167
172
},
168
173
Spec : caaphv1.HelmChartProxySpec {
169
- RepoURL : helmChart .Repository ,
170
- ChartName : helmChart .Name ,
174
+ RepoURL : storageChart .Repository ,
175
+ ChartName : storageChart .Name ,
171
176
ClusterSelector : metav1.LabelSelector {
172
177
MatchLabels : map [string ]string {clusterv1 .ClusterNameLabel : req .Cluster .Name },
173
178
},
174
179
ReleaseNamespace : defaultStorageHelmReleaseNamespace ,
175
180
ReleaseName : defaultStorageHelmReleaseName ,
176
- Version : helmChart .Version ,
181
+ Version : storageChart .Version ,
177
182
ValuesTemplate : values ,
178
183
},
179
184
}
180
185
181
- if err = controllerutil .SetOwnerReference (& req .Cluster , hcp , n .client .Scheme ()); err != nil {
182
- return fmt .Errorf (
183
- "failed to set owner reference on nutanix-csi installation HelmChartProxy: %w" ,
184
- err ,
185
- )
186
- }
187
-
188
- if err = client .ServerSideApply (ctx , n .client , hcp , client .ForceOwnership ); err != nil {
189
- return fmt .Errorf ("failed to apply nutanix-csi installation HelmChartProxy: %w" , err )
190
- }
191
-
192
- snapshotHelmChart , err := n .helmChartInfoGetter .For (ctx , log , config .NutanixSnapshotCSI )
193
- if err != nil {
194
- return fmt .Errorf ("failed to get values for nutanix-csi-config %w" , err )
195
- }
196
-
197
- snapshotChart := & caaphv1.HelmChartProxy {
186
+ snapshotChartProxy := & caaphv1.HelmChartProxy {
198
187
TypeMeta : metav1.TypeMeta {
199
188
APIVersion : caaphv1 .GroupVersion .String (),
200
189
Kind : "HelmChartProxy" ,
@@ -215,11 +204,16 @@ func (n *NutanixCSI) handleHelmAddonApply(
215
204
},
216
205
}
217
206
218
- if err = client .ServerSideApply (ctx , n .client , snapshotChart , client .ForceOwnership ); err != nil {
219
- return fmt .Errorf (
220
- "failed to apply nutanix-csi-snapshot installation HelmChartProxy: %w" ,
221
- err ,
222
- )
207
+ // We use a slice of pointers to satisfy the gocritic linter rangeValCopy check.
208
+ for _ , cp := range []* caaphv1.HelmChartProxy {storageChartProxy , snapshotChartProxy } {
209
+ if err = controllerutil .SetOwnerReference (& req .Cluster , cp , n .client .Scheme ()); err != nil {
210
+ return fmt .Errorf (
211
+ "failed to set owner reference on HelmChartProxy %q: %w" , cp .Name , err )
212
+ }
213
+
214
+ if err = client .ServerSideApply (ctx , n .client , cp , client .ForceOwnership ); err != nil {
215
+ return fmt .Errorf ("failed to apply HelmChartProxy %q: %w" , cp .Name , err )
216
+ }
223
217
}
224
218
225
219
return nil
0 commit comments