Skip to content

Commit 8b94f6a

Browse files
committed
wip: versioning
1 parent ec980f4 commit 8b94f6a

4 files changed

Lines changed: 1166 additions & 283 deletions

File tree

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ use serde::{Deserialize, Serialize};
77
use stackable_shared::time::Duration;
88
use url::Url;
99

10-
use crate::versioned::versioned;
10+
use crate::{crd::git_sync::v1alpha2::Credentials, versioned::versioned};
1111

1212
mod v1alpha1_impl;
13+
mod v1alpha2_impl;
1314

14-
#[versioned(version(name = "v1alpha1"))]
15+
#[versioned(version(name = "v1alpha1"), version(name = "v1alpha2"))]
1516
pub mod versioned {
1617
pub mod v1alpha1 {
1718
pub use v1alpha1_impl::{Error, GitSyncResources};
1819
}
20+
pub mod v1alpha2 {
21+
pub use v1alpha2_impl::{Error, GitSyncResources};
22+
}
1923

2024
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Eq, Serialize)]
2125
#[serde(rename_all = "camelCase")]
@@ -26,24 +30,24 @@ pub mod versioned {
2630
/// The branch to clone; defaults to `main`.
2731
///
2832
/// Since git-sync v4.x.x this field is mapped to the flag `--ref`.
29-
#[serde(default = "GitSync::default_branch")]
33+
#[serde(default = "v1alpha2::GitSync::default_branch")]
3034
pub branch: String,
3135

3236
/// Location in the Git repository containing the resource; defaults to the root folder.
3337
///
3438
/// It can optionally start with `/`, however, no trailing slash is recommended.
3539
/// An empty string (``) or slash (`/`) corresponds to the root folder in Git.
36-
#[serde(default = "GitSync::default_git_folder")]
40+
#[serde(default = "v1alpha2::GitSync::default_git_folder")]
3741
pub git_folder: PathBuf,
3842

3943
/// The depth of syncing, i.e. the number of commits to clone; defaults to 1.
40-
#[serde(default = "GitSync::default_depth")]
44+
#[serde(default = "v1alpha2::GitSync::default_depth")]
4145
pub depth: u32,
4246

4347
/// The synchronization interval, e.g. `20s` or `5m`; defaults to `20s`.
4448
///
4549
/// Since git-sync v4.x.x this field is mapped to the flag `--period`.
46-
#[serde(default = "GitSync::default_wait")]
50+
#[serde(default = "v1alpha2::GitSync::default_wait")]
4751
pub wait: Duration,
4852

4953
/// A map of optional configuration settings that are listed in the git-sync [documentation].
@@ -56,6 +60,13 @@ pub mod versioned {
5660
pub git_sync_conf: BTreeMap<String, String>,
5761

5862
/// An optional secret used for git access.
63+
#[versioned(changed(
64+
since = "v1alpha2",
65+
from_name = "credentials_secret",
66+
from_type = "Option<String>",
67+
upgrade_with = credentials_secret_to_basic_auth,
68+
downgrade_with = credentials_to_secret
69+
))]
5970
pub credentials: Option<Credentials>,
6071
}
6172

@@ -79,3 +90,15 @@ pub mod versioned {
7990
SshPrivateKeySecretName(String),
8091
}
8192
}
93+
94+
pub fn credentials_to_secret(input: Option<Credentials>) -> Option<String> {
95+
if let Some(Credentials::BasicAuthSecretName(credentials_secret)) = input {
96+
Some(credentials_secret)
97+
} else {
98+
None
99+
}
100+
}
101+
102+
pub fn credentials_secret_to_basic_auth(input: Option<String>) -> Option<Credentials> {
103+
input.map(Credentials::BasicAuthSecretName)
104+
}

0 commit comments

Comments
 (0)