Skip to content

Commit 672b468

Browse files
committed
Remove redundant image policy.
1 parent 0a207ca commit 672b468

File tree

3 files changed

+16
-135
lines changed

3 files changed

+16
-135
lines changed

deploy/helm/spark-k8s-operator/crds/crds.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10163,23 +10163,6 @@ spec:
1016310163
nullable: true
1016410164
type: string
1016510165
type: object
10166-
sparkImagePullPolicy:
10167-
enum:
10168-
- Always
10169-
- IfNotPresent
10170-
- Never
10171-
nullable: true
10172-
type: string
10173-
sparkImagePullSecrets:
10174-
items:
10175-
description: LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace.
10176-
properties:
10177-
name:
10178-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
10179-
type: string
10180-
type: object
10181-
nullable: true
10182-
type: array
1018310166
stopped:
1018410167
nullable: true
1018510168
type: boolean

rust/crd/src/lib.rs

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ use stackable_operator::{
3636
merge::{Atomic, Merge},
3737
},
3838
k8s_openapi::{
39-
api::core::v1::{
40-
EmptyDirVolumeSource, EnvVar, LocalObjectReference, PodTemplateSpec, Volume,
41-
VolumeMount,
42-
},
39+
api::core::v1::{EmptyDirVolumeSource, EnvVar, PodTemplateSpec, Volume, VolumeMount},
4340
apimachinery::pkg::api::resource::Quantity,
4441
},
4542
kube::{CustomResource, ResourceExt},
@@ -49,7 +46,7 @@ use stackable_operator::{
4946
role_utils::pod_overrides_schema,
5047
schemars::{self, JsonSchema},
5148
};
52-
use strum::{Display, EnumIter, EnumString};
49+
use strum::{Display, EnumIter};
5350

5451
#[derive(Snafu, Debug)]
5552
pub enum Error {
@@ -178,10 +175,6 @@ pub struct SparkApplicationSpec {
178175
#[serde(default, skip_serializing_if = "Option::is_none")]
179176
pub image: Option<String>,
180177
pub spark_image: ProductImage,
181-
#[serde(default, skip_serializing_if = "Option::is_none")]
182-
pub spark_image_pull_policy: Option<ImagePullPolicy>,
183-
#[serde(default, skip_serializing_if = "Option::is_none")]
184-
pub spark_image_pull_secrets: Option<Vec<LocalObjectReference>>,
185178
/// Name of the Vector aggregator discovery ConfigMap.
186179
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
187180
#[serde(skip_serializing_if = "Option::is_none")]
@@ -210,13 +203,6 @@ pub struct SparkApplicationSpec {
210203
pub log_file_directory: Option<LogFileDirectorySpec>,
211204
}
212205

213-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize, Display, EnumString)]
214-
pub enum ImagePullPolicy {
215-
Always,
216-
IfNotPresent,
217-
Never,
218-
}
219-
220206
#[derive(Clone, Debug, Default, Deserialize, JsonSchema, PartialEq, Eq, Serialize)]
221207
#[serde(rename_all = "camelCase")]
222208
pub struct JobDependencies {
@@ -247,14 +233,6 @@ impl SparkApplication {
247233
self.spec.image.as_deref()
248234
}
249235

250-
pub fn spark_image_pull_policy(&self) -> Option<ImagePullPolicy> {
251-
self.spec.spark_image_pull_policy.clone()
252-
}
253-
254-
pub fn spark_image_pull_secrets(&self) -> Option<Vec<LocalObjectReference>> {
255-
self.spec.spark_image_pull_secrets.clone()
256-
}
257-
258236
pub fn version(&self) -> Option<&str> {
259237
self.spec.version.as_deref()
260238
}
@@ -1072,11 +1050,9 @@ impl ExecutorConfig {
10721050

10731051
#[cfg(test)]
10741052
mod tests {
1075-
use crate::{
1076-
cores_from_quantity, resources_to_executor_props, ExecutorConfig, ImagePullPolicy,
1077-
};
1053+
use crate::DriverConfig;
1054+
use crate::{cores_from_quantity, resources_to_executor_props, ExecutorConfig};
10781055
use crate::{resources_to_driver_props, SparkApplication};
1079-
use crate::{DriverConfig, LocalObjectReference};
10801056
use crate::{Quantity, SparkStorageConfig};
10811057
use rstest::rstest;
10821058
use stackable_operator::builder::ObjectMetaBuilder;
@@ -1087,7 +1063,6 @@ mod tests {
10871063
use stackable_operator::k8s_openapi::api::core::v1::PodTemplateSpec;
10881064
use stackable_operator::product_logging::spec::Logging;
10891065
use std::collections::{BTreeMap, HashMap};
1090-
use std::str::FromStr;
10911066

10921067
#[test]
10931068
fn test_spark_examples_s3() {
@@ -1258,75 +1233,6 @@ spec:
12581233
assert!(spark_application.spec.image.is_none());
12591234
}
12601235

1261-
#[test]
1262-
fn test_image_actions() {
1263-
let spark_application = serde_yaml::from_str::<SparkApplication>(
1264-
r#"
1265-
---
1266-
apiVersion: spark.stackable.tech/v1alpha1
1267-
kind: SparkApplication
1268-
metadata:
1269-
name: spark-pi-local
1270-
namespace: default
1271-
spec:
1272-
version: "1.0"
1273-
sparkImage:
1274-
productVersion: 3.2.1
1275-
sparkImagePullPolicy: Always
1276-
sparkImagePullSecrets:
1277-
- name: myregistrykey
1278-
mode: cluster
1279-
mainClass: org.apache.spark.examples.SparkPi
1280-
mainApplicationFile: local:///stackable/spark/examples/jars/spark-examples.jar
1281-
sparkConf:
1282-
spark.kubernetes.node.selector.node: "2"
1283-
driver:
1284-
cores: 1
1285-
coreLimit: "1200m"
1286-
memory: "512m"
1287-
executor:
1288-
cores: 1
1289-
instances: 1
1290-
memory: "512m"
1291-
"#,
1292-
)
1293-
.unwrap();
1294-
1295-
assert_eq!(
1296-
Some(vec![LocalObjectReference {
1297-
name: Some("myregistrykey".to_string())
1298-
}]),
1299-
spark_application.spark_image_pull_secrets()
1300-
);
1301-
assert_eq!(
1302-
Some(ImagePullPolicy::Always),
1303-
spark_application.spark_image_pull_policy()
1304-
);
1305-
}
1306-
1307-
#[test]
1308-
fn test_image_pull_policy_ser() {
1309-
assert_eq!("Never", ImagePullPolicy::Never.to_string());
1310-
assert_eq!("Always", ImagePullPolicy::Always.to_string());
1311-
assert_eq!("IfNotPresent", ImagePullPolicy::IfNotPresent.to_string());
1312-
}
1313-
1314-
#[test]
1315-
fn test_image_pull_policy_de() {
1316-
assert_eq!(
1317-
ImagePullPolicy::Always,
1318-
ImagePullPolicy::from_str("Always").unwrap()
1319-
);
1320-
assert_eq!(
1321-
ImagePullPolicy::Never,
1322-
ImagePullPolicy::from_str("Never").unwrap()
1323-
);
1324-
assert_eq!(
1325-
ImagePullPolicy::IfNotPresent,
1326-
ImagePullPolicy::from_str("IfNotPresent").unwrap()
1327-
);
1328-
}
1329-
13301236
#[test]
13311237
fn test_default_resource_limits() {
13321238
let spark_application = serde_yaml::from_str::<SparkApplication>(

rust/operator-binary/src/spark_k8s_controller.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn init_containers(
325325
logging: &Logging<SparkContainer>,
326326
s3conn: &Option<S3ConnectionSpec>,
327327
s3logdir: &Option<S3LogDir>,
328-
spark_image: &str,
328+
spark_image: &ResolvedProductImage,
329329
) -> Result<Vec<Container>> {
330330
let mut jcb = ContainerBuilder::new(&SparkContainer::Job.to_string())
331331
.context(IllegalContainerNameSnafu)?;
@@ -383,14 +383,12 @@ fn init_containers(
383383
"pip install --target={VOLUME_MOUNT_PATH_REQ} {req}"
384384
));
385385

386-
rcb.image(spark_image)
386+
rcb.image(&spark_image.image)
387387
.command(vec!["/bin/bash".to_string(), "-c".to_string()])
388388
.args(vec![args.join(" && ")])
389389
.add_volume_mount(VOLUME_MOUNT_NAME_REQ, VOLUME_MOUNT_PATH_REQ)
390-
.add_volume_mount(VOLUME_MOUNT_NAME_LOG, VOLUME_MOUNT_PATH_LOG);
391-
if let Some(image_pull_policy) = spark_application.spark_image_pull_policy() {
392-
rcb.image_pull_policy(image_pull_policy.to_string());
393-
}
390+
.add_volume_mount(VOLUME_MOUNT_NAME_LOG, VOLUME_MOUNT_PATH_LOG)
391+
.image_pull_policy(&spark_image.image_pull_policy);
394392

395393
rcb.resources(
396394
ResourceRequirementsBuilder::new()
@@ -418,7 +416,7 @@ fn init_containers(
418416
format!("{STACKABLE_MOUNT_PATH_TLS}/{cert_secret}"),
419417
);
420418
}
421-
tcb.image(spark_image)
419+
tcb.image(&spark_image.image)
422420
.command(vec!["/bin/bash".to_string(), "-c".to_string()])
423421
.args(vec![args.join(" && ")])
424422
.add_volume_mount(STACKABLE_TRUST_STORE_NAME, STACKABLE_TRUST_STORE)
@@ -453,7 +451,8 @@ fn pod_template(
453451
let mut cb = ContainerBuilder::new(&container_name).context(IllegalContainerNameSnafu)?;
454452
cb.add_volume_mounts(config.volume_mounts.clone())
455453
.add_env_vars(env.to_vec())
456-
.resources(config.resources.clone().into());
454+
.resources(config.resources.clone().into())
455+
.image_pull_policy(&spark_image.image_pull_policy);
457456

458457
if config.logging.enable_vector_agent {
459458
cb.add_env_var(
@@ -467,10 +466,6 @@ fn pod_template(
467466
);
468467
}
469468

470-
if let Some(image_pull_policy) = spark_application.spark_image_pull_policy() {
471-
cb.image_pull_policy(image_pull_policy.to_string());
472-
}
473-
474469
let mut pb = PodBuilder::new();
475470
pb.metadata(
476471
ObjectMetaBuilder::new()
@@ -493,15 +488,15 @@ fn pod_template(
493488
&config.logging,
494489
s3conn,
495490
s3logdir,
496-
&spark_image.image,
491+
spark_image,
497492
)
498493
.unwrap();
499494

500495
for init_container in init_containers {
501496
pb.add_init_container(init_container.clone());
502497
}
503498

504-
if let Some(image_pull_secrets) = spark_application.spark_image_pull_secrets() {
499+
if let Some(image_pull_secrets) = spark_image.pull_secrets.as_ref() {
505500
pb.image_pull_secrets(
506501
image_pull_secrets
507502
.iter()
@@ -697,11 +692,8 @@ fn spark_job(
697692
),
698693
)
699694
// TODO: move this to the image
700-
.add_env_var("SPARK_CONF_DIR", "/stackable/spark/conf");
701-
702-
if let Some(image_pull_policy) = spark_application.spark_image_pull_policy() {
703-
cb.image_pull_policy(image_pull_policy.to_string());
704-
}
695+
.add_env_var("SPARK_CONF_DIR", "/stackable/spark/conf")
696+
.image_pull_policy(&spark_image.image_pull_policy);
705697

706698
let mut volumes = vec![
707699
VolumeBuilder::new(VOLUME_MOUNT_NAME_CONFIG)
@@ -754,7 +746,7 @@ fn spark_job(
754746
restart_policy: Some("Never".to_string()),
755747
service_account_name: serviceaccount.metadata.name.clone(),
756748
volumes: Some(volumes),
757-
image_pull_secrets: spark_application.spark_image_pull_secrets(),
749+
image_pull_secrets: spark_image.pull_secrets.clone(),
758750
security_context: Some(security_context()),
759751
..PodSpec::default()
760752
}),

0 commit comments

Comments
 (0)