Skip to content

Add ListenerOperatorVolumeSourceBuilder::build_pvc #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ All notable changes to this project will be documented in this file.
### Added

- Added `Option::as_ref_or_else` to `utils` ([#717]).
- Added `ListenerOperatorVolumeSourceBuilder::build_pvc` ([#719]).

### Changed

- Split `utils` into submodules ([#717]).
- Renamed `ListenerOperatorVolumeSourceBuilder::build` to `::build_ephemeral` ([#719]).

[#717]: https://github.com/stackabletech/operator-rs/pull/717
[#719]: https://github.com/stackabletech/operator-rs/pull/719

## [0.61.0] - 2024-01-15

Expand Down
4 changes: 2 additions & 2 deletions src/builder/pod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl PodBuilder {
) -> Result<&mut Self> {
let listener_reference = ListenerReference::ListenerClass(listener_class.to_string());
let volume = ListenerOperatorVolumeSourceBuilder::new(&listener_reference)
.build()
.build_ephemeral()
.context(ListenerVolumeSnafu { name: volume_name })?;

self.add_volume(Volume {
Expand Down Expand Up @@ -440,7 +440,7 @@ impl PodBuilder {
) -> Result<&mut Self> {
let listener_reference = ListenerReference::ListenerName(listener_name.to_string());
let volume = ListenerOperatorVolumeSourceBuilder::new(&listener_reference)
.build()
.build_ephemeral()
.context(ListenerVolumeSnafu { name: volume_name })?;

self.add_volume(Volume {
Expand Down
60 changes: 46 additions & 14 deletions src/builder/pod/volume.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use k8s_openapi::{
api::core::v1::{
CSIVolumeSource, ConfigMapVolumeSource, DownwardAPIVolumeSource, EmptyDirVolumeSource,
EphemeralVolumeSource, HostPathVolumeSource, PersistentVolumeClaimSpec,
PersistentVolumeClaimTemplate, PersistentVolumeClaimVolumeSource, ProjectedVolumeSource,
ResourceRequirements, SecretVolumeSource, Volume, VolumeMount,
EphemeralVolumeSource, HostPathVolumeSource, PersistentVolumeClaim,
PersistentVolumeClaimSpec, PersistentVolumeClaimTemplate,
PersistentVolumeClaimVolumeSource, ProjectedVolumeSource, ResourceRequirements,
SecretVolumeSource, Volume, VolumeMount,
},
apimachinery::pkg::api::resource::Quantity,
};
Expand Down Expand Up @@ -461,8 +462,27 @@ impl ListenerOperatorVolumeSourceBuilder {
}
}

/// Build an [`EphemeralVolumeSource`] from the builder
fn build_spec(&self) -> PersistentVolumeClaimSpec {
PersistentVolumeClaimSpec {
storage_class_name: Some("listeners.stackable.tech".to_string()),
resources: Some(ResourceRequirements {
requests: Some([("storage".to_string(), Quantity("1".to_string()))].into()),
..ResourceRequirements::default()
}),
access_modes: Some(vec!["ReadWriteMany".to_string()]),
..PersistentVolumeClaimSpec::default()
}
}

#[deprecated(note = "renamed to `build_ephemeral`", since = "0.61.1")]
pub fn build(&self) -> Result<EphemeralVolumeSource, ListenerOperatorVolumeSourceBuilderError> {
self.build_ephemeral()
}

/// Build an [`EphemeralVolumeSource`] from the builder.
pub fn build_ephemeral(
&self,
) -> Result<EphemeralVolumeSource, ListenerOperatorVolumeSourceBuilderError> {
let listener_reference_annotation = self
.listener_reference
.to_annotation()
Expand All @@ -475,18 +495,30 @@ impl ListenerOperatorVolumeSourceBuilder {
.with_annotation(listener_reference_annotation)
.build(),
),
spec: PersistentVolumeClaimSpec {
storage_class_name: Some("listeners.stackable.tech".to_string()),
resources: Some(ResourceRequirements {
requests: Some([("storage".to_string(), Quantity("1".to_string()))].into()),
..ResourceRequirements::default()
}),
access_modes: Some(vec!["ReadWriteMany".to_string()]),
..PersistentVolumeClaimSpec::default()
},
spec: self.build_spec(),
}),
})
}

/// Build a [`PersistentVolumeClaim`] from the builder.
pub fn build_pvc(
&self,
name: impl Into<String>,
) -> Result<PersistentVolumeClaim, ListenerOperatorVolumeSourceBuilderError> {
let listener_reference_annotation = self
.listener_reference
.to_annotation()
.context(ListenerReferenceAnnotationSnafu)?;

Ok(PersistentVolumeClaim {
metadata: ObjectMetaBuilder::new()
.name(name)
.with_annotation(listener_reference_annotation)
.build(),
spec: Some(self.build_spec()),
..Default::default()
})
}
}

#[cfg(test)]
Expand Down Expand Up @@ -556,7 +588,7 @@ mod tests {
"public".into(),
));

let volume_source = builder.build().unwrap();
let volume_source = builder.build_ephemeral().unwrap();

let volume_claim_template = volume_source.volume_claim_template;
let annotations = volume_claim_template
Expand Down