diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-06-15 13:38:35 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-06-15 13:58:59 +0200 |
commit | 9aba0cad6c00627e6572eb7f6c19c9c67304db75 (patch) | |
tree | 2da2fa051c4b1c4c074fe84ba7ab86750c6c4a11 /controller-server | |
parent | f34efe30c2a17ba6fc9b4b80fabd1c612d958bee (diff) |
Maintain routing policies for system applications
Diffstat (limited to 'controller-server')
4 files changed, 107 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java index 6f3e868dc1a..ca695a2d234 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java @@ -43,6 +43,7 @@ public class ControllerMaintenance extends AbstractComponent { private final CloudEventReporter cloudEventReporter; private final RotationStatusUpdater rotationStatusUpdater; private final ResourceTagMaintainer resourceTagMaintainer; + private final SystemRoutingPolicyMaintainer systemRoutingPolicyMaintainer; @Inject @SuppressWarnings("unused") // instantiated by Dependency Injection @@ -71,6 +72,7 @@ public class ControllerMaintenance extends AbstractComponent { cloudEventReporter = new CloudEventReporter(controller, Duration.ofDays(1)); rotationStatusUpdater = new RotationStatusUpdater(controller, maintenanceInterval); resourceTagMaintainer = new ResourceTagMaintainer(controller, Duration.ofMinutes(30), controller.serviceRegistry().resourceTagger()); + systemRoutingPolicyMaintainer = new SystemRoutingPolicyMaintainer(controller, Duration.ofMinutes(10)); } public Upgrader upgrader() { return upgrader; } @@ -97,6 +99,7 @@ public class ControllerMaintenance extends AbstractComponent { cloudEventReporter.close(); rotationStatusUpdater.close(); resourceTagMaintainer.close(); + systemRoutingPolicyMaintainer.close(); } /** Create one OS upgrader per cloud found in the zone registry of controller */ diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemRoutingPolicyMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemRoutingPolicyMaintainer.java new file mode 100644 index 00000000000..6c271ed0470 --- /dev/null +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemRoutingPolicyMaintainer.java @@ -0,0 +1,40 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.maintenance; + +import com.yahoo.config.application.api.DeploymentSpec; +import com.yahoo.vespa.flags.BooleanFlag; +import com.yahoo.vespa.flags.FetchVector; +import com.yahoo.vespa.flags.Flags; +import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.application.SystemApplication; +import com.yahoo.vespa.hosted.controller.routing.RoutingPolicy; + +import java.time.Duration; + +/** + * This maintains {@link RoutingPolicy}'s for {@link SystemApplication}s. In contrast to regular applications, this + * refreshes policies at an interval, not on deployment. + * + * @author mpolden + */ +public class SystemRoutingPolicyMaintainer extends ControllerMaintainer { + + private final BooleanFlag featureFlag; + + public SystemRoutingPolicyMaintainer(Controller controller, Duration interval) { + super(controller, interval); + this.featureFlag = Flags.CONFIGSERVER_PROVISION_LB.bindTo(controller.flagSource()); + } + + @Override + protected void maintain() { + for (var zone : controller().zoneRegistry().zones().all().ids()) { + for (var application : SystemApplication.values()) { + if (!application.hasEndpoint()) continue; + if (!featureFlag.with(FetchVector.Dimension.ZONE_ID, zone.value()).value()) continue; + controller().routing().policies().refresh(application.id(), DeploymentSpec.empty, zone); + } + } + } + +} diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemRoutingPolicyMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemRoutingPolicyMaintainerTest.java new file mode 100644 index 00000000000..8d6316d447f --- /dev/null +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemRoutingPolicyMaintainerTest.java @@ -0,0 +1,61 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.maintenance; + +import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.flags.Flags; +import com.yahoo.vespa.flags.InMemoryFlagSource; +import com.yahoo.vespa.hosted.controller.ControllerTester; +import com.yahoo.vespa.hosted.controller.api.integration.configserver.LoadBalancer; +import com.yahoo.vespa.hosted.controller.api.integration.dns.Record; +import com.yahoo.vespa.hosted.controller.application.SystemApplication; +import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock; +import org.junit.Test; + +import java.time.Duration; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +/** + * @author mpolden + */ +public class SystemRoutingPolicyMaintainerTest { + + @Test + public void maintain() { + var tester = new ControllerTester(); + var updater = new SystemRoutingPolicyMaintainer(tester.controller(), Duration.ofDays(1)); + var dispatcher = new NameServiceDispatcher(tester.controller(), Duration.ofDays(1), Integer.MAX_VALUE); + + var zone = ZoneId.from("prod", "us-west-1"); + tester.zoneRegistry().exclusiveRoutingIn(ZoneApiMock.from(zone)); + tester.configServer().putLoadBalancers(zone, List.of(new LoadBalancer("lb1", + SystemApplication.configServer.id(), + ClusterSpec.Id.from("config"), + HostName.from("lb1.example.com"), + LoadBalancer.State.active, + Optional.of("dns-zone-1")))); + + // Nothing happens without feature flag + updater.run(); + dispatcher.run(); + assertEquals(Set.of(), tester.nameService().records()); + + // Record is created + ((InMemoryFlagSource) tester.controller().flagSource()).withBooleanFlag(Flags.CONFIGSERVER_PROVISION_LB.id(), true); + updater.run(); + dispatcher.run(); + Set<Record> records = tester.nameService().records(); + assertEquals(1, records.size()); + Record record = records.iterator().next(); + assertSame(Record.Type.CNAME, record.type()); + assertEquals("cfg.prod.us-west-1.test.vip", record.name().asString()); + assertEquals("lb1.example.com.", record.data().asString()); + } + +} diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/maintenance.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/maintenance.json index ecb5c319f44..acd542b001c 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/maintenance.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/controller/responses/maintenance.json @@ -52,6 +52,9 @@ "name": "RotationStatusUpdater" }, { + "name": "SystemRoutingPolicyMaintainer" + }, + { "name": "SystemUpgrader" }, { |