-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat(stackable-operator): Add git-sync support #1024
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First initial (partial, I didn't look at the unit tests yet) review.
|
||
mod v1alpha1_impl; | ||
|
||
#[versioned(version(name = "v1alpha1"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Nice job versioning this right from the start!
/// The git repository URL that will be cloned, for example: `https://github.com/stackabletech/airflow-operator`. | ||
pub repo: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Is there any particular reason why this field is named repo
? I think we should name it repository
.
note: Additionally, the type of this field should be Url
instead of a plain String
.
/// Location in the Git repository containing the resource. | ||
/// | ||
/// It can optionally start with `/`, however, no trailing slash is recommended. | ||
/// An empty string (``) or slash (`/`) corresponds to the root folder in Git. | ||
#[serde(default = "GitSync::default_git_folder")] | ||
pub git_folder: PathBuf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: All other fields document the default value. This one should then also do that.
/// Since git-sync v4.x.x this field is mapped to the flag `--ref`. | ||
#[serde(default = "GitSync::default_branch")] | ||
pub branch: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This is a perfect case for a future v1alpha2
version of this struct, to rename the field to ref
instead.
/// Since git-sync v4.x.x this field is mapped to the flag `--period`. | ||
#[serde(default = "GitSync::default_wait")] | ||
pub wait: Duration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Another candidate for version v1alpha2
to rename the field to period
.
let internal_args = [ | ||
Some(("--repo".to_string(), git_sync.repo.to_owned())), | ||
Some(("--ref".to_string(), git_sync.branch.to_owned())), | ||
Some(("--depth".to_string(), git_sync.depth.to_string())), | ||
Some(( | ||
"--period".to_string(), | ||
format!("{}s", git_sync.wait.as_secs()), | ||
)), | ||
Some(("--link".to_string(), GIT_SYNC_LINK.to_string())), | ||
Some(("--root".to_string(), GIT_SYNC_ROOT_DIR.to_string())), | ||
one_time.then_some(("--one-time".to_string(), "true".to_string())), | ||
] | ||
.into_iter() | ||
.flatten() | ||
.collect::<BTreeMap<_, _>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Remove the Some
s (and the no longer required flatten
call) and also remove the explicit into_iter
call.
let internal_args = [ | |
Some(("--repo".to_string(), git_sync.repo.to_owned())), | |
Some(("--ref".to_string(), git_sync.branch.to_owned())), | |
Some(("--depth".to_string(), git_sync.depth.to_string())), | |
Some(( | |
"--period".to_string(), | |
format!("{}s", git_sync.wait.as_secs()), | |
)), | |
Some(("--link".to_string(), GIT_SYNC_LINK.to_string())), | |
Some(("--root".to_string(), GIT_SYNC_ROOT_DIR.to_string())), | |
one_time.then_some(("--one-time".to_string(), "true".to_string())), | |
] | |
.into_iter() | |
.flatten() | |
.collect::<BTreeMap<_, _>>(); | |
let mut internal_args = BTreeMap::from([ | |
("--repo".to_string(), git_sync.repo.to_owned()), | |
("--ref".to_string(), git_sync.branch.to_owned()), | |
("--depth".to_string(), git_sync.depth.to_string()), | |
( | |
"--period".to_string(), | |
format!("{}s", git_sync.wait.as_secs()), | |
), | |
("--link".to_string(), GIT_SYNC_LINK.to_string()), | |
("--root".to_string(), GIT_SYNC_ROOT_DIR.to_string()), | |
]); | |
if one_time { | |
internal_args.insert("--one-time".into(), "true".into()); | |
} |
let internal_git_config = [( | ||
GIT_SYNC_SAFE_DIR_OPTION.to_string(), | ||
GIT_SYNC_ROOT_DIR.to_string(), | ||
)] | ||
.into_iter() | ||
.collect::<BTreeMap<_, _>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Simplify this.
let internal_git_config = [( | |
GIT_SYNC_SAFE_DIR_OPTION.to_string(), | |
GIT_SYNC_ROOT_DIR.to_string(), | |
)] | |
.into_iter() | |
.collect::<BTreeMap<_, _>>(); | |
let internal_git_config = BTreeMap::from([( | |
GIT_SYNC_SAFE_DIR_OPTION.to_string(), | |
GIT_SYNC_ROOT_DIR.to_string(), | |
)]); |
// (https://github.com/stackabletech/airflow-operator/pull/381) | ||
// used this condition to find Git configs. It is also used here | ||
// for backwards-compatibility: | ||
if key.to_lowercase().ends_with("-git-config") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This condition seems a little weird. As far as I can see, the only way to provide custom git configs in git-sync is to use --git-config
. Why don't we instead use the following expression:
if key.to_lowercase() == "--git-config" {}
Independent of which approach we finally go with, the value we compare against should live in a constant.
if internal_git_config.keys().any(|key| value.contains(key)) { | ||
tracing::warn!("Config option {value:?} contains a value for {GIT_SYNC_SAFE_DIR_OPTION} that overrides | ||
the value of this operator. Git-sync functionality will probably not work as expected!"); | ||
} | ||
user_defined_git_configs.push(value.to_owned()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Do we want to allow that? This can potentially break what the operator wants to do. Basically user freedom vs opinionated approach.
let mut args = internal_args; | ||
args.extend(user_defined_args); | ||
args.insert("--git-config".to_string(), format!("'{git_config}'")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Any particular reason why we don't operate on the internal_args
directly? One of the above suggestions even makes them mut
.
Description
Add git-sync support
Currently used in:
Definition of Done Checklist