in computer-test/src/main/java/org/apache/hugegraph/computer/k8s/MiniKubeTest.java [360:420]
public void testMountConfigMapAndSecret() {
String dataBase64 = Base64.getEncoder()
.encodeToString("test123\ntest".getBytes());
String configMapName = "config-map-test";
ConfigMap configMap = new ConfigMapBuilder()
.withNewMetadata()
.withNamespace(this.namespace)
.withName(configMapName)
.endMetadata()
.addToData("1.txt", "test123\ntest")
.build();
this.kubeClient.configMaps().createOrReplace(configMap);
String secretName = "secret-test";
Secret secret = new SecretBuilder().withNewMetadata()
.withNamespace(this.namespace)
.withName(secretName)
.endMetadata()
.withType("Opaque")
.addToData("2.txt", dataBase64)
.addToData("3.txt", dataBase64)
.build();
this.kubeClient.secrets().createOrReplace(secret);
ArrayList<String> args = Lists.newArrayList(
"cat /opt/configmap123/1.txt && " +
"cat /opt/secret123/2.txt &&" +
"cat /opt/secret123/3.txt");
super.updateOptions(KubeSpecOptions.MASTER_ARGS.name(), args);
super.updateOptions(KubeSpecOptions.WORKER_ARGS.name(), args);
Object defaultSpec = Whitebox.invoke(KubernetesDriver.class,
"defaultSpec", this.driver);
Whitebox.setInternalState(this.driver, "defaultSpec", defaultSpec);
Map<String, String> params = new HashMap<>();
params.put(KubeSpecOptions.CONFIG_MAP_PATHS.name(),
String.format("[%s:/opt/configmap123]",
configMapName));
params.put(KubeSpecOptions.SECRET_PATHS.name(),
String.format("[%s:/opt/secret123]", secretName));
String jobId = this.driver.submitJob(ALGORITHM_NAME, params);
JobObserver jobObserver = Mockito.mock(JobObserver.class);
CompletableFuture<Void> future = this.driver.waitJobAsync(jobId, params,
jobObserver);
DefaultJobState jobState = new DefaultJobState();
jobState.jobStatus(JobStatus.INITIALIZING);
Mockito.verify(jobObserver, Mockito.timeout(150000L).atLeast(1))
.onJobStateChanged(Mockito.eq(jobState));
DefaultJobState jobState2 = new DefaultJobState();
jobState2.jobStatus(JobStatus.SUCCEEDED);
Mockito.verify(jobObserver, Mockito.timeout(150000L).atLeast(1))
.onJobStateChanged(Mockito.eq(jobState2));
future.cancel(true);
}