-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: automatic cluster detection #1068
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
592fdc1
added kubelet.rs
razvan 77e8e1b
fetch kubelet config when initializing operators
razvan dd4b5d1
deserialize proxy reposponse once
razvan f6b4aef
don't fetch cluster domain from kubelet if the user has set it already
razvan 5fe91bd
remove comment with typo
razvan ecd63cd
revert unintended auto-format
razvan ea12f24
Apply suggestions from code review
razvan 357a62d
better error messages
razvan 2e71f67
move kubelet query to cluster_info mod
razvan 4a07fd3
review feedback
razvan ca69256
Merge branch 'main' into feat/issues/662
razvan a5120a2
Update crates/stackable-operator/CHANGELOG.md
razvan 3338c56
fix md lint
razvan 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use http; | ||
use k8s_openapi::api::core::v1::Node; | ||
use kube::{ | ||
Api, | ||
api::{ListParams, ResourceExt}, | ||
client::Client, | ||
}; | ||
use serde::Deserialize; | ||
use snafu::{OptionExt, ResultExt, Snafu}; | ||
|
||
use crate::commons::networking::DomainName; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub enum Error { | ||
#[snafu(display("failed to list nodes"))] | ||
ListNodes { source: kube::Error }, | ||
|
||
#[snafu(display("failed to build request for url path \"{url_path}\""))] | ||
BuildConfigzRequest { | ||
source: http::Error, | ||
url_path: String, | ||
}, | ||
|
||
#[snafu(display("failed to fetch kubelet config from node {node:?}"))] | ||
FetchNodeKubeletConfig { source: kube::Error, node: String }, | ||
|
||
#[snafu(display("failed to fetch `kubeletconfig` JSON key from configz response"))] | ||
KubeletConfigJsonKey, | ||
|
||
#[snafu(display("failed to deserialize kubelet config JSON"))] | ||
KubeletConfigJson { source: serde_json::Error }, | ||
|
||
#[snafu(display( | ||
"empty Kubernetes nodes list. At least one node is required to fetch the cluster domain from the kubelet config" | ||
))] | ||
EmptyKubernetesNodesList, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct ProxyConfigResponse { | ||
kubeletconfig: KubeletConfig, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct KubeletConfig { | ||
pub cluster_domain: DomainName, | ||
} | ||
|
||
impl KubeletConfig { | ||
/// Fetches the kubelet configuration from the "first" node in the Kubernetes cluster. | ||
pub async fn fetch(client: &Client) -> Result<Self, Error> { | ||
let api: Api<Node> = Api::all(client.clone()); | ||
let nodes = api | ||
.list(&ListParams::default()) | ||
.await | ||
.context(ListNodesSnafu)?; | ||
let node = nodes.iter().next().context(EmptyKubernetesNodesListSnafu)?; | ||
let node_name = node.name_any(); | ||
|
||
let url_path = format!("/api/v1/nodes/{node_name}/proxy/configz"); | ||
let req = http::Request::get(url_path.clone()) | ||
.body(Default::default()) | ||
.context(BuildConfigzRequestSnafu { url_path })?; | ||
|
||
let resp = client | ||
.request::<ProxyConfigResponse>(req) | ||
.await | ||
.context(FetchNodeKubeletConfigSnafu { node: node_name })?; | ||
|
||
Ok(resp.kubeletconfig) | ||
} | ||
} |
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,6 +1,7 @@ | ||
pub mod bash; | ||
pub mod cluster_info; | ||
pub mod crds; | ||
pub mod kubelet; | ||
pub mod logging; | ||
mod option; | ||
mod url; | ||
|
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.
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.
We can inject this through the downwards API instead.
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.
slick! forgot about that :(
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.
I'll do a followup PR.
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.
Thanks, good idea!
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.
#1071