Skip to content

Commit 341f162

Browse files
committed
fix: do not modify deployment as it is live and reused elsewhere
Fixes #855 Signed-off-by: Chris Laprun <[email protected]>
1 parent 91a3e6b commit 341f162

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/DeserializedKubernetesResourcesBuildItem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public DeserializedKubernetesResourcesBuildItem(List<HasMetadata> resources) {
1212
this.resources = resources;
1313
}
1414

15+
/**
16+
* Note that these resources are "live" so any modification made to them will be propagated anywhere this method is called
17+
* and a reference on the result is kept so if you don't want local changes to be propagated, make a copy of the resources
18+
* you interact with, first.
19+
*/
1520
public List<HasMetadata> getResources() {
1621
return resources;
1722
}

core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/helm/HelmChartProcessor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.quarkus.kubernetes.deployment.ResourceNameUtil;
3737
import io.quarkus.qute.Qute;
3838

39+
// Note that steps of this processor won't be run in dev mode because ArtifactResultBuildItems are only considered in NORMAL mode
3940
@BuildSteps(onlyIf = HelmGenerationEnabled.class)
4041
public class HelmChartProcessor {
4142

@@ -154,7 +155,7 @@ private List<HasMetadata> filterOutStandardResources(List<HasMetadata> resources
154155
return !r.getMetadata().getName().equals(operatorName);
155156
}
156157
return true;
157-
}).collect(Collectors.toList());
158+
}).toList();
158159
}
159160

160161
@BuildStep
@@ -170,13 +171,16 @@ void addGeneratedDeployment(HelmTargetDirectoryBuildItem helmDirBI,
170171
ControllerConfigurationsBuildItem controllerConfigurations,
171172
ApplicationInfoBuildItem appInfo) {
172173
// add an env var for each reconciler's watch namespace in the operator's deployment
173-
final var deployment = (Deployment) deserializedKubernetesResources.getResources().stream()
174+
var deployment = (Deployment) deserializedKubernetesResources.getResources().stream()
174175
.filter(Deployment.class::isInstance).findFirst()
175176
.orElseThrow();
176-
final var envs = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
177+
// copy the deployment so that changes are not propagated outside of this method
178+
final var firstContainer = deployment.edit().editSpec().editTemplate().editSpec().editFirstContainer();
177179
controllerConfigurations.getControllerConfigs()
178-
.forEach((name, unused) -> envs.add(new EnvVar(ConfigurationUtils.getNamespacesPropertyName(name, true),
179-
"{watchNamespaces}", null)));
180+
.forEach((name, unused) -> firstContainer.addNewEnv()
181+
.withName(ConfigurationUtils.getNamespacesPropertyName(name, true))
182+
.withValue("{watchNamespaces}").endEnv());
183+
deployment = firstContainer.endContainer().endSpec().endTemplate().endSpec().build();
180184

181185
// a bit hacky solution to get the exact placeholder without brackets
182186
final var template = FileUtils.asYaml(deployment);
@@ -194,7 +198,7 @@ void addGeneratedDeployment(HelmTargetDirectoryBuildItem helmDirBI,
194198
private void addCRDs(HelmTargetDirectoryBuildItem helmDirBI, GeneratedCRDInfoBuildItem generatedCRDInfoBuildItem) {
195199
var crdInfos = generatedCRDInfoBuildItem.getCRDGenerationInfo().getCrds().values().stream()
196200
.flatMap(m -> m.values().stream())
197-
.collect(Collectors.toList());
201+
.toList();
198202

199203
final var crdDir = helmDirBI.getPathToHelmDir().resolve(CRD_DIR);
200204
crdInfos.forEach(crdInfo -> {

0 commit comments

Comments
 (0)