@@ -9,7 +9,9 @@ use strum::{EnumDiscriminants, IntoStaticStr};
99
1010use crate :: {
1111 builder:: pod:: {
12- container:: ContainerBuilder , resources:: ResourceRequirementsBuilder , volume:: VolumeBuilder ,
12+ container:: ContainerBuilder ,
13+ resources:: ResourceRequirementsBuilder ,
14+ volume:: { VolumeBuilder , VolumeMountBuilder } ,
1315 } ,
1416 commons:: product_image_selection:: ResolvedProductImage ,
1517 crd:: git_sync:: v1alpha1:: GitSync ,
@@ -24,6 +26,8 @@ use crate::{
2426pub const CONTAINER_NAME_PREFIX : & str = "git-sync" ;
2527pub const VOLUME_NAME_PREFIX : & str = "content-from-git" ;
2628pub const MOUNT_PATH_PREFIX : & str = "/stackable/app/git" ;
29+ pub const SSH_VOLUME_NAME_PREFIX : & str = "ssh-keys-info" ;
30+ pub const SSH_MOUNT_PATH_PREFIX : & str = "/stackable/gitssh" ;
2731pub const GIT_SYNC_SAFE_DIR_OPTION : & str = "safe.directory" ;
2832pub const GIT_SYNC_ROOT_DIR : & str = "/tmp/git" ;
2933pub const GIT_SYNC_LINK : & str = "current" ;
@@ -58,6 +62,10 @@ impl GitSync {
5862 pub ( crate ) fn default_wait ( ) -> Duration {
5963 Duration :: from_secs ( 20 )
6064 }
65+
66+ pub ( crate ) fn default_ssh_known_hosts ( ) -> bool {
67+ true
68+ }
6169}
6270
6371/// Kubernetes resources generated from `GitSync` specifications which should be added to the Pod.
@@ -77,6 +85,12 @@ pub struct GitSyncResources {
7785
7886 /// Absolute paths to the Git contents in the mounted volumes
7987 pub git_content_folders : Vec < PathBuf > ,
88+
89+ /// GitSync volumes containing the synchronized repository
90+ pub git_ssh_volumes : Vec < Volume > ,
91+
92+ /// Volume mounts for the GitSync volumes
93+ pub git_ssh_volume_mounts : Vec < VolumeMount > ,
8094}
8195
8296impl GitSyncResources {
@@ -120,6 +134,25 @@ impl GitSyncResources {
120134 "password" ,
121135 ) ) ;
122136 }
137+ if git_sync. ssh_secret . is_some ( ) {
138+ env_vars. push ( EnvVar {
139+ name : "GITSYNC_SSH_KEY_FILE" . to_owned ( ) ,
140+ value : Some ( format ! ( "{SSH_MOUNT_PATH_PREFIX}-{i}/key" ) . to_owned ( ) ) ,
141+ value_from : None ,
142+ } ) ;
143+ env_vars. push ( EnvVar {
144+ name : "GITSYNC_SSH_KNOWN_HOSTS_FILE" . to_owned ( ) ,
145+ value : Some ( format ! ( "{SSH_MOUNT_PATH_PREFIX}-{i}/knownHosts" ) . to_owned ( ) ) ,
146+ value_from : None ,
147+ } ) ;
148+ }
149+ // TODO should we leave to the defaults?
150+ // env_vars.push(EnvVar {
151+ // name: "GITSYNC_SSH_KNOWN_HOSTS".to_owned(),
152+ // value: Some(git_sync.ssh_known_hosts.to_string()),
153+ // value_from: None,
154+ // });
155+
123156 env_vars = insert_or_update_env_vars ( & env_vars, extra_env_vars) ;
124157
125158 let volume_name = format ! ( "{VOLUME_NAME_PREFIX}-{i}" ) ;
@@ -186,6 +219,23 @@ impl GitSyncResources {
186219 . git_content_volume_mounts
187220 . push ( git_content_volume_mount) ;
188221 resources. git_content_folders . push ( git_content_folder) ;
222+
223+ if let Some ( get_ssh_secret) = & git_sync. ssh_secret {
224+ let ssh_volume_name = format ! ( "{SSH_VOLUME_NAME_PREFIX}-{i}" ) ;
225+ let ssh_mount_path = format ! ( "{SSH_MOUNT_PATH_PREFIX}-{i}" ) ;
226+
227+ let ssh_secret_volume = VolumeBuilder :: new ( & ssh_volume_name)
228+ . with_secret ( get_ssh_secret, false )
229+ . build ( ) ;
230+ resources. git_ssh_volumes . push ( ssh_secret_volume) ;
231+
232+ let ssh_secret_volume_mount =
233+ VolumeMountBuilder :: new ( ssh_volume_name, ssh_mount_path) . build ( ) ;
234+
235+ resources
236+ . git_ssh_volume_mounts
237+ . push ( ssh_secret_volume_mount) ;
238+ }
189239 }
190240
191241 Ok ( resources)
0 commit comments