Search in sources :

Example 1 with JinjaJarResource

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();
}
Also used : JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)

Example 2 with JinjaJarResource

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;
}
Also used : HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 3 with JinjaJarResource

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();
}
Also used : ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) 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) JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with JinjaJarResource

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();
}
Also used : JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)

Aggregations

JinjaJarResource (com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource)4 TemplatedResource (com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)4 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)3 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)3 KubernetesSharedServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings)3 HashMap (java.util.HashMap)2 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 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)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 SecretMountPair (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Utils.SecretMountPair)1 Strings (io.fabric8.utils.Strings)1