Skip to content

Commit

Permalink
Group and re-order imports, use ResourceRequirementsBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Jul 7, 2023
1 parent 68d4acd commit 6c39bd2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/builder/pod/container.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fmt;

use k8s_openapi::api::core::v1::{
ConfigMapKeySelector, Container, ContainerPort, EnvVar, EnvVarSource, ObjectFieldSelector,
Probe, ResourceRequirements, SecretKeySelector, SecurityContext, VolumeMount,
};
use std::fmt;

use crate::{
commons::product_image_selection::ResolvedProductImage, error::Error,
Expand Down
55 changes: 27 additions & 28 deletions src/builder/pod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ pub mod volume;

use std::collections::BTreeMap;

use crate::builder::meta::ObjectMetaBuilder;
use crate::commons::affinity::StackableAffinity;
use crate::commons::product_image_selection::ResolvedProductImage;
use crate::commons::resources::{
ComputeResource, ResourceRequirementsExt, ResourceRequirementsType, LIMIT_REQUEST_RATIO_CPU,
LIMIT_REQUEST_RATIO_MEMORY,
};
use crate::error::{Error, OperatorResult};

use super::{ListenerOperatorVolumeSourceBuilder, ListenerReference, VolumeBuilder};
use k8s_openapi::{
api::core::v1::{
Affinity, Container, LocalObjectReference, NodeAffinity, Pod, PodAffinity, PodAntiAffinity,
PodCondition, PodSecurityContext, PodSpec, PodStatus, PodTemplateSpec,
ResourceRequirements, Toleration, Volume,
PodCondition, PodSecurityContext, PodSpec, PodStatus, PodTemplateSpec, Toleration, Volume,
},
apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::ObjectMeta},
};
use tracing::warn;

use crate::{
builder::{
meta::ObjectMetaBuilder, resources::ResourceRequirementsBuilder,
ListenerOperatorVolumeSourceBuilder, ListenerReference, VolumeBuilder,
},
commons::{
affinity::StackableAffinity,
product_image_selection::ResolvedProductImage,
resources::{
ComputeResource, ResourceRequirementsExt, ResourceRequirementsType,
LIMIT_REQUEST_RATIO_CPU, LIMIT_REQUEST_RATIO_MEMORY,
},
},
error::{Error, OperatorResult},
};

/// A builder to build [`Pod`] or [`PodTemplateSpec`] objects.
#[derive(Clone, Default)]
pub struct PodBuilder {
Expand Down Expand Up @@ -187,22 +192,16 @@ impl PodBuilder {
// instead be set inside the container builder. Having container types
// should greatly simplify setting the default resource requirements.
// This method should instead be "as dumb" as it can be and should
// simply add the provided container to the internal vector. The problem
// with the solution down below is that wie side-step the common
// interface provided by the `with_resource`, `with_cpu` and
// `with_memory` methods of the builder.

if container.resources.is_none() {
let limits = Some(BTreeMap::from([
("cpu".to_string(), Quantity("10m".to_string())),
("memory".to_string(), Quantity("128Mi".to_string())),
]));
container.resources = Some(ResourceRequirements {
limits: limits.clone(),
requests: limits,
..ResourceRequirements::default()
});
}
// simply add the provided container to the internal vector.

container.resources = container.resources.or(Some(
ResourceRequirementsBuilder::new()
.with_cpu_request("10m")
.with_cpu_limit("10m")
.with_memory_request("128Mi")
.with_memory_limit("128Mi")
.build(),
));

self.init_containers
.get_or_insert_with(Vec::new)
Expand Down

0 comments on commit 6c39bd2

Please sign in to comment.