Search in sources :

Example 16 with ServiceSettings

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

the class GoogleDistributedService method buildConnectionDetails.

default VaultConnectionDetails buildConnectionDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, String secretName) {
    GoogleVaultServerService vaultService = getVaultServerService();
    VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
    ServiceSettings vaultSettings = runtimeSettings.getServiceSettings(vaultService);
    RunningServiceDetails vaultDetails = vaultService.getRunningServiceDetails(details, runtimeSettings);
    Integer latestVaultVersion = vaultDetails.getLatestEnabledVersion();
    if (latestVaultVersion == null) {
        throw new IllegalStateException("No vault services have been started yet. This is a bug.");
    }
    List<RunningServiceDetails.Instance> instances = vaultDetails.getInstances().get(latestVaultVersion);
    if (instances.isEmpty()) {
        throw new IllegalStateException("Current vault service has no running instances. This is a bug.");
    }
    String instanceId = instances.get(0).getId();
    String address = new URIBuilder().setScheme("http").setHost(instanceId).setPort(vaultSettings.getPort()).toString();
    String token = vaultService.getToken(details.getDeploymentName(), vault);
    return new VaultConnectionDetails().setAddress(address).setSecret(secretName).setToken(token);
}
Also used : VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 17 with ServiceSettings

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

the class GoogleDistributedService method sshTunnelIntoService.

default <S> URI sshTunnelIntoService(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar);
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer enabledVersion = runningServiceDetails.getLatestEnabledVersion();
    if (enabledVersion == null) {
        throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no server groups have been deployed yet");
    }
    List<RunningServiceDetails.Instance> instances = runningServiceDetails.getInstances().get(enabledVersion);
    if (instances == null || instances.isEmpty()) {
        throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no instances have been deployed yet");
    }
    try {
        return GoogleProviderUtils.openSshTunnel(details, instances.get(0).getId(), settings);
    } catch (InterruptedException e) {
        throw new DaemonTaskInterrupted(e);
    }
}
Also used : ManagedInstance(com.google.api.services.compute.model.ManagedInstance) 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) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)

Example 18 with ServiceSettings

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

the class GoogleDistributedService method connectCommand.

@Override
default String connectCommand(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = runningServiceDetails.getLatestEnabledVersion();
    if (version == null) {
        throw new HalException(FATAL, "No version of " + getServiceName() + " to connect to.");
    }
    List<RunningServiceDetails.Instance> instances = runningServiceDetails.getInstances().get(version);
    if (instances.isEmpty()) {
        throw new HalException(FATAL, "Version " + version + " of " + getServiceName() + " has no instances to connect to");
    }
    RunningServiceDetails.Instance instance = instances.get(0);
    String instanceName = instance.getId();
    String zone = instance.getLocation();
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    int port = settings.getPort();
    return String.format("gcloud compute ssh %s --zone %s -- -L %d:localhost:%d -N", instanceName, zone, port, port);
}
Also used : ManagedInstance(com.google.api.services.compute.model.ManagedInstance) 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)

Example 19 with ServiceSettings

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

the class GoogleDistributedService method ensureRunning.

@Override
default void ensureRunning(AccountDeploymentDetails<GoogleAccount> details, ResolvedConfiguration resolvedConfiguration, List<ConfigSource> configSources, boolean recreate) {
    DaemonTaskHandler.newStage("Deploying " + getServiceName() + " via GCE API");
    Integer version = 0;
    ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    GoogleAccount account = details.getAccount();
    Compute compute = GoogleProviderUtils.getCompute(details);
    String project = account.getProject();
    String zone = settings.getLocation();
    boolean exists = runningServiceDetails.getInstances().containsKey(version);
    if (!recreate && exists) {
        DaemonTaskHandler.message("Service " + getServiceName() + " is already deployed and not safe to restart");
        return;
    } else if (exists) {
        DaemonTaskHandler.message("Recreating existing " + getServiceName() + "...");
        deleteVersion(details, settings, version);
    }
    InstanceGroupManager manager = new InstanceGroupManager();
    InstanceTemplate template = new InstanceTemplate().setName(getServiceName() + "-hal-" + System.currentTimeMillis()).setDescription("Halyard-generated instance template for deploying Spinnaker");
    Metadata metadata = new Metadata().setItems(getMetadata(details, runtimeSettings, configSources, version));
    AccessConfig accessConfig = new AccessConfig().setName("External NAT").setType("ONE_TO_ONE_NAT");
    NetworkInterface networkInterface = new NetworkInterface().setNetwork(GoogleProviderUtils.ensureSpinnakerNetworkExists(details)).setAccessConfigs(Collections.singletonList(accessConfig));
    ServiceAccount sa = new ServiceAccount().setEmail(GoogleProviderUtils.defaultServiceAccount(details)).setScopes(getScopes());
    InstanceProperties properties = new InstanceProperties().setMachineType(getDefaultInstanceType()).setMetadata(metadata).setServiceAccounts(Collections.singletonList(sa)).setNetworkInterfaces(Collections.singletonList(networkInterface));
    AttachedDisk disk = new AttachedDisk().setBoot(true).setAutoDelete(true).setType("PERSISTENT");
    AttachedDiskInitializeParams diskParams = new AttachedDiskInitializeParams().setDiskSizeGb(20L).setDiskStorageType(GCEUtil.buildDiskTypeUrl(project, zone, GoogleDiskType.PD_SSD)).setSourceImage(getArtifactId(details.getDeploymentName()));
    disk.setInitializeParams(diskParams);
    List<AttachedDisk> disks = new ArrayList<>();
    disks.add(disk);
    properties.setDisks(disks);
    template.setProperties(properties);
    String instanceTemplateUrl;
    Operation operation;
    try {
        DaemonTaskHandler.message("Creating an instance template");
        operation = compute.instanceTemplates().insert(project, template).execute();
        instanceTemplateUrl = operation.getTargetLink();
        GoogleProviderUtils.waitOnGlobalOperation(compute, project, operation);
    } catch (IOException e) {
        throw new HalException(FATAL, "Failed to create instance template for " + settings.getArtifactId() + ": " + e.getMessage(), e);
    }
    String migName = getVersionedName(version);
    manager.setInstanceTemplate(instanceTemplateUrl);
    manager.setBaseInstanceName(migName);
    manager.setTargetSize(settings.getTargetSize());
    manager.setName(migName);
    try {
        DaemonTaskHandler.message("Deploying the instance group manager");
        operation = compute.instanceGroupManagers().insert(project, settings.getLocation(), manager).execute();
        GoogleProviderUtils.waitOnZoneOperation(compute, project, settings.getLocation(), operation);
    } catch (IOException e) {
        throw new HalException(FATAL, "Failed to create instance group to run artifact " + settings.getArtifactId() + ": " + e.getMessage(), e);
    }
    boolean ready = false;
    DaemonTaskHandler.message("Waiting for all instances to become healthy.");
    while (!ready) {
        ready = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion() == version;
        DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(2));
    }
}
Also used : GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) ServiceAccount(com.google.api.services.compute.model.ServiceAccount) InstanceGroupManager(com.google.api.services.compute.model.InstanceGroupManager) InstanceProperties(com.google.api.services.compute.model.InstanceProperties) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) Metadata(com.google.api.services.compute.model.Metadata) ArrayList(java.util.ArrayList) NetworkInterface(com.google.api.services.compute.model.NetworkInterface) AttachedDisk(com.google.api.services.compute.model.AttachedDisk) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) AttachedDiskInitializeParams(com.google.api.services.compute.model.AttachedDiskInitializeParams) Operation(com.google.api.services.compute.model.Operation) IOException(java.io.IOException) AccessConfig(com.google.api.services.compute.model.AccessConfig) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) Compute(com.google.api.services.compute.Compute) InstanceTemplate(com.google.api.services.compute.model.InstanceTemplate)

Example 20 with ServiceSettings

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

the class KubectlDeployer method deploy.

@Override
public RemoteAction deploy(KubectlServiceProvider serviceProvider, AccountDeploymentDetails<KubernetesAccount> deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
    List<KubernetesV2Service> services = serviceProvider.getServicesByPriority(serviceTypes);
    services.stream().forEach((service) -> {
        ServiceSettings settings = resolvedConfiguration.getServiceSettings((SpinnakerService) service);
        if (settings.getEnabled() != null && !settings.getEnabled()) {
            return;
        }
        if (settings.getSkipLifeCycleManagement() != null && settings.getSkipLifeCycleManagement()) {
            return;
        }
        DaemonTaskHandler.newStage("Deploying " + service.getServiceName() + " with kubectl");
        KubernetesAccount account = deploymentDetails.getAccount();
        String namespaceDefinition = service.getNamespaceYaml(resolvedConfiguration);
        String serviceDefinition = service.getServiceYaml(resolvedConfiguration);
        if (!KubernetesV2Utils.exists(account, namespaceDefinition)) {
            KubernetesV2Utils.apply(account, namespaceDefinition);
        }
        if (!KubernetesV2Utils.exists(account, serviceDefinition)) {
            KubernetesV2Utils.apply(account, serviceDefinition);
        }
        String resourceDefinition = service.getResourceYaml(deploymentDetails, resolvedConfiguration);
        DaemonTaskHandler.message("Running kubectl apply on the resource definition...");
        KubernetesV2Utils.apply(account, resourceDefinition);
    });
    return new RemoteAction();
}
Also used : KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) KubernetesV2Service(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Service)

Aggregations

ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)35 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)18 ArrayList (java.util.ArrayList)18 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)14 HashMap (java.util.HashMap)14 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)12 Map (java.util.Map)12 List (java.util.List)10 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)9 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)9 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)8 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)8 HashSet (java.util.HashSet)7 Names (com.netflix.frigga.Names)6 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)6 Collectors (java.util.stream.Collectors)6 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)5 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)5 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)5 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)5