use of com.netflix.spinnaker.halyard.core.job.v1.JobRequest in project halyard by spinnaker.
the class KubernetesV1ProviderUtils method openProxy.
static Proxy openProxy(JobExecutor jobExecutor, AccountDeploymentDetails<KubernetesAccount> details) {
KubernetesAccount account = details.getAccount();
Proxy proxy = proxyMap.getOrDefault(Proxy.buildKey(details.getDeploymentName()), new Proxy());
String jobId = proxy.jobId;
if (StringUtils.isEmpty(jobId) || !jobExecutor.jobExists(jobId)) {
DaemonTaskHandler.newStage("Connecting to the Kubernetes cluster in account \"" + account.getName() + "\"");
List<String> command = kubectlAccountCommand(details);
command.add("proxy");
// select a random port
command.add("--port=0");
JobRequest request = new JobRequest().setTokenizedCommand(command);
proxy.jobId = jobExecutor.startJob(request);
JobStatus status = jobExecutor.updateJob(proxy.jobId);
while (status == null) {
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(2));
status = jobExecutor.updateJob(proxy.jobId);
}
// This should be a long-running job.
if (status.getState() == JobStatus.State.COMPLETED) {
throw new HalException(Severity.FATAL, "Unable to establish a proxy against account " + account.getName() + ":\n" + status.getStdOut() + "\n" + status.getStdErr());
}
String connectionMessage = status.getStdOut();
Pattern portPattern = Pattern.compile(":(\\d+)");
Matcher matcher = portPattern.matcher(connectionMessage);
if (matcher.find()) {
proxy.setPort(Integer.valueOf(matcher.group(1)));
proxyMap.put(Proxy.buildKey(details.getDeploymentName()), proxy);
DaemonTaskHandler.message("Connected to kubernetes cluster for account " + account.getName() + " on port " + proxy.getPort());
DaemonTaskHandler.message("View the kube ui on http://localhost:" + proxy.getPort() + "/ui/");
} else {
throw new HalException(Severity.FATAL, "Could not parse connection information from:\n" + connectionMessage + "(" + status.getStdErr() + ")");
}
}
return proxy;
}
use of com.netflix.spinnaker.halyard.core.job.v1.JobRequest in project halyard by spinnaker.
the class VaultService method publishSecret.
public void publishSecret(DeploymentConfiguration deploymentConfiguration, String name, String contents) {
String vaultAddress = deploymentConfiguration.getDeploymentEnvironment().getVault().getAddress();
String encodedContents = Base64.getEncoder().encodeToString(contents.getBytes());
String secretName = vaultSecretPrefix + name;
List<String> command = new ArrayList<>();
command.add("vault");
command.add("write");
command.add("--address");
command.add(vaultAddress);
command.add(secretName);
command.add(encodedContents);
JobRequest request = new JobRequest().setTokenizedCommand(command).setTimeoutMillis(TimeUnit.SECONDS.toMillis(vaultTimeoutSeconds));
String id = jobExecutor.startJob(request);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = jobExecutor.updateJob(id);
if (!status.getResult().equals(JobStatus.Result.SUCCESS)) {
throw new HalException(Problem.Severity.FATAL, "Failed to publish secret " + name + ": " + status.getStdOut() + status.getStdErr());
}
}
Aggregations