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;
}
Aggregations