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