Search in sources :

Example 1 with ConsulConfig

use of com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig in project halyard by spinnaker.

the class OpenstackAccountValidator method validate.

@Override
public void validate(ConfigProblemSetBuilder psBuilder, OpenstackAccount account) {
    DaemonTaskHandler.message("Validating " + account.getNodeName() + " with " + OpenstackAccountValidator.class.getSimpleName());
    String environment = account.getEnvironment();
    String accountType = account.getAccountType();
    String username = account.getUsername();
    String password = account.getPassword();
    String projectName = account.getPassword();
    String domainName = account.getDomainName();
    String authUrl = account.getAuthUrl();
    List<String> regions = account.getRegions();
    Boolean insecure = account.getInsecure();
    String heatTemplateLocation = account.getHeatTemplateLocation();
    OpenstackAccount.OpenstackLbaasOptions lbaas = account.getLbaas();
    ConsulConfig consulConfig = new ConsulConfig();
    String userDataFile = account.getUserDataFile();
    if (StringUtils.isEmpty(environment)) {
        psBuilder.addProblem(Problem.Severity.ERROR, "You must provide an environment name");
    }
    if (StringUtils.isEmpty(password) || StringUtils.isEmpty(username)) {
        psBuilder.addProblem(Problem.Severity.ERROR, "You must provide a both a username and a password");
    }
    if (StringUtils.isEmpty(projectName)) {
        psBuilder.addProblem(Problem.Severity.ERROR, "You must provide a project name");
    }
    if (!StringUtils.endsWith(authUrl, "/v3")) {
        psBuilder.addProblem(Problem.Severity.WARNING, "You must use Keystone v3. The default auth url will be of the format IP:5000/v3.");
    }
    if (StringUtils.isEmpty(domainName)) {
        psBuilder.addProblem(Problem.Severity.ERROR, "You must provide a domain name");
    }
    if (regions.size() == 0 || StringUtils.isEmpty(regions.get(0))) {
        psBuilder.addProblem(Problem.Severity.ERROR, "You must provide one region");
    }
    if (insecure) {
        psBuilder.addProblem(Problem.Severity.WARNING, "You've chosen to not validate SSL connections. This setup is not recommended in production deployments.");
    }
    if (heatTemplateLocation != null && heatTemplateLocation.isEmpty()) {
        psBuilder.addProblem(Problem.Severity.ERROR, "Not a valid Heat template location: ''");
    }
    if (lbaas.getPollInterval() < 0) {
        psBuilder.addProblem(Problem.Severity.ERROR, "Poll interval cannot be less than 0.").setRemediation("Update this value to be reasonable. Default is 5.");
    }
    if (lbaas.getPollTimeout() < 0) {
        psBuilder.addProblem(Problem.Severity.ERROR, "Poll timeout cannot be less than 0.").setRemediation("Update this value to be reasonable. Default is 60.");
    }
    boolean userDataProvided = userDataFile != null && !userDataFile.isEmpty();
    if (userDataProvided) {
        String resolvedUserData = ValidatingFileReader.contents(psBuilder, userDataFile);
        if (resolvedUserData == null) {
            return;
        } else if (resolvedUserData.isEmpty()) {
            psBuilder.addProblem(Problem.Severity.WARNING, "The supplied user data file is empty.").setRemediation("Please provide a non empty file, or remove the user data file.");
        }
        List<String> validTokens = Arrays.asList("account", "accounttype", "env", "region", "group", "autogrp", "cluster", "stack", "detail", "launchconfig");
        List<String> tokens = Arrays.asList(StringUtils.substringsBetween(resolvedUserData, "%%", "%%"));
        List<String> invalidTokens = tokens.stream().filter(t -> !validTokens.contains(t)).collect(Collectors.toList());
        if (invalidTokens.size() != 0) {
            psBuilder.addProblem(Problem.Severity.WARNING, "The supplied user data file contains tokens that won't be replaced. " + "Tokens \"" + StringUtils.join(invalidTokens, ", ") + "\" are not supported.").setRemediation("Please use only the supported tokens \"" + StringUtils.join(validTokens, ", ") + "\".");
        }
    }
    OpenstackConfigurationProperties.LbaasConfig lbaasConfig = new OpenstackConfigurationProperties.LbaasConfig();
    lbaasConfig.setPollInterval(lbaas.getPollInterval());
    lbaasConfig.setPollTimeout(lbaas.getPollTimeout());
    try {
        OpenstackNamedAccountCredentials openstackCredentials = new OpenstackNamedAccountCredentials.Builder().name(account.getName()).environment(environment).accountType(accountType).authUrl(authUrl).username(username).password(password).projectName(projectName).domainName(domainName).regions(regions).insecure(insecure).heatTemplateLocation(heatTemplateLocation).consulConfig(consulConfig).lbaasConfig(lbaasConfig).userDataFile(userDataFile).build();
        credentialsList.add(openstackCredentials);
    // TODO(emjburns) verify that these credentials can connect w/o error to the openstack instance
    } catch (Exception e) {
        psBuilder.addProblem(Problem.Severity.ERROR, "Failed to instantiate openstack credentials for account \"" + account.getName() + "\".");
    }
}
Also used : OpenstackNamedAccountCredentials(com.netflix.spinnaker.clouddriver.openstack.security.OpenstackNamedAccountCredentials) Arrays(java.util.Arrays) OpenstackConfigurationProperties(com.netflix.spinnaker.clouddriver.openstack.config.OpenstackConfigurationProperties) OpenstackAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackAccount) EqualsAndHashCode(lombok.EqualsAndHashCode) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) ConsulConfig(com.netflix.spinnaker.clouddriver.consul.config.ConsulConfig) List(java.util.List) Validator(com.netflix.spinnaker.halyard.config.model.v1.node.Validator) Data(lombok.Data) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) ValidatingFileReader(com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader) ConsulConfig(com.netflix.spinnaker.clouddriver.consul.config.ConsulConfig) OpenstackConfigurationProperties(com.netflix.spinnaker.clouddriver.openstack.config.OpenstackConfigurationProperties) OpenstackNamedAccountCredentials(com.netflix.spinnaker.clouddriver.openstack.security.OpenstackNamedAccountCredentials) OpenstackAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackAccount)

Example 2 with ConsulConfig

use of com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig in project halyard by spinnaker.

the class OpenstackAddAccountCommand method buildAccount.

@Override
protected Account buildAccount(String accountName) {
    OpenstackAccount account = (OpenstackAccount) new OpenstackAccount().setName(accountName);
    OpenstackAccount.OpenstackLbaasOptions lbaas = new OpenstackAccount.OpenstackLbaasOptions();
    if (isSet(lbaasPollInterval)) {
        lbaas.setPollInterval(lbaasPollInterval);
    }
    if (isSet(lbaasPollTimeout)) {
        lbaas.setPollTimeout(lbaasPollTimeout);
    }
    account.setAuthUrl(authUrl).setUsername(username).setPassword(password).setEnvironment(environment).setAccountType(accountType).setHeatTemplateLocation(heatTemplateLocation).setProjectName(projectName).setDomainName(domainName).setRegions(regions).setInsecure(insecure).setUserDataFile(userDataFile).setConsulConfig(consulConfig).setLbaas(lbaas);
    return account;
}
Also used : OpenstackAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackAccount)

Example 3 with ConsulConfig

use of com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig in project halyard by spinnaker.

the class ClouddriverBootstrapProfileFactory method setProfile.

@Override
@SuppressWarnings("unchecked")
protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    super.setProfile(profile, deploymentConfiguration, endpoints);
    DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
    if (deploymentEnvironment.getType() != DeploymentEnvironment.DeploymentType.Distributed) {
        throw new IllegalStateException("There is no need to produce a bootstrapping clouddriver for a non-remote deployment of Spinnaker. This is a bug.");
    }
    // We need to make modifications to this deployment configuration, but can't use helpful objects
    // like the accountService on a clone. Therefore, we'll make the modifications in place and
    // restore to the original state when the modifications are written out.
    Providers originalProviders = deploymentConfiguration.getProviders().cloneNode(Providers.class);
    Providers modifiedProviders = deploymentConfiguration.getProviders();
    String deploymentName = deploymentConfiguration.getName();
    String bootstrapAccountName = deploymentEnvironment.getAccountName();
    Account bootstrapAccount = accountService.getAnyProviderAccount(deploymentName, bootstrapAccountName);
    bootstrapAccount.makeBootstrappingAccount(artifactSourcesConfig);
    Provider bootstrapProvider = (Provider) bootstrapAccount.getParent();
    disableAllProviders(modifiedProviders);
    bootstrapProvider.setEnabled(true);
    bootstrapProvider.setAccounts(Collections.singletonList(bootstrapAccount));
    if (bootstrapAccount instanceof ContainerAccount) {
        ContainerAccount containerAccount = (ContainerAccount) bootstrapAccount;
        List<DockerRegistryAccount> bootstrapRegistries = containerAccount.getDockerRegistries().stream().map(ref -> (DockerRegistryAccount) accountService.getProviderAccount(deploymentName, DOCKER_REGISTRY, ref.getAccountName())).collect(Collectors.toList());
        DockerRegistryProvider dockerProvider = modifiedProviders.getDockerRegistry();
        dockerProvider.setEnabled(true);
        dockerProvider.setAccounts(bootstrapRegistries);
    }
    if (bootstrapAccount instanceof SupportsConsul) {
        SupportsConsul consulAccount = (SupportsConsul) bootstrapAccount;
        ConsulConfig config = consulAccount.getConsul();
        if (config == null) {
            config = new ConsulConfig();
            consulAccount.setConsul(config);
        }
        consulAccount.getConsul().setEnabled(true);
    } else {
        log.warn("Attempting to perform a distributed deployment to account \"" + bootstrapAccount.getName() + "\" without a discovery mechanism");
    }
    List<String> files = backupRequiredFiles(modifiedProviders, deploymentConfiguration.getName());
    profile.appendContents(yamlToString(modifiedProviders)).appendContents("services.fiat.enabled: false").appendContents(profile.getBaseContents()).setRequiredFiles(files);
    deploymentConfiguration.setProviders(originalProviders);
}
Also used : ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Autowired(org.springframework.beans.factory.annotation.Autowired) SpinnakerArtifact(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) ProviderService(com.netflix.spinnaker.halyard.config.services.v1.ProviderService) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) Providers(com.netflix.spinnaker.halyard.config.model.v1.node.Providers) ContainerAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount) ConsulConfig(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider) Collectors(java.util.stream.Collectors) SupportsConsul(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.SupportsConsul) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) AccountService(com.netflix.spinnaker.halyard.config.services.v1.AccountService) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) DockerRegistryAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) Optional(java.util.Optional) Collections(java.util.Collections) ContainerAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) DockerRegistryAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) DockerRegistryAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount) ConsulConfig(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig) Providers(com.netflix.spinnaker.halyard.config.model.v1.node.Providers) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider) ContainerAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount) SupportsConsul(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.SupportsConsul) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider)

Aggregations

OpenstackAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackAccount)2 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ConsulConfig (com.netflix.spinnaker.clouddriver.consul.config.ConsulConfig)1 OpenstackConfigurationProperties (com.netflix.spinnaker.clouddriver.openstack.config.OpenstackConfigurationProperties)1 OpenstackNamedAccountCredentials (com.netflix.spinnaker.clouddriver.openstack.security.OpenstackNamedAccountCredentials)1 ArtifactSourcesConfig (com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig)1 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)1 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 DeploymentEnvironment (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment)1 NodeIterator (com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator)1 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)1 Providers (com.netflix.spinnaker.halyard.config.model.v1.node.Providers)1 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)1 ConsulConfig (com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig)1 SupportsConsul (com.netflix.spinnaker.halyard.config.model.v1.providers.consul.SupportsConsul)1 ContainerAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount)1 DockerRegistryAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount)1