Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub use toleration::TolerationExt;
pub use typed_object_reference::TypedObjectReferenceExt;
pub use volume::VolumeExt;
pub use volume_mount::VolumeMountExt;
pub use stateful_set::StatefulSetExt;

use effect::Effect;

Expand Down Expand Up @@ -89,6 +90,7 @@ mod security_context;
mod service;
mod service_account;
mod service_port;
mod stateful_set;
mod storage_class;
mod subject;
mod taint;
Expand Down
18 changes: 9 additions & 9 deletions src/ext/container_port.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
use super::*;

pub trait ContainerPortExt: Sized {
fn new(port: i32, protocol: impl ToString) -> Self;
fn new(port: impl Into<i32>, protocol: impl ToString) -> Self;

fn tcp(port: i32) -> Self {
fn tcp(port: impl Into<i32>) -> Self {
Self::new(port, "TCP")
}

fn udp(port: i32) -> Self {
fn udp(port: impl Into<i32>) -> Self {
Self::new(port, "UDP")
}

fn sctp(port: i32) -> Self {
fn sctp(port: impl Into<i32>) -> Self {
Self::new(port, "SCTP")
}

fn name(self, name: impl ToString) -> Self;

fn host_ip(self, ip: impl ToString) -> Self;

fn host_port(self, port: i32) -> Self;
fn host_port(self, port: impl Into<i32>) -> Self;
}

impl ContainerPortExt for corev1::ContainerPort {
fn new(port: i32, protocol: impl ToString) -> Self {
fn new(port: impl Into<i32>, protocol: impl ToString) -> Self {
let protocol = Some(protocol.to_string());
Self {
container_port: port,
container_port: port.into(),
protocol,
// host_ip: (),
// host_port: (),
Expand All @@ -45,8 +45,8 @@ impl ContainerPortExt for corev1::ContainerPort {
Self { host_ip, ..self }
}

fn host_port(self, port: i32) -> Self {
let host_port = Some(port);
fn host_port(self, port: impl Into<i32>) -> Self {
let host_port = Some(port.into());
Self { host_port, ..self }
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/ext/service_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
pub trait ServicePortExt {
/// Construct new `ServicePort`
///
fn new(name: impl ToString, port: i32) -> Self;
fn new(name: impl ToString, port: impl Into<i32>) -> Self;

/// Set targetPort
///
Expand All @@ -15,7 +15,7 @@ pub trait ServicePortExt {

/// Create TCP ServicePort
///
fn tcp(name: impl ToString, port: i32) -> Self
fn tcp(name: impl ToString, port: impl Into<i32>) -> Self
where
Self: Sized,
{
Expand All @@ -24,7 +24,7 @@ pub trait ServicePortExt {

/// Create UDP ServicePort
///
fn udp(name: impl ToString, port: i32) -> Self
fn udp(name: impl ToString, port: impl Into<i32>) -> Self
where
Self: Sized,
{
Expand All @@ -33,7 +33,7 @@ pub trait ServicePortExt {

/// Create SCTP ServicePort
///
fn sctp(name: impl ToString, port: i32) -> Self
fn sctp(name: impl ToString, port: impl Into<i32>) -> Self
where
Self: Sized,
{
Expand All @@ -42,8 +42,9 @@ pub trait ServicePortExt {
}

impl ServicePortExt for corev1::ServicePort {
fn new(name: impl ToString, port: i32) -> Self {
fn new(name: impl ToString, port: impl Into<i32>) -> Self {
let name = Some(name.to_string());
let port = port.into();
Self {
name,
port,
Expand Down
88 changes: 88 additions & 0 deletions src/ext/stateful_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use super::*;

pub trait StatefulSetExt: super::ResourceBuilder {
fn new(name: impl ToString) -> Self;
fn with_labels(
name: impl ToString,
labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self;

fn replicas(self, replicas: i32) -> Self;

fn revision_history_limit(self, limit: i32) -> Self;

fn selector(self, selector: metav1::LabelSelector) -> Self;

fn match_labels(
self,
match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self;

fn template(self, template: corev1::PodTemplateSpec) -> Self;

fn pod(self, pod: corev1::PodSpec) -> Self;
}

impl StatefulSetExt for appsv1::StatefulSet {
fn new(name: impl ToString) -> Self {
let metadata = metadata(name);
Self {
metadata,
// spec: todo!(),
// status: todo!(),
..default()
}
}

fn with_labels(
name: impl ToString,
labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self {
Self::new(name).labels(labels)
}

fn replicas(mut self, replicas: i32) -> Self {
self.spec_mut().replicas.replace(replicas);
self
}

fn revision_history_limit(mut self, limit: i32) -> Self {
self.spec_mut().revision_history_limit.replace(limit);
self
}

fn selector(mut self, selector: metav1::LabelSelector) -> Self {
self.spec_mut().selector = selector;
self
}

fn match_labels(
self,
match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self {
let mut spec = self.spec.unwrap_or_default();
spec.selector = spec.selector.match_labels(match_labels);
Self {
spec: Some(spec),
..self
}
}

fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
self.spec_mut().template = template;
self
}

fn pod(mut self, pod_spec: corev1::PodSpec) -> Self {
self.spec_mut().template.spec.replace(pod_spec);
self
}
}

impl HasSpec for appsv1::StatefulSet {
type Spec = appsv1::StatefulSetSpec;

fn spec_mut(&mut self) -> &mut Self::Spec {
self.spec.get_or_insert_default()
}
}
39 changes: 39 additions & 0 deletions src/ext/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::*;
pub trait VolumeExt: Sized {
fn secret(name: impl ToString, secret: corev1::SecretVolumeSource) -> Self;
fn configmap(name: impl ToString, configmap: corev1::ConfigMapVolumeSource) -> Self;
fn emptydir(name: impl ToString, emptydir: corev1::EmptyDirVolumeSource) -> Self;
}

impl VolumeExt for corev1::Volume {
Expand Down Expand Up @@ -81,4 +82,42 @@ impl VolumeExt for corev1::Volume {
..default()
}
}

fn emptydir(name: impl ToString, emptydir: corev1::EmptyDirVolumeSource) -> Self {
let name = name.to_string();
Self {
name,
empty_dir: Some(emptydir),
// aws_elastic_block_store: todo!(),
// azure_disk: todo!(),
// azure_file: todo!(),
// cephfs: todo!(),
// cinder: todo!(),
// config_map: todo!(),
// csi: todo!(),
// downward_api: todo!(),
// ephemeral: todo!(),
// fc: todo!(),
// flex_volume: todo!(),
// flocker: todo!(),
// gce_persistent_disk: todo!(),
// git_repo: todo!(),
// glusterfs: todo!(),
// host_path: todo!(),
// image: todo!(),
// iscsi: todo!(),
// nfs: todo!(),
// persistent_volume_claim: todo!(),
// photon_persistent_disk: todo!(),
// portworx_volume: todo!(),
// projected: todo!(),
// quobyte: todo!(),
// rbd: todo!(),
// scale_io: todo!(),
// secret: todo!(),
// storageos: todo!(),
// vsphere_volume: todo!(),
..default()
}
}
}
7 changes: 7 additions & 0 deletions src/ext/volume_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub trait VolumeMountExt: Sized {
fn new(mount_path: impl ToString, volume: &corev1::Volume) -> Self;

fn read_only(self) -> Self;

fn sub_path(self, path: impl ToString) -> Self;
}

impl VolumeMountExt for corev1::VolumeMount {
Expand All @@ -26,4 +28,9 @@ impl VolumeMountExt for corev1::VolumeMount {
self.read_only = Some(true);
self
}

fn sub_path(mut self, path: impl ToString) -> Self {
self.sub_path = Some(path.to_string());
self
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub use ext::SecurityContextExt;
pub use ext::ServiceAccountExt;
pub use ext::ServiceExt;
pub use ext::ServicePortExt;
pub use ext::StatefulSetExt;
pub use ext::StorageClassExt;
pub use ext::SubjectExt;
pub use ext::TaintExt;
Expand Down