Adapt to Java with string literals
MODIFY
gcp-java-gke-hello-world/pom.xml
gcp-java-gke-hello-world/pom.xml
<properties>
<encoding>UTF-8</encoding>
- <maven.compiler.source>11</maven.compiler.source>
- <maven.compiler.target>11</maven.compiler.target>
- <maven.compiler.release>11</maven.compiler.release>
+ <maven.compiler.source>15</maven.compiler.source>
+ <maven.compiler.target>15</maven.compiler.target>
+ <maven.compiler.release>15</maven.compiler.release>
<mainClass>gcpgke.App</mainClass>
<mainArgs/>
</properties>

MODIFY
gcp-java-gke-hello-world/src/main/java/gcpgke/App.java
gcp-java-gke-hello-world/src/main/java/gcpgke/App.java
@@ -99,9 +99,7 @@ public class App {
var masterAuthClusterCaCertificate = cluster.masterAuth()
.applyValue(a -> a.clusterCaCertificate().orElseThrow());
- var kubeconfig = cluster.endpoint()
- .apply(endpoint -> masterAuthClusterCaCertificate.applyValue(
- caCert -> MessageFormat.format("""
+ var yamlTemplate = """
apiVersion: v1,
clusters:,
- cluster:,
@@ -125,8 +123,12 @@ users:,
installHint: Install gke-gcloud-auth-plugin for use with kubectl by following
https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
provideClusterInfo: true
-"""), clusterName, endpoint, caCert)
- ));
+ """;
+
+ var kubeconfig = cluster.endpoint()
+ .apply(endpoint -> masterAuthClusterCaCertificate.applyValue(
+ caCert -> MessageFormat.format(yamlTemplate, clusterName, endpoint, caCert)));
+
ctx.export("kubeconfig", kubeconfig);
// Create a Kubernetes provider instance that uses our cluster from above.

Adapt to Java with string literals (#1285)