use of io.dekorate.kubernetes.config.Port in project quarkus by quarkusio.
the class KubernetesCommonHelper method combinePorts.
/**
* Creates the configurator build items.
*/
public static Map<String, Port> combinePorts(List<KubernetesPortBuildItem> ports, PlatformConfiguration config) {
Map<String, Port> allPorts = new HashMap<>();
allPorts.putAll(verifyPorts(ports).entrySet().stream().map(e -> new PortBuilder().withName(e.getKey()).withContainerPort(e.getValue()).build()).collect(Collectors.toMap(Port::getName, p -> p)));
config.getPorts().entrySet().forEach(e -> {
String name = e.getKey();
Port configuredPort = PortConverter.convert(e);
Port buildItemPort = allPorts.get(name);
Port combinedPort = buildItemPort == null ? configuredPort : new PortBuilder().withName(name).withHostPort(configuredPort.getHostPort() != null && configuredPort.getHostPort() != 0 ? configuredPort.getHostPort() : buildItemPort.getHostPort()).withContainerPort(configuredPort.getContainerPort() != null && configuredPort.getContainerPort() != 0 ? configuredPort.getContainerPort() : buildItemPort.getContainerPort()).withPath(Strings.isNotNullOrEmpty(configuredPort.getPath()) ? configuredPort.getPath() : buildItemPort.getPath()).build();
allPorts.put(name, combinedPort);
});
return allPorts;
}
use of io.dekorate.kubernetes.config.Port in project quarkus by quarkusio.
the class ContainerAdapter method adapt.
public static Container adapt(io.dekorate.kubernetes.config.Container container) {
String name = container.getName();
if (Strings.isNullOrEmpty(name)) {
name = Images.getName(container.getImage());
}
ContainerBuilder builder = new ContainerBuilder().withName(name).withImage(container.getImage()).withWorkingDir(container.getWorkingDir()).withCommand(container.getCommand()).withArgs(container.getArguments());
for (Env env : container.getEnvVars()) {
builder.accept(new AddEnvVarDecorator(ANY, name, env));
}
for (Port port : container.getPorts()) {
// this was changed to use our patched port decorator
builder.accept(new AddPortDecorator(ANY, name, port));
}
for (Mount mount : container.getMounts()) {
builder.accept(new AddMountDecorator(ANY, name, mount));
}
builder.accept(new ApplyImagePullPolicyDecorator(name, container.getImagePullPolicy()));
builder.accept(new AddLivenessProbeDecorator(name, container.getLivenessProbe()));
builder.accept(new AddReadinessProbeDecorator(name, container.getReadinessProbe()));
return builder.build();
}
use of io.dekorate.kubernetes.config.Port in project dekorate by dekorateio.
the class AddIngressDecorator method visit.
public void visit(KubernetesListBuilder list) {
Optional<Port> p = getHttpPort(config);
if (!p.isPresent() || !config.isExpose()) {
return;
}
if (contains(list, ANY, "Ingress", config.getName())) {
return;
}
Port port = p.get();
list.addToItems(new IngressBuilder().withNewMetadata().withName(config.getName()).withLabels(allLabels).endMetadata().withNewSpec().addNewRule().withHost(config.getHost()).withNewHttp().addNewPath().withNewPathType("Prefix").withPath(Strings.isNotNullOrEmpty(port.getPath()) ? port.getPath() : "/").withNewBackend().withNewService().withName(config.getName()).withNewPort().withName(port.getName()).withNumber(Strings.isNullOrEmpty(port.getName()) && port.getHostPort() != null && port.getHostPort() > 0 ? port.getHostPort() : null).endPort().endService().endBackend().endPath().endHttp().endRule().endSpec().build());
}
use of io.dekorate.kubernetes.config.Port in project dekorate by dekorateio.
the class ContainerAdapter method applyContainerToBuilder.
/**
* Applies all container properties to the {@link ContainerBuilder}.
*
* @param builder The container builder
* @param container The container
*/
public static void applyContainerToBuilder(ContainerBuilder builder, io.dekorate.kubernetes.config.Container container) {
String name = container.getName();
builder.withName(container.getName()).withImage(container.getImage()).withCommand(container.getCommand()).withArgs(container.getArguments());
for (Env env : container.getEnvVars()) {
builder.accept(new AddEnvVarDecorator(env));
}
for (Port port : container.getPorts()) {
builder.accept(new AddPortDecorator(port));
}
for (Mount mount : container.getMounts()) {
builder.accept(new AddMountDecorator(mount));
}
builder.accept(new ApplyImagePullPolicyDecorator(container.getImagePullPolicy()));
// Probes
if (Probes.isConfigured(container.getLivenessProbe())) {
builder.accept(new AddLivenessProbeDecorator(name, container.getLivenessProbe()));
}
if (Probes.isConfigured(container.getReadinessProbe())) {
builder.accept(new AddReadinessProbeDecorator(name, container.getReadinessProbe()));
}
// Container resources
if (container.getLimitResources() != null && Strings.isNotNullOrEmpty(container.getLimitResources().getCpu())) {
builder.accept(new ApplyLimitsCpuDecorator(name, container.getLimitResources().getCpu()));
}
if (container.getLimitResources() != null && Strings.isNotNullOrEmpty(container.getLimitResources().getMemory())) {
builder.accept(new ApplyLimitsMemoryDecorator(name, container.getLimitResources().getMemory()));
}
if (container.getRequestResources() != null && Strings.isNotNullOrEmpty(container.getRequestResources().getCpu())) {
builder.accept(new ApplyRequestsCpuDecorator(name, container.getRequestResources().getCpu()));
}
if (container.getRequestResources() != null && Strings.isNotNullOrEmpty(container.getRequestResources().getMemory())) {
builder.accept(new ApplyRequestsMemoryDecorator(name, container.getRequestResources().getMemory()));
}
}
use of io.dekorate.kubernetes.config.Port in project dekorate by dekorateio.
the class ApplyPort method visit.
@Override
public void visit(BaseConfigFluent<?> config) {
Port updated = Ports.populateHostPort(port);
Predicate<PortBuilder> matchingPortName = p -> updated.getName().equals(p.getName());
Predicate<PortBuilder> matchingHostPort = p -> updated.getHostPort() != null && updated.getHostPort().equals(p.getHostPort());
boolean matchFound = false;
if (config.hasMatchingPort(matchingPortName)) {
matchFound = true;
applyPath(config, updated, matchingPortName);
applyContainerPort(config, updated, matchingPortName);
}
if (config.hasMatchingPort(matchingHostPort)) {
matchFound = true;
applyPath(config, updated, matchingHostPort);
applyContainerPort(config, updated, matchingHostPort);
}
if (!matchFound) {
config.addToPorts(updated);
}
}
Aggregations