Skip to content

Commit

Permalink
feat(artifacts): Orca sends an an artifact to clouddriver (#2121)
Browse files Browse the repository at this point in the history
When a deploy description sets the image to deploy to an artifact,
Orca should send the entire artifact to clouddriver, rather than
just the name of the image.
  • Loading branch information
ezimanyi committed Apr 5, 2018
1 parent 1b48de9 commit 274420a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.orca.clouddriver.tasks.providers.gce

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
import com.netflix.spinnaker.orca.pipeline.model.Stage
Expand Down Expand Up @@ -49,34 +50,39 @@ class GoogleServerGroupCreator implements ServerGroupCreator, DeploymentDetailsA
operation.credentials = operation.account
}

operation.image = operation.image ?: getImage(stage)

if (!operation.image) {
throw new IllegalStateException("No image could be found in ${stage.context.region}.")
if (stage.context.imageSource == "artifact") {
operation.imageSource = "ARTIFACT"
operation.imageArtifact = getImageArtifact(stage)
} else {
operation.imageSource = "STRING"
operation.image = operation.image ?: getImage(stage)
if (!operation.image) {
throw new IllegalStateException("No image could be found in ${stage.context.region}.")
}
}

return [[(ServerGroupCreator.OPERATION): operation]]
}

private String getImage(Stage stage) {
private Artifact getImageArtifact(Stage stage) {
def stageContext = stage.getContext()

def artifactId = stageContext.imageArtifactId as String
if (artifactId == null) {
throw new IllegalArgumentException("Image source was set to artifact but no artifact was specified.")
}
return artifactResolver.getBoundArtifactForId(stage, artifactId)
}

private String getImage(Stage stage) {
String image

if (stageContext.imageSource == "artifact") {
def artifactId = stageContext.imageArtifactId
if (artifactId == null) {
throw new IllegalStateException("Image source was set to artifact but no artifact was specified.")
}
def resolvedArtifact = artifactResolver.getBoundArtifactForId(stage, artifactId)
image = resolvedArtifact.getName()
} else {
withImageFromPrecedingStage(stage, null, cloudProvider) {
image = image ?: it.imageId
}
withImageFromPrecedingStage(stage, null, cloudProvider) {
image = image ?: it.imageId
}

withImageFromDeploymentDetails(stage, null, cloudProvider) {
image = image ?: it.imageId
}
withImageFromDeploymentDetails(stage, null, cloudProvider) {
image = image ?: it.imageId
}

return image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GoogleServerGroupCreatorSpec extends Specification {
account : "abc",
credentials : "abc",
image : "specifiedImage",
imageSource : "STRING",
region : "north-pole",
zone : "north-pole-1",
],
Expand All @@ -70,6 +71,7 @@ class GoogleServerGroupCreatorSpec extends Specification {
account : "abc",
credentials : "abc",
image : "testImageId",
imageSource : "STRING",
region : "north-pole",
zone : "north-pole-1",
deploymentDetails: [[imageId: "testImageId", region: "north-pole"]],
Expand All @@ -93,6 +95,7 @@ class GoogleServerGroupCreatorSpec extends Specification {
account : "abc",
credentials : "abc",
image : "testImageId",
imageSource : "STRING",
region : "south-pole",
zone : "south-pole-1",
deploymentDetails: [[imageId: "testImageId", region: "north-pole"]],
Expand All @@ -107,22 +110,19 @@ class GoogleServerGroupCreatorSpec extends Specification {
stage = ExecutionBuilder.stage {
context.putAll(ctx)
}
artifactResolver.getBoundArtifactForId(*_) >> {
Artifact artifact = new Artifact();
artifact.setName("santaImage")
return artifact
}
Artifact buildArtifact = Artifact.ArtifactBuilder.newInstance().name("santaImage").build();
artifactResolver.getBoundArtifactForId(*_) >> buildArtifact
ops = new GoogleServerGroupCreator(artifactResolver: artifactResolver).getOperations(stage)

then:
ops == [
[
"createServerGroup": [
imageSource : "artifact",
imageSource : "ARTIFACT",
imageArtifact : buildArtifact,
imageArtifactId : "b3d33e5a-0423-4bdc-8e37-dea923b57c9a",
account : "abc",
credentials : "abc",
image : "santaImage",
region : "north-pole",
zone : "north-pole-1",
deploymentDetails: [[imageId: "testImageId", region: "north-pole"]],
Expand All @@ -144,8 +144,8 @@ class GoogleServerGroupCreatorSpec extends Specification {
ops = new GoogleServerGroupCreator(artifactResolver: artifactResolver).getOperations(stage)

then:
IllegalStateException ise = thrown()
ise.message == "Image source was set to artifact but no artifact was specified."
IllegalArgumentException illegalArgumentException = thrown()
illegalArgumentException.message == "Image source was set to artifact but no artifact was specified."

when: "throw error if no image found"
ctx = [:] << basectx
Expand All @@ -156,7 +156,7 @@ class GoogleServerGroupCreatorSpec extends Specification {
new GoogleServerGroupCreator(artifactResolver: artifactResolver).getOperations(stage)

then:
ise = thrown()
ise.message == "No image could be found in north-pole."
IllegalStateException illegalStagteException = thrown()
illegalStagteException.message == "No image could be found in north-pole."
}
}

0 comments on commit 274420a

Please sign in to comment.