diff options
author | jonmv <venstad@gmail.com> | 2022-09-26 11:16:36 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-09-26 11:16:36 +0200 |
commit | 02f2add4405c0f92f1342097800121b013a19a42 (patch) | |
tree | 99ecb41223c26bd0cb162171bf69f7892fb8aa70 /controller-server | |
parent | ed48985f772b02dbb19ab9f1324ee65f37659b05 (diff) |
Ensure operators may force downgrade to unknown version
Diffstat (limited to 'controller-server')
4 files changed, 60 insertions, 28 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java index 6b8ecc95cd9..8b7df7932ff 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java @@ -45,6 +45,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -349,26 +350,28 @@ public class DeploymentStatus { /** Fall back to the newest, deployable platform, which is compatible with what we want to deploy. */ - public Version fallbackPlatform(Change change, JobId job) { - InstanceName instance = job.application().instance(); - Optional<Version> compileVersion = change.revision().map(application.revisions()::get).flatMap(ApplicationVersion::compileVersion); - List<Version> targets = targetsForPolicy(versionStatus, - systemVersion, - application.deploymentSpec().instance(instance) - .map(DeploymentInstanceSpec::upgradePolicy) - .orElse(UpgradePolicy.defaultPolicy)); - - // Prefer fallback with proper confidence. - for (Version target : targets) - if (compileVersion.isEmpty() || versionCompatibility.apply(instance).accept(target, compileVersion.get())) - return target; - - // Try fallback with any confidence. - for (VespaVersion target : reversed(versionStatus.deployableVersions())) - if (compileVersion.isEmpty() || versionCompatibility.apply(instance).accept(target.versionNumber(), compileVersion.get())) - return target.versionNumber(); - - throw new IllegalArgumentException("no legal platform version exists in this system for compile version " + compileVersion.get()); + public Supplier<Version> fallbackPlatform(Change change, JobId job) { + return () -> { + InstanceName instance = job.application().instance(); + Optional<Version> compileVersion = change.revision().map(application.revisions()::get).flatMap(ApplicationVersion::compileVersion); + List<Version> targets = targetsForPolicy(versionStatus, + systemVersion, + application.deploymentSpec().instance(instance) + .map(DeploymentInstanceSpec::upgradePolicy) + .orElse(UpgradePolicy.defaultPolicy)); + + // Prefer fallback with proper confidence. + for (Version target : targets) + if (compileVersion.isEmpty() || versionCompatibility.apply(instance).accept(target, compileVersion.get())) + return target; + + // Try fallback with any confidence. + for (VespaVersion target : reversed(versionStatus.deployableVersions())) + if (compileVersion.isEmpty() || versionCompatibility.apply(instance).accept(target.versionNumber(), compileVersion.get())) + return target.versionNumber(); + + return compileVersion.orElseThrow(() -> new IllegalArgumentException("no legal platform version exists in this system for compile version " + compileVersion.get())); + }; } @@ -639,7 +642,7 @@ public class DeploymentStatus { boolean platformReadyFirst = platformReadyAt.get().isBefore(revisionReadyAt.get()); boolean revisionReadyFirst = revisionReadyAt.get().isBefore(platformReadyAt.get()); boolean failingUpgradeOnlyTests = ! jobs().type(systemTest(job.type()), stagingTest(job.type())) - .failingHardOn(Versions.from(change.withoutApplication(), application, deploymentFor(job), systemVersion)) + .failingHardOn(Versions.from(change.withoutApplication(), application, deploymentFor(job), () -> systemVersion)) .isEmpty(); switch (rollout) { case separate: // Let whichever change rolled out first, keep rolling first, unless upgrade alone is failing. diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java index a172671fc8e..e7371561636 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/Versions.java @@ -11,6 +11,7 @@ import com.yahoo.vespa.hosted.controller.application.Deployment; import java.util.Objects; import java.util.Optional; +import java.util.function.Supplier; import static java.util.Objects.requireNonNull; @@ -111,7 +112,7 @@ public class Versions { /** Create versions using given change and application */ public static Versions from(Change change, Application application, Optional<Version> existingPlatform, - Optional<RevisionId> existingRevision, Version defaultPlatformVersion) { + Optional<RevisionId> existingRevision, Supplier<Version> defaultPlatformVersion) { return new Versions(targetPlatform(application, change, existingPlatform, defaultPlatformVersion), targetRevision(application, change, existingRevision), existingPlatform, @@ -119,17 +120,17 @@ public class Versions { } /** Create versions using given change and application */ - public static Versions from(Change change, Application application, Optional<Deployment> deployment, Version defaultPlatformVersion) { + public static Versions from(Change change, Application application, Optional<Deployment> deployment, Supplier<Version> defaultPlatformVersion) { return from(change, application, deployment.map(Deployment::version), deployment.map(Deployment::revision), defaultPlatformVersion); } private static Version targetPlatform(Application application, Change change, Optional<Version> existing, - Version defaultVersion) { + Supplier<Version> defaultVersion) { if (change.isPinned() && change.platform().isPresent()) return change.platform().get(); return max(change.platform(), existing) - .orElseGet(() -> application.oldestDeployedPlatform().orElse(defaultVersion)); + .orElseGet(() -> application.oldestDeployedPlatform().orElseGet(defaultVersion)); } private static RevisionId targetRevision(Application application, Change change, diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/ApplicationPackageBuilder.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/ApplicationPackageBuilder.java index 8ddd0ef2be3..7909651716a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/ApplicationPackageBuilder.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/ApplicationPackageBuilder.java @@ -351,9 +351,10 @@ public class ApplicationPackageBuilder { } private static byte[] buildMeta(Version compileVersion) { - return ("{\"compileVersion\":\"" + compileVersion.toFullString() + - "\",\"buildTime\":1000,\"parentVersion\":\"" + - compileVersion.toFullString() + "\"}").getBytes(UTF_8); + return compileVersion == null ? new byte[0] + : ("{\"compileVersion\":\"" + compileVersion.toFullString() + + "\",\"buildTime\":1000,\"parentVersion\":\"" + + compileVersion.toFullString() + "\"}").getBytes(UTF_8); } public ApplicationPackage build() { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java index f7d74373ac7..d8cef45f124 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java @@ -2352,6 +2352,33 @@ public class DeploymentTriggerTest { } @Test + void operatorMayForceUnknownVersion() { + Version oldVersion = Version.fromString("6"); + Version currentVersion = Version.fromString("7"); + tester.controllerTester().flagSource().withListFlag(PermanentFlags.INCOMPATIBLE_VERSIONS.id(), List.of("7"), String.class); + tester.controllerTester().upgradeSystem(currentVersion); + assertEquals(List.of(currentVersion), + tester.controller().readVersionStatus().versions().stream().map(VespaVersion::versionNumber).toList()); + + DeploymentContext app = tester.newDeploymentContext(); + assertEquals("compile version 6 is incompatible with the current major version of this system", + assertThrows(IllegalArgumentException.class, + () -> app.submit(new ApplicationPackageBuilder().region("us-east-3") + .majorVersion(6) + .compileVersion(oldVersion) + .build())) + .getMessage()); + + tester.deploymentTrigger().forceChange(app.instanceId(), Change.of(oldVersion).with(app.application().revisions().last().get().id()).withPin()); + app.deploy(); + assertEquals(oldVersion, app.deployment(ZoneId.from("prod", "us-east-3")).version()); + + tester.controllerTester().computeVersionStatus(); + assertEquals(List.of(oldVersion, currentVersion), + tester.controller().readVersionStatus().versions().stream().map(VespaVersion::versionNumber).toList()); + } + + @Test void testInitialDeploymentPlatform() { Version version0 = tester.controllerTester().controller().readSystemVersion(); Version version1 = new Version("6.2"); |