Skip to content
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

Allow arbitrary python code #530

Merged
merged 17 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

## [Unreleased]

### Added

- Allowing arbitrary python code as EXPERIMENTAL_FILE_HEADER and EXPERIMENTAL_FILE_FOOTER in superset_config.py ([#530])

### Changed

- Reduce CRD size from `472KB` to `45KB` by accepting arbitrary YAML input instead of the underlying schema for the following fields ([#528]):
- `podOverrides`
- `affinity`

[#528]: https://github.com/stackabletech/superset-operator/pull/528
[#530]: https://github.com/stackabletech/superset-operator/pull/530

## [24.7.0] - 2024-07-24

Expand Down
7 changes: 3 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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.73.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.74.0" }
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.39", features = ["full"] }
tracing = "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@
For a full list of configuration options we refer to the
https://github.com/apache/superset/blob/master/superset/config.py[main config file for Superset].

As Superset can be configured with python code too, arbitrary code can be added to the `superset_conf.py`.
You can use either `EXPERIMENTAL_FILE_HEADER` to add code to the top or `EXPERIMENTAL_FILE_FOOTER` to add to the bottom.

IMPORTANT: This is an experimental feature

[source,yaml]
----
nodes:
configOverrides:
superset_config.py:
CSV_EXPORT: "{'encoding': 'utf-8'}"
EXPERIMENTAL_FILE_HEADER: |
from modules.my_module import my_class
EXPERIMENTAL_FILE_FOOTER: |
import logging
from superset.security import SupersetSecurityManager

Check notice on line 77 in docs/modules/superset/pages/usage-guide/configuration-environment-overrides.adoc

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] docs/modules/superset/pages/usage-guide/configuration-environment-overrides.adoc#L77

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Security`, ` security` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
docs/modules/superset/pages/usage-guide/configuration-environment-overrides.adoc:77:22: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Security`, ` security`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING

class myCustomSecurityManger(SupersetSecurityManager):
def __init__():
init()

CUSTOM_SECURITY_MANAGER = myCustomSecurityManger
roleGroups:
default:
config: {}
----

== Environment Variables

In a similar fashion, environment variables can be (over)written. For example per role group:
Expand All @@ -85,4 +112,5 @@
config: {}
----


// cliOverrides don't make sense for this operator, so the feature is omitted for now
3 changes: 2 additions & 1 deletion rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ impl SupersetConfig {
logging: product_logging::spec::default_logging(),
affinity: get_affinity(cluster_name, role),
graceful_shutdown_timeout: Some(DEFAULT_NODE_GRACEFUL_SHUTDOWN_TIMEOUT),
..Default::default()
row_limit: None,
webserver_timeout: None,
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion rust/operator-binary/src/superset_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet, HashMap},
io::Write,
sync::Arc,
};

Expand Down Expand Up @@ -39,7 +40,10 @@ use stackable_operator::{
kube::{runtime::controller::Action, Resource, ResourceExt},
kvp::{Label, Labels},
logging::controller::ReconcilerError,
product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config},
product_config_utils::{
transform_all_roles_to_config, validate_all_roles_and_groups_config,
CONFIG_OVERRIDE_FILE_FOOTER_KEY, CONFIG_OVERRIDE_FILE_HEADER_KEY,
},
product_logging::{
self,
framework::{create_vector_shutdown_file_command, remove_vector_shutdown_file_command},
Expand Down Expand Up @@ -250,6 +254,11 @@ pub enum Error {
AddTlsVolumesAndVolumeMounts {
source: stackable_operator::commons::authentication::tls::TlsClientDetailsError,
},

#[snafu(display(
"failed to write to String (Vec<u8> to be precise) containing superset config"
))]
WriteToConfigFileString { source: std::io::Error },
}

type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -523,6 +532,14 @@ fn build_rolegroup_config_map(
);

let mut config_file = Vec::new();

Maleware marked this conversation as resolved.
Show resolved Hide resolved
// By removing the keys from `config_properties`, we avoid pasting the Python code into a Python variable as well
// (which would be bad)
if let Some(header) = config_properties.remove(CONFIG_OVERRIDE_FILE_HEADER_KEY) {
writeln!(config_file, "{}", header).context(WriteToConfigFileStringSnafu)?;
}
let temp_file_footer = config_properties.remove(CONFIG_OVERRIDE_FILE_FOOTER_KEY);

flask_app_config_writer::write::<SupersetConfigOptions, _, _>(
&mut config_file,
config_properties.iter(),
Expand All @@ -532,6 +549,10 @@ fn build_rolegroup_config_map(
rolegroup: rolegroup.clone(),
})?;

if let Some(footer) = temp_file_footer {
writeln!(config_file, "{}", footer).context(WriteToConfigFileStringSnafu)?;
}

let mut cm_builder = ConfigMapBuilder::new();

cm_builder
Expand Down
8 changes: 8 additions & 0 deletions tests/templates/kuttl/smoke/30-install-superset.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ spec:
config:
logging:
enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }}
configOverrides:
superset_config.py:
razvan marked this conversation as resolved.
Show resolved Hide resolved
COMMON_CONF_VAR: '"role-value"' # overridden by role group below
ROLE_CONF_VAR: '"role-value"' # only defined here at role level
roleGroups:
default:
configOverrides:
superset_config.py:
COMMON_CONF_VAR: '"group-value"' # overrides role value
GROUP_CONF_VAR: '"group-value"' # only defined here at group level
replicas: 1
12 changes: 12 additions & 0 deletions tests/templates/kuttl/smoke/32-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
razvan marked this conversation as resolved.
Show resolved Hide resolved
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 600
commands:
#
# Test confOverrides
#
- script: |
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "COMMON_CONF_VAR = \"group-value\""
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_CONF_VAR = \"role-value\""
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "GROUP_CONF_VAR = \"group-value\""
Loading