Skip to content

Commit f31b965

Browse files
committed
flatten enum and re-name fields
1 parent 0e024d4 commit f31b965

3 files changed

Lines changed: 54 additions & 42 deletions

File tree

crates/stackable-operator/crds/DummyCluster.yaml

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ spec:
7676
description: A validated domain name type conforming to RFC 1123, so e.g. not an IP address
7777
type: string
7878
gitSync:
79-
anyOf:
80-
- required:
81-
- credentialsSecret
82-
- required:
83-
- sshSecret
8479
properties:
8580
branch:
8681
default: main
@@ -89,16 +84,34 @@ spec:
8984
9085
Since git-sync v4.x.x this field is mapped to the flag `--ref`.
9186
type: string
92-
credentialsSecret:
93-
description: |-
94-
The name of the Secret used to access the repository if it is not public.
87+
credentials:
88+
anyOf:
89+
- required:
90+
- basicAuthSecretName
91+
- required:
92+
- sshPrivateKeySecretName
93+
description: An optional secret used for git access.
94+
nullable: true
95+
properties:
96+
basicAuthSecretName:
97+
description: |-
98+
The name of the Secret used to access the repository via Basic Authentication if it is not public.
9599
96-
The referenced Secret must include two fields: `user` and `password`.
97-
The `password` field can either be an actual password (not recommended) or a GitHub token,
98-
as described in the git-sync [documentation].
100+
The referenced Secret must include two fields: `user` and `password`.
101+
The `password` field can either be an actual password (not recommended) or a GitHub token,
102+
as described in the git-sync [documentation].
99103
100-
[documentation]: https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual
101-
type: string
104+
[documentation]: https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual
105+
type: string
106+
sshPrivateKeySecretName:
107+
description: |-
108+
The name of the Secret used for SSH access to the repository.
109+
110+
The referenced Secret must include two fields: `key` and `knownHosts`.
111+
112+
[documentation]: https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual
113+
type: string
114+
type: object
102115
depth:
103116
default: 1
104117
description: The depth of syncing, i.e. the number of commits to clone; defaults to 1.
@@ -129,14 +142,6 @@ spec:
129142
description: 'The git repository URL that will be cloned, for example: `https://github.com/stackabletech/airflow-operator` or `ssh://git@github.com:stackable-airflow/dags.git`.'
130143
format: uri
131144
type: string
132-
sshSecret:
133-
description: |-
134-
The name of the Secret used for SSH access to the repository.
135-
136-
The referenced Secret must include two fields: `key` and `knownHosts`.
137-
138-
[documentation]: https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual
139-
type: string
140145
wait:
141146
default: 20s
142147
description: |-

crates/stackable-operator/src/crd/git_sync/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,36 @@ pub mod versioned {
5555
#[serde(default)]
5656
pub git_sync_conf: BTreeMap<String, String>,
5757

58-
#[serde(flatten)]
59-
pub access_secret: Option<AccessSecret>,
58+
/// An optional secret used for git access.
59+
pub credentials: Option<Credentials>,
6060
}
6161

6262
#[derive(strum::Display, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
6363
#[serde(untagged)]
6464
#[serde(rename_all = "camelCase")]
6565
#[schemars(rename_all = "camelCase")]
66-
pub enum AccessSecret {
67-
Credentials {
68-
/// The name of the Secret used to access the repository if it is not public.
66+
pub enum Credentials {
67+
BasicAuth {
68+
/// The name of the Secret used to access the repository via Basic Authentication if it is not public.
6969
///
7070
/// The referenced Secret must include two fields: `user` and `password`.
7171
/// The `password` field can either be an actual password (not recommended) or a GitHub token,
7272
/// as described in the git-sync [documentation].
7373
///
7474
/// [documentation]: https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual
75-
#[serde(rename = "credentialsSecret")]
76-
#[schemars(rename = "credentialsSecret")]
77-
credentials_secret: String,
75+
#[serde(rename = "basicAuthSecretName")]
76+
#[schemars(rename = "basicAuthSecretName")]
77+
basic_auth_secret_name: String,
7878
},
7979
Ssh {
8080
/// The name of the Secret used for SSH access to the repository.
8181
///
8282
/// The referenced Secret must include two fields: `key` and `knownHosts`.
8383
///
8484
/// [documentation]: https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual
85-
#[serde(rename = "sshSecret")]
86-
#[schemars(rename = "sshSecret")]
87-
ssh_secret: String,
85+
#[serde(rename = "sshPrivateKeySecretName")]
86+
#[schemars(rename = "sshPrivateKeySecretName")]
87+
ssh_private_key_secret_name: String,
8888
},
8989
}
9090
}

crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
volume::{VolumeBuilder, VolumeMountBuilder},
1515
},
1616
commons::product_image_selection::ResolvedProductImage,
17-
crd::git_sync::v1alpha1::{AccessSecret, GitSync},
17+
crd::git_sync::v1alpha1::{Credentials, GitSync},
1818
product_config_utils::insert_or_update_env_vars,
1919
product_logging::{
2020
framework::capture_shell_output,
@@ -119,20 +119,22 @@ impl GitSyncResources {
119119
for (i, git_sync) in git_syncs.iter().enumerate() {
120120
let mut env_vars = vec![];
121121

122-
if let Some(AccessSecret::Credentials { credentials_secret }) = &git_sync.access_secret
122+
if let Some(Credentials::BasicAuth {
123+
basic_auth_secret_name,
124+
}) = &git_sync.credentials
123125
{
124126
env_vars.push(GitSyncResources::env_var_from_secret(
125127
"GITSYNC_USERNAME",
126-
credentials_secret,
128+
basic_auth_secret_name,
127129
"user",
128130
));
129131
env_vars.push(GitSyncResources::env_var_from_secret(
130132
"GITSYNC_PASSWORD",
131-
credentials_secret,
133+
basic_auth_secret_name,
132134
"password",
133135
));
134136
}
135-
if matches!(git_sync.access_secret, Some(AccessSecret::Ssh { .. })) {
137+
if matches!(git_sync.credentials, Some(Credentials::Ssh { .. })) {
136138
env_vars.push(EnvVar {
137139
name: "GITSYNC_SSH_KEY_FILE".to_owned(),
138140
value: Some(format!("{SSH_MOUNT_PATH_PREFIX}-{i}/key").to_owned()),
@@ -167,7 +169,7 @@ impl GitSyncResources {
167169

168170
git_sync_container_volume_mounts.extend_from_slice(extra_volume_mounts);
169171

170-
if matches!(git_sync.access_secret, Some(AccessSecret::Ssh { .. })) {
172+
if matches!(git_sync.credentials, Some(Credentials::Ssh { .. })) {
171173
let ssh_mount_path = format!("{SSH_MOUNT_PATH_PREFIX}-{i}");
172174
let ssh_volume_name = format!("{SSH_VOLUME_NAME_PREFIX}-{i}");
173175

@@ -222,11 +224,14 @@ impl GitSyncResources {
222224
.push(git_content_volume_mount);
223225
resources.git_content_folders.push(git_content_folder);
224226

225-
if let Some(AccessSecret::Ssh { ssh_secret }) = &git_sync.access_secret {
227+
if let Some(Credentials::Ssh {
228+
ssh_private_key_secret_name,
229+
}) = &git_sync.credentials
230+
{
226231
let ssh_volume_name = format!("{SSH_VOLUME_NAME_PREFIX}-{i}");
227232

228233
let ssh_secret_volume = VolumeBuilder::new(&ssh_volume_name)
229-
.with_secret(ssh_secret, false)
234+
.with_secret(ssh_private_key_secret_name, false)
230235
.build();
231236
resources.git_ssh_volumes.push(ssh_secret_volume);
232237
}
@@ -460,7 +465,8 @@ mod tests {
460465
gitFolder: ""
461466
depth: 3
462467
wait: 1m
463-
credentialsSecret: git-credentials
468+
credentials:
469+
basicAuthSecretName: git-credentials
464470
gitSyncConf:
465471
--rev: HEAD
466472
--git-config: http.sslCAInfo:/tmp/ca-cert/ca.crt
@@ -930,7 +936,8 @@ name: content-from-git-2
930936
gitFolder: ""
931937
depth: 3
932938
wait: 1m
933-
sshSecret: git-sync-ssh
939+
credentials:
940+
sshPrivateKeySecretName: git-sync-ssh
934941
gitSyncConf:
935942
--rev: HEAD
936943
--git-config: http.sslCAInfo:/tmp/ca-cert/ca.crt

0 commit comments

Comments
 (0)