Skip to content

Commit

Permalink
fix(baking): don't rebake when we find a region-only diff (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Apr 13, 2020
1 parent 1447959 commit ad42f72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.netflix.spinnaker.keel.bakery.artifact
import com.netflix.frigga.ami.AppVersion
import com.netflix.spinnaker.igor.ArtifactService
import com.netflix.spinnaker.keel.actuation.ArtifactHandler
import com.netflix.spinnaker.keel.api.ResourceDiff
import com.netflix.spinnaker.keel.api.actuation.Task
import com.netflix.spinnaker.keel.api.actuation.TaskLauncher
import com.netflix.spinnaker.keel.api.artifacts.DebianArtifact
Expand Down Expand Up @@ -46,7 +47,9 @@ class ImageHandler(
val current = artifact.findLatestAmi()
val diff = DefaultResourceDiff(desired, current)

if (diff.hasChanges()) {
if (current != null && diff.isRegionsOnly()) {
publisher.publishEvent(ImageRegionMismatchDetected(current, artifact.vmOptions.regions))
} else if (diff.hasChanges()) {
if (current == null) {
log.info("No AMI found for {}", artifact.name)
} else {
Expand All @@ -63,10 +66,6 @@ class ImageHandler(
} else {
log.debug("Existing image for {} is up-to-date", artifact.name)
}

if (current != null && diff.affectedRootPropertyNames == setOf("regions")) {
publisher.publishEvent(ImageRegionMismatchDetected(current, artifact.vmOptions.regions))
}
}
}
}
Expand Down Expand Up @@ -176,6 +175,12 @@ class ImageHandler(
}
} ?: defaultCredentials

/**
* @return `true` if the only changes in the diff are to the regions of an image.
*/
private fun ResourceDiff<Image>.isRegionsOnly(): Boolean =
current != null && affectedRootPropertyNames.all { it == "regions" }

private val log by lazy { LoggerFactory.getLogger(javaClass) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,10 @@ internal class ImageHandlerTests : JUnit5Minutests {
runHandler(artifact)
}

test("a bake is launched") {
expectThat(bakeTask)
.isCaptured()
.captured
.hasSize(1)
.first()
.and {
get("type").isEqualTo("bake")
get("regions").isEqualTo(artifact.vmOptions.regions)
}
test("no bake is launched") {
verify(exactly = 0) {
taskLauncher.submitJob(any(), any(), any(), any(), any(), any(), any(), any<List<Map<String, Any?>>>())
}
}

test("an event is triggered because we want to track region mismatches") {
Expand Down

0 comments on commit ad42f72

Please sign in to comment.