diff options
author | jonmv <venstad@gmail.com> | 2023-05-30 11:59:25 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-05-30 11:59:25 +0200 |
commit | 9d59de7b07d5476ed587df0c361406fb3ce4b368 (patch) | |
tree | a6451f05b1b15f2e719f27706f7f076c8d4e0030 /controller-server | |
parent | cdd9d7bb5fcdb154f6cc9fa129d3a65e22f7a63a (diff) |
Respect host TTL (and cloud account) for tester deployments
Diffstat (limited to 'controller-server')
2 files changed, 80 insertions, 30 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackage.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackage.java index afb854b2aaa..7d4cd6b8747 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackage.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackage.java @@ -5,7 +5,9 @@ import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.application.api.DeploymentSpec.Step; import com.yahoo.config.provision.AthenzDomain; import com.yahoo.config.provision.AthenzService; +import com.yahoo.config.provision.CloudAccount; import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.path.Path; @@ -128,10 +130,7 @@ public class TestPackage { testerApp))); entries.put(deploymentFile, - __ -> new ByteArrayInputStream(deploymentXml(id.tester(), - spec.athenzDomain(), - spec.requireInstance(id.application().instance()) - .athenzService(id.type().zone().environment(), id.type().zone().region())))); + __ -> new ByteArrayInputStream(deploymentXml(id.tester(), id.application().instance(), id.type().zone(), spec))); if (certificate != null) { entries.put("artifacts/key", __ -> new ByteArrayInputStream(KeyUtils.toPem(keyPair.getPrivate()).getBytes(UTF_8))); @@ -297,13 +296,26 @@ public class TestPackage { } /** Returns a dummy deployment xml which sets up the service identity for the tester, if present. */ - static byte[] deploymentXml(TesterId id, Optional<AthenzDomain> athenzDomain, Optional<AthenzService> athenzService) { + static byte[] deploymentXml(TesterId id, InstanceName instance, ZoneId zone, DeploymentSpec original) { + Optional<AthenzDomain> athenzDomain = original.athenzDomain(); + Optional<AthenzService> athenzService = original.requireInstance(instance) + .athenzService(zone.environment(), zone.region()); + Optional<CloudAccount> cloudAccount = original.requireInstance(instance) + .cloudAccount(zone.environment(), Optional.of(zone.region())); + Optional<Duration> hostTTL = zone.environment().isProduction() + ? original.requireInstance(instance) + .steps().stream().filter(step -> step.isTest() && step.concerns(zone.environment(), Optional.of(zone.region()))) + .findFirst().flatMap(Step::hostTTL) + : original.requireInstance(instance).hostTTL(zone.environment(), Optional.of(zone.region())); String deploymentSpec = "<?xml version='1.0' encoding='UTF-8'?>\n" + - "<deployment version=\"1.0\" " + - athenzDomain.map(domain -> "athenz-domain=\"" + domain.value() + "\" ").orElse("") + - athenzService.map(service -> "athenz-service=\"" + service.value() + "\" ").orElse("") + ">" + - " <instance id=\"" + id.id().instance().value() + "\" />" + + "<deployment version='1.0'" + + athenzDomain.map(domain -> " athenz-domain='" + domain.value() + "'").orElse("") + + athenzService.map(service -> " athenz-service='" + service.value() + "'").orElse("") + + cloudAccount.map(account -> " cloud-account='" + account.value() + "'").orElse("") + + hostTTL.map(ttl -> " empty-host-ttl='" + ttl.getSeconds() / 60 + "m'").orElse("") + + ">" + + " <instance id='" + id.id().instance().value() + "' />" + "</deployment>"; return deploymentSpec.getBytes(UTF_8); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackageTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackageTest.java index 6da8db1c259..2bfd081914b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackageTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/pkg/TestPackageTest.java @@ -2,10 +2,12 @@ package com.yahoo.vespa.hosted.controller.application.pkg; import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType; import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; +import com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterId; import com.yahoo.vespa.hosted.controller.application.pkg.TestPackage.TestSummary; import com.yahoo.vespa.hosted.controller.config.ControllerConfig; import com.yahoo.vespa.hosted.controller.config.ControllerConfig.Steprunner.Testerapp; @@ -19,6 +21,9 @@ import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.UnaryOperator; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; @@ -147,28 +152,61 @@ public class TestPackageTest { } @Test + void generates_correct_deployment_spec() { + DeploymentSpec spec = DeploymentSpec.fromXml(""" + <deployment version='1.0' athenz-domain='domain' athenz-service='service' cloud-account='123123123123' empty-host-ttl='1h'> + <test empty-host-ttl='1d' /> + <staging cloud-account='321321321321'/> + <prod> + <region>us-east-3</region> + <test>us-east-3</test> + <region>us-west-1</region> + <test empty-host-ttl='0m'>us-west-1</test> + <region empty-host-ttl='1d'>us-central-1</region> + <test>us-central-1</test> + </prod> + </deployment> + """); + verifyAttributes("123123123123", 1440, ZoneId.from("test", "us-east-1"), spec); + verifyAttributes("321321321321", 60, ZoneId.from("staging", "us-east-2"), spec); + verifyAttributes("123123123123", 60, ZoneId.from("prod", "us-east-3"), spec); + verifyAttributes("123123123123", 0, ZoneId.from("prod", "us-west-1"), spec); + verifyAttributes("123123123123", 60, ZoneId.from("prod", "us-central-1"), spec); + } + + private void verifyAttributes(String expectedAccount, int expectedTTL, ZoneId zone, DeploymentSpec spec) { + assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + + "<deployment version='1.0' athenz-domain='domain' athenz-service='service' " + + "cloud-account='" + expectedAccount + "' empty-host-ttl='" + expectedTTL + "m'> " + + "<instance id='default-t' /></deployment>", + new String(TestPackage.deploymentXml(TesterId.of(ApplicationId.defaultId()), InstanceName.defaultName(), zone, spec))); + } + + @Test void generates_correct_tester_flavor() { - DeploymentSpec spec = DeploymentSpec.fromXml("<deployment version='1.0' athenz-domain='domain' athenz-service='service'>\n" + - " <instance id='first'>\n" + - " <test tester-flavor=\"d-6-16-100\" />\n" + - " <prod>\n" + - " <region active=\"true\">us-west-1</region>\n" + - " <test>us-west-1</test>\n" + - " </prod>\n" + - " </instance>\n" + - " <instance id='second'>\n" + - " <test />\n" + - " <staging />\n" + - " <prod tester-flavor=\"d-6-16-100\">\n" + - " <parallel>\n" + - " <region active=\"true\">us-east-3</region>\n" + - " <region active=\"true\">us-central-1</region>\n" + - " </parallel>\n" + - " <region active=\"true\">us-west-1</region>\n" + - " <test>us-west-1</test>\n" + - " </prod>\n" + - " </instance>\n" + - "</deployment>\n"); + DeploymentSpec spec = DeploymentSpec.fromXml(""" + <deployment version='1.0' athenz-domain='domain' athenz-service='service'> + <instance id='first'> + <test tester-flavor="d-6-16-100" /> + <prod> + <region active="true">us-west-1</region> + <test>us-west-1</test> + </prod> + </instance> + <instance id='second'> + <test /> + <staging /> + <prod tester-flavor="d-6-16-100"> + <parallel> + <region active="true">us-east-3</region> + <region active="true">us-central-1</region> + </parallel> + <region active="true">us-west-1</region> + <test>us-west-1</test> + </prod> + </instance> + </deployment> + """); NodeResources firstResources = TestPackage.testerResourcesFor(ZoneId.from("prod", "us-west-1"), spec.requireInstance("first")); assertEquals(TestPackage.DEFAULT_TESTER_RESOURCES, firstResources); |