Skip to content

Commit 61b649b

Browse files
committed
add image_pull_policy for containers
1 parent f1b1a82 commit 61b649b

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
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/status/pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ pub struct Pool {
2727

2828
#[derive(Deserialize, Serialize, Clone, Debug, Display)]
2929
pub enum PoolState {
30-
#[strum(serialize = "PoolCreated")]
30+
#[strum(to_string = "PoolCreated")]
3131
Created,
3232

33-
#[strum(serialize = "PoolNotCreated")]
33+
#[strum(to_string = "PoolNotCreated")]
3434
NotCreated,
3535

36-
#[strum(serialize = "PoolInitialized")]
36+
#[strum(to_string = "PoolInitialized")]
3737
Initialized,
3838
}
3939

src/types/v1alpha1/status/state.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ use strum::Display;
1616

1717
#[derive(Display)]
1818
pub enum State {
19-
#[strum(serialize = "Initialized")]
19+
#[strum(to_string = "Initialized")]
2020
Initialized,
2121

22-
#[strum(serialize = "Statefulset not controlled by operator")]
22+
#[strum(to_string = "Statefulset not controlled by operator")]
2323
NotOwned,
2424

25-
#[strum(serialize = "Pool Decommissioning Not Allowed")]
25+
#[strum(to_string = "Pool Decommissioning Not Allowed")]
2626
DecommissioningNotAllowed,
2727

28-
#[strum(serialize = "Provisioning IO Service")]
28+
#[strum(to_string = "Provisioning IO Service")]
2929
ProvisioningIOService,
3030

31-
#[strum(serialize = "Provisioning Console Service")]
31+
#[strum(to_string = "Provisioning Console Service")]
3232
ProvisioningConsoleService,
3333

34-
#[strum(serialize = "Provisioning Headless Service")]
34+
#[strum(to_string = "Provisioning Headless Service")]
3535
ProvisioningHeadlessService,
3636

37-
#[strum(serialize = "Multiple tenants exist in the namespace")]
37+
#[strum(to_string = "Multiple tenants exist in the namespace")]
3838
MultipleTenantsExist,
3939
}

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)