Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for Vault API to be ready in Vault tests #21154

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public String toString() {
return "VaultSealStatus{" +
"type: '" + type + '\'' +
", sealed: " + sealed +
", initialized: " + initialized +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static WebClient createHttpClient(Vertx vertx, VaultBootstrapConfig vault

WebClientOptions options = new WebClientOptions()
.setConnectTimeout((int) vaultBootstrapConfig.connectTimeout.toMillis())
.setIdleTimeout((int) vaultBootstrapConfig.readTimeout.getSeconds());
.setIdleTimeout((int) vaultBootstrapConfig.readTimeout.getSeconds() * 2);

if (vaultBootstrapConfig.nonProxyHosts.isPresent()) {
options.setNonProxyHosts(vaultBootstrapConfig.nonProxyHosts.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.quarkus.vault.VaultException;
import io.quarkus.vault.VaultKVSecretEngine;
import io.quarkus.vault.runtime.VaultConfigHolder;
import io.quarkus.vault.runtime.VaultIOException;
import io.quarkus.vault.runtime.VaultVersions;
import io.quarkus.vault.runtime.client.VaultClientException;
import io.quarkus.vault.runtime.client.backend.VaultInternalSystemBackend;
Expand Down Expand Up @@ -251,16 +252,16 @@ private String getVaultImage() {

private void initVault() throws InterruptedException, IOException {

waitForContainerToStart();
vaultClient = createVaultClient();
VaultInternalSystemBackend vaultInternalSystemBackend = new VaultInternalSystemBackend();
vaultInternalSystemBackend.setVaultClient(vaultClient);
waitForVaultAPIToBeReady(vaultInternalSystemBackend);

VaultInitResponse vaultInit = vaultInternalSystemBackend.init(1, 1);
String unsealKey = vaultInit.keys.get(0);
rootToken = vaultInit.rootToken;

waitForContainerToStart();

try {
vaultInternalSystemBackend.systemHealthStatus(false, false);
} catch (VaultClientException e) {
Expand Down Expand Up @@ -423,9 +424,28 @@ private void waitForContainerToStart() throws InterruptedException, IOException
Instant started = Instant.now();
while (Instant.now().isBefore(started.plusSeconds(20))) {
Container.ExecResult vault_status = vaultContainer.execInContainer(createVaultCommand("vault status"));
if (vault_status.getExitCode() == 2) { // 2 => sealed
int exitCode = vault_status.getExitCode();
log.info("vault status exit code = " + exitCode + " (0=unsealed, 1=error, 2=sealed)");
if (exitCode == 2) { // 2 => sealed
return;
}
Thread.sleep(1000);
}
fail("vault failed to start");
}

private void waitForVaultAPIToBeReady(VaultInternalSystemBackend vaultInternalSystemBackend) throws InterruptedException {
Instant started = Instant.now();
while (Instant.now().isBefore(started.plusSeconds(20))) {
try {
log.info("checking seal status");
VaultSealStatusResult sealStatus = vaultInternalSystemBackend.systemSealStatus();
log.info(sealStatus);
return;
} catch (VaultIOException e) {
log.info("vault api not ready: " + e);
}
Thread.sleep(1000L);
}
fail("vault failed to start");
}
Expand Down