Search in sources :

Example 1 with ContainerBuilder

use of io.dekorate.kubernetes.config.ContainerBuilder in project dekorate by dekorateio.

the class KubernetesManifestGenerator method addDecorators.

@Override
protected void addDecorators(String group, KubernetesConfig config) {
    super.addDecorators(group, config);
    ImageConfiguration imageConfig = getImageConfiguration(getProject(), config, configurationRegistry);
    String image = Strings.isNotNullOrEmpty(imageConfig.getImage()) ? imageConfig.getImage() : Images.getImage(imageConfig.isAutoPushEnabled() ? (Strings.isNullOrEmpty(imageConfig.getRegistry()) ? DEFAULT_REGISTRY : imageConfig.getRegistry()) : imageConfig.getRegistry(), imageConfig.getGroup(), imageConfig.getName(), imageConfig.getVersion());
    Container appContainer = new ContainerBuilder().withName(config.getName()).withImage(image).withImagePullPolicy(ImagePullPolicy.IfNotPresent).addNewEnvVar().withName(KUBERNETES_NAMESPACE).withField(METADATA_NAMESPACE).endEnvVar().build();
    Project project = getProject();
    Optional<VcsConfig> vcsConfig = configurationRegistry.get(VcsConfig.class);
    String remote = vcsConfig.map(VcsConfig::getRemote).orElse(Git.ORIGIN);
    boolean httpsPrefered = vcsConfig.map(VcsConfig::isHttpsPreferred).orElse(false);
    String vcsUrl = project.getScmInfo() != null && Strings.isNotNullOrEmpty(project.getScmInfo().getRemote().get(Git.ORIGIN)) ? Git.getRemoteUrl(project.getRoot(), remote, httpsPrefered).orElse(Labels.UNKNOWN) : Labels.UNKNOWN;
    resourceRegistry.decorate(group, new AddVcsUrlAnnotationDecorator(config.getName(), Annotations.VCS_URL, vcsUrl));
    resourceRegistry.decorate(group, new AddCommitIdAnnotationDecorator());
    resourceRegistry.decorate(group, new ApplyApplicationContainerDecorator(config.getName(), appContainer));
    resourceRegistry.decorate(group, new ApplyImageDecorator(config.getName(), image));
    for (Container container : config.getInitContainers()) {
        resourceRegistry.decorate(group, new AddInitContainerDecorator(config.getName(), container));
    }
    if (config.getPorts().length > 0) {
        resourceRegistry.decorate(group, new AddServiceResourceDecorator(config));
    }
    Ports.getHttpPort(config).ifPresent(p -> {
        resourceRegistry.decorate(group, new AddIngressDecorator(config, Labels.createLabelsAsMap(config, "Ingress")));
        resourceRegistry.decorate(group, new AddIngressRuleDecorator(config.getName(), config.getHost(), p));
    });
    if (config.isHeadless()) {
        resourceRegistry.decorate(KUBERNETES, new ApplyHeadlessDecorator(config.getName()));
    }
    if (config.getReplicas() != null && config.getReplicas() != 1) {
        resourceRegistry.decorate(KUBERNETES, new ApplyReplicasDecorator(config.getName(), config.getReplicas()));
    }
    resourceRegistry.decorate(KUBERNETES, new ApplyDeploymentStrategyDecorator(config.getName(), config.getDeploymentStrategy(), config.getRollingUpdate()));
}
Also used : AddIngressRuleDecorator(io.dekorate.kubernetes.decorator.AddIngressRuleDecorator) ApplyApplicationContainerDecorator(io.dekorate.kubernetes.decorator.ApplyApplicationContainerDecorator) ApplyImageDecorator(io.dekorate.kubernetes.decorator.ApplyImageDecorator) AddVcsUrlAnnotationDecorator(io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator) AddServiceResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceResourceDecorator) VcsConfig(io.dekorate.option.config.VcsConfig) ApplyHeadlessDecorator(io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator) AddIngressDecorator(io.dekorate.kubernetes.decorator.AddIngressDecorator) ApplyDeploymentStrategyDecorator(io.dekorate.kubernetes.decorator.ApplyDeploymentStrategyDecorator) WithProject(io.dekorate.WithProject) Project(io.dekorate.project.Project) Container(io.dekorate.kubernetes.config.Container) ContainerBuilder(io.dekorate.kubernetes.config.ContainerBuilder) AddCommitIdAnnotationDecorator(io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) ApplyReplicasDecorator(io.dekorate.kubernetes.decorator.ApplyReplicasDecorator) AddInitContainerDecorator(io.dekorate.kubernetes.decorator.AddInitContainerDecorator)

Example 2 with ContainerBuilder

use of io.dekorate.kubernetes.config.ContainerBuilder in project quarkus by quarkusio.

the class ContainerConverter method convert.

private static ContainerBuilder convert(String name, ContainerConfig c) {
    ContainerBuilder b = new ContainerBuilder();
    b.withName(name);
    c.image.ifPresent(b::withImage);
    c.workingDir.ifPresent(b::withWorkingDir);
    c.command.ifPresent(w -> b.withCommand(w.toArray(new String[0])));
    c.arguments.ifPresent(w -> b.withArguments(w.toArray(new String[0])));
    if (c.readinessProbe != null && c.readinessProbe.hasUserSuppliedAction()) {
        b.withReadinessProbe(ProbeConverter.convert(c.readinessProbe));
    }
    if (c.livenessProbe != null && c.livenessProbe.hasUserSuppliedAction()) {
        b.withLivenessProbe(ProbeConverter.convert(c.livenessProbe));
    }
    b.addAllToEnvVars(c.convertToEnvs());
    c.ports.entrySet().forEach(e -> b.addToPorts(PortConverter.convert(e)));
    c.mounts.entrySet().forEach(e -> b.addToMounts(MountConverter.convert(e)));
    if (c.resources.requests.memory.isPresent() || c.resources.requests.cpu.isPresent()) {
        b.withNewRequestResources(c.resources.requests.memory.orElse(null), c.resources.requests.cpu.orElse(null));
    }
    if (c.resources.limits.memory.isPresent() || c.resources.limits.cpu.isPresent()) {
        b.withNewLimitResources(c.resources.limits.memory.orElse(null), c.resources.limits.cpu.orElse(null));
    }
    return b;
}
Also used : ContainerBuilder(io.dekorate.kubernetes.config.ContainerBuilder)

Example 3 with ContainerBuilder

use of io.dekorate.kubernetes.config.ContainerBuilder in project dekorate by dekorateio.

the class JaegerProcessor method generate.

@Override
public void generate(JaegerAgentConfig config) {
    if (config.isOperatorEnabled()) {
        resourceRegistry.decorate(new AddAnnotationDecorator(new AnnotationBuilder().withKey("sidecar.jaegertracing.io/inject").withValue("true").build()));
    } else {
        ContainerBuilder builder = new ContainerBuilder().withName(AGENT_NAME).withImage(AGENT_IMAGE + ":" + config.getVersion()).withArguments("--collector.host-port=" + collectorHostPort(config));
        for (Port port : config.getPorts()) {
            // We can't use the AddPortToContainerDecorator as it expects to be applies on a top level resource.
            builder = builder.addNewPort().withName(port.getName()).withHostPort(port.getHostPort() > 0 ? port.getHostPort() : 0).withContainerPort(port.getContainerPort()).withProtocol(port.getProtocol() != null ? port.getProtocol() : Protocol.TCP).endPort();
        }
        resourceRegistry.decorate(new AddSidecarDecorator(builder.build()));
    }
}
Also used : ContainerBuilder(io.dekorate.kubernetes.config.ContainerBuilder) AddAnnotationDecorator(io.dekorate.kubernetes.decorator.AddAnnotationDecorator) AnnotationBuilder(io.dekorate.kubernetes.config.AnnotationBuilder) Port(io.dekorate.kubernetes.config.Port) AddSidecarDecorator(io.dekorate.kubernetes.decorator.AddSidecarDecorator)

Aggregations

ContainerBuilder (io.dekorate.kubernetes.config.ContainerBuilder)3 WithProject (io.dekorate.WithProject)1 AnnotationBuilder (io.dekorate.kubernetes.config.AnnotationBuilder)1 Container (io.dekorate.kubernetes.config.Container)1 ImageConfiguration (io.dekorate.kubernetes.config.ImageConfiguration)1 Port (io.dekorate.kubernetes.config.Port)1 AddAnnotationDecorator (io.dekorate.kubernetes.decorator.AddAnnotationDecorator)1 AddCommitIdAnnotationDecorator (io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator)1 AddIngressDecorator (io.dekorate.kubernetes.decorator.AddIngressDecorator)1 AddIngressRuleDecorator (io.dekorate.kubernetes.decorator.AddIngressRuleDecorator)1 AddInitContainerDecorator (io.dekorate.kubernetes.decorator.AddInitContainerDecorator)1 AddServiceResourceDecorator (io.dekorate.kubernetes.decorator.AddServiceResourceDecorator)1 AddSidecarDecorator (io.dekorate.kubernetes.decorator.AddSidecarDecorator)1 AddVcsUrlAnnotationDecorator (io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator)1 ApplyApplicationContainerDecorator (io.dekorate.kubernetes.decorator.ApplyApplicationContainerDecorator)1 ApplyDeploymentStrategyDecorator (io.dekorate.kubernetes.decorator.ApplyDeploymentStrategyDecorator)1 ApplyHeadlessDecorator (io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator)1 ApplyImageDecorator (io.dekorate.kubernetes.decorator.ApplyImageDecorator)1 ApplyReplicasDecorator (io.dekorate.kubernetes.decorator.ApplyReplicasDecorator)1 VcsConfig (io.dekorate.option.config.VcsConfig)1