Skip to content

Commit da8df1f

Browse files
authored
Make GKE the default in alpha and qa (#2624)
1 parent f649d96 commit da8df1f

File tree

7 files changed

+66
-14
lines changed

7 files changed

+66
-14
lines changed

core/src/main/java/google/registry/request/auth/AuthModule.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package google.registry.request.auth;
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
18+
import static com.google.common.base.Suppliers.memoizeWithExpiration;
1819
import static com.google.common.net.HttpHeaders.AUTHORIZATION;
1920
import static google.registry.util.RegistryEnvironment.UNITTEST;
2021

@@ -37,8 +38,11 @@
3738
import google.registry.util.GoogleCredentialsBundle;
3839
import google.registry.util.RegistryEnvironment;
3940
import java.io.IOException;
41+
import java.time.Duration;
42+
import java.util.function.Supplier;
4043
import javax.annotation.Nullable;
4144
import javax.inject.Named;
45+
import javax.inject.Provider;
4246
import javax.inject.Qualifier;
4347
import javax.inject.Singleton;
4448

@@ -87,13 +91,13 @@ ImmutableList<AuthenticationMechanism> provideApiAuthenticationMechanisms(
8791
TokenVerifier provideIapTokenVerifier(
8892
@Config("projectId") String projectId,
8993
@Config("projectIdNumber") long projectIdNumber,
90-
@Named("backendServiceIdMap") ImmutableMap<String, Long> backendServiceIdMap) {
94+
@Named("backendServiceIdMap") Supplier<ImmutableMap<String, Long>> backendServiceIdMap) {
9195
com.google.auth.oauth2.TokenVerifier.Builder tokenVerifierBuilder =
9296
com.google.auth.oauth2.TokenVerifier.newBuilder().setIssuer(IAP_ISSUER_URL);
9397
return (String service, String token) -> {
9498
String audience;
9599
if (RegistryEnvironment.isOnJetty()) {
96-
Long backendServiceId = backendServiceIdMap.get(service);
100+
Long backendServiceId = backendServiceIdMap.get().get(service);
97101
checkNotNull(
98102
backendServiceId,
99103
"Backend service ID not found for service: %s, available IDs are %s",
@@ -156,7 +160,6 @@ static BackendServicesClient provideBackendServicesClients(
156160
}
157161

158162
@Provides
159-
@Singleton
160163
@Named("backendServiceIdMap")
161164
static ImmutableMap<String, Long> provideBackendServiceList(
162165
Lazy<BackendServicesClient> client, @Config("projectId") String projectId) {
@@ -174,4 +177,15 @@ static ImmutableMap<String, Long> provideBackendServiceList(
174177
}
175178
return builder.build();
176179
}
180+
181+
// Use an expiring cache so that the backend service ID map can be refreshed without restarting
182+
// the server. The map is very unlikely to change, except for when services are just deployed
183+
// for the first time, because some pods might receive traffic before all services are deployed.
184+
@Provides
185+
@Singleton
186+
@Named("backendServiceIdMap")
187+
static Supplier<ImmutableMap<String, Long>> provideBackendServiceIdMapSupplier(
188+
@Named("backendServiceIdMap") Provider<ImmutableMap<String, Long>> backendServiceIdMap) {
189+
return memoizeWithExpiration(backendServiceIdMap::get, Duration.ofMinutes(15));
190+
}
177191
}

core/src/main/java/google/registry/tools/RegistryCli.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.beust.jcommander.ParametersDelegate;
2626
import com.google.common.base.Throwables;
2727
import com.google.common.collect.ImmutableMap;
28+
import com.google.common.collect.ImmutableSet;
2829
import com.google.common.collect.Iterables;
2930
import google.registry.persistence.transaction.JpaTransactionManager;
3031
import google.registry.persistence.transaction.TransactionManagerFactory;
@@ -41,6 +42,9 @@
4142
@Parameters(separators = " =", commandDescription = "Command-line interface to the registry")
4243
final class RegistryCli implements CommandRunner {
4344

45+
private static final ImmutableSet<RegistryToolEnvironment> DEFAULT_GKE_ENVIRONMENTS =
46+
ImmutableSet.of(RegistryToolEnvironment.ALPHA, RegistryToolEnvironment.QA);
47+
4448
// The environment parameter is parsed twice: once here, and once with {@link
4549
// RegistryToolEnvironment#parseFromArgs} in the {@link RegistryTool#main} function.
4650
//
@@ -73,6 +77,9 @@ final class RegistryCli implements CommandRunner {
7377
@Parameter(names = "--gke", description = "Whether to use GKE runtime, instead of GAE")
7478
private boolean useGke = false;
7579

80+
@Parameter(names = "--gae", description = "Whether to use GAE runtime, instead of GKE")
81+
private boolean useGae = false;
82+
7683
@Parameter(names = "--canary", description = "Whether to connect to the canary instances")
7784
private boolean useCanary = false;
7885

@@ -149,6 +156,13 @@ public void run(String[] args) throws Exception {
149156
}
150157
throw e;
151158
}
159+
160+
checkState(!useGke || !useGae, "Cannot specify both --gke and --gae");
161+
// Special logic to set the default based on the environment if neither --gae nor --gke is set.
162+
if (!useGke && !useGae) {
163+
useGke = DEFAULT_GKE_ENVIRONMENTS.contains(environment);
164+
}
165+
152166
String parsedCommand = jcommander.getParsedCommand();
153167
// Show the list of all commands either if requested or if no subcommand name was specified
154168
// (which does not throw a ParameterException parse error above).

jetty/build.gradle

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,36 @@ tasks.register('run', JavaExec) {
8282
dependsOn(tasks.named('stage'))
8383
}
8484

85+
tasks.register('buildDeployer', Exec) {
86+
workingDir("${rootDir}/release/builder/")
87+
commandLine 'go', 'build', '-o', "${buildDir}/deployer", 'deployCloudSchedulerAndQueue.go'
88+
}
89+
90+
// Once GKE is the only option, we can use the same task in the root project instaead.
91+
tasks.register('deployCloudSchedulerAndQueue') {
92+
dependsOn(tasks.named('deployCloudScheduler'), tasks.named('deployQueue'))
93+
}
94+
95+
tasks.register('deployCloudScheduler', Exec) {
96+
dependsOn(tasks.named('buildDeployer'))
97+
workingDir("$buildDir")
98+
commandLine './deployer',
99+
"${rootDir}/core/src/main/java/google/registry/config/files/nomulus-config-${rootProject.environment}.yaml",
100+
"${rootDir}/core/src/main/java/google/registry/env/${rootProject.environment}/default/WEB-INF/cloud-scheduler-tasks.xml",
101+
rootProject.gcpProject, '--gke'
102+
}
103+
104+
tasks.register('deployQueue', Exec) {
105+
dependsOn(tasks.named('buildDeployer'))
106+
workingDir("$buildDir")
107+
commandLine './deployer',
108+
"${rootDir}/core/src/main/java/google/registry/config/files/nomulus-config-${rootProject.environment}.yaml",
109+
"${rootDir}/core/src/main/java/google/registry/env/common/default/WEB-INF/cloud-tasks-queue.xml",
110+
rootProject.gcpProject, '--gke'
111+
}
112+
85113
tasks.register('deployNomulus', Exec) {
86-
dependsOn('pushNomulusImage', ':proxy:pushProxyImage')
114+
dependsOn('pushNomulusImage', 'deployCloudSchedulerAndQueue')
87115
configure verifyDeploymentConfig
88116
commandLine './deploy-nomulus-for-env.sh', "${rootProject.environment}", "${rootProject.baseDomain}"
89117
}

proxy/deploy-proxy-for-env.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ do
3232
gcloud container clusters get-credentials "${parts[0]}" \
3333
--project "${project}" --zone "${parts[1]}"
3434
sed s/GCP_PROJECT/${project}/g "./kubernetes/proxy-deployment-${environment}.yaml" | \
35-
kubectl replace -f -
36-
kubectl replace -f "./kubernetes/proxy-service.yaml" --force
35+
kubectl apply -f -
36+
kubectl apply -f "./kubernetes/proxy-service.yaml" --force
3737
# Alpha does not have canary
3838
if [[ ${environment} != "alpha" ]]; then
3939
sed s/GCP_PROJECT/${project}/g "./kubernetes/proxy-deployment-${environment}-canary.yaml" | \
40-
kubectl replace -f -
41-
kubectl replace -f "./kubernetes/proxy-service-canary.yaml" --force
40+
kubectl apply -f -
41+
kubectl apply -f "./kubernetes/proxy-service-canary.yaml" --force
4242
fi
4343
# Kills all running pods, new pods created will be pulling the new image.
4444
kubectl delete pods --all

proxy/src/main/java/google/registry/proxy/ProxyConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ enum Environment {
4141

4242
public String projectId;
4343
public String oauthClientId;
44-
public boolean canary;
4544
public List<String> gcpScopes;
4645
public int serverCertificateCacheSeconds;
4746
public Gcs gcs;

proxy/src/main/java/google/registry/proxy/ProxyModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ static Supplier<String> provideOidcToken(
281281
@Singleton
282282
@Provides
283283
@Named("canary")
284-
static boolean provideIsCanary(ProxyConfig config) {
285-
return config.canary;
284+
boolean provideIsCanary(Environment env) {
285+
return env.name().endsWith("_CANARY");
286286
}
287287

288288
@Singleton

proxy/src/main/java/google/registry/proxy/config/default-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
# GCP project ID
99
projectId: your-gcp-project-id
1010

11-
# Whether to connect to the canary (instead of regular) service.
12-
canary: false
13-
1411
# OAuth client ID set as the audience of the OIDC token. This value must be the
1512
# same as the auth.oauthClientId value in Nomulus config file, which usually is
1613
# the IAP client ID, to allow the request to access IAP protected endpoints.

0 commit comments

Comments
 (0)