Skip to content

Commit

Permalink
refactor(artifacts): Remove mutations of artifacts (#4638)
Browse files Browse the repository at this point in the history
In an upcoming kork release, artifacts will become immutable to
prevent confusing bugs where (primarily in orca) we are mutating
copies of what we think we are mutating. There are a small number
of places in clouddriver where artifacts are mutated, but these
can be replaced by returning a copy with the desired changed.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
ezimanyi and mergify[bot] committed Jun 1, 2020
1 parent 27e1bc4 commit 3669232
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ private ArtifactCredentials getArtifactCredentials(
String artifactAccount = artifact.getArtifactAccount();
if (CloudFoundryArtifactCredentials.TYPE.equals(artifact.getType())) {
CloudFoundryCredentials credentials = getCredentialsObject(artifactAccount);
artifact.setUuid(
getServerGroupId(artifact.getName(), artifact.getLocation(), credentials.getClient()));
String uuid =
getServerGroupId(artifact.getName(), artifact.getLocation(), credentials.getClient());
converted.setApplicationArtifact(artifact.toBuilder().uuid(uuid).build());
return new CloudFoundryArtifactCredentials(credentials.getClient());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,11 @@ private File downloadTaskDefinitionArtifact(Artifact taskDefArtifact) {
|| taskDefArtifact.getArtifactAccount().isEmpty()
&& description.getTaskDefinitionArtifactAccount() != null
&& !description.getTaskDefinitionArtifactAccount().isEmpty()) {
taskDefArtifact.setArtifactAccount(description.getTaskDefinitionArtifactAccount());
taskDefArtifact =
taskDefArtifact
.toBuilder()
.artifactAccount(description.getTaskDefinitionArtifactAccount())
.build();
}
try {
InputStream artifactInput = artifactDownloader.download(taskDefArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ private static Optional<Keys.CacheKey> convertAsArtifact(
try {
KubernetesManifest lastAppliedConfiguration =
KubernetesManifestAnnotater.getLastAppliedConfiguration(manifest);
if (artifact.getMetadata() == null) {
artifact.setMetadata(new HashMap<>());
}
artifact.getMetadata().put("lastAppliedConfiguration", lastAppliedConfiguration);
artifact.getMetadata().put("account", account);
} catch (Exception e) {
Expand Down

0 comments on commit 3669232

Please sign in to comment.