Search in sources :

Example 1 with Env

use of io.dekorate.kubernetes.config.Env 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 2 with Env

use of io.dekorate.kubernetes.config.Env 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 3 with Env

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

the class EnvConverter method convert.

public static List<Env> convert(EnvVarsConfig e) {
    List<Env> envs = new LinkedList<>();
    e.secrets.ifPresent(sl -> sl.forEach(s -> envs.add(new EnvBuilder().withName(convertName(s)).withSecret(s).build())));
    e.configmaps.ifPresent(cl -> cl.forEach(c -> envs.add(new EnvBuilder().withName(convertName(c)).withConfigmap(c).build())));
    e.vars.forEach((k, v) -> envs.add(new EnvBuilder().withName(convertName(k)).withValue(v).build()));
    e.fields.forEach((k, v) -> {
        // env vars from fields need to have their name set in addition to their field field :)
        final String field = convertName(k);
        envs.add(new EnvBuilder().withName(field).withField(field).withValue(v).build());
    });
    e.mapping.forEach((k, v) -> envs.add(new EnvBuilder().withName(convertName(k)).withSecret(v.fromSecret.orElse(null)).withConfigmap(v.fromConfigmap.orElse(null)).withValue(v.withKey).build()));
    return envs;
}
Also used : List(java.util.List) EnvBuilder(io.dekorate.kubernetes.config.EnvBuilder) Env(io.dekorate.kubernetes.config.Env) Map(java.util.Map) LinkedList(java.util.LinkedList) EnvBuilder(io.dekorate.kubernetes.config.EnvBuilder) Env(io.dekorate.kubernetes.config.Env) LinkedList(java.util.LinkedList)

Example 4 with Env

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

the class S2iManifestGenerator method generate.

public void generate(S2iBuildConfig config) {
    if (config.isEnabled()) {
        LOGGER.info("Processing s2i configuration.");
        // TODO: We are temporarily limit S2i to openshift until we find a better way to handle this (#367).
        resourceRegistry.decorate(OPENSHIFT, new AddBuilderImageStreamResourceDecorator(config));
        resourceRegistry.decorate(OPENSHIFT, new AddOutputImageStreamResourceDecorator(config));
        resourceRegistry.decorate(OPENSHIFT, new AddBuildConfigResourceDecorator(config));
        for (Env env : config.getBuildEnvVars()) {
            resourceRegistry.decorate(new AddBuildEnvDecorator(env));
        }
        resourceRegistry.decorate(OPENSHIFT, new AddEnvVarDecorator(config.getName(), config.getName(), new EnvBuilder().withName(JAVA_APP_JAR).withValue("/deployments/" + config.getProject().getBuildInfo().getOutputFile().getFileName().toString()).build()));
    } else {
        // If S2i is disabled, check if other build configs are available and check it makes sense to create an ImageStream
        ImageConfiguration imageConfig = configurationRegistry.getImageConfig(BuildServiceFactories.supplierMatches(getProject())).orElse(null);
        String registry = Strings.isNullOrEmpty(imageConfig.getRegistry()) ? "docker.io" : imageConfig.getRegistry();
        if (imageConfig != null) {
            String image = Images.getImage(registry, imageConfig.getGroup(), imageConfig.getName(), imageConfig.getVersion());
            String repository = registry + "/" + Images.getRepository(image);
            resourceRegistry.decorate(OPENSHIFT, new AddDockerImageStreamResourceDecorator(imageConfig, repository));
        }
    }
}
Also used : EnvBuilder(io.dekorate.kubernetes.config.EnvBuilder) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) AddDockerImageStreamResourceDecorator(io.dekorate.s2i.decorator.AddDockerImageStreamResourceDecorator) AddBuildConfigResourceDecorator(io.dekorate.s2i.decorator.AddBuildConfigResourceDecorator) AddBuildEnvDecorator(io.dekorate.s2i.decorator.AddBuildEnvDecorator) AddEnvVarDecorator(io.dekorate.kubernetes.decorator.AddEnvVarDecorator) Env(io.dekorate.kubernetes.config.Env) AddBuilderImageStreamResourceDecorator(io.dekorate.s2i.decorator.AddBuilderImageStreamResourceDecorator) AddOutputImageStreamResourceDecorator(io.dekorate.s2i.decorator.AddOutputImageStreamResourceDecorator)

Example 5 with Env

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

the class ServiceBindingConfigAdapter method newBuilder.

public static ServiceBindingConfigBuilder newBuilder(ServiceBinding instance) {
    Application app = instance.application();
    BindingPath bindingPath = instance.bindingPath();
    return new ServiceBindingConfigBuilder(new io.dekorate.servicebinding.config.ServiceBindingConfig(null, null, null, instance.name(), null, new ApplicationConfigBuilder().withResource(app.resource()).withKind(app.kind()).withGroup(app.group()).withVersion(app.version()).withName(app.name()).build(), Arrays.stream(instance.services()).map(s -> new ServiceConfig(null, null, s.group(), s.kind(), s.name(), s.version(), s.id(), s.namespace(), s.envVarPrefix())).toArray(ServiceConfig[]::new), instance.envVarPrefix(), instance.detectBindingResources(), instance.bindAsFiles(), instance.mountPath(), Arrays.stream(instance.customEnvVar()).map(c -> new Env(c.name(), c.value(), c.secret(), c.configmap(), c.field(), c.resourceField())).toArray(Env[]::new), new BindingPathConfig(null, null, bindingPath.containerPath(), bindingPath.secretPath())));
}
Also used : ApplicationConfigBuilder(io.dekorate.servicebinding.config.ApplicationConfigBuilder) Arrays(java.util.Arrays) ApplicationConfigBuilder(io.dekorate.servicebinding.config.ApplicationConfigBuilder) Application(io.dekorate.servicebinding.annotation.Application) BindingPathConfig(io.dekorate.servicebinding.config.BindingPathConfig) ServiceBindingConfigBuilder(io.dekorate.servicebinding.config.ServiceBindingConfigBuilder) ApplicationConfig(io.dekorate.servicebinding.config.ApplicationConfig) BindingPath(io.dekorate.servicebinding.annotation.BindingPath) ServiceBinding(io.dekorate.servicebinding.annotation.ServiceBinding) ServiceConfig(io.dekorate.servicebinding.config.ServiceConfig) Env(io.dekorate.kubernetes.config.Env) Map(java.util.Map) ServiceBindingConfig(io.dekorate.servicebinding.config.ServiceBindingConfig) ServiceConfigBuilder(io.dekorate.servicebinding.config.ServiceConfigBuilder) ServiceConfig(io.dekorate.servicebinding.config.ServiceConfig) BindingPathConfig(io.dekorate.servicebinding.config.BindingPathConfig) ServiceBindingConfigBuilder(io.dekorate.servicebinding.config.ServiceBindingConfigBuilder) Env(io.dekorate.kubernetes.config.Env) Application(io.dekorate.servicebinding.annotation.Application) BindingPath(io.dekorate.servicebinding.annotation.BindingPath) ServiceBindingConfig(io.dekorate.servicebinding.config.ServiceBindingConfig)

Aggregations

Env (io.dekorate.kubernetes.config.Env)6 AddEnvVarDecorator (io.dekorate.kubernetes.decorator.AddEnvVarDecorator)4 Mount (io.dekorate.kubernetes.config.Mount)3 Port (io.dekorate.kubernetes.config.Port)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 EnvBuilder (io.dekorate.kubernetes.config.EnvBuilder)2 ApplyLimitsCpuDecorator (io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator)2 ApplyLimitsMemoryDecorator (io.dekorate.kubernetes.decorator.ApplyLimitsMemoryDecorator)2 ApplyRequestsCpuDecorator (io.dekorate.kubernetes.decorator.ApplyRequestsCpuDecorator)2 ApplyRequestsMemoryDecorator (io.dekorate.kubernetes.decorator.ApplyRequestsMemoryDecorator)2 Map (java.util.Map)2 Annotation (io.dekorate.kubernetes.config.Annotation)1 AwsElasticBlockStoreVolume (io.dekorate.kubernetes.config.AwsElasticBlockStoreVolume)1 AzureDiskVolume (io.dekorate.kubernetes.config.AzureDiskVolume)1 AzureFileVolume (io.dekorate.kubernetes.config.AzureFileVolume)1 ConfigMapVolume (io.dekorate.kubernetes.config.ConfigMapVolume)1