Search in sources :

Example 1 with DCOSCluster

use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.

the class DCOSAddClusterCommand method executeThis.

@Override
protected void executeThis() {
    DCOSCluster cluster = new DCOSCluster();
    cluster.setName(getClusterName()).setDcosUrl(dcosUrl).setCaCertFile(caCertFile).setInsecureSkipTlsVerify(insecureSkipTlsVerify);
    if (nonNull(loadBalancerImage)) {
        final DCOSCluster.LoadBalancer loadBalancer = new DCOSCluster.LoadBalancer().setImage(loadBalancerImage).setServiceAccountSecret(loadBalancerServiceAccountSecret);
        cluster.setLoadBalancer(loadBalancer);
    }
    new OperationHandler<Void>().setFailureMesssage("Failed to add cluster " + getClusterName() + " for provider " + getProviderName() + ".").setSuccessMessage("Successfully added cluster " + getClusterName() + " for provider " + getProviderName() + ".").setOperation(Daemon.addCluster(getCurrentDeployment(), getProviderName(), !noValidate, cluster)).get();
}
Also used : DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 2 with DCOSCluster

use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.

the class DCOSListClusterCommand method executeThis.

@Override
protected void executeThis() {
    Provider provider = getProvider();
    DCOSProvider dcosProvider = (DCOSProvider) provider;
    List<DCOSCluster> clusters = dcosProvider.getClusters();
    if (clusters.isEmpty()) {
        AnsiUi.success("No configured clusters for " + getProviderName() + ".");
    } else {
        AnsiUi.success("Clusters for " + getProviderName() + ":");
        clusters.forEach(cluster -> AnsiUi.listItem(cluster.getName()));
    }
}
Also used : DCOSProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) DCOSProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider)

Example 3 with DCOSCluster

use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.

the class DCOSEditClusterCommand method executeThis.

@Override
protected void executeThis() {
    String clusterName = getClusterName();
    String providerName = getProviderName();
    String currentDeployment = getCurrentDeployment();
    // Disable validation here, since we don't want an illegal config to prevent us from fixing it.
    DCOSCluster cluster = (DCOSCluster) new OperationHandler<Cluster>().setFailureMesssage("Failed to get cluster " + clusterName + " for provider " + providerName + ".").setOperation(Daemon.getCluster(currentDeployment, providerName, clusterName, false)).get();
    int originalHash = cluster.hashCode();
    if (!isStringEmpty(dcosUrl)) {
        cluster.setDcosUrl(dcosUrl);
    }
    if (!isStringEmpty(caCertFile)) {
        cluster.setCaCertFile(caCertFile);
    }
    if (removeCaCertFile) {
        cluster.setCaCertFile(null);
    }
    if (Objects.nonNull(insecureSkipTlsVerify)) {
        cluster.setInsecureSkipTlsVerify(insecureSkipTlsVerify);
    }
    if (!isStringEmpty(loadBalancerImage)) {
        DCOSCluster.LoadBalancer loadBalancer = cluster.getLoadBalancer();
        if (loadBalancer == null) {
            loadBalancer = new DCOSCluster.LoadBalancer();
            cluster.setLoadBalancer(loadBalancer);
        }
        loadBalancer.setImage(loadBalancerImage);
    }
    if (!isStringEmpty(loadBalancerServiceAccountSecret)) {
        DCOSCluster.LoadBalancer loadBalancer = cluster.getLoadBalancer();
        if (loadBalancer == null) {
            loadBalancer = new DCOSCluster.LoadBalancer();
            cluster.setLoadBalancer(loadBalancer);
        }
        loadBalancer.setServiceAccountSecret(loadBalancerServiceAccountSecret);
    }
    if (removeLoadBalancer) {
        cluster.setLoadBalancer(null);
    }
    if (originalHash == cluster.hashCode()) {
        AnsiUi.failure("No changes supplied.");
        return;
    }
    new OperationHandler<Void>().setFailureMesssage("Failed to edit cluster " + clusterName + " for provider " + providerName + ".").setSuccessMessage("Successfully edited cluster " + clusterName + " for provider " + providerName + ".").setOperation(Daemon.setCluster(currentDeployment, providerName, clusterName, !noValidate, cluster)).get();
}
Also used : DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 4 with DCOSCluster

use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.

the class DCOSAccountValidator method validateClusters.

private void validateClusters(final ConfigProblemSetBuilder problems, final DCOSAccount account) {
    final NodeIterator children = account.getParent().getChildren();
    Node n = children.getNext();
    Set<String> definedClusters = new HashSet<>();
    while (n != null) {
        if (n instanceof DCOSCluster) {
            definedClusters.add(((DCOSCluster) n).getName());
        }
        n = children.getNext();
    }
    final Set<String> accountClusters = account.getClusters().stream().map(c -> c.getName()).collect(Collectors.toSet());
    accountClusters.removeAll(definedClusters);
    accountClusters.forEach(c -> problems.addProblem(ERROR, "Cluster \"" + c.toString() + "\" not defined for provider").setRemediation("Add cluster to the provider or remove from the account").setOptions(Lists.newArrayList(definedClusters)));
    Set<List<String>> credentials = new HashSet<>();
    account.getClusters().forEach(c -> {
        final List<String> key = Lists.newArrayList(c.getName(), c.getUid());
        if (credentials.contains(key)) {
            problems.addProblem(ERROR, "Account contains duplicate credentials for cluster \"" + c.getName() + "\" and user id \"" + c.getUid() + "\".").setRemediation("Remove the duplicate credentials");
        } else {
            credentials.add(key);
        }
        // we can connect without a password
        if (Strings.isStringEmpty(c.getPassword()) && Strings.isStringEmpty(c.getServiceKeyFile())) {
            problems.addProblem(WARNING, "Account has no password or service key.  Unless the cluster has security disabled this may be an error").setRemediation("Add a password or service key.");
        }
        if (!Strings.isStringEmpty(c.getPassword()) && !Strings.isStringEmpty(c.getServiceKeyFile())) {
            problems.addProblem(ERROR, "Account has both a password and service key").setRemediation("Remove either the password or service key.");
        }
        if (!Strings.isStringEmpty(c.getServiceKeyFile())) {
            String resolvedServiceKey = ValidatingFileReader.contents(problems, c.getServiceKeyFile());
            if (Strings.isStringEmpty(resolvedServiceKey)) {
                problems.addProblem(ERROR, "The supplied service key file does not exist or is empty.").setRemediation("Supply a valid service key file.");
            }
        }
    });
}
Also used : NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Set(java.util.Set) ERROR(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.ERROR) Lists(com.beust.jcommander.internal.Lists) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount) Component(org.springframework.stereotype.Component) List(java.util.List) WARNING(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.WARNING) Strings(com.beust.jcommander.Strings) Validator(com.netflix.spinnaker.halyard.config.model.v1.node.Validator) DockerRegistryReferenceValidation.validateDockerRegistries(com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) ValidatingFileReader(com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) List(java.util.List) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) HashSet(java.util.HashSet)

Aggregations

DCOSCluster (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster)4 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)2 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)2 Strings (com.beust.jcommander.Strings)1 Lists (com.beust.jcommander.internal.Lists)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)1 NodeIterator (com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator)1 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)1 DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)1 DCOSAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)1 DCOSProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider)1 ConfigProblemSetBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)1 DockerRegistryReferenceValidation.validateDockerRegistries (com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries)1 ValidatingFileReader (com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader)1 ERROR (com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.ERROR)1 WARNING (com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.WARNING)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1