Skip to content

Commit f3eac55

Browse files
Malewaresbernauer
andauthored
Allow arbitrary python code (#530)
* Starting with Superset-Operator * Add snafu error * Add snafu error message * Add comment * Fixing footer variable * Adding comments on open todo to reference footer and header with vars from operator-rs * Comment about removing key and write later * Removing comments * Bump operator-rs to 0.74.0, using constants rather then strings for header and footer keys * Remove todo's * Updating changelog * Apply suggestions from code review Co-authored-by: Sebastian Bernauer <[email protected]> * Adding docs * Adding tests configs respect role and group level configs * Revert: tests for conf overrides * retrigger pipeline --------- Co-authored-by: Sebastian Bernauer <[email protected]> Co-authored-by: Sebastian Bernauer <[email protected]>
1 parent be2fa0b commit f3eac55

File tree

6 files changed

+61
-7
lines changed

6 files changed

+61
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Allowing arbitrary python code as EXPERIMENTAL_FILE_HEADER and EXPERIMENTAL_FILE_FOOTER in superset_config.py ([#530])
8+
59
### Changed
610

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

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

1318
## [24.7.0] - 2024-07-24
1419

Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"] }
2121
serde_json = "1.0"
2222
serde_yaml = "0.9"
2323
snafu = "0.8"
24-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.73.0" }
24+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.74.0" }
2525
strum = { version = "0.26", features = ["derive"] }
2626
tokio = { version = "1.39", features = ["full"] }
2727
tracing = "0.1"

docs/modules/superset/pages/usage-guide/configuration-environment-overrides.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@ be taken to produce a valid configuration.
5959
For a full list of configuration options we refer to the
6060
https://github.com/apache/superset/blob/master/superset/config.py[main config file for Superset].
6161

62+
As Superset can be configured with python code too, arbitrary code can be added to the `superset_conf.py`.
63+
You can use either `EXPERIMENTAL_FILE_HEADER` to add code to the top or `EXPERIMENTAL_FILE_FOOTER` to add to the bottom.
64+
65+
IMPORTANT: This is an experimental feature
66+
67+
[source,yaml]
68+
----
69+
nodes:
70+
configOverrides:
71+
superset_config.py:
72+
CSV_EXPORT: "{'encoding': 'utf-8'}"
73+
EXPERIMENTAL_FILE_HEADER: |
74+
from modules.my_module import my_class
75+
EXPERIMENTAL_FILE_FOOTER: |
76+
import logging
77+
from superset.security import SupersetSecurityManager
78+
79+
class myCustomSecurityManger(SupersetSecurityManager):
80+
def __init__():
81+
init()
82+
83+
CUSTOM_SECURITY_MANAGER = myCustomSecurityManger
84+
roleGroups:
85+
default:
86+
config: {}
87+
----
88+
6289
== Environment Variables
6390

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

115+
88116
// cliOverrides don't make sense for this operator, so the feature is omitted for now

rust/crd/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ impl SupersetConfig {
369369
logging: product_logging::spec::default_logging(),
370370
affinity: get_affinity(cluster_name, role),
371371
graceful_shutdown_timeout: Some(DEFAULT_NODE_GRACEFUL_SHUTDOWN_TIMEOUT),
372-
..Default::default()
372+
row_limit: None,
373+
webserver_timeout: None,
373374
}
374375
}
375376
}

rust/operator-binary/src/superset_controller.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::{
33
borrow::Cow,
44
collections::{BTreeMap, BTreeSet, HashMap},
5+
io::Write,
56
sync::Arc,
67
};
78

@@ -39,7 +40,10 @@ use stackable_operator::{
3940
kube::{runtime::controller::Action, Resource, ResourceExt},
4041
kvp::{Label, Labels},
4142
logging::controller::ReconcilerError,
42-
product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config},
43+
product_config_utils::{
44+
transform_all_roles_to_config, validate_all_roles_and_groups_config,
45+
CONFIG_OVERRIDE_FILE_FOOTER_KEY, CONFIG_OVERRIDE_FILE_HEADER_KEY,
46+
},
4347
product_logging::{
4448
self,
4549
framework::{create_vector_shutdown_file_command, remove_vector_shutdown_file_command},
@@ -250,6 +254,11 @@ pub enum Error {
250254
AddTlsVolumesAndVolumeMounts {
251255
source: stackable_operator::commons::authentication::tls::TlsClientDetailsError,
252256
},
257+
258+
#[snafu(display(
259+
"failed to write to String (Vec<u8> to be precise) containing superset config"
260+
))]
261+
WriteToConfigFileString { source: std::io::Error },
253262
}
254263

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

525534
let mut config_file = Vec::new();
535+
536+
// By removing the keys from `config_properties`, we avoid pasting the Python code into a Python variable as well
537+
// (which would be bad)
538+
if let Some(header) = config_properties.remove(CONFIG_OVERRIDE_FILE_HEADER_KEY) {
539+
writeln!(config_file, "{}", header).context(WriteToConfigFileStringSnafu)?;
540+
}
541+
let temp_file_footer = config_properties.remove(CONFIG_OVERRIDE_FILE_FOOTER_KEY);
542+
526543
flask_app_config_writer::write::<SupersetConfigOptions, _, _>(
527544
&mut config_file,
528545
config_properties.iter(),
@@ -532,6 +549,10 @@ fn build_rolegroup_config_map(
532549
rolegroup: rolegroup.clone(),
533550
})?;
534551

552+
if let Some(footer) = temp_file_footer {
553+
writeln!(config_file, "{}", footer).context(WriteToConfigFileStringSnafu)?;
554+
}
555+
535556
let mut cm_builder = ConfigMapBuilder::new();
536557

537558
cm_builder

0 commit comments

Comments
 (0)