From 9e6f4702d16c7791654f37caddbff23eef75b1c5 Mon Sep 17 00:00:00 2001 From: Jammy Louie Date: Wed, 3 Jul 2019 15:10:22 -0400 Subject: [PATCH] feat(gce): Support new artifact model for deploy SG (#3018) --- .../tasks/providers/gce/GoogleServerGroupCreator.groovy | 9 +++++++-- .../providers/gce/GoogleServerGroupCreatorSpec.groovy | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreator.groovy b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreator.groovy index 12b6aba507..a5a037225e 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreator.groovy +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreator.groovy @@ -16,6 +16,7 @@ package com.netflix.spinnaker.orca.clouddriver.tasks.providers.gce +import com.fasterxml.jackson.databind.ObjectMapper import com.netflix.spinnaker.kork.artifacts.model.Artifact import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.ServerGroupCreator import com.netflix.spinnaker.orca.kato.tasks.DeploymentDetailsAware @@ -35,6 +36,9 @@ class GoogleServerGroupCreator implements ServerGroupCreator, DeploymentDetailsA @Autowired ArtifactResolver artifactResolver + @Autowired + ObjectMapper objectMapper + @Override List getOperations(Stage stage) { def operation = [:] @@ -68,10 +72,11 @@ class GoogleServerGroupCreator implements ServerGroupCreator, DeploymentDetailsA def stageContext = stage.getContext() def artifactId = stageContext.imageArtifactId as String - if (artifactId == null) { + Artifact imageArtifact = stageContext.imageArtifact ? objectMapper.convertValue(stageContext.imageArtifact, Artifact.class) : null + if (artifactId == null && imageArtifact == null) { throw new IllegalArgumentException("Image source was set to artifact but no artifact was specified.") } - return artifactResolver.getBoundArtifactForId(stage, artifactId) + return artifactResolver.getBoundArtifactForStage(stage, artifactId, imageArtifact) } private String getImage(Stage stage) { diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy index 483882a5c7..99d11fbd0b 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy @@ -111,7 +111,7 @@ class GoogleServerGroupCreatorSpec extends Specification { context.putAll(ctx) } Artifact buildArtifact = Artifact.ArtifactBuilder.newInstance().name("santaImage").build(); - artifactResolver.getBoundArtifactForId(*_) >> buildArtifact + artifactResolver.getBoundArtifactForStage(*_) >> buildArtifact ops = new GoogleServerGroupCreator(artifactResolver: artifactResolver).getOperations(stage) then: