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