Search in sources :

Example 11 with ConfigSource

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

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource 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)

Aggregations

ArrayList (java.util.ArrayList)10 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)8 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)6 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)5 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)5 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Names (com.netflix.frigga.Names)4 KubernetesUtil (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil)4 KubernetesContainerDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerDescription)4 DeploymentEnvironment (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment)4 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)4 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)4 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)4