private void validateDistributedDeployment(ConfigProblemSetBuilder p, DeploymentEnvironment n) { String accountName = n.getAccountName(); if (StringUtils.isEmpty(accountName)) { p.addProblem(Problem.Severity.FATAL, "An account name must be specified when using a Distributed deployment."); return; } DeploymentConfiguration deploymentConfiguration = n.parentOfType(DeploymentConfiguration.class); Account account; try { account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), n.getAccountName()); } catch (ConfigNotFoundException e) { p.addProblem(Problem.Severity.FATAL, "Account " + accountName + " not defined."); return; } if (account instanceof GoogleAccount) { p.addProblem(Problem.Severity.WARNING, "Support for distributed deployments on GCE aren't fully supported yet."); } else if (account instanceof KubernetesAccount) { kubernetesAccountValidator.ensureKubectlExists(p); } else { p.addProblem(Problem.Severity.FATAL, "Account " + accountName + " is not in a provider that supports distributed installation of Spinnaker yet"); } } }
default String prepArtifactCommand(DeploymentDetails deploymentDetails) { Map<String, Object> bindings = new HashMap<>(); String artifactName = getArtifact().getName(); bindings.put("artifact", artifactName); bindings.put("repo", artifactName); // TODO(lwander): make configurable bindings.put("version", getArtifactCommit(deploymentDetails.getDeploymentName())); bindings.put("git-root", getGitRoot()); DeploymentEnvironment env = deploymentDetails.getDeploymentConfiguration() .getDeploymentEnvironment(); DeploymentEnvironment.GitConfig gitConfig = env.getGitConfig(); boolean update = env.getUpdateVersions(); bindings.put("update", update ? "true" : ""); bindings.put("origin", gitConfig.getOriginUser()); bindings.put("upstream", gitConfig.getUpstreamUser()); TemplatedResource prepResource = new StringReplaceJarResource("/git/prep-component.sh"); prepResource.setBindings(bindings); return prepResource.toString(); }
@Override public String getDeployLocation() { return StringUtils.isEmpty(deploymentConfiguration.getDeploymentEnvironment().getLocation()) ? "spinnaker" : deploymentConfiguration.getDeploymentEnvironment().getLocation(); } }
int originalHash = deploymentEnvironment.hashCode(); DeploymentEnvironment.GitConfig gitConfig = deploymentEnvironment.getGitConfig(); if (gitConfig == null) { gitConfig = new DeploymentEnvironment.GitConfig(); deploymentEnvironment.setGitConfig(gitConfig); DeploymentEnvironment.Consul consul = deploymentEnvironment.getConsul(); if (consul == null) { consul = new DeploymentEnvironment.Consul(); DeploymentEnvironment.Vault vault = deploymentEnvironment.getVault(); if (vault == null) { vault = new DeploymentEnvironment.Vault(); deploymentEnvironment.setAccountName(isSet(accountName) ? accountName : deploymentEnvironment.getAccountName()); deploymentEnvironment.setBootstrapOnly(isSet(bootstrapOnly) ? bootstrapOnly : deploymentEnvironment.getBootstrapOnly()); deploymentEnvironment.setUpdateVersions(isSet(updateVersions) ? updateVersions : deploymentEnvironment.getUpdateVersions()); deploymentEnvironment.setType(type != null ? type : deploymentEnvironment.getType()); deploymentEnvironment.setConsul(consul); deploymentEnvironment.setVault(vault); deploymentEnvironment.setLocation(isSet(location) ? location : deploymentEnvironment.getLocation()); if (originalHash == deploymentEnvironment.hashCode()) { AnsiUi.failure("No changes supplied.");
private Deployer getDeployer(DeploymentConfiguration deploymentConfiguration) { DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment(); DeploymentEnvironment.DeploymentType type = deploymentEnvironment.getType(); String accountName = deploymentEnvironment.getAccountName(); switch (type) { case BakeDebian: return bakeDeployer; case LocalGit: return localGitDeployer; case LocalDebian: return localDeployer; case Distributed: if (StringUtils.isEmpty(accountName)) { throw new HalException(Problem.Severity.FATAL, "An account name must be " + "specified as the desired place to run your distributed deployment."); } Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName); Provider.ProviderType providerType = ((Provider) account.getParent()).providerType(); if (providerType == Provider.ProviderType.KUBERNETES && account.getProviderVersion() == V2) { return kubectlDeployer; } else { return distributedDeployer; } default: throw new IllegalArgumentException("Unrecognized deployment type " + type); } }
@Override protected boolean hasServiceOverrides(DeploymentConfiguration deployment) { HaServices haServices = deployment.getDeploymentEnvironment().getHaServices(); return haServices.getClouddriver().isEnabled(); }
public SpinnakerServiceProvider create(DeploymentConfiguration deploymentConfiguration) { DeploymentEnvironment.DeploymentType type = deploymentConfiguration.getDeploymentEnvironment().getType(); // TODO(lwander) what's the best UX here? mashing together deploys & installs feels wrong. switch (type) { case BakeDebian: return bakeDebianServiceProvider; case LocalDebian: return localDebianServiceProvider; case LocalGit: return localGitServiceProvider; case Distributed: return createDeployableServiceProvider(deploymentConfiguration); default: throw new IllegalArgumentException("Unrecognized deployment type " + type); } }
@Override protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { super.setProfile(profile, deploymentConfiguration, endpoints); // 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(); DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment(); if (deploymentEnvironment.getBootstrapOnly() != null && deploymentEnvironment.getBootstrapOnly()) { String bootstrapAccountName = deploymentEnvironment.getAccountName(); removeBootstrapOnlyAccount(modifiedProviders, deploymentConfiguration.getName(), bootstrapAccountName); } Artifacts artifacts = deploymentConfiguration.getArtifacts(); List<String> files = backupRequiredFiles(modifiedProviders, deploymentConfiguration.getName()); files.addAll(backupRequiredFiles(artifacts, deploymentConfiguration.getName())); if (deploymentConfiguration.getProviders() != null) { processProviders(deploymentConfiguration.getProviders()); } profile.appendContents(yamlToString(modifiedProviders)) .appendContents(yamlToString(new ArtifactWrapper(artifacts))) .appendContents(profile.getBaseContents()) .setRequiredFiles(files); deploymentConfiguration.setProviders(originalProviders); }
private void validateGitDeployment(ConfigProblemSetBuilder p, DeploymentEnvironment n) { if (StringUtils.isEmpty(n.getGitConfig().getOriginUser())) { p.addProblem(Problem.Severity.FATAL, "A git origin user must be supplied when deploying from git.") .setRemediation("Your github username is recommended."); } if (StringUtils.isEmpty(n.getGitConfig().getUpstreamUser())) { p.addProblem(Problem.Severity.FATAL, "A git upstream user must be supplied when deploying from git.") .setRemediation("The user 'spinnaker' is recommended (unless you have a fork maintained by the org you develop under)."); } }
private SpinnakerServiceProvider createDeployableServiceProvider(DeploymentConfiguration deploymentConfiguration) { DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment(); String accountName = deploymentEnvironment.getAccountName(); if (accountName == null || accountName.isEmpty()) { throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "An account name must be " + "specified as the desired place to run your simple clustered deployment.").build()); } Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName); Provider.ProviderType providerType = ((Provider) account.getParent()).providerType(); switch (providerType) { case KUBERNETES: switch (account.getProviderVersion()) { case V1: return kubernetesV1DistributedServiceProvider; case V2: return kubectlServiceProvider; default: return kubernetesV1DistributedServiceProvider; } case GOOGLE: return googleDistributedServiceProvider; default: throw new IllegalArgumentException("No Clustered Simple Deployment for " + providerType.getName()); } } }
public void setLocation(String deploymentName, String location) { DeploymentConfiguration deploymentConfiguration = getDeploymentConfiguration(deploymentName); deploymentConfiguration.getDeploymentEnvironment().setLocation(location); }
public void publishSecret(DeploymentConfiguration deploymentConfiguration, String name, String contents) { String vaultAddress = deploymentConfiguration.getDeploymentEnvironment().getVault().getAddress(); String encodedContents = Base64.getEncoder().encodeToString(contents.getBytes()); String secretName = vaultSecretPrefix + name; List<String> command = new ArrayList<>(); command.add("vault"); command.add("write"); command.add("--address"); command.add(vaultAddress); command.add(secretName); command.add(encodedContents); JobRequest request = new JobRequest() .setTokenizedCommand(command) .setTimeoutMillis(TimeUnit.SECONDS.toMillis(vaultTimeoutSeconds)); String id = jobExecutor.startJob(request); DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); JobStatus status = jobExecutor.updateJob(id); if (!status.getResult().equals(JobStatus.Result.SUCCESS)) { throw new HalException(Problem.Severity.FATAL, "Failed to publish secret " + name + ": " + status.getStdOut() + status.getStdErr()); } } }
int originalHash = deploymentEnvironment.hashCode(); DeploymentEnvironment.GitConfig gitConfig = deploymentEnvironment.getGitConfig(); if (gitConfig == null) { gitConfig = new DeploymentEnvironment.GitConfig(); deploymentEnvironment.setGitConfig(gitConfig); DeploymentEnvironment.Consul consul = deploymentEnvironment.getConsul(); if (consul == null) { consul = new DeploymentEnvironment.Consul(); DeploymentEnvironment.Vault vault = deploymentEnvironment.getVault(); if (vault == null) { vault = new DeploymentEnvironment.Vault(); deploymentEnvironment.setAccountName(isSet(accountName) ? accountName : deploymentEnvironment.getAccountName()); deploymentEnvironment.setBootstrapOnly(isSet(bootstrapOnly) ? bootstrapOnly : deploymentEnvironment.getBootstrapOnly()); deploymentEnvironment.setUpdateVersions(isSet(updateVersions) ? updateVersions : deploymentEnvironment.getUpdateVersions()); deploymentEnvironment.setType(type != null ? type : deploymentEnvironment.getType()); deploymentEnvironment.setConsul(consul); deploymentEnvironment.setVault(vault); deploymentEnvironment.setLocation(isSet(location) ? location : deploymentEnvironment.getLocation()); if (originalHash == deploymentEnvironment.hashCode()) { AnsiUi.failure("No changes supplied.");
private Deployer getDeployer(DeploymentConfiguration deploymentConfiguration) { DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment(); DeploymentEnvironment.DeploymentType type = deploymentEnvironment.getType(); String accountName = deploymentEnvironment.getAccountName(); switch (type) { case BakeDebian: return bakeDeployer; case LocalGit: return localGitDeployer; case LocalDebian: return localDeployer; case Distributed: if (StringUtils.isEmpty(accountName)) { throw new HalException(Problem.Severity.FATAL, "An account name must be " + "specified as the desired place to run your distributed deployment."); } Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName); Provider.ProviderType providerType = ((Provider) account.getParent()).providerType(); if (providerType == Provider.ProviderType.KUBERNETES && account.getProviderVersion() == V2) { return kubectlDeployer; } else { return distributedDeployer; } default: throw new IllegalArgumentException("Unrecognized deployment type " + type); } }
@Override protected boolean hasServiceOverrides(DeploymentConfiguration deployment) { HaServices haServices = deployment.getDeploymentEnvironment().getHaServices(); return haServices.getClouddriver().isEnabled(); }
@Override public void validate(ConfigProblemSetBuilder p, DeploymentEnvironment n) { DeploymentType type = n.getType(); switch (type) { case LocalDebian: case BakeDebian: break; case Distributed: validateDistributedDeployment(p, n); break; case LocalGit: validateGitDeployment(p, n); break; default: throw new RuntimeException("Unknown deployment environment type " + type); } }
@Override protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { super.setProfile(profile, deploymentConfiguration, endpoints); // 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(); DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment(); if (deploymentEnvironment.getBootstrapOnly() != null && deploymentEnvironment.getBootstrapOnly()) { String bootstrapAccountName = deploymentEnvironment.getAccountName(); removeBootstrapOnlyAccount(modifiedProviders, deploymentConfiguration.getName(), bootstrapAccountName); } Artifacts artifacts = deploymentConfiguration.getArtifacts(); List<String> files = backupRequiredFiles(modifiedProviders, deploymentConfiguration.getName()); files.addAll(backupRequiredFiles(artifacts, deploymentConfiguration.getName())); if (deploymentConfiguration.getProviders() != null) { processProviders(deploymentConfiguration.getProviders()); } profile.appendContents(yamlToString(modifiedProviders)) .appendContents(yamlToString(new ArtifactWrapper(artifacts))) .appendContents(profile.getBaseContents()) .setRequiredFiles(files); deploymentConfiguration.setProviders(originalProviders); }
private void validateGitDeployment(ConfigProblemSetBuilder p, DeploymentEnvironment n) { if (StringUtils.isEmpty(n.getGitConfig().getOriginUser())) { p.addProblem(Problem.Severity.FATAL, "A git origin user must be supplied when deploying from git.") .setRemediation("Your github username is recommended."); } if (StringUtils.isEmpty(n.getGitConfig().getUpstreamUser())) { p.addProblem(Problem.Severity.FATAL, "A git upstream user must be supplied when deploying from git.") .setRemediation("The user 'spinnaker' is recommended (unless you have a fork maintained by the org you develop under)."); } }
private SpinnakerServiceProvider createDeployableServiceProvider(DeploymentConfiguration deploymentConfiguration) { DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment(); String accountName = deploymentEnvironment.getAccountName(); if (accountName == null || accountName.isEmpty()) { throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "An account name must be " + "specified as the desired place to run your simple clustered deployment.").build()); } Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName); Provider.ProviderType providerType = ((Provider) account.getParent()).providerType(); switch (providerType) { case KUBERNETES: switch (account.getProviderVersion()) { case V1: return kubernetesV1DistributedServiceProvider; case V2: return kubectlServiceProvider; default: return kubernetesV1DistributedServiceProvider; } case GOOGLE: return googleDistributedServiceProvider; default: throw new IllegalArgumentException("No Clustered Simple Deployment for " + providerType.getName()); } } }
public void setLocation(String deploymentName, String location) { DeploymentConfiguration deploymentConfiguration = getDeploymentConfiguration(deploymentName); deploymentConfiguration.getDeploymentEnvironment().setLocation(location); }