Search in sources :

Example 1 with Port

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;
}
Also used : PortBuilder(io.dekorate.kubernetes.config.PortBuilder) HashMap(java.util.HashMap) Port(io.dekorate.kubernetes.config.Port)

Example 2 with Port

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();
}
Also used : ApplyImagePullPolicyDecorator(io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) AddReadinessProbeDecorator(io.dekorate.kubernetes.decorator.AddReadinessProbeDecorator) AddLivenessProbeDecorator(io.dekorate.kubernetes.decorator.AddLivenessProbeDecorator) Port(io.dekorate.kubernetes.config.Port) Mount(io.dekorate.kubernetes.config.Mount) AddEnvVarDecorator(io.dekorate.kubernetes.decorator.AddEnvVarDecorator) Env(io.dekorate.kubernetes.config.Env) AddPortDecorator(io.dekorate.kubernetes.decorator.AddPortDecorator) AddMountDecorator(io.dekorate.kubernetes.decorator.AddMountDecorator)

Example 3 with Port

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());
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) Port(io.dekorate.kubernetes.config.Port) Ports.getHttpPort(io.dekorate.utils.Ports.getHttpPort)

Example 4 with Port

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()));
    }
}
Also used : AddLivenessProbeDecorator(io.dekorate.kubernetes.decorator.AddLivenessProbeDecorator) Port(io.dekorate.kubernetes.config.Port) ApplyLimitsMemoryDecorator(io.dekorate.kubernetes.decorator.ApplyLimitsMemoryDecorator) Mount(io.dekorate.kubernetes.config.Mount) AddEnvVarDecorator(io.dekorate.kubernetes.decorator.AddEnvVarDecorator) Env(io.dekorate.kubernetes.config.Env) ApplyRequestsMemoryDecorator(io.dekorate.kubernetes.decorator.ApplyRequestsMemoryDecorator) ApplyImagePullPolicyDecorator(io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator) AddReadinessProbeDecorator(io.dekorate.kubernetes.decorator.AddReadinessProbeDecorator) ApplyLimitsCpuDecorator(io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator) ApplyRequestsCpuDecorator(io.dekorate.kubernetes.decorator.ApplyRequestsCpuDecorator) AddPortDecorator(io.dekorate.kubernetes.decorator.AddPortDecorator) AddMountDecorator(io.dekorate.kubernetes.decorator.AddMountDecorator)

Example 5 with Port

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);
    }
}
Also used : PortBuilder(io.dekorate.kubernetes.config.PortBuilder) Strings(io.dekorate.utils.Strings) Port(io.dekorate.kubernetes.config.Port) Predicate(java.util.function.Predicate) Map(java.util.Map) Configurator(io.dekorate.kubernetes.config.Configurator) BaseConfigFluent(io.dekorate.kubernetes.config.BaseConfigFluent) Ports(io.dekorate.utils.Ports) PortBuilder(io.dekorate.kubernetes.config.PortBuilder) Port(io.dekorate.kubernetes.config.Port)

Aggregations

Port (io.dekorate.kubernetes.config.Port)10 Env (io.dekorate.kubernetes.config.Env)3 Mount (io.dekorate.kubernetes.config.Mount)3 AddEnvVarDecorator (io.dekorate.kubernetes.decorator.AddEnvVarDecorator)3 AddLivenessProbeDecorator (io.dekorate.kubernetes.decorator.AddLivenessProbeDecorator)3 AddMountDecorator (io.dekorate.kubernetes.decorator.AddMountDecorator)3 AddPortDecorator (io.dekorate.kubernetes.decorator.AddPortDecorator)3 AddReadinessProbeDecorator (io.dekorate.kubernetes.decorator.AddReadinessProbeDecorator)3 ApplyImagePullPolicyDecorator (io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator)3 Session (io.dekorate.Session)2 PortBuilder (io.dekorate.kubernetes.config.PortBuilder)2 AddAnnotationDecorator (io.dekorate.kubernetes.decorator.AddAnnotationDecorator)2 AddSidecarDecorator (io.dekorate.kubernetes.decorator.AddSidecarDecorator)2 WithSession (io.dekorate.WithSession)1 Annotation (io.dekorate.kubernetes.config.Annotation)1 AnnotationBuilder (io.dekorate.kubernetes.config.AnnotationBuilder)1 AwsElasticBlockStoreVolume (io.dekorate.kubernetes.config.AwsElasticBlockStoreVolume)1 AzureDiskVolume (io.dekorate.kubernetes.config.AzureDiskVolume)1 AzureFileVolume (io.dekorate.kubernetes.config.AzureFileVolume)1 BaseConfigFluent (io.dekorate.kubernetes.config.BaseConfigFluent)1