Search in sources :

Example 1 with AddEnvVarDecorator

use of io.dekorate.kubernetes.decorator.AddEnvVarDecorator 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 AddEnvVarDecorator

use of io.dekorate.kubernetes.decorator.AddEnvVarDecorator 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 AddEnvVarDecorator

use of io.dekorate.kubernetes.decorator.AddEnvVarDecorator in project quarkus by quarkusio.

the class KubernetesCommonHelper method createAppConfigVolumeAndEnvDecorators.

private static List<DecoratorBuildItem> createAppConfigVolumeAndEnvDecorators(Optional<Project> project, String target, String name, PlatformConfiguration config) {
    List<DecoratorBuildItem> result = new ArrayList<>();
    Set<String> paths = new HashSet<>();
    config.getAppSecret().ifPresent(s -> {
        result.add(new DecoratorBuildItem(target, new AddSecretVolumeDecorator(new SecretVolumeBuilder().withSecretName(s).withVolumeName("app-secret").build())));
        result.add(new DecoratorBuildItem(target, new AddMountDecorator(new MountBuilder().withName("app-secret").withPath("/mnt/app-secret").build())));
        paths.add("/mnt/app-secret");
    });
    config.getAppConfigMap().ifPresent(s -> {
        result.add(new DecoratorBuildItem(target, new AddConfigMapVolumeDecorator(new ConfigMapVolumeBuilder().withConfigMapName(s).withVolumeName("app-config-map").build())));
        result.add(new DecoratorBuildItem(target, new AddMountDecorator(new MountBuilder().withName("app-config-map").withPath("/mnt/app-config-map").build())));
        paths.add("/mnt/app-config-map");
    });
    if (!paths.isEmpty()) {
        result.add(new DecoratorBuildItem(target, new AddEnvVarDecorator(ApplicationContainerDecorator.ANY, name, new EnvBuilder().withName("SMALLRYE_CONFIG_LOCATIONS").withValue(paths.stream().collect(Collectors.joining(","))).build())));
    }
    return result;
}
Also used : ConfigMapVolumeBuilder(io.dekorate.kubernetes.config.ConfigMapVolumeBuilder) DecoratorBuildItem(io.quarkus.kubernetes.spi.DecoratorBuildItem) ArrayList(java.util.ArrayList) AddEnvVarDecorator(io.dekorate.kubernetes.decorator.AddEnvVarDecorator) AddConfigMapVolumeDecorator(io.dekorate.kubernetes.decorator.AddConfigMapVolumeDecorator) EnvBuilder(io.dekorate.kubernetes.config.EnvBuilder) AddSecretVolumeDecorator(io.dekorate.kubernetes.decorator.AddSecretVolumeDecorator) MountBuilder(io.dekorate.kubernetes.config.MountBuilder) AddMountDecorator(io.dekorate.kubernetes.decorator.AddMountDecorator) SecretVolumeBuilder(io.dekorate.kubernetes.config.SecretVolumeBuilder) HashSet(java.util.HashSet)

Example 4 with AddEnvVarDecorator

use of io.dekorate.kubernetes.decorator.AddEnvVarDecorator 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 AddEnvVarDecorator

use of io.dekorate.kubernetes.decorator.AddEnvVarDecorator in project dekorate by dekorateio.

the class AbstractKubernetesManifestGenerator method addDecorators.

/**
 * Add all decorator to the resources.
 * This method will read the config and then add all the required decorator to the resources.
 * The method is intended to be called from the generate method and thus marked as protected.
 *
 * @param group The group..
 * @param config The config.
 */
protected void addDecorators(String group, C config) {
    if (Strings.isNotNullOrEmpty(config.getServiceAccount())) {
        resourceRegistry.decorate(new ApplyServiceAccountNamedDecorator(config.getName(), config.getServiceAccount()));
    }
    if (config.getImagePullPolicy() != ImagePullPolicy.IfNotPresent) {
        resourceRegistry.decorate(group, new ApplyImagePullPolicyDecorator(config.getImagePullPolicy()));
    }
    for (String imagePullSecret : config.getImagePullSecrets()) {
        resourceRegistry.decorate(new AddImagePullSecretDecorator(config.getName(), imagePullSecret));
    }
    // Metadata handling
    Labels.createLabels(config).forEach(l -> {
        resourceRegistry.decorate(group, new AddLabelDecorator(config.getName(), l));
        resourceRegistry.decorate(group, new AddToSelectorDecorator(config.getName(), l.getKey(), l.getValue()));
        resourceRegistry.decorate(group, new AddToMatchingLabelsDecorator(config.getName(), l.getKey(), l.getValue()));
    });
    for (Annotation annotation : config.getAnnotations()) {
        resourceRegistry.decorate(new AddAnnotationDecorator(config.getName(), annotation));
    }
    if (Strings.isNotNullOrEmpty(config.getServiceAccount())) {
        resourceRegistry.decorate(group, new ApplyServiceAccountNamedDecorator(config.getName(), config.getServiceAccount()));
    }
    if (config.getImagePullPolicy() != ImagePullPolicy.IfNotPresent) {
        resourceRegistry.decorate(group, new ApplyImagePullPolicyDecorator(config.getName(), config.getImagePullPolicy()));
    }
    for (String imagePullSecret : config.getImagePullSecrets()) {
        resourceRegistry.decorate(group, new AddImagePullSecretDecorator(config.getName(), imagePullSecret));
    }
    for (HostAlias hostAlias : config.getHostAliases()) {
        resourceRegistry.decorate(new AddHostAliasesDecorator(config.getName(), hostAlias));
    }
    for (Container container : config.getSidecars()) {
        resourceRegistry.decorate(group, new AddSidecarDecorator(config.getName(), container));
    }
    for (Env env : config.getEnvVars()) {
        resourceRegistry.decorate(group, new AddEnvVarDecorator(config.getName(), config.getName(), env));
    }
    for (Port port : config.getPorts()) {
        resourceRegistry.decorate(group, new AddPortDecorator(config.getName(), config.getName(), port));
    }
    for (Mount mount : config.getMounts()) {
        resourceRegistry.decorate(group, new AddMountDecorator(config.getName(), config.getName(), mount));
    }
    for (SecretVolume volume : config.getSecretVolumes()) {
        validateVolume(volume);
        resourceRegistry.decorate(group, new AddSecretVolumeDecorator(volume));
    }
    for (ConfigMapVolume volume : config.getConfigMapVolumes()) {
        validateVolume(volume);
        resourceRegistry.decorate(group, new AddConfigMapVolumeDecorator(volume));
    }
    for (PersistentVolumeClaimVolume volume : config.getPvcVolumes()) {
        resourceRegistry.decorate(group, new AddPvcVolumeDecorator(volume));
    }
    for (AzureFileVolume volume : config.getAzureFileVolumes()) {
        resourceRegistry.decorate(group, new AddAzureFileVolumeDecorator(volume));
    }
    for (AzureDiskVolume volume : config.getAzureDiskVolumes()) {
        resourceRegistry.decorate(group, new AddAzureDiskVolumeDecorator(volume));
    }
    for (AwsElasticBlockStoreVolume volume : config.getAwsElasticBlockStoreVolumes()) {
        resourceRegistry.decorate(group, new AddAwsElasticBlockStoreVolumeDecorator(volume));
    }
    if (config.getCommand() != null && config.getCommand().length > 0) {
        resourceRegistry.decorate(group, new ApplyCommandDecorator(config.getName(), config.getName(), config.getCommand()));
    }
    if (config.getArguments() != null && config.getArguments().length > 0) {
        resourceRegistry.decorate(group, new ApplyArgsDecorator(config.getName(), config.getName(), config.getArguments()));
    }
    if (Probes.isConfigured(config.getLivenessProbe())) {
        resourceRegistry.decorate(group, new AddLivenessProbeDecorator(config.getName(), config.getName(), config.getLivenessProbe()));
    }
    if (Probes.isConfigured(config.getReadinessProbe())) {
        resourceRegistry.decorate(group, new AddReadinessProbeDecorator(config.getName(), config.getName(), config.getReadinessProbe()));
    }
    // Container resources
    if (config.getLimitResources() != null) {
        if (Strings.isNotNullOrEmpty(config.getLimitResources().getCpu())) {
            resourceRegistry.decorate(group, new ApplyLimitsCpuDecorator(config.getName(), config.getName(), config.getLimitResources().getCpu()));
        }
        if (Strings.isNotNullOrEmpty(config.getLimitResources().getMemory())) {
            resourceRegistry.decorate(group, new ApplyLimitsMemoryDecorator(config.getName(), config.getName(), config.getLimitResources().getMemory()));
        }
    }
    if (config.getRequestResources() != null) {
        if (Strings.isNotNullOrEmpty(config.getRequestResources().getCpu())) {
            resourceRegistry.decorate(group, new ApplyRequestsCpuDecorator(config.getName(), config.getName(), config.getRequestResources().getCpu()));
        }
        if (Strings.isNotNullOrEmpty(config.getRequestResources().getMemory())) {
            resourceRegistry.decorate(group, new ApplyRequestsMemoryDecorator(config.getName(), config.getName(), config.getRequestResources().getMemory()));
        }
    }
    resourceRegistry.decorate(group, new RemoveProbesFromInitContainerDecorator());
}
Also used : AddPvcVolumeDecorator(io.dekorate.kubernetes.decorator.AddPvcVolumeDecorator) AddImagePullSecretDecorator(io.dekorate.kubernetes.decorator.AddImagePullSecretDecorator) AddAzureFileVolumeDecorator(io.dekorate.kubernetes.decorator.AddAzureFileVolumeDecorator) AzureDiskVolume(io.dekorate.kubernetes.config.AzureDiskVolume) PersistentVolumeClaimVolume(io.dekorate.kubernetes.config.PersistentVolumeClaimVolume) AddLivenessProbeDecorator(io.dekorate.kubernetes.decorator.AddLivenessProbeDecorator) AddAzureDiskVolumeDecorator(io.dekorate.kubernetes.decorator.AddAzureDiskVolumeDecorator) Port(io.dekorate.kubernetes.config.Port) ApplyLimitsMemoryDecorator(io.dekorate.kubernetes.decorator.ApplyLimitsMemoryDecorator) Mount(io.dekorate.kubernetes.config.Mount) AddEnvVarDecorator(io.dekorate.kubernetes.decorator.AddEnvVarDecorator) AddConfigMapVolumeDecorator(io.dekorate.kubernetes.decorator.AddConfigMapVolumeDecorator) Env(io.dekorate.kubernetes.config.Env) AddSidecarDecorator(io.dekorate.kubernetes.decorator.AddSidecarDecorator) ApplyRequestsMemoryDecorator(io.dekorate.kubernetes.decorator.ApplyRequestsMemoryDecorator) ApplyImagePullPolicyDecorator(io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator) Container(io.dekorate.kubernetes.config.Container) ApplyLimitsCpuDecorator(io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator) AddToSelectorDecorator(io.dekorate.kubernetes.decorator.AddToSelectorDecorator) AddPortDecorator(io.dekorate.kubernetes.decorator.AddPortDecorator) AwsElasticBlockStoreVolume(io.dekorate.kubernetes.config.AwsElasticBlockStoreVolume) ConfigMapVolume(io.dekorate.kubernetes.config.ConfigMapVolume) ApplyCommandDecorator(io.dekorate.kubernetes.decorator.ApplyCommandDecorator) RemoveProbesFromInitContainerDecorator(io.dekorate.kubernetes.decorator.RemoveProbesFromInitContainerDecorator) AddAnnotationDecorator(io.dekorate.kubernetes.decorator.AddAnnotationDecorator) AddHostAliasesDecorator(io.dekorate.kubernetes.decorator.AddHostAliasesDecorator) SecretVolume(io.dekorate.kubernetes.config.SecretVolume) AddToMatchingLabelsDecorator(io.dekorate.kubernetes.decorator.AddToMatchingLabelsDecorator) AddAwsElasticBlockStoreVolumeDecorator(io.dekorate.kubernetes.decorator.AddAwsElasticBlockStoreVolumeDecorator) Annotation(io.dekorate.kubernetes.config.Annotation) HostAlias(io.dekorate.kubernetes.config.HostAlias) AzureFileVolume(io.dekorate.kubernetes.config.AzureFileVolume) ApplyArgsDecorator(io.dekorate.kubernetes.decorator.ApplyArgsDecorator) AddReadinessProbeDecorator(io.dekorate.kubernetes.decorator.AddReadinessProbeDecorator) ApplyRequestsCpuDecorator(io.dekorate.kubernetes.decorator.ApplyRequestsCpuDecorator) AddSecretVolumeDecorator(io.dekorate.kubernetes.decorator.AddSecretVolumeDecorator) AddLabelDecorator(io.dekorate.kubernetes.decorator.AddLabelDecorator) ApplyServiceAccountNamedDecorator(io.dekorate.kubernetes.decorator.ApplyServiceAccountNamedDecorator) AddMountDecorator(io.dekorate.kubernetes.decorator.AddMountDecorator)

Aggregations

AddEnvVarDecorator (io.dekorate.kubernetes.decorator.AddEnvVarDecorator)5 Env (io.dekorate.kubernetes.config.Env)4 AddMountDecorator (io.dekorate.kubernetes.decorator.AddMountDecorator)4 Mount (io.dekorate.kubernetes.config.Mount)3 Port (io.dekorate.kubernetes.config.Port)3 AddLivenessProbeDecorator (io.dekorate.kubernetes.decorator.AddLivenessProbeDecorator)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 AddConfigMapVolumeDecorator (io.dekorate.kubernetes.decorator.AddConfigMapVolumeDecorator)2 AddSecretVolumeDecorator (io.dekorate.kubernetes.decorator.AddSecretVolumeDecorator)2 ApplyLimitsCpuDecorator (io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator)2 ApplyLimitsMemoryDecorator (io.dekorate.kubernetes.decorator.ApplyLimitsMemoryDecorator)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 ConfigMapVolumeBuilder (io.dekorate.kubernetes.config.ConfigMapVolumeBuilder)1