Search in sources :

Example 1 with SecretMountPair

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Utils.SecretMountPair in project halyard by spinnaker.

the class KubernetesV2Service method stageConfig.

default List<ConfigSource> stageConfig(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration) {
    Map<String, Profile> profiles = resolvedConfiguration.getProfilesForService(getService().getType());
    String stagingPath = getSpinnakerStagingPath(details.getDeploymentName());
    Map<String, Set<Profile>> profilesByDirectory = new HashMap<>();
    List<String> requiredFiles = new ArrayList<>();
    List<ConfigSource> configSources = new ArrayList<>();
    String secretNamePrefix = getServiceName() + "-files";
    String namespace = getNamespace(resolvedConfiguration.getServiceSettings(getService()));
    KubernetesAccount account = details.getAccount();
    for (Entry<String, Profile> entry : profiles.entrySet()) {
        Profile profile = entry.getValue();
        String outputFile = profile.getOutputFile();
        String mountPoint = Paths.get(outputFile).getParent().toString();
        Set<Profile> profilesInDirectory = profilesByDirectory.getOrDefault(mountPoint, new HashSet<>());
        profilesInDirectory.add(profile);
        requiredFiles.addAll(profile.getRequiredFiles());
        profilesByDirectory.put(mountPoint, profilesInDirectory);
    }
    for (Entry<String, Set<Profile>> entry : profilesByDirectory.entrySet()) {
        Set<Profile> profilesInDirectory = entry.getValue();
        String mountPath = entry.getKey();
        List<SecretMountPair> files = profilesInDirectory.stream().map(p -> {
            File input = new File(p.getStagedFile(stagingPath));
            File output = new File(p.getOutputFile());
            return new SecretMountPair(input, output);
        }).collect(Collectors.toList());
        Map<String, String> env = profilesInDirectory.stream().map(Profile::getEnv).map(Map::entrySet).flatMap(Collection::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
        String name = KubernetesV2Utils.createSecret(account, namespace, secretNamePrefix, files);
        configSources.add(new ConfigSource().setId(name).setMountPath(mountPath).setEnv(env));
    }
    if (!requiredFiles.isEmpty()) {
        List<SecretMountPair> files = requiredFiles.stream().map(File::new).map(SecretMountPair::new).collect(Collectors.toList());
        String name = KubernetesV2Utils.createSecret(account, namespace, secretNamePrefix, files);
        configSources.add(new ConfigSource().setId(name).setMountPath(files.get(0).getContents().getParent()));
    }
    return configSources;
}
Also used : 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) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) SecretMountPair(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Utils.SecretMountPair) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 KubernetesUtil (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil)1 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)1 JinjaJarResource (com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource)1 TemplatedResource (com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)1 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)1 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)1 GenerateService (com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService)1 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)1 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)1 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)1 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)1 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)1 KubernetesSharedServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings)1 SecretMountPair (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Utils.SecretMountPair)1 Strings (io.fabric8.utils.Strings)1 File (java.io.File)1 Paths (java.nio.file.Paths)1