Search in sources :

Example 11 with SpinnakerService

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.

the class KubernetesV1DistributedService method connectToService.

@Override
default <S> S connectToService(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> service) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(service);
    KubernetesV1ProviderUtils.Proxy proxy = KubernetesV1ProviderUtils.openProxy(getJobExecutor(), details);
    String endpoint = KubernetesV1ProviderUtils.proxyServiceEndpoint(proxy, getNamespace(settings), getServiceName(), settings.getPort()).toString();
    return getServiceInterfaceFactory().createService(endpoint, service);
}
Also used : ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)

Example 12 with SpinnakerService

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.

the class GoogleDistributedService method stageProfiles.

@Override
default List<ConfigSource> stageProfiles(AccountDeploymentDetails<GoogleAccount> details, ResolvedConfiguration resolvedConfiguration) {
    String deploymentName = details.getDeploymentName();
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    SpinnakerService thisService = getService();
    ServiceSettings thisServiceSettings = resolvedConfiguration.getServiceSettings(thisService);
    Map<String, String> env = new HashMap<>();
    Integer version = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion();
    if (version == null) {
        version = 0;
    } else {
        version++;
    }
    List<ConfigSource> configSources = new ArrayList<>();
    String stagingPath = getSpinnakerStagingPath(deploymentName);
    GoogleVaultServerService vaultService = getVaultServerService();
    VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
    for (SidecarService sidecarService : getSidecars(runtimeSettings)) {
        for (Profile profile : sidecarService.getSidecarProfiles(resolvedConfiguration, thisService)) {
            if (profile == null) {
                throw new HalException(Problem.Severity.FATAL, "Service " + sidecarService.getService().getCanonicalName() + " is required but was not supplied for deployment.");
            }
            String secretName = secretName(profile.getName(), version);
            String mountPoint = Paths.get(profile.getOutputFile()).toString();
            Path stagedFile = Paths.get(profile.getStagedFile(stagingPath));
            VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(stagedFile.toFile(), mountPoint);
            secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
            configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
        }
    }
    Map<String, Profile> serviceProfiles = resolvedConfiguration.getProfilesForService(thisService.getType());
    Set<String> requiredFiles = new HashSet<>();
    for (Map.Entry<String, Profile> entry : serviceProfiles.entrySet()) {
        Profile profile = entry.getValue();
        requiredFiles.addAll(profile.getRequiredFiles());
        env.putAll(profile.getEnv());
        String mountPoint = profile.getOutputFile();
        String secretName = secretName("profile-" + profile.getName(), version);
        Path stagedFile = Paths.get(profile.getStagedFile(stagingPath));
        VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(stagedFile.toFile(), mountPoint);
        secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
        configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
    }
    for (String file : requiredFiles) {
        String mountPoint = Paths.get(file).toString();
        String secretName = secretName("dependencies-" + file, version);
        VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(Paths.get(file).toFile(), mountPoint);
        secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
        configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
    }
    env.putAll(thisServiceSettings.getEnv());
    String envSourceFile = env.entrySet().stream().reduce("", (s, e) -> String.format("%s\n%s=%s", s, e.getKey(), e.getValue()), (s1, s2) -> String.join("\n", s1, s2));
    String mountPoint = getEnvFile();
    String secretName = secretName("env", version);
    VaultConfigMount vaultConfigMount = VaultConfigMount.fromString(envSourceFile, mountPoint);
    secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
    configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
    return configSources;
}
Also used : Path(java.nio.file.Path) SidecarService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.SidecarService) HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) Map(java.util.Map) HashMap(java.util.HashMap) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) VaultConfigMount(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount) HashSet(java.util.HashSet)

Example 13 with SpinnakerService

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.

the class SpinnakerMonitoringDaemonService method getSidecarProfiles.

@Override
public List<Profile> getSidecarProfiles(GenerateService.ResolvedConfiguration resolvedConfiguration, SpinnakerService service) {
    List<Profile> result = new ArrayList<>();
    Map<String, Profile> monitoringProfiles = resolvedConfiguration.getProfilesForService(getType());
    String profileName = serviceRegistryProfileName(service.getCanonicalName());
    Profile profile = monitoringProfiles.get(profileName);
    result.add(profile);
    profile = monitoringProfiles.get(monitoringProfileName());
    result.add(profile);
    return result;
}
Also used : Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)

Example 14 with SpinnakerService

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.

the class DistributedDeployer method deploy.

@Override
public RemoteAction deploy(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    DaemonTaskHandler.newStage("Deploying Spinnaker");
    // First deploy all services not owned by Spinnaker
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = resolvedConfiguration.getServiceSettings(service);
        if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        DaemonTaskHandler.newStage("Determining status of " + distributedService.getServiceName());
        boolean safeToUpdate = settings.getSafeToUpdate();
        RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(deploymentDetails, runtimeSettings);
        if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
            deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
        } else {
            DaemonResponse.StaticRequestBuilder<Void> builder = new DaemonResponse.StaticRequestBuilder<>(() -> {
                if (runningServiceDetails.getLatestEnabledVersion() == null) {
                    DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via provider API");
                    deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
                } else {
                    DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via red/black");
                    Orca orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA_BOOTSTRAP, Orca.class).connectToPrimaryService(deploymentDetails, runtimeSettings);
                    deployServiceWithOrca(deploymentDetails, resolvedConfiguration, orca, distributedService);
                }
                return null;
            });
            DaemonTaskHandler.submitTask(builder::build, "Deploy " + distributedService.getServiceName());
        }
    }
    DaemonTaskHandler.message("Waiting on deployments to complete");
    DaemonTaskHandler.reduceChildren(null, (t1, t2) -> null, (t1, t2) -> null).getProblemSet().throwifSeverityExceeds(Problem.Severity.WARNING);
    DistributedService<Orca, T> orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA);
    Set<Integer> unknownVersions = reapOrcaServerGroups(deploymentDetails, runtimeSettings, orca);
    reapRoscoServerGroups(deploymentDetails, runtimeSettings, serviceProvider.getDeployableService(SpinnakerService.Type.ROSCO));
    if (!unknownVersions.isEmpty()) {
        String versions = String.join(", ", unknownVersions.stream().map(orca::getVersionedName).collect(Collectors.toList()));
        throw new HalException(new ProblemBuilder(Problem.Severity.ERROR, "The following orca versions (" + versions + ") could not safely be drained of work.").setRemediation("Please make sure that no pipelines are running, and manually destroy the server groups at those versions.").build());
    }
    return new RemoteAction();
}
Also used : Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction)

Example 15 with SpinnakerService

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.

the class DistributedDeployer method rollback.

@Override
public void rollback(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings, List<SpinnakerService.Type> serviceTypes) {
    DaemonTaskHandler.newStage("Checking if it is safe to roll back all services");
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = runtimeSettings.getServiceSettings(service);
        boolean safeToUpdate = settings.getSafeToUpdate();
        if (!settings.getEnabled() || distributedService.isRequiredToBootstrap() || !safeToUpdate || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(deploymentDetails, runtimeSettings);
        if (runningServiceDetails.getInstances().keySet().size() == 1) {
            throw new HalException(Problem.Severity.FATAL, "Service " + service.getCanonicalName() + " has only one server group - there is nothing to rollback to.");
        }
    }
    DaemonTaskHandler.newStage("Rolling back all updatable services");
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = runtimeSettings.getServiceSettings(service);
        if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        boolean safeToUpdate = settings.getSafeToUpdate();
        if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
        // Do nothing, the bootstrapping services should already be running, and the services that can't be updated
        // having nothing to rollback to
        } else {
            DaemonResponse.StaticRequestBuilder<Void> builder = new DaemonResponse.StaticRequestBuilder<>(() -> {
                Orca orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA_BOOTSTRAP, Orca.class).connectToPrimaryService(deploymentDetails, runtimeSettings);
                DaemonTaskHandler.message("Rolling back " + distributedService.getServiceName() + " via Spinnaker red/black");
                rollbackService(deploymentDetails, orca, distributedService, runtimeSettings);
                return null;
            });
            DaemonTaskHandler.submitTask(builder::build, "Rollback " + distributedService.getServiceName());
        }
    }
    DaemonTaskHandler.message("Waiting on rollbacks to complete");
    DaemonTaskHandler.reduceChildren(null, (t1, t2) -> null, (t1, t2) -> null).getProblemSet().throwifSeverityExceeds(Problem.Severity.WARNING);
}
Also used : DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)

Aggregations

ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)9 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)9 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)8 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)7 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)5 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)5 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)5 DeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails)4 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)4 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)3 BakeDeployer (com.netflix.spinnaker.halyard.deploy.deployment.v1.BakeDeployer)3 Deployer (com.netflix.spinnaker.halyard.deploy.deployment.v1.Deployer)3 DistributedDeployer (com.netflix.spinnaker.halyard.deploy.deployment.v1.DistributedDeployer)3 KubectlDeployer (com.netflix.spinnaker.halyard.deploy.deployment.v1.KubectlDeployer)3 LocalDeployer (com.netflix.spinnaker.halyard.deploy.deployment.v1.LocalDeployer)3 LocalGitDeployer (com.netflix.spinnaker.halyard.deploy.deployment.v1.LocalGitDeployer)3 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)2