use of com.netflix.spinnaker.halyard.config.model.v1.node.Cluster in project halyard by spinnaker.
the class DCOSAddAccountCommand method buildAccount.
@Override
protected Account buildAccount(String accountName) {
DCOSAccount account = (DCOSAccount) new DCOSAccount().setName(accountName);
dockerRegistries.forEach(registryName -> account.getDockerRegistries().add(new DockerRegistryReference().setAccountName(registryName)));
if (!isNull(serviceKeyFile) && !isNull(password)) {
throw new IllegalArgumentException("Only one of --service-key-file or --password may be set");
}
account.setClusters(Lists.newArrayList(new ClusterCredential(cluster, uid, password, serviceKeyFile)));
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Cluster in project halyard by spinnaker.
the class ClusterController method setCluster.
@RequestMapping(value = "/cluster/{clusterName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setCluster(@PathVariable String deploymentName, @PathVariable String providerName, @PathVariable String clusterName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Problem.Severity severity, @RequestBody Object rawCluster) {
Cluster cluster = objectMapper.convertValue(rawCluster, Providers.translateClusterType(providerName));
DaemonResponse.UpdateRequestBuilder builder = new DaemonResponse.UpdateRequestBuilder();
builder.setUpdate(() -> clusterService.setCluster(deploymentName, providerName, clusterName, cluster));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> clusterService.validateCluster(deploymentName, providerName, cluster.getName());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
return DaemonTaskHandler.submitTask(builder::build, "Edit the " + clusterName + " cluster");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Cluster in project halyard by spinnaker.
the class ClusterController method addCluster.
@RequestMapping(value = "/", method = RequestMethod.POST)
DaemonTask<Halconfig, Void> addCluster(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Problem.Severity severity, @RequestBody Object rawCluster) {
Cluster cluster = objectMapper.convertValue(rawCluster, Providers.translateClusterType(providerName));
DaemonResponse.UpdateRequestBuilder builder = new DaemonResponse.UpdateRequestBuilder();
builder.setSeverity(severity);
builder.setUpdate(() -> clusterService.addCluster(deploymentName, providerName, cluster));
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> clusterService.validateCluster(deploymentName, providerName, cluster.getName());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
return DaemonTaskHandler.submitTask(builder::build, "Add the " + cluster.getName() + " cluster");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Cluster in project halyard by spinnaker.
the class KubernetesV1ProviderUtils method kubectlAccountCommand.
private static List<String> kubectlAccountCommand(AccountDeploymentDetails<KubernetesAccount> details) {
KubernetesAccount account = details.getAccount();
List<String> command = new ArrayList<>();
command.add("kubectl");
String context = account.getContext();
if (context != null && !context.isEmpty()) {
command.add("--context");
command.add(context);
}
String cluster = account.getCluster();
if (cluster != null && !cluster.isEmpty()) {
command.add("--cluster");
command.add(cluster);
}
String user = account.getUser();
if (user != null && !user.isEmpty()) {
command.add("--user");
command.add(user);
}
String kubeconfig = account.getKubeconfigFile();
if (kubeconfig != null && !kubeconfig.isEmpty()) {
command.add("--kubeconfig");
command.add(kubeconfig);
}
return command;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Cluster 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;
}
Aggregations