@@ -144,14 +144,42 @@ impl SecurityContextBuilder {
144144 }
145145}
146146
147- #[ derive( Clone , Default ) ]
147+ /// A builder to construct a [`PodSecurityContext`].
148+ ///
149+ /// # Basic usage
150+ ///
151+ /// ```
152+ /// use stackable_operator::builder::pod::security::PodSecurityContextBuilder;
153+ ///
154+ /// let _ = PodSecurityContextBuilder::with_stackable_defaults()
155+ /// // Configure any arbitrary fields
156+ /// .run_as_user(1234)
157+ /// .build();
158+ /// ```
159+ #[ derive( Clone , Debug ) ]
148160pub struct PodSecurityContextBuilder {
149161 pod_security_context : PodSecurityContext ,
150162}
151163
152164impl PodSecurityContextBuilder {
153- pub fn new ( ) -> Self {
154- Self :: default ( )
165+ /// Construct a new [`PodSecurityContextBuilder`] that is pre-filled with Stackable's defaults.
166+ pub fn with_stackable_defaults ( ) -> Self {
167+ Self {
168+ pod_security_context : Self :: stackable_default_pod_security_context ( ) ,
169+ }
170+ }
171+
172+ /// The Stackable's defaults for a [`PodSecurityContext`].
173+ ///
174+ /// It is recommended to use the [`PodSecurityContextBuilder::with_stackable_defaults`] instead
175+ /// (if possible).
176+ pub fn stackable_default_pod_security_context ( ) -> PodSecurityContext {
177+ todo ! ( "Lars needs to define the exact settings he wants" ) ;
178+
179+ PodSecurityContext {
180+ run_as_non_root : Some ( true ) ,
181+ ..Default :: default ( )
182+ }
155183 }
156184
157185 pub fn build ( & self ) -> PodSecurityContext {
@@ -173,8 +201,8 @@ impl PodSecurityContextBuilder {
173201 self
174202 }
175203
176- pub fn run_as_non_root ( & mut self ) -> & mut Self {
177- self . pod_security_context . run_as_non_root = Some ( true ) ;
204+ pub fn run_as_non_root ( & mut self , non_root : bool ) -> & mut Self {
205+ self . pod_security_context . run_as_non_root = Some ( non_root ) ;
178206 self
179207 }
180208
@@ -381,13 +409,13 @@ mod tests {
381409
382410 #[ test]
383411 fn security_context_builder ( ) {
384- let mut builder = PodSecurityContextBuilder :: new ( ) ;
412+ let mut builder = PodSecurityContextBuilder :: with_stackable_defaults ( ) ;
385413 let context = builder
386414 . fs_group ( 1000 )
387415 . fs_group_change_policy ( "policy" )
388416 . run_as_user ( 1001 )
389417 . run_as_group ( 1001 )
390- . run_as_non_root ( )
418+ . run_as_non_root ( true )
391419 . supplemental_groups ( & [ 1002 , 1003 ] )
392420 . se_linux_level ( "level" )
393421 . se_linux_role ( "role" )
0 commit comments