Skip to content

Commit 09ea9d9

Browse files
committed
add image_pull_policy for containers
1 parent f1b1a82 commit 09ea9d9

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/reconcile.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use kube::runtime::controller::Action;
2020
use snafu::Snafu;
2121
use std::sync::Arc;
2222
use std::time::Duration;
23-
use tracing::error;
23+
use tracing::{debug, error};
2424

2525
#[derive(Snafu, Debug)]
2626
pub enum Error {
@@ -36,6 +36,11 @@ pub async fn reconcile_rustfs(tenant: Arc<Tenant>, ctx: Arc<Context>) -> Result<
3636
let latest_tenant = ctx.get::<Tenant>(&tenant.name(), &ns).await?;
3737

3838
if latest_tenant.metadata.deletion_timestamp.is_some() {
39+
debug!(
40+
"tenant {} is deleted, deletion_timestamp is {:?}",
41+
tenant.name(),
42+
latest_tenant.metadata.deletion_timestamp
43+
);
3944
return Ok(Action::await_change());
4045
}
4146

src/types/v1alpha1/k8s.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@
1616
1717
use k8s_openapi::schemars::JsonSchema;
1818
use serde::{Deserialize, Serialize};
19+
use strum::Display;
1920

2021
/// Pod management policy for StatefulSets
21-
#[derive(Default, Deserialize, Serialize, Clone, Debug, JsonSchema)]
22+
/// - OrderedReady: Respect the ordering guarantees demonstrated
23+
/// - Parallel: launch or terminate all Pods in parallel, and not to wait for Pods to become Running
24+
/// and Ready or completely terminated prior to launching or terminating another Pod
25+
///
26+
///https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#pod-management-policy
27+
#[derive(Default, Deserialize, Serialize, Clone, Debug, JsonSchema, Display)]
2228
#[serde(rename_all = "PascalCase")]
2329
#[schemars(rename_all = "PascalCase")]
2430
pub enum PodManagementPolicy {
31+
#[strum(to_string = "OrderedReady")]
2532
OrderedReady,
2633

34+
#[strum(to_string = "Parallel")]
2735
#[default]
2836
Parallel,
2937
}
@@ -32,12 +40,19 @@ pub enum PodManagementPolicy {
3240
/// - Always: Always pull the image
3341
/// - Never: Never pull the image
3442
/// - IfNotPresent: Pull the image if not present locally (default)
35-
#[derive(Default, Deserialize, Serialize, Clone, Debug, JsonSchema)]
43+
///
44+
/// https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy
45+
#[derive(Default, Deserialize, Serialize, Clone, Debug, JsonSchema, Display)]
3646
#[serde(rename_all = "PascalCase")]
3747
#[schemars(rename_all = "PascalCase")]
3848
pub enum ImagePullPolicy {
49+
#[strum(to_string = "Always")]
3950
Always,
51+
52+
#[strum(to_string = "Never")]
4053
Never,
54+
55+
#[strum(to_string = "IfNotPresent")]
4156
#[default]
4257
IfNotPresent,
4358
}

src/types/v1alpha1/tenant/workloads.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use super::Tenant;
1616
use crate::types;
17-
use crate::types::v1alpha1::k8s::PodManagementPolicy;
1817
use crate::types::v1alpha1::pool::Pool;
1918
use k8s_openapi::api::apps::v1;
2019
use k8s_openapi::api::core::v1 as corev1;
@@ -206,6 +205,11 @@ impl Tenant {
206205
lifecycle: self.spec.lifecycle.clone(),
207206
// Apply pool-level resource requirements to container
208207
resources: pool.scheduling.resources.clone(),
208+
image_pull_policy: self
209+
.spec
210+
.image_pull_policy
211+
.as_ref()
212+
.map(ToString::to_string),
209213
..Default::default()
210214
};
211215

@@ -220,10 +224,11 @@ impl Tenant {
220224
spec: Some(v1::StatefulSetSpec {
221225
replicas: Some(pool.servers),
222226
service_name: Some(self.headless_service_name()),
223-
pod_management_policy: Some(match self.spec.pod_management_policy {
224-
Some(PodManagementPolicy::Parallel) | None => "Parallel".to_owned(),
225-
Some(PodManagementPolicy::OrderedReady) => "OrderedReady".to_owned(),
226-
}),
227+
pod_management_policy: self
228+
.spec
229+
.pod_management_policy
230+
.as_ref()
231+
.map(ToString::to_string),
227232
selector: metav1::LabelSelector {
228233
match_labels: Some(selector_labels),
229234
..Default::default()

0 commit comments

Comments
 (0)