@@ -38,9 +38,10 @@ impl SecretClassVolume {
3838
3939 pub fn to_ephemeral_volume_source (
4040 & self ,
41+ provision_parts : SecretClassVolumeProvisionParts ,
4142 ) -> Result < EphemeralVolumeSource , SecretClassVolumeError > {
4243 let mut secret_operator_volume_builder =
43- SecretOperatorVolumeSourceBuilder :: new ( & self . secret_class ) ;
44+ SecretOperatorVolumeSourceBuilder :: new ( & self . secret_class , provision_parts ) ;
4445
4546 if let Some ( scope) = & self . scope {
4647 if scope. pod {
@@ -62,8 +63,12 @@ impl SecretClassVolume {
6263 . context ( SecretOperatorVolumeSnafu )
6364 }
6465
65- pub fn to_volume ( & self , volume_name : & str ) -> Result < Volume , SecretClassVolumeError > {
66- let ephemeral = self . to_ephemeral_volume_source ( ) ?;
66+ pub fn to_volume (
67+ & self ,
68+ volume_name : & str ,
69+ provision_parts : SecretClassVolumeProvisionParts ,
70+ ) -> Result < Volume , SecretClassVolumeError > {
71+ let ephemeral = self . to_ephemeral_volume_source ( provision_parts) ?;
6772 Ok ( VolumeBuilder :: new ( volume_name) . ephemeral ( ephemeral) . build ( ) )
6873 }
6974}
@@ -94,14 +99,33 @@ pub struct SecretClassVolumeScope {
9499 pub listener_volumes : Vec < String > ,
95100}
96101
102+ /// What parts of secret material should be provisioned into the requested volume.
103+ //
104+ // There intentionally isn't a global [`Default`] impl, as it is secret-operator's concern what it
105+ // chooses as a default.
106+ // TODO (@Techassi): This to me is a HUGE indicator this lives in the wrong place. All these secret
107+ // volume builders/helpers should be defined as part of a secret-operator library to be as close as
108+ // possible to secret-operator, which is the authoritative source of truth for all of this.
109+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , strum:: AsRefStr ) ]
110+ #[ strum( serialize_all = "kebab-case" ) ]
111+ pub enum SecretClassVolumeProvisionParts {
112+ /// Only provision public parts, such as the CA certificate (either as PEM or truststore) or
113+ /// `krb5.conf`.
114+ Public ,
115+
116+ /// Provision all parts, which includes all [`Public`](Self::Public) ones as well as additional
117+ /// private parts, such as a TLS cert + private key, a keystore or a keytab.
118+ PublicPrivate ,
119+ }
120+
97121#[ cfg( test) ]
98122mod tests {
99123 use std:: collections:: BTreeMap ;
100124
101125 use super :: * ;
102126
103127 #[ test]
104- fn volume_to_csi_volume_source ( ) {
128+ fn volume_to_ephemeral_volume_source ( ) {
105129 let secret_class_volume_source = SecretClassVolume {
106130 secret_class : "myclass" . to_string ( ) , // pragma: allowlist secret
107131 scope : Some ( SecretClassVolumeScope {
@@ -111,7 +135,8 @@ mod tests {
111135 listener_volumes : vec ! [ "mylistener" . to_string( ) ] ,
112136 } ) ,
113137 }
114- . to_ephemeral_volume_source ( )
138+ // Let's assume we need some form of private data (e.g. a certificate or S3 credentials)
139+ . to_ephemeral_volume_source ( SecretClassVolumeProvisionParts :: PublicPrivate )
115140 . unwrap ( ) ;
116141
117142 let expected_volume_attributes = BTreeMap :: from ( [
@@ -123,6 +148,10 @@ mod tests {
123148 "secrets.stackable.tech/scope" . to_string ( ) ,
124149 "pod,service=myservice,listener-volume=mylistener" . to_string ( ) ,
125150 ) ,
151+ (
152+ "secrets.stackable.tech/provision-parts" . to_string ( ) ,
153+ "public-private" . to_string ( ) ,
154+ ) ,
126155 ] ) ;
127156
128157 assert_eq ! (
0 commit comments