use of com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource in project halyard by spinnaker.
the class KubernetesV2Service method getNamespaceYaml.
default String getNamespaceYaml(GenerateService.ResolvedConfiguration resolvedConfiguration) {
ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
String name = getNamespace(settings);
TemplatedResource namespace = new JinjaJarResource("/kubernetes/manifests/namespace.yml");
namespace.addBinding("name", name);
return namespace.toString();
}
use of com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource in project halyard by spinnaker.
the class KubernetesV2Utils method createSecret.
public static String createSecret(KubernetesAccount account, String namespace, String name, List<SecretMountPair> files) {
Map<String, String> contentMap = new HashMap<>();
for (SecretMountPair pair : files) {
String contents;
try {
contents = new String(Base64.getEncoder().encode(IOUtils.toByteArray(new FileInputStream(pair.getContents()))));
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to read required config file: " + pair.getContents().getAbsolutePath() + ": " + e.getMessage(), e);
}
contentMap.put(pair.getName(), contents);
}
name = name + "-" + Math.abs(contentMap.hashCode());
TemplatedResource secret = new JinjaJarResource("/kubernetes/manifests/secret.yml");
Map<String, Object> bindings = new HashMap<>();
bindings.put("files", contentMap);
bindings.put("name", name);
bindings.put("namespace", namespace);
secret.extendBindings(bindings);
apply(account, secret.toString());
return name;
}
use of com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource 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();
}
use of com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource 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();
}
Aggregations