Search in sources :

Example 6 with DeploymentEnvironment

use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.

the class LocalGitService method prepArtifactCommand.

default String prepArtifactCommand(DeploymentDetails deploymentDetails) {
    Map<String, Object> bindings = new HashMap<>();
    String artifactName = getArtifact().getName();
    bindings.put("artifact", artifactName);
    // TODO(lwander): make configurable
    bindings.put("repo", artifactName);
    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();
}
Also used : StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) HashMap(java.util.HashMap) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)

Example 7 with DeploymentEnvironment

use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.

the class DeploymentEnvironmentService method setDeploymentEnvironment.

public void setDeploymentEnvironment(String deploymentName, DeploymentEnvironment newDeploymentEnvironment) {
    DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
    deploymentConfiguration.setDeploymentEnvironment(newDeploymentEnvironment);
}
Also used : DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 8 with DeploymentEnvironment

use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.

the class KubernetesV1DistributedService method ensureRunning.

default void ensureRunning(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration, List<ConfigSource> configSources, boolean recreate) {
    ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    String namespace = getNamespace(settings);
    String serviceName = getServiceName();
    String replicaSetName = serviceName + "-v000";
    int port = settings.getPort();
    SpinnakerMonitoringDaemonService monitoringService = getMonitoringDaemonService();
    ServiceSettings monitoringSettings = runtimeSettings.getServiceSettings(monitoringService);
    KubernetesClient client = KubernetesV1ProviderUtils.getClient(details);
    KubernetesV1ProviderUtils.createNamespace(details, namespace);
    Map<String, String> serviceSelector = new HashMap<>();
    serviceSelector.put("load-balancer-" + serviceName, "true");
    Map<String, String> replicaSetSelector = new HashMap<>();
    replicaSetSelector.put("replication-controller", replicaSetName);
    Map<String, String> podLabels = new HashMap<>();
    podLabels.putAll(replicaSetSelector);
    podLabels.putAll(serviceSelector);
    Map<String, String> serviceLabels = new HashMap<>();
    serviceLabels.put("app", "spin");
    serviceLabels.put("stack", getCanonicalName());
    ServiceBuilder serviceBuilder = new ServiceBuilder();
    serviceBuilder = serviceBuilder.withNewMetadata().withName(serviceName).withNamespace(namespace).withLabels(serviceLabels).endMetadata().withNewSpec().withSelector(serviceSelector).withPorts(new ServicePortBuilder().withPort(port).withName("http").build(), new ServicePortBuilder().withPort(monitoringSettings.getPort()).withName("monitoring").build()).endSpec();
    boolean create = true;
    if (client.services().inNamespace(namespace).withName(serviceName).get() != null) {
        if (recreate) {
            client.services().inNamespace(namespace).withName(serviceName).delete();
        } else {
            create = false;
        }
    }
    if (create) {
        client.services().inNamespace(namespace).create(serviceBuilder.build());
    }
    List<Container> containers = new ArrayList<>();
    DeploymentEnvironment deploymentEnvironment = details.getDeploymentConfiguration().getDeploymentEnvironment();
    containers.add(ResourceBuilder.buildContainer(serviceName, settings, configSources, deploymentEnvironment));
    for (SidecarService sidecarService : getSidecars(runtimeSettings)) {
        String sidecarName = sidecarService.getService().getServiceName();
        ServiceSettings sidecarSettings = resolvedConfiguration.getServiceSettings(sidecarService.getService());
        containers.add(ResourceBuilder.buildContainer(sidecarName, sidecarSettings, configSources, deploymentEnvironment));
    }
    List<Volume> volumes = configSources.stream().map(c -> {
        return new VolumeBuilder().withName(c.getId()).withSecret(new SecretVolumeSourceBuilder().withSecretName(c.getId()).build()).build();
    }).collect(Collectors.toList());
    ReplicaSetBuilder replicaSetBuilder = new ReplicaSetBuilder();
    List<LocalObjectReference> imagePullSecrets = getImagePullSecrets(settings);
    Map componentSizing = deploymentEnvironment.getCustomSizing().get(serviceName);
    replicaSetBuilder = replicaSetBuilder.withNewMetadata().withName(replicaSetName).withNamespace(namespace).endMetadata().withNewSpec().withReplicas(retrieveKubernetesTargetSize(componentSizing)).withNewSelector().withMatchLabels(replicaSetSelector).endSelector().withNewTemplate().withNewMetadata().withAnnotations(settings.getKubernetes().getPodAnnotations()).withLabels(podLabels).endMetadata().withNewSpec().withContainers(containers).withTerminationGracePeriodSeconds(5L).withVolumes(volumes).withImagePullSecrets(imagePullSecrets).endSpec().endTemplate().endSpec();
    create = true;
    if (client.extensions().replicaSets().inNamespace(namespace).withName(replicaSetName).get() != null) {
        if (recreate) {
            client.extensions().replicaSets().inNamespace(namespace).withName(replicaSetName).delete();
            RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
            while (runningServiceDetails.getLatestEnabledVersion() != null) {
                DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
                runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
            }
        } else {
            create = false;
        }
    }
    if (create) {
        client.extensions().replicaSets().inNamespace(namespace).create(replicaSetBuilder.build());
    }
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = runningServiceDetails.getLatestEnabledVersion();
    while (version == null || runningServiceDetails.getInstances().get(version).stream().anyMatch(i -> !(i.isHealthy() && i.isRunning()))) {
        DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
        runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
        version = runningServiceDetails.getLatestEnabledVersion();
    }
}
Also used : KubernetesResourceDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesResourceDescription) KubernetesUtil(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil) SpinnakerMonitoringDaemonService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerMonitoringDaemonService) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) LogCollector(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.LogCollector) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) SidecarService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.SidecarService) Pair(org.apache.commons.lang3.tuple.Pair) Names(com.netflix.frigga.Names) Map(java.util.Map) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Strings(io.fabric8.utils.Strings) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) ServiceInterfaceFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceInterfaceFactory) KubernetesVolumeMount(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesVolumeMount) Set(java.util.Set) KubernetesProbe(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesProbe) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) KubernetesVolumeSource(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesVolumeSource) SocketUtils(org.springframework.util.SocketUtils) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) KubernetesContainerDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerDescription) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) JobStatus(com.netflix.spinnaker.halyard.core.job.v1.JobStatus) Container(io.fabric8.kubernetes.api.model.Container) DeployKubernetesAtomicOperationDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.DeployKubernetesAtomicOperationDescription) CustomSizing(com.netflix.spinnaker.halyard.config.model.v1.node.CustomSizing) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) HashMap(java.util.HashMap) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) KubernetesHandler(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesHandler) AccountDeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) JobExecutor(com.netflix.spinnaker.halyard.core.job.v1.JobExecutor) KubernetesImageDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription) KubernetesContainerPort(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerPort) Instance(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails.Instance) KubernetesNamedServicePort(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.loadbalancer.KubernetesNamedServicePort) Volume(io.fabric8.kubernetes.api.model.Volume) ReplicaSetBuilder(io.fabric8.kubernetes.api.model.extensions.ReplicaSetBuilder) KubernetesLoadBalancerDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.loadbalancer.KubernetesLoadBalancerDescription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KubernetesEnvVar(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesEnvVar) KubernetesSecretVolumeSource(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesSecretVolumeSource) JobRequest(com.netflix.spinnaker.halyard.core.job.v1.JobRequest) Pod(io.fabric8.kubernetes.api.model.Pod) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) Paths(java.nio.file.Paths) KubernetesHttpGetAction(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesHttpGetAction) KubernetesVolumeSourceType(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesVolumeSourceType) KubernetesTcpSocketAction(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesTcpSocketAction) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) Collections(java.util.Collections) KubernetesHandlerType(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesHandlerType) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Container(io.fabric8.kubernetes.api.model.Container) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ReplicaSetBuilder(io.fabric8.kubernetes.api.model.extensions.ReplicaSetBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) SidecarService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.SidecarService) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Volume(io.fabric8.kubernetes.api.model.Volume) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) SpinnakerMonitoringDaemonService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerMonitoringDaemonService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with DeploymentEnvironment

use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment 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 10 with DeploymentEnvironment

use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.

the class ClouddriverProfileFactory method setProfile.

@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);
}
Also used : Artifacts(com.netflix.spinnaker.halyard.config.model.v1.node.Artifacts) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) Providers(com.netflix.spinnaker.halyard.config.model.v1.node.Providers)

Aggregations

DeploymentEnvironment (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment)12 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)5 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)4 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)3 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)3 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)3 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Names (com.netflix.frigga.Names)2 DeployKubernetesAtomicOperationDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.DeployKubernetesAtomicOperationDescription)2 KubernetesContainerDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerDescription)2 KubernetesSecretVolumeSource (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesSecretVolumeSource)2 KubernetesVolumeSource (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesVolumeSource)2 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)2 CustomSizing (com.netflix.spinnaker.halyard.config.model.v1.node.CustomSizing)2 Providers (com.netflix.spinnaker.halyard.config.model.v1.node.Providers)2 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)2 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)2