Search in sources :

Example 6 with AccountDeploymentDetails

use of com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails in project halyard by spinnaker.

the class KubernetesV2Service method getResourceYaml.

default String getResourceYaml(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration) {
    ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
    String namespace = getNamespace(settings);
    List<ConfigSource> configSources = stageConfig(details, resolvedConfiguration);
    Map<String, String> env = configSources.stream().map(ConfigSource::getEnv).map(Map::entrySet).flatMap(Collection::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
    env.putAll(settings.getEnv());
    List<String> volumes = configSources.stream().map(c -> {
        TemplatedResource volume = new JinjaJarResource("/kubernetes/manifests/volume.yml");
        volume.addBinding("name", c.getId());
        return volume.toString();
    }).collect(Collectors.toList());
    List<String> volumeMounts = configSources.stream().map(c -> {
        TemplatedResource volume = new JinjaJarResource("/kubernetes/manifests/volumeMount.yml");
        volume.addBinding("name", c.getId());
        volume.addBinding("mountPath", c.getMountPath());
        return volume.toString();
    }).collect(Collectors.toList());
    TemplatedResource probe;
    if (StringUtils.isNotEmpty(settings.getHealthEndpoint())) {
        probe = new JinjaJarResource("/kubernetes/manifests/execReadinessProbe.yml");
        probe.addBinding("command", getReadinessExecCommand(settings));
    } else {
        probe = new JinjaJarResource("/kubernetes/manifests/tcpSocketReadinessProbe.yml");
        probe.addBinding("port", settings.getPort());
    }
    TemplatedResource container = new JinjaJarResource("/kubernetes/manifests/container.yml");
    container.addBinding("name", getService().getCanonicalName());
    container.addBinding("imageId", settings.getArtifactId());
    container.addBinding("port", settings.getPort());
    container.addBinding("volumeMounts", volumeMounts);
    container.addBinding("probe", probe.toString());
    container.addBinding("env", env);
    List<String> containers = Collections.singletonList(container.toString());
    TemplatedResource podSpec = new JinjaJarResource("/kubernetes/manifests/podSpec.yml").addBinding("containers", containers).addBinding("volumes", volumes);
    return new JinjaJarResource("/kubernetes/manifests/deployment.yml").addBinding("name", getService().getCanonicalName()).addBinding("namespace", namespace).addBinding("replicas", settings.getTargetSize()).addBinding("podAnnotations", settings.getKubernetes().getPodAnnotations()).addBinding("podSpec", podSpec.toString()).toString();
}
Also used : ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) Arrays(java.util.Arrays) KubernetesUtil(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) HashMap(java.util.HashMap) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) SecretMountPair(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Utils.SecretMountPair) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccountDeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails) Map(java.util.Map) KubernetesImageDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription) JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) Strings(io.fabric8.utils.Strings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) Collectors(java.util.stream.Collectors) File(java.io.File) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) List(java.util.List) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) Paths(java.nio.file.Paths) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) Entry(java.util.Map.Entry) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) Collections(java.util.Collections) JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with AccountDeploymentDetails

use of com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails in project halyard by spinnaker.

the class GoogleDistributedService method getRunningServiceDetails.

@Override
default RunningServiceDetails getRunningServiceDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    RunningServiceDetails result = new RunningServiceDetails();
    // All GCE load balancing is done via consul
    result.setLoadBalancer(new RunningServiceDetails.LoadBalancer().setExists(true));
    Compute compute = GoogleProviderUtils.getCompute(details);
    GoogleAccount account = details.getAccount();
    List<InstanceGroupManager> migs;
    try {
        migs = compute.instanceGroupManagers().list(account.getProject(), settings.getLocation()).execute().getItems();
        if (migs == null) {
            migs = Collections.emptyList();
        }
    } catch (IOException e) {
        throw new HalException(FATAL, "Failed to load MIGS: " + e.getMessage(), e);
    }
    boolean consulEnabled = getSidecars(runtimeSettings).stream().anyMatch(s -> s.getService().getType().equals(SpinnakerService.Type.CONSUL_CLIENT));
    Set<String> healthyConsulInstances = consulEnabled ? getConsulServerService().connectToPrimaryService(details, runtimeSettings).serviceHealth(getService().getCanonicalName(), true).stream().map(s -> s != null && s.getNode() != null ? s.getNode().getNodeName() : null).filter(Objects::nonNull).collect(Collectors.toSet()) : new HashSet<>();
    String serviceName = getService().getServiceName();
    migs = migs.stream().filter(ig -> ig.getName().startsWith(serviceName + "-v")).collect(Collectors.toList());
    Map<Integer, List<RunningServiceDetails.Instance>> instances = migs.stream().reduce(new HashMap<>(), (map, mig) -> {
        Names names = Names.parseName(mig.getName());
        Integer version = names.getSequence();
        List<RunningServiceDetails.Instance> computeInstances;
        try {
            List<ManagedInstance> managedInstances = compute.instanceGroupManagers().listManagedInstances(account.getProject(), settings.getLocation(), mig.getName()).execute().getManagedInstances();
            if (managedInstances == null) {
                managedInstances = new ArrayList<>();
            }
            computeInstances = managedInstances.stream().map(i -> {
                String instanceUrl = i.getInstance();
                String instanceStatus = i.getInstanceStatus();
                boolean running = instanceStatus != null && instanceStatus.equalsIgnoreCase("running");
                String instanceName = instanceUrl.substring(instanceUrl.lastIndexOf('/') + 1, instanceUrl.length());
                return new RunningServiceDetails.Instance().setId(instanceName).setLocation(settings.getLocation()).setRunning(running).setHealthy(!consulEnabled || healthyConsulInstances.contains(instanceName));
            }).collect(Collectors.toList());
        } catch (IOException e) {
            throw new HalException(FATAL, "Failed to load target pools for " + serviceName, e);
        }
        map.put(version, computeInstances);
        return map;
    }, (m1, m2) -> {
        m1.putAll(m2);
        return m1;
    });
    result.setInstances(instances);
    return result;
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) ServiceAccount(com.google.api.services.compute.model.ServiceAccount) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) AttachedDisk(com.google.api.services.compute.model.AttachedDisk) SidecarService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.SidecarService) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Names(com.netflix.frigga.Names) Map(java.util.Map) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) URI(java.net.URI) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Path(java.nio.file.Path) InstanceTemplate(com.google.api.services.compute.model.InstanceTemplate) ServiceInterfaceFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceInterfaceFactory) VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) URIBuilder(org.apache.http.client.utils.URIBuilder) Set(java.util.Set) NetworkInterface(com.google.api.services.compute.model.NetworkInterface) Operation(com.google.api.services.compute.model.Operation) Collectors(java.util.stream.Collectors) AttachedDiskInitializeParams(com.google.api.services.compute.model.AttachedDiskInitializeParams) Objects(java.util.Objects) List(java.util.List) InstanceProperties(com.google.api.services.compute.model.InstanceProperties) VaultConfigMount(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount) FATAL(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL) GoogleDiskType(com.netflix.spinnaker.clouddriver.google.model.GoogleDiskType) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) Compute(com.google.api.services.compute.Compute) Metadata(com.google.api.services.compute.model.Metadata) VaultConfigMountSet(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet) HashMap(java.util.HashMap) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccountDeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails) AccessConfig(com.google.api.services.compute.model.AccessConfig) GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) ResolvedConfiguration(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService.ResolvedConfiguration) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) InstanceGroupManager(com.google.api.services.compute.model.InstanceGroupManager) IOException(java.io.IOException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) TimeUnit(java.util.concurrent.TimeUnit) GCEUtil(com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) Paths(java.nio.file.Paths) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) Collections(java.util.Collections) GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) Names(com.netflix.frigga.Names) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) List(java.util.List) ArrayList(java.util.ArrayList) InstanceGroupManager(com.google.api.services.compute.model.InstanceGroupManager) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) IOException(java.io.IOException) Compute(com.google.api.services.compute.Compute) Objects(java.util.Objects) ManagedInstance(com.google.api.services.compute.model.ManagedInstance)

Example 8 with AccountDeploymentDetails

use of com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails in project halyard by spinnaker.

the class DistributedLogCollector method collectLogs.

@Override
public void collectLogs(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) {
    DistributedService<T, A> distributedService = (DistributedService<T, A>) getService();
    RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(details, runtimeSettings);
    runningServiceDetails.getInstances().values().forEach(is -> is.stream().filter(RunningServiceDetails.Instance::isRunning).forEach(i -> {
        File outputDir = getDirectoryStructure().getServiceLogsPath(details.getDeploymentName(), i.getId(), getService().getCanonicalName()).toFile();
        collectInstanceLogs(details, runtimeSettings, outputDir, i.getId());
    }));
}
Also used : HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) AccountDeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) DefaultLogCollector(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.DefaultLogCollector) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) HalconfigDirectoryStructure(com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure) File(java.io.File) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) File(java.io.File)

Aggregations

AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)8 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)7 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)6 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)6 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)6 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)6 File (java.io.File)6 Paths (java.nio.file.Paths)6 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 KubernetesUtil (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil)5 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)5 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)5