3
3
pub mod constants;
4
4
5
5
use constants:: * ;
6
- use stackable_operator:: k8s_openapi:: api:: core:: v1:: { EnvVar , Volume , VolumeMount } ;
6
+ use stackable_operator:: k8s_openapi:: api:: core:: v1:: {
7
+ EnvVar , EnvVarSource , SecretKeySelector , Volume , VolumeMount ,
8
+ } ;
7
9
8
10
use std:: collections:: { BTreeMap , HashMap } ;
9
11
@@ -77,6 +79,8 @@ pub struct SparkApplicationSpec {
77
79
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
78
80
pub deps : Option < JobDependencies > ,
79
81
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
82
+ pub s3 : Option < S3 > ,
83
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
80
84
pub args : Option < Vec < String > > ,
81
85
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
82
86
pub volumes : Option < Vec < Volume > > ,
@@ -97,6 +101,14 @@ pub struct JobDependencies {
97
101
pub exclude_packages : Option < Vec < String > > ,
98
102
}
99
103
104
+ #[ derive( Clone , Debug , Default , Deserialize , JsonSchema , PartialEq , Serialize ) ]
105
+ #[ serde( rename_all = "camelCase" ) ]
106
+ pub struct S3 {
107
+ pub credentials_secret : String ,
108
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
109
+ pub endpoint : Option < String > ,
110
+ }
111
+
100
112
impl SparkApplication {
101
113
pub fn enable_monitoring ( & self ) -> Option < bool > {
102
114
let spec: & SparkApplicationSpec = & self . spec ;
@@ -136,7 +148,20 @@ impl SparkApplication {
136
148
137
149
pub fn env ( & self ) -> Vec < EnvVar > {
138
150
let tmp = self . spec . env . as_ref ( ) ;
139
- tmp. iter ( ) . flat_map ( |e| e. iter ( ) ) . cloned ( ) . collect ( )
151
+ let mut e: Vec < EnvVar > = tmp. iter ( ) . flat_map ( |e| e. iter ( ) ) . cloned ( ) . collect ( ) ;
152
+ if let Some ( s3) = self . spec . s3 . as_ref ( ) {
153
+ e. push ( env_var_from_secret (
154
+ ENV_AWS_ACCESS_KEY_ID ,
155
+ & s3. credentials_secret ,
156
+ ACCESS_KEY_ID ,
157
+ ) ) ;
158
+ e. push ( env_var_from_secret (
159
+ ENV_AWS_SECRET_ACCESS_KEY ,
160
+ & s3. credentials_secret ,
161
+ SECRET_ACCESS_KEY ,
162
+ ) ) ;
163
+ }
164
+ e
140
165
}
141
166
142
167
pub fn volumes ( & self ) -> Vec < Volume > {
@@ -195,12 +220,12 @@ impl SparkApplication {
195
220
format!( "--conf spark.kubernetes.driver.container.image={}" , self . spec. spark_image. as_ref( ) . context( NoSparkImageSnafu ) ?) ,
196
221
format!( "--conf spark.kubernetes.executor.container.image={}" , self . spec. spark_image. as_ref( ) . context( NoSparkImageSnafu ) ?) ,
197
222
format!( "--conf spark.kubernetes.authenticate.driver.serviceAccountName={}" , serviceaccount_name) ,
198
- //"--conf spark.kubernetes.file.upload.path=s3a://stackable-spark-k8s-jars/jobs".to_string(),
199
- //"--conf spark.hadoop.fs.s3a.impl=org.apache.hadoop.fs.s3a.S3AFileSystem".to_string(),
200
- //"--conf spark.driver.extraClassPath=/stackable/.ivy2/cache".to_string(),
201
- //"--conf spark.hadoop.fs.s3a.fast.upload=true".to_string(),
202
223
] ;
203
224
225
+ if let Some ( endpoint) = self . spec . s3 . as_ref ( ) . and_then ( |s3| s3. endpoint . as_ref ( ) ) {
226
+ submit_cmd. push ( format ! ( "--conf spark.hadoop.fs.s3a.endpoint={}" , endpoint) ) ;
227
+ }
228
+
204
229
// conf arguments that are not driver or executor specific
205
230
if let Some ( spark_conf) = self . spec . spark_conf . clone ( ) {
206
231
for ( key, value) in spark_conf {
@@ -325,6 +350,21 @@ pub struct CommandStatus {
325
350
pub finished_at : Option < Time > ,
326
351
}
327
352
353
+ fn env_var_from_secret ( var_name : & str , secret : & str , secret_key : & str ) -> EnvVar {
354
+ EnvVar {
355
+ name : String :: from ( var_name) ,
356
+ value_from : Some ( EnvVarSource {
357
+ secret_key_ref : Some ( SecretKeySelector {
358
+ name : Some ( String :: from ( secret) ) ,
359
+ key : String :: from ( secret_key) ,
360
+ ..Default :: default ( )
361
+ } ) ,
362
+ ..Default :: default ( )
363
+ } ) ,
364
+ ..Default :: default ( )
365
+ }
366
+ }
367
+
328
368
#[ cfg( test) ]
329
369
mod tests {
330
370
use crate :: SparkApplication ;
0 commit comments