use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class KubernetesV2Utils method apply.
public static void apply(KubernetesAccount account, String manifest) {
manifest = prettify(manifest);
List<String> command = kubectlPrefix(account);
command.add("apply");
command.add("-f");
// read from stdin
command.add("-");
JobRequest request = new JobRequest().setTokenizedCommand(command);
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
String jobId = DaemonTaskHandler.getJobExecutor().startJob(request, System.getenv(), new ByteArrayInputStream(manifest.getBytes()), stdout, stderr);
JobStatus status;
try {
status = DaemonTaskHandler.getJobExecutor().backoffWait(jobId);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
if (status.getState() != JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Unterminated deployment of manifest:", manifest, stderr.toString(), stdout.toString()));
}
if (status.getResult() != JobStatus.Result.SUCCESS) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed to deploy manifest:", manifest, stderr.toString(), stdout.toString()));
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class KubernetesV2Utils method createSecret.
public static String createSecret(KubernetesAccount account, String namespace, String name, List<SecretMountPair> files) {
Map<String, String> contentMap = new HashMap<>();
for (SecretMountPair pair : files) {
String contents;
try {
contents = new String(Base64.getEncoder().encode(IOUtils.toByteArray(new FileInputStream(pair.getContents()))));
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to read required config file: " + pair.getContents().getAbsolutePath() + ": " + e.getMessage(), e);
}
contentMap.put(pair.getName(), contents);
}
name = name + "-" + Math.abs(contentMap.hashCode());
TemplatedResource secret = new JinjaJarResource("/kubernetes/manifests/secret.yml");
Map<String, Object> bindings = new HashMap<>();
bindings.put("files", contentMap);
bindings.put("name", name);
bindings.put("namespace", namespace);
secret.extendBindings(bindings);
apply(account, secret.toString());
return name;
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class KubernetesV2Utils method exists.
private static boolean exists(KubernetesAccount account, String namespace, String kind, String name) {
log.info("Checking for " + kind + "/" + name);
List<String> command = kubectlPrefix(account);
if (StringUtils.isNotEmpty(namespace)) {
command.add("-n");
command.add(namespace);
}
command.add("get");
command.add(kind);
command.add(name);
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = DaemonTaskHandler.getJobExecutor().startJob(request);
JobStatus status;
try {
status = DaemonTaskHandler.getJobExecutor().backoffWait(jobId);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
if (status.getState() != JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Unterminated check for " + kind + "/" + name + " in " + namespace, status.getStdErr(), status.getStdOut()));
}
if (status.getResult() == JobStatus.Result.SUCCESS) {
return true;
} else if (status.getStdErr().contains("NotFound")) {
return false;
} else {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed check for " + kind + "/" + name + " in " + namespace, status.getStdErr(), status.getStdOut()));
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class KubernetesV1RedisService method connectToPrimaryService.
@Override
public Jedis connectToPrimaryService(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(this);
List<String> command = Arrays.stream(connectCommand(details, runtimeSettings).split(" ")).collect(Collectors.toList());
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = getJobExecutor().startJob(request);
// Wait for the proxy to spin up.
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = getJobExecutor().updateJob(jobId);
// This should be a long-running job.
if (status.getState() == JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against Redis:\n" + status.getStdOut() + "\n" + status.getStdErr());
}
return new Jedis("localhost", settings.getPort());
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleProviderUtils method getCompute.
static Compute getCompute(AccountDeploymentDetails<GoogleAccount> details) {
ConfigProblemSetBuilder problemSetBuilder = new ConfigProblemSetBuilder(null);
GoogleNamedAccountCredentials credentials = details.getAccount().getNamedAccountCredentials("", problemSetBuilder);
if (credentials == null) {
throw new HalException(problemSetBuilder.build().getProblems());
}
return credentials.getCompute();
}
Aggregations