use of io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator 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.decorator.ApplyLimitsCpuDecorator in project quarkus by quarkusio.
the class KubernetesCommonHelper method createPodDecorators.
/**
* Creates pod decorator build items.
*
* @param target The deployment target (e.g. kubernetes, openshift, knative)
* @param name The name of the resource to accept the configuration
* @param config The {@link PlatformConfiguration} instance
*/
private static List<DecoratorBuildItem> createPodDecorators(Optional<Project> project, String target, String name, PlatformConfiguration config) {
List<DecoratorBuildItem> result = new ArrayList<>();
config.getImagePullSecrets().ifPresent(l -> {
l.forEach(s -> result.add(new DecoratorBuildItem(target, new AddImagePullSecretDecorator(name, s))));
});
config.getHostAliases().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(target, new AddHostAliasesDecorator(name, HostAliasConverter.convert(e))));
});
config.getServiceAccount().ifPresent(s -> {
result.add(new DecoratorBuildItem(target, new ApplyServiceAccountNameDecorator(name, s)));
});
config.getInitContainers().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(target, new AddInitContainerDecorator(name, ContainerConverter.convert(e))));
});
config.getSidecars().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(target, new AddSidecarDecorator(name, ContainerConverter.convert(e))));
});
config.getResources().limits.cpu.ifPresent(c -> {
result.add(new DecoratorBuildItem(target, new ApplyLimitsCpuDecorator(name, c)));
});
config.getResources().limits.memory.ifPresent(m -> {
result.add(new DecoratorBuildItem(target, new ApplyLimitsMemoryDecorator(name, m)));
});
config.getResources().requests.cpu.ifPresent(c -> {
result.add(new DecoratorBuildItem(target, new ApplyRequestsCpuDecorator(name, c)));
});
config.getResources().requests.memory.ifPresent(m -> {
result.add(new DecoratorBuildItem(target, new ApplyRequestsMemoryDecorator(name, m)));
});
if (config.getSecurityContext().isAnyPropertySet()) {
result.add(new DecoratorBuildItem(target, new ApplySecuritySettingsDecorator(name, config.getSecurityContext())));
}
return result;
}
use of io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator 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());
}
Aggregations