Search in sources :

Example 6 with Cluster

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;
}
Also used : DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) ClusterCredential(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount.ClusterCredential) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)

Example 7 with Cluster

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");
}
Also used : DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Cluster(com.netflix.spinnaker.halyard.config.model.v1.node.Cluster) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with 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");
}
Also used : DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Cluster(com.netflix.spinnaker.halyard.config.model.v1.node.Cluster) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with 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;
}
Also used : KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)

Example 10 with Cluster

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;
}
Also used : JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) Pattern(java.util.regex.Pattern) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) Matcher(java.util.regex.Matcher) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Aggregations

Cluster (com.netflix.spinnaker.halyard.config.model.v1.node.Cluster)4 DCOSCluster (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster)4 List (java.util.List)4 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)3 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)3 DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)3 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)3 ConfigProblemSetBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)3 ValidatingFileReader (com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader)3 Collectors (java.util.stream.Collectors)3 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)2 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)2 HasClustersProvider (com.netflix.spinnaker.halyard.config.model.v1.node.HasClustersProvider)2 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)2 DCOSAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)2 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)2 DockerRegistryReferenceValidation.validateDockerRegistries (com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries)2 DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)2 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)2 JobRequest (com.netflix.spinnaker.halyard.core.job.v1.JobRequest)2