Skip to content

chore: Version CRD and AirflowClusterConfig #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 273 additions & 44 deletions Cargo.lock

Large diffs are not rendered by default.

1,351 changes: 1,140 additions & 211 deletions Cargo.nix

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["rust/crd", "rust/operator-binary"]
members = ["rust/operator-binary"]
resolver = "2"

[workspace.package]
Expand All @@ -10,21 +10,23 @@ edition = "2021"
repository = "https://github.com/stackabletech/airflow-operator"

[workspace.dependencies]
stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.5.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.85.0" }
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }

anyhow = "1.0"
built = { version = "0.7", features = ["chrono", "git2"] }
clap = "4.5"
const_format = "0.2"
fnv = "1.0"
futures = { version = "0.3", features = ["compat"] }
indoc = "2.0"
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
rstest = "0.24"
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
snafu = "0.8"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.85.0" }
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.40", features = ["full"] }
tracing = "0.1"
Expand Down
3 changes: 3 additions & 0 deletions crate-hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions rust/crd/Cargo.toml

This file was deleted.

7 changes: 4 additions & 3 deletions rust/operator-binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ repository.workspace = true
publish = false

[dependencies]
stackable-airflow-crd = { path = "../crd" }
stackable-versioned.workspace = true
stackable-operator.workspace = true
product-config.workspace = true

anyhow.workspace = true
clap.workspace = true
const_format.workspace = true
fnv.workspace = true
futures.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
snafu.workspace = true
stackable-operator.workspace = true
product-config.workspace = true
strum.workspace = true
tokio.workspace = true
tracing.workspace = true
Expand Down
79 changes: 37 additions & 42 deletions rust/operator-binary/src/airflow_controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Ensures that `Pod`s are configured and running for each [`AirflowCluster`]
//! Ensures that `Pod`s are configured and running for each [`v1alpha1::AirflowCluster`]
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
io::Write,
Expand All @@ -13,18 +13,6 @@ use product_config::{
ProductConfigManager,
};
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_airflow_crd::{
authentication::{
AirflowAuthenticationClassResolved, AirflowClientAuthenticationDetailsResolved,
},
build_recommended_labels,
git_sync::GitSync,
AirflowCluster, AirflowClusterStatus, AirflowConfig, AirflowConfigOptions, AirflowExecutor,
AirflowRole, Container, ExecutorConfig, ExecutorConfigFragment, AIRFLOW_CONFIG_FILENAME,
AIRFLOW_UID, APP_NAME, CONFIG_PATH, GIT_CONTENT, GIT_ROOT, GIT_SYNC_NAME, LOG_CONFIG_DIR,
OPERATOR_NAME, STACKABLE_LOG_DIR, TEMPLATE_CONFIGMAP_NAME, TEMPLATE_LOCATION, TEMPLATE_NAME,
TEMPLATE_VOLUME_NAME,
};
use stackable_operator::{
builder::{
self,
Expand Down Expand Up @@ -86,6 +74,18 @@ use strum::{EnumDiscriminants, IntoEnumIterator, IntoStaticStr};
use crate::{
config::{self, PYTHON_IMPORTS},
controller_commons::{self, CONFIG_VOLUME_NAME, LOG_CONFIG_VOLUME_NAME, LOG_VOLUME_NAME},
crd::{
self,
authentication::{
AirflowAuthenticationClassResolved, AirflowClientAuthenticationDetailsResolved,
},
build_recommended_labels,
git_sync::{GitSync, GIT_SYNC_CONTENT, GIT_SYNC_NAME, GIT_SYNC_ROOT},
v1alpha1, AirflowClusterStatus, AirflowConfig, AirflowConfigOptions, AirflowExecutor,
AirflowRole, Container, ExecutorConfig, ExecutorConfigFragment, AIRFLOW_CONFIG_FILENAME,
AIRFLOW_UID, APP_NAME, CONFIG_PATH, LOG_CONFIG_DIR, OPERATOR_NAME, STACKABLE_LOG_DIR,
TEMPLATE_CONFIGMAP_NAME, TEMPLATE_LOCATION, TEMPLATE_NAME, TEMPLATE_VOLUME_NAME,
},
env_vars::{
self, build_airflow_template_envs, build_gitsync_statefulset_envs, build_gitsync_template,
},
Expand Down Expand Up @@ -113,7 +113,6 @@ pub struct Ctx {

#[derive(Snafu, Debug, EnumDiscriminants)]
#[strum_discriminants(derive(IntoStaticStr))]
#[allow(clippy::enum_variant_names)]
pub enum Error {
#[snafu(display("object has no namespace"))]
ObjectHasNoNamespace,
Expand All @@ -129,19 +128,19 @@ pub enum Error {
#[snafu(display("failed to apply Service for {rolegroup}"))]
ApplyRoleGroupService {
source: stackable_operator::cluster_resources::Error,
rolegroup: RoleGroupRef<AirflowCluster>,
rolegroup: RoleGroupRef<v1alpha1::AirflowCluster>,
},

#[snafu(display("failed to apply ConfigMap for {rolegroup}"))]
ApplyRoleGroupConfig {
source: stackable_operator::cluster_resources::Error,
rolegroup: RoleGroupRef<AirflowCluster>,
rolegroup: RoleGroupRef<v1alpha1::AirflowCluster>,
},

#[snafu(display("failed to apply StatefulSet for {rolegroup}"))]
ApplyRoleGroupStatefulSet {
source: stackable_operator::cluster_resources::Error,
rolegroup: RoleGroupRef<AirflowCluster>,
rolegroup: RoleGroupRef<v1alpha1::AirflowCluster>,
},

#[snafu(display("invalid product config"))]
Expand Down Expand Up @@ -192,19 +191,17 @@ pub enum Error {
#[snafu(display("failed to build config file for {rolegroup}"))]
BuildRoleGroupConfigFile {
source: FlaskAppConfigWriterError,
rolegroup: RoleGroupRef<AirflowCluster>,
rolegroup: RoleGroupRef<v1alpha1::AirflowCluster>,
},

#[snafu(display("failed to build ConfigMap for {rolegroup}"))]
BuildRoleGroupConfig {
source: stackable_operator::builder::configmap::Error,
rolegroup: RoleGroupRef<AirflowCluster>,
rolegroup: RoleGroupRef<v1alpha1::AirflowCluster>,
},

#[snafu(display("failed to resolve and merge config for role and role group"))]
FailedToResolveConfig {
source: stackable_airflow_crd::Error,
},
FailedToResolveConfig { source: crd::Error },

#[snafu(display("could not parse Airflow role [{role}]"))]
UnidentifiedAirflowRole {
Expand Down Expand Up @@ -249,9 +246,7 @@ pub enum Error {
},

#[snafu(display("failed to apply authentication configuration"))]
InvalidAuthenticationConfig {
source: stackable_airflow_crd::authentication::Error,
},
InvalidAuthenticationConfig { source: crd::authentication::Error },

#[snafu(display("pod template serialization"))]
PodTemplateSerde { source: serde_yaml::Error },
Expand Down Expand Up @@ -336,7 +331,7 @@ impl ReconcilerError for Error {
}

pub async fn reconcile_airflow(
airflow: Arc<DeserializeGuard<AirflowCluster>>,
airflow: Arc<DeserializeGuard<v1alpha1::AirflowCluster>>,
ctx: Arc<Ctx>,
) -> Result<Action> {
tracing::info!("Starting reconcile");
Expand Down Expand Up @@ -558,7 +553,7 @@ pub async fn reconcile_airflow(

#[allow(clippy::too_many_arguments)]
async fn build_executor_template(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
common_config: &CommonConfiguration<ExecutorConfigFragment, GenericProductSpecificCommonConfig>,
resolved_product_image: &ResolvedProductImage,
authentication_config: &AirflowClientAuthenticationDetailsResolved,
Expand Down Expand Up @@ -612,7 +607,7 @@ async fn build_executor_template(
/// The server-role service is the primary endpoint that should be used by clients that do not perform internal load balancing,
/// including targets outside the cluster.
fn build_role_service(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
resolved_product_image: &ResolvedProductImage,
role_name: &str,
port: u16,
Expand Down Expand Up @@ -674,9 +669,9 @@ fn role_port(role_name: &str) -> Option<u16> {
/// The rolegroup [`ConfigMap`] configures the rolegroup based on the configuration given by the administrator
#[allow(clippy::too_many_arguments)]
fn build_rolegroup_config_map(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
resolved_product_image: &ResolvedProductImage,
rolegroup: &RoleGroupRef<AirflowCluster>,
rolegroup: &RoleGroupRef<v1alpha1::AirflowCluster>,
rolegroup_config: &HashMap<PropertyNameKind, BTreeMap<String, String>>,
authentication_config: &AirflowClientAuthenticationDetailsResolved,
logging: &Logging<Container>,
Expand Down Expand Up @@ -760,9 +755,9 @@ fn build_rolegroup_config_map(
///
/// This is mostly useful for internal communication between peers, or for clients that perform client-side load balancing.
fn build_rolegroup_service(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
resolved_product_image: &ResolvedProductImage,
rolegroup: &RoleGroupRef<AirflowCluster>,
rolegroup: &RoleGroupRef<v1alpha1::AirflowCluster>,
) -> Result<Service> {
let mut ports = vec![ServicePort {
name: Some(METRICS_PORT_NAME.into()),
Expand Down Expand Up @@ -807,9 +802,9 @@ fn build_rolegroup_service(
}

fn build_rolegroup_metadata(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
resolved_product_image: &&ResolvedProductImage,
rolegroup: &&RoleGroupRef<AirflowCluster>,
rolegroup: &&RoleGroupRef<v1alpha1::AirflowCluster>,
prometheus_label: Label,
) -> Result<ObjectMeta, Error> {
let metadata = ObjectMetaBuilder::new()
Expand All @@ -835,10 +830,10 @@ fn build_rolegroup_metadata(
/// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the corresponding [`Service`] (from [`build_rolegroup_service`]).
#[allow(clippy::too_many_arguments)]
fn build_server_rolegroup_statefulset(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
resolved_product_image: &ResolvedProductImage,
airflow_role: &AirflowRole,
rolegroup_ref: &RoleGroupRef<AirflowCluster>,
rolegroup_ref: &RoleGroupRef<v1alpha1::AirflowCluster>,
rolegroup_config: &HashMap<PropertyNameKind, BTreeMap<String, String>>,
authentication_config: &AirflowClientAuthenticationDetailsResolved,
service_account: &ServiceAccount,
Expand Down Expand Up @@ -1008,7 +1003,7 @@ fn build_server_rolegroup_statefulset(
)?;

pb.add_volume(
VolumeBuilder::new(GIT_CONTENT)
VolumeBuilder::new(GIT_SYNC_CONTENT)
.empty_dir(EmptyDirVolumeSource::default())
.build(),
)
Expand Down Expand Up @@ -1116,14 +1111,14 @@ fn build_logging_container(

#[allow(clippy::too_many_arguments)]
fn build_executor_template_config_map(
airflow: &AirflowCluster,
airflow: &v1alpha1::AirflowCluster,
resolved_product_image: &ResolvedProductImage,
authentication_config: &AirflowClientAuthenticationDetailsResolved,
sa_name: &str,
merged_executor_config: &ExecutorConfig,
env_overrides: &HashMap<String, String>,
pod_overrides: &PodTemplateSpec,
rolegroup_ref: &RoleGroupRef<AirflowCluster>,
rolegroup_ref: &RoleGroupRef<v1alpha1::AirflowCluster>,
) -> Result<ConfigMap> {
let mut pb = PodBuilder::new();
let pb_metadata = ObjectMetaBuilder::new()
Expand Down Expand Up @@ -1203,7 +1198,7 @@ fn build_executor_template_config_map(
airflow.volume_mounts(),
)?;
pb.add_volume(
VolumeBuilder::new(GIT_CONTENT)
VolumeBuilder::new(GIT_SYNC_CONTENT)
.empty_dir(EmptyDirVolumeSource::default())
.build(),
)
Expand Down Expand Up @@ -1275,7 +1270,7 @@ fn build_gitsync_container(
"-c".to_string(),
])
.args(vec![gitsync.get_args(one_time).join("\n")])
.add_volume_mount(GIT_CONTENT, GIT_ROOT)
.add_volume_mount(GIT_SYNC_CONTENT, GIT_SYNC_ROOT)
.context(AddVolumeMountSnafu)?
.add_volume_mounts(volume_mounts)
.context(AddVolumeMountSnafu)?
Expand All @@ -1292,7 +1287,7 @@ fn build_gitsync_container(
}

pub fn error_policy(
_obj: Arc<DeserializeGuard<AirflowCluster>>,
_obj: Arc<DeserializeGuard<v1alpha1::AirflowCluster>>,
error: &Error,
_ctx: Arc<Ctx>,
) -> Action {
Expand Down
25 changes: 14 additions & 11 deletions rust/operator-binary/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use std::collections::BTreeMap;

use indoc::formatdoc;
use snafu::{ResultExt, Snafu};
use stackable_airflow_crd::{
use stackable_operator::commons::{
authentication::{ldap::AuthenticationProvider, oidc},
tls_verification::TlsVerification,
};

use crate::crd::{
authentication::{
AirflowAuthenticationClassResolved, AirflowClientAuthenticationDetailsResolved,
FlaskRolesSyncMoment, DEFAULT_OIDC_PROVIDER,
},
AirflowConfigOptions,
};
use stackable_operator::commons::{
authentication::{ldap::AuthenticationProvider, oidc},
tls_verification::TlsVerification,
};

pub const PYTHON_IMPORTS: &[&str] = &[
"import os",
Expand Down Expand Up @@ -280,13 +281,15 @@ mod tests {

use indoc::formatdoc;
use rstest::rstest;
use stackable_airflow_crd::authentication::{
default_sync_roles_at, default_user_registration, AirflowAuthenticationClassResolved,
AirflowClientAuthenticationDetailsResolved, FlaskRolesSyncMoment,
};
use stackable_operator::commons::authentication::{ldap, oidc};

use crate::config::add_airflow_config;
use crate::{
config::add_airflow_config,
crd::authentication::{
default_user_registration, AirflowAuthenticationClassResolved,
AirflowClientAuthenticationDetailsResolved, FlaskRolesSyncMoment,
},
};

#[test]
fn test_auth_db_config() {
Expand Down Expand Up @@ -421,7 +424,7 @@ mod tests {
],
user_registration: default_user_registration(),
user_registration_role: "Admin".to_string(),
sync_roles_at: default_sync_roles_at(),
sync_roles_at: FlaskRolesSyncMoment::Registration,
};

let mut result = BTreeMap::new();
Expand Down
3 changes: 2 additions & 1 deletion rust/operator-binary/src/controller_commons.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use stackable_airflow_crd::MAX_LOG_FILES_SIZE;
use stackable_operator::{
builder::pod::volume::VolumeBuilder,
k8s_openapi::api::core::v1::{ConfigMapVolumeSource, EmptyDirVolumeSource, Volume},
Expand All @@ -11,6 +10,8 @@ use stackable_operator::{
},
};

use crate::crd::MAX_LOG_FILES_SIZE;

pub const CONFIG_VOLUME_NAME: &str = "config";
pub const LOG_CONFIG_VOLUME_NAME: &str = "log-config";
pub const LOG_VOLUME_NAME: &str = "log";
Expand Down
Loading
Loading