Skip to content

Commit 5d7a007

Browse files
Version the git_sync structure as v1alpha1
1 parent 1ad347d commit 5d7a007

File tree

6 files changed

+79
-73
lines changed

6 files changed

+79
-73
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//! GitSync structure for CRDs
2+
3+
use std::{collections::BTreeMap, path::PathBuf};
4+
5+
use schemars::{self, JsonSchema};
6+
use serde::{Deserialize, Serialize};
7+
8+
use crate::{time::Duration, versioned::versioned};
9+
10+
mod v1alpha1_impl;
11+
12+
#[versioned(version(name = "v1alpha1"))]
13+
pub mod versioned {
14+
pub mod v1alpha1 {
15+
pub use v1alpha1_impl::{Error, GitSyncResources};
16+
}
17+
18+
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Eq, Serialize)]
19+
#[serde(rename_all = "camelCase")]
20+
pub struct GitSync {
21+
/// The git repository URL that will be cloned, for example: `https://github.com/stackabletech/airflow-operator`.
22+
pub repo: String,
23+
24+
/// The branch to clone; defaults to `main`.
25+
///
26+
/// Since git-sync v4.x.x this field is mapped to the flag `--ref`.
27+
#[serde(default = "GitSync::default_branch")]
28+
pub branch: String,
29+
30+
/// The location of the DAG folder, relative to the synced repository root.
31+
///
32+
/// It can optionally start with `/`, however, no trailing slash is recommended.
33+
/// An empty string (``) or slash (`/`) corresponds to the root folder in Git.
34+
#[serde(default = "GitSync::default_git_folder")]
35+
pub git_folder: PathBuf,
36+
37+
/// The depth of syncing, i.e. the number of commits to clone; defaults to 1.
38+
#[serde(default = "GitSync::default_depth")]
39+
pub depth: u32,
40+
41+
/// The synchronization interval, e.g. `20s` or `5m`; defaults to `20s`.
42+
///
43+
/// Since git-sync v4.x.x this field is mapped to the flag `--period`.
44+
#[serde(default = "GitSync::default_wait")]
45+
pub wait: Duration,
46+
47+
/// The name of the Secret used to access the repository if it is not public.
48+
/// This should include two fields: `user` and `password`.
49+
/// The `password` field can either be an actual password (not recommended) or a GitHub token,
50+
/// as described [here](https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual).
51+
pub credentials_secret: Option<String>,
52+
53+
/// A map of optional configuration settings that are listed in the [git-sync documentation](https://github.com/kubernetes/git-sync/tree/v4.2.4?tab=readme-ov-file#manual).
54+
/// Read the [git sync example](DOCS_BASE_URL_PLACEHOLDER/airflow/usage-guide/mounting-dags#_example).
55+
#[serde(default)]
56+
pub git_sync_conf: BTreeMap<String, String>,
57+
}
58+
}

crates/stackable-operator/src/git_sync/framework.rs renamed to crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use k8s_openapi::api::core::v1::{
66
use snafu::{ResultExt, Snafu};
77
use strum::{EnumDiscriminants, IntoStaticStr};
88

9-
use super::spec::GitSync;
109
use crate::{
1110
builder::pod::{
1211
container::ContainerBuilder, resources::ResourceRequirementsBuilder, volume::VolumeBuilder,
1312
},
1413
commons::product_image_selection::ResolvedProductImage,
14+
crd::git_sync::v1alpha1::GitSync,
1515
product_config_utils::insert_or_update_env_vars,
16+
time::Duration,
1617
utils::COMMON_BASH_TRAP_FUNCTIONS,
1718
};
1819

@@ -37,6 +38,24 @@ pub enum Error {
3738
},
3839
}
3940

41+
impl GitSync {
42+
pub(crate) fn default_branch() -> String {
43+
"main".to_string()
44+
}
45+
46+
pub(crate) fn default_git_folder() -> PathBuf {
47+
PathBuf::from("/")
48+
}
49+
50+
pub(crate) fn default_depth() -> u32 {
51+
1
52+
}
53+
54+
pub(crate) fn default_wait() -> Duration {
55+
Duration::from_secs(20)
56+
}
57+
}
58+
4059
/// Kubernetes resources generated from `GitSync` specifications which should be added to the Pod.
4160
#[derive(Default)]
4261
pub struct GitSyncResources {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use schemars::JsonSchema;
55
use serde::{Deserialize, Serialize};
66

77
pub mod authentication;
8+
pub mod git_sync;
89
pub mod listener;
910
pub mod s3;
1011

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

crates/stackable-operator/src/git_sync/spec.rs

Lines changed: 0 additions & 67 deletions
This file was deleted.

crates/stackable-operator/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub mod config;
1515
pub mod constants;
1616
pub mod cpu;
1717
pub mod crd;
18-
pub mod git_sync;
1918
pub mod helm;
2019
pub mod iter;
2120
pub mod kvp;

0 commit comments

Comments
 (0)