-
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Support objectOverrides
#1118
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
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
00fd1b7
feat: Support `objectOverrides`
sbernauer 38a0996
refactor: Switch to a lis of objects (as opposed to a big string field)
sbernauer d87791f
changelog
sbernauer aaf74c2
Add TODO for docs
sbernauer 22b1732
Add a test for Listener merging
sbernauer ec5b882
Fix doctests
sbernauer a46cada
Improve CRD docs
sbernauer 058a828
Remove unused error variant
sbernauer 58ab5ca
Add to DummyCluster
sbernauer 45a2ec5
Improve CRD docs
sbernauer 7cb1b89
Link to concepts page
sbernauer bf1d753
Derive PartialEq again
sbernauer cb0de44
Move import
sbernauer 4873ac2
Take owned value
sbernauer 5071be8
Update crates/stackable-operator/src/cluster_resources.rs
sbernauer 713ea10
PartialEq again
sbernauer 9f5019b
Improve changelog
sbernauer e28d64e
Add a comment in DeepMerge impl
sbernauer 0d6c134
Add some rustdocs
sbernauer c573b7a
patchinator -> deep_merger
sbernauer 7fde5b3
Fix remaining "patch" mentions
sbernauer d8274d0
Fixup accidential change
sbernauer 956d523
Rename patch -> merge
sbernauer b4f98e0
Use indoc for tests
sbernauer fc38a7c
refactor: Move stuff into ObjectOverrides::apply_to
sbernauer fe29dcb
refactor: Switch ObjectOverrides to unit struct
sbernauer cdbde7d
fix tests
sbernauer 22d1dc6
Update crates/stackable-operator/CHANGELOG.md
sbernauer 53d9af5
Merge the merge into the onto
sbernauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 142 additions & 1 deletion
143
crates/stackable-operator/src/crd/listener/listeners/v1alpha1_impl.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,148 @@ | ||
| use crate::crd::listener::listeners::v1alpha1::ListenerSpec; | ||
| use k8s_openapi::{DeepMerge, merge_strategies}; | ||
|
|
||
| use crate::crd::listener::listeners::v1alpha1::{ | ||
| Listener, ListenerIngress, ListenerPort, ListenerSpec, ListenerStatus, | ||
| }; | ||
|
|
||
| impl ListenerSpec { | ||
| pub(super) const fn default_publish_not_ready_addresses() -> Option<bool> { | ||
| Some(true) | ||
| } | ||
| } | ||
|
|
||
| impl DeepMerge for Listener { | ||
| fn merge_from(&mut self, other: Self) { | ||
| DeepMerge::merge_from(&mut self.metadata, other.metadata); | ||
| DeepMerge::merge_from(&mut self.spec, other.spec); | ||
| DeepMerge::merge_from(&mut self.status, other.status); | ||
| } | ||
| } | ||
|
|
||
| impl DeepMerge for ListenerSpec { | ||
| fn merge_from(&mut self, other: Self) { | ||
| DeepMerge::merge_from(&mut self.class_name, other.class_name); | ||
| merge_strategies::map::granular( | ||
| &mut self.extra_pod_selector_labels, | ||
| other.extra_pod_selector_labels, | ||
| |current_item, other_item| { | ||
| DeepMerge::merge_from(current_item, other_item); | ||
| }, | ||
| ); | ||
| merge_strategies::list::map( | ||
| &mut self.ports, | ||
| other.ports, | ||
| &[|lhs, rhs| lhs.name == rhs.name], | ||
| |current_item, other_item| { | ||
| DeepMerge::merge_from(current_item, other_item); | ||
| }, | ||
| ); | ||
Techassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| DeepMerge::merge_from( | ||
| &mut self.publish_not_ready_addresses, | ||
| other.publish_not_ready_addresses, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| impl DeepMerge for ListenerStatus { | ||
| fn merge_from(&mut self, other: Self) { | ||
| DeepMerge::merge_from(&mut self.service_name, other.service_name); | ||
| merge_strategies::list::map( | ||
| &mut self.ingress_addresses, | ||
| other.ingress_addresses, | ||
| &[|lhs, rhs| lhs.address == rhs.address], | ||
| |current_item, other_item| { | ||
| DeepMerge::merge_from(current_item, other_item); | ||
| }, | ||
| ); | ||
| merge_strategies::map::granular( | ||
| &mut self.node_ports, | ||
| other.node_ports, | ||
| |current_item, other_item| { | ||
| DeepMerge::merge_from(current_item, other_item); | ||
| }, | ||
| ); | ||
Techassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| impl DeepMerge for ListenerIngress { | ||
| fn merge_from(&mut self, other: Self) { | ||
| DeepMerge::merge_from(&mut self.address, other.address); | ||
| self.address_type = other.address_type; | ||
| merge_strategies::map::granular( | ||
| &mut self.ports, | ||
| other.ports, | ||
| |current_item, other_item| { | ||
| DeepMerge::merge_from(current_item, other_item); | ||
| }, | ||
| ); | ||
Techassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| impl DeepMerge for ListenerPort { | ||
| fn merge_from(&mut self, other: Self) { | ||
| DeepMerge::merge_from(&mut self.name, other.name); | ||
| DeepMerge::merge_from(&mut self.port, other.port); | ||
| DeepMerge::merge_from(&mut self.protocol, other.protocol); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn deep_merge_listener() { | ||
| let mut base: ListenerSpec = serde_yaml::from_str( | ||
Techassi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| " | ||
| className: my-listener-class | ||
| extraPodSelectorLabels: | ||
| foo: bar | ||
| ports: | ||
| - name: http | ||
| port: 8080 | ||
| protocol: http | ||
| - name: https | ||
| port: 8080 | ||
| protocol: https | ||
| # publishNotReadyAddresses defaults to true | ||
| ", | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| let patch: ListenerSpec = serde_yaml::from_str( | ||
| " | ||
| className: custom-listener-class | ||
| extraPodSelectorLabels: | ||
| foo: overridden | ||
| extra: label | ||
| ports: | ||
| - name: https | ||
| port: 8443 | ||
| publishNotReadyAddresses: false | ||
| ", | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| base.merge_from(patch); | ||
|
|
||
| let expected: ListenerSpec = serde_yaml::from_str( | ||
| " | ||
| className: custom-listener-class | ||
| extraPodSelectorLabels: | ||
| foo: overridden | ||
| extra: label | ||
| ports: | ||
| - name: http | ||
| port: 8080 | ||
| protocol: http | ||
| - name: https | ||
| port: 8443 # overridden | ||
| protocol: https | ||
| publishNotReadyAddresses: false | ||
| ", | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!(base, expected); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use kube::api::DynamicObject; | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::utils::crds::raw_object_list_schema; | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ObjectOverrides { | ||
| /// A list of generic Kubernetes objects, which are merged onto the objects that the operator | ||
| /// creates. | ||
| /// | ||
| /// List entries are arbitrary YAML objects, which need to be valid Kubernetes objects. | ||
| /// | ||
| /// Read the [Object overrides documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/overrides#object-overrides) | ||
| /// for more information. | ||
| #[serde(default)] | ||
| #[schemars(schema_with = "raw_object_list_schema")] | ||
| pub object_overrides: Vec<DynamicObject>, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.