Search in sources :

Example 26 with ServiceSettings

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

the class KubernetesV2Service method connectCommand.

default String connectCommand(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    KubernetesAccount account = details.getAccount();
    String namespace = settings.getLocation();
    String name = getServiceName();
    int port = settings.getPort();
    String podNameCommand = String.join(" ", KubernetesV2Utils.kubectlPodServiceCommand(account, namespace, name));
    return String.join(" ", KubernetesV2Utils.kubectlConnectPodCommand(account, namespace, "$(" + podNameCommand + ")", port));
}
Also used : KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) 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)

Example 27 with ServiceSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings 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 28 with ServiceSettings

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

the class KubernetesV2Service method getServiceYaml.

default String getServiceYaml(GenerateService.ResolvedConfiguration resolvedConfiguration) {
    ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
    String namespace = getNamespace(settings);
    TemplatedResource service = new JinjaJarResource("/kubernetes/manifests/service.yml");
    service.addBinding("name", getService().getCanonicalName());
    service.addBinding("namespace", namespace);
    service.addBinding("port", settings.getPort());
    return service.toString();
}
Also used : 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)

Example 29 with ServiceSettings

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

the class ResourceBuilder method buildContainer.

static Container buildContainer(String name, ServiceSettings settings, List<ConfigSource> configSources, DeploymentEnvironment deploymentEnvironment) {
    int port = settings.getPort();
    List<EnvVar> envVars = settings.getEnv().entrySet().stream().map(e -> {
        EnvVarBuilder envVarBuilder = new EnvVarBuilder();
        return envVarBuilder.withName(e.getKey()).withValue(e.getValue()).build();
    }).collect(Collectors.toList());
    configSources.forEach(c -> {
        c.getEnv().entrySet().forEach(envEntry -> {
            EnvVarBuilder envVarBuilder = new EnvVarBuilder();
            envVars.add(envVarBuilder.withName(envEntry.getKey()).withValue(envEntry.getValue()).build());
        });
    });
    ProbeBuilder probeBuilder = new ProbeBuilder();
    if (settings.getHealthEndpoint() != null) {
        probeBuilder = probeBuilder.withNewHttpGet().withNewPort(port).withPath(settings.getHealthEndpoint()).endHttpGet();
    } else {
        probeBuilder = probeBuilder.withNewTcpSocket().withNewPort().withIntVal(port).endPort().endTcpSocket();
    }
    List<VolumeMount> volumeMounts = configSources.stream().map(c -> {
        return new VolumeMountBuilder().withMountPath(c.getMountPath()).withName(c.getId()).build();
    }).collect(Collectors.toList());
    ContainerBuilder containerBuilder = new ContainerBuilder();
    containerBuilder = containerBuilder.withName(name).withImage(settings.getArtifactId()).withPorts(new ContainerPortBuilder().withContainerPort(port).build()).withVolumeMounts(volumeMounts).withEnv(envVars).withReadinessProbe(probeBuilder.build()).withResources(buildResourceRequirements(name, deploymentEnvironment));
    return containerBuilder.build();
}
Also used : DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) CustomSizing(com.netflix.spinnaker.halyard.config.model.v1.node.CustomSizing) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) QuantityBuilder(io.fabric8.kubernetes.api.model.QuantityBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Map(java.util.Map) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 30 with ServiceSettings

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

the class DistributedService method getSidecars.

default List<SidecarService> getSidecars(SpinnakerRuntimeSettings runtimeSettings) {
    SpinnakerMonitoringDaemonService monitoringService = getMonitoringDaemonService();
    ServiceSettings monitoringSettings = runtimeSettings.getServiceSettings(monitoringService);
    ServiceSettings thisSettings = runtimeSettings.getServiceSettings(getService());
    List<SidecarService> result = new ArrayList<>();
    if (monitoringSettings.getEnabled() && thisSettings.getMonitored()) {
        result.add(monitoringService);
    }
    return result;
}
Also used : HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) SpinnakerMonitoringDaemonService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerMonitoringDaemonService)

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