aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Tokle <mortent@yahooinc.com>2023-09-11 12:55:23 +0200
committerGitHub <noreply@github.com>2023-09-11 12:55:23 +0200
commit2b1c1a08162e83a1d0d89a0e6159c52712802845 (patch)
tree7fc2435c96c1eea7b438cca4b1c8eef180d5de74
parentc38fcd2e6f09273459ade724fd571e615ff3f6c9 (diff)
parent00962984aee8495b3195fe915c6643aa490a5331 (diff)
Merge pull request #28473 from vespa-engine/mpolden/generate-endpoints-once
Ensure prepare only generates endpoints once MERGEOK
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java16
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyList.java6
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/routing/RoutingPoliciesTest.java9
3 files changed, 28 insertions, 3 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java
index 8bba92f36e3..1272bf4d00d 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java
@@ -35,6 +35,8 @@ import com.yahoo.vespa.hosted.controller.routing.GeneratedEndpoints;
import com.yahoo.vespa.hosted.controller.routing.PreparedEndpoints;
import com.yahoo.vespa.hosted.controller.routing.RoutingId;
import com.yahoo.vespa.hosted.controller.routing.RoutingPolicies;
+import com.yahoo.vespa.hosted.controller.routing.RoutingPolicy;
+import com.yahoo.vespa.hosted.controller.routing.RoutingPolicyList;
import com.yahoo.vespa.hosted.controller.routing.context.DeploymentRoutingContext;
import com.yahoo.vespa.hosted.controller.routing.context.DeploymentRoutingContext.ExclusiveDeploymentRoutingContext;
import com.yahoo.vespa.hosted.controller.routing.context.DeploymentRoutingContext.SharedDeploymentRoutingContext;
@@ -133,12 +135,20 @@ public class RoutingController {
if (randomizedEndpointsEnabled(deployment.applicationId())) { // TODO(mpolden): Remove this guard once config-models < 8.220 are gone
boolean includeTokenEndpoint = tokenEndpointEnabled(deployment.applicationId());
Map<ClusterSpec.Id, List<GeneratedEndpoint>> generatedEndpointsByCluster = new HashMap<>();
+ RoutingPolicyList deploymentPolicies = policies().read(deployment);
for (var container : services.containers()) {
ClusterSpec.Id clusterId = ClusterSpec.Id.from(container.id());
boolean tokenSupported = includeTokenEndpoint && container.authMethods().contains(BasicServicesXml.Container.AuthMethod.token);
- List<GeneratedEndpoint> generatedForCluster = certificate.flatMap(EndpointCertificate::randomizedId)
- .map(id -> generateEndpoints(id, deployment.applicationId(), tokenSupported))
- .orElseGet(List::of);
+ // Use already existing generated endpoints, if any
+ List<GeneratedEndpoint> generatedForCluster = deploymentPolicies.cluster(clusterId)
+ .first()
+ .map(RoutingPolicy::generatedEndpoints)
+ .orElseGet(List::of);
+ if (generatedForCluster.isEmpty()) {
+ generatedForCluster = certificate.flatMap(EndpointCertificate::randomizedId)
+ .map(id -> generateEndpoints(id, deployment.applicationId(), tokenSupported))
+ .orElseGet(List::of);
+ }
if (!generatedForCluster.isEmpty()) {
generatedEndpointsByCluster.put(clusterId, generatedForCluster);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyList.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyList.java
index a5efc016c68..366c28a6be0 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyList.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyList.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.controller.routing;
import com.yahoo.collections.AbstractFilteringList;
import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.application.EndpointId;
@@ -46,6 +47,11 @@ public class RoutingPolicyList extends AbstractFilteringList<RoutingPolicy, Rout
return matching(policy -> policy.id().owner().equals(instance));
}
+ /** Returns the subset of policies applying to given cluster */
+ public RoutingPolicyList cluster(ClusterSpec.Id cluster) {
+ return matching(policy -> policy.id().cluster().equals(cluster));
+ }
+
/** Returns the subset of policies applying to given deployment */
public RoutingPolicyList deployment(DeploymentId deployment) {
return matching(policy -> policy.appliesTo(deployment));
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/routing/RoutingPoliciesTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/routing/RoutingPoliciesTest.java
index d029987707f..b9da87771c0 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/routing/RoutingPoliciesTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/routing/RoutingPoliciesTest.java
@@ -22,6 +22,7 @@ import com.yahoo.vespa.hosted.controller.ControllerTester;
import com.yahoo.vespa.hosted.controller.Instance;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.api.integration.certificates.EndpointCertificate;
+import com.yahoo.vespa.hosted.controller.api.integration.configserver.ContainerEndpoint;
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.api.integration.dns.Record.Type;
@@ -1091,6 +1092,7 @@ public class RoutingPoliciesTest {
assertEquals(2, generated.cluster(cluster1).size());
assertEquals(1, generated.cluster(cluster1).authMethod(AuthMethod.token).size());
}
+ Map<DeploymentId, Set<ContainerEndpoint>> containerEndpointsInProd = tester.containerEndpoints(Environment.prod);
// Ordinary endpoints point to expected targets
tester.assertTargets(context.instanceId(), EndpointId.of("foo"), cluster0, 0,
@@ -1109,6 +1111,7 @@ public class RoutingPoliciesTest {
// Next deployment does not change generated names
context.submit(applicationPackage).deferLoadBalancerProvisioningIn(Environment.prod).deploy();
assertEquals(expectedRecords, tester.recordNames());
+ assertEquals(containerEndpointsInProd, tester.containerEndpoints(Environment.prod));
}
private void addCertificateToPool(String id, UnassignedCertificate.State state, RoutingPoliciesTester tester) {
@@ -1200,6 +1203,12 @@ public class RoutingPoliciesTest {
}
}
+ public Map<DeploymentId, Set<ContainerEndpoint>> containerEndpoints(Environment environment) {
+ return tester.controllerTester().configServer().containerEndpoints().entrySet().stream()
+ .filter(kv -> kv.getKey().zoneId().environment() == environment)
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ }
+
public RoutingPolicies routingPolicies() {
return tester.controllerTester().controller().routing().policies();
}