Skip to content

Commit

Permalink
fix(k8s): fix deserialization for patchBody (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy Louie authored and ezimanyi committed Jun 26, 2019
1 parent 4781dc4 commit d5cfc44
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.orca.clouddriver.tasks.manifest;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import lombok.Builder;
import lombok.Value;

@Value
@JsonDeserialize(builder = PatchManifestContext.PatchManifestContextBuilder.class)
@Builder(builderClassName = "PatchManifestContextBuilder", toBuilder = true)
public class PatchManifestContext implements ManifestContext {
private Map<Object, Object> patchBody;
private Source source;

private String manifestArtifactId;
private Artifact manifestArtifact;
private String manifestArtifactAccount;
private String manifestName;

private List<String> requiredArtifactIds;
private List<BindArtifact> requiredArtifacts;

@Builder.Default private boolean skipExpressionEvaluation = false;

@Nullable
@Override
public List<Map<Object, Object>> getManifests() {
return Collections.singletonList(patchBody);
}

@JsonPOJOBuilder(withPrefix = "")
public static class PatchManifestContextBuilder {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@

package com.netflix.spinnaker.orca.clouddriver.tasks.manifest;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.orca.Task;
import com.netflix.spinnaker.orca.TaskResult;
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

Expand All @@ -42,32 +35,6 @@ public class PatchManifestTask extends AbstractCloudProviderAwareTask implements

private final ManifestEvaluator manifestEvaluator;

@Value
@JsonDeserialize(builder = PatchManifestContext.PatchManifestContextBuilder.class)
@Builder(builderClassName = "PatchManifestContextBuilder", toBuilder = true)
private static class PatchManifestContext implements ManifestContext {
private List<Map<Object, Object>> patchBody;
private Source source;

private String manifestArtifactId;
private Artifact manifestArtifact;
private String manifestArtifactAccount;

private List<String> requiredArtifactIds;
private List<BindArtifact> requiredArtifacts;

@Builder.Default private boolean skipExpressionEvaluation = false;

@Nullable
@Override
public List<Map<Object, Object>> getManifests() {
return patchBody;
}

@JsonPOJOBuilder(withPrefix = "")
public static class PatchManifestContextBuilder {}
}

@Nonnull
@Override
public TaskResult execute(@Nonnull Stage stage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Collections;
import org.junit.jupiter.api.Test;

class ManifestContextTest {
Expand Down Expand Up @@ -52,4 +53,25 @@ void deserialize() throws IOException {
DeployManifestContext context = new ObjectMapper().readValue(json, DeployManifestContext.class);
assertThat(context.getSource()).isEqualTo(ManifestContext.Source.Text);
}

@Test
void deserializePatchManifestNoArtifacts() throws IOException {
String json =
"{\n"
+ " \"manifestArtifactAccount\": \"account\",\n"
+ " \"source\": \"text\",\n"
+ " \"patchBody\": {\n"
+ " \"spec\": {\n"
+ " \"replicas\": \"3\"\n"
+ " }\n"
+ " }\n"
+ "}";

PatchManifestContext context = new ObjectMapper().readValue(json, PatchManifestContext.class);
assertThat(context.getSource()).isEqualTo(ManifestContext.Source.Text);
assertThat(context.getManifestArtifactAccount()).isEqualTo("account");
assertThat(context.getPatchBody()).containsOnlyKeys("spec");
assertThat(context.getPatchBody().get("spec"))
.isEqualTo(Collections.singletonMap("replicas", "3"));
}
}

0 comments on commit d5cfc44

Please sign in to comment.