-
Notifications
You must be signed in to change notification settings - Fork 7
K8s-less mode #1164
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
+615
−142
Merged
K8s-less mode #1164
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e98ba6
feat(k8s-intf): add utils to read crd from json/yaml
Fredi-raspall 5c12409
feat(k8s-less): add k8s-less crate
Fredi-raspall e504bfa
feat(args): add cmd line arg for k8sless mode
Fredi-raspall 0678410
feat(mgmt): add k8s-less mode
Fredi-raspall 30a181c
feat(k8s-intf): extend utils to save json/yaml
Fredi-raspall 2df71ae
feat(mgmt): add function build_gateway_status()
Fredi-raspall 5264ae1
feat(k8s-less): augment k8s-less to write status to file
Fredi-raspall 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
Large diffs are not rendered by default.
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
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,86 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Open Network Fabric Authors | ||
|
|
||
| //! Utils to build the gateway CRD `GatewayAgentSpec` from JSON / YAML text files. | ||
|
|
||
| use crate::gateway_agent_crd::GatewayAgentSpec; | ||
| use serde::Serialize; | ||
| use serde_yaml_ng; | ||
| use std::fs; | ||
| use std::path::Path; | ||
|
|
||
| /// Read the file at `path` and deserialize it from YAML into a `GatewayAgentSpec` object. | ||
| fn load_crd_from_yaml(path: &str) -> Result<GatewayAgentSpec, String> { | ||
| let yaml = fs::read_to_string(path) | ||
| .map_err(|e| format!("Failed to read CRD from YAML file ({path}): {e}"))?; | ||
| let crd: GatewayAgentSpec = serde_yaml_ng::from_str(&yaml) | ||
| .map_err(|e| format!("Failed to deserialize CRD from YAML file ({path}): {e}"))?; | ||
| Ok(crd) | ||
| } | ||
|
|
||
| /// Read the file at `path` and deserialize it from JSON into a `GatewayAgentSpec` object. | ||
| fn load_crd_from_json(path: &str) -> Result<GatewayAgentSpec, String> { | ||
| let json = fs::read_to_string(path) | ||
| .map_err(|e| format!("Failed to read CRD from JSON file ({path}): {e}"))?; | ||
| let crd: GatewayAgentSpec = serde_json::from_str(&json) | ||
| .map_err(|e| format!("Failed to deserialize CRD from JSON file ({path}): {e}"))?; | ||
| Ok(crd) | ||
| } | ||
|
|
||
| /// Read the file at `path` and deserialize into a `GatewayAgentSpec` object. | ||
| /// The file is assumed to contain a gateway spec CRD in JSON or YAML. | ||
| /// | ||
| /// # Errors | ||
| /// This function may fail if the file does not exist or cannot be opened / read, or if the contents | ||
| /// cannot be deserialized. | ||
| pub fn load_crd_from_file(path: &str) -> Result<GatewayAgentSpec, String> { | ||
| let ext = Path::new(path).extension(); | ||
| match ext { | ||
| Some(ext) if ext.eq_ignore_ascii_case("yaml") || ext.eq_ignore_ascii_case("yml") => { | ||
| load_crd_from_yaml(path) | ||
| } | ||
| Some(ext) if ext.eq_ignore_ascii_case("json") => load_crd_from_json(path), | ||
| Some(ext) => Err(format!("Unsupported file extension {}", ext.display())), | ||
| None => Err("Missing file extension".to_string()), | ||
| } | ||
| } | ||
|
|
||
| /// Serialize an object as JSON and store it in the file at path `path`. | ||
| /// This function will create the file if it does not exist. | ||
| /// | ||
| /// # Errors | ||
| /// This function may fail if the object cannot be serialized or if the | ||
| /// full directory path does not exist. | ||
| pub fn save_as_json<T: Serialize>(path: &str, object: &T) -> Result<(), String> { | ||
| let json = | ||
| serde_json::to_string(object).map_err(|e| format!("Failed to serialize as JSON: {e}"))?; | ||
| fs::write(path, json).map_err(|e| format!("Failed to write json file at {path}: {e}")) | ||
| } | ||
|
|
||
| /// Serialize an object as YAML and store it in the file at path `path`. | ||
| /// This function will create the file if it does not exist. | ||
| /// | ||
| /// # Errors | ||
| /// This function may fail if the object cannot be serialized or if the | ||
| /// full directory path does not exist. | ||
| pub fn save_as_yaml<T: Serialize>(path: &str, object: &T) -> Result<(), String> { | ||
| let yaml = serde_yaml_ng::to_string(object) | ||
| .map_err(|e| format!("Failed to serialize as YAML: {e}"))?; | ||
| fs::write(path, yaml).map_err(|e| format!("Failed to write YAML file at {path}: {e}")) | ||
| } | ||
|
|
||
| /// Serialize an object as JSON and YAML and store both in separate files | ||
| /// with extensions .json and .yaml added to the indicated filename in `path`. | ||
| /// The files will be created if they do not exist. | ||
| /// | ||
| /// # Errors | ||
| /// This function may fail if the object cannot be serialized or if the | ||
| /// full directory path does not exist. | ||
| pub fn save<T: Serialize>(path: &str, object: &T) -> Result<(), String> { | ||
| let p = Path::new(path); | ||
| let yaml_file = p.with_added_extension("yaml"); | ||
| let json_file = p.with_added_extension("json"); | ||
| save_as_yaml(yaml_file.to_str().unwrap_or_else(|| unreachable!()), object)?; | ||
| save_as_json(json_file.to_str().unwrap_or_else(|| unreachable!()), object)?; | ||
| Ok(()) | ||
| } |
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,16 @@ | ||
| [package] | ||
| name = "dataplane-k8s-less" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| publish.workspace = true | ||
| repository.workspace = true | ||
|
|
||
| [dependencies] | ||
| gwname = { workspace = true } | ||
| inotify = { workspace = true, features = ["stream"] } | ||
| k8s-intf = { workspace = true } | ||
| tokio = { workspace = true, features = ["macros", "rt", "fs"] } | ||
| tracectl = { workspace = true } | ||
| tracing = { workspace = true } | ||
| tracing-test = { workspace = true } |
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,8 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Open Network Fabric Authors | ||
|
|
||
| //! Support for k8s-less mode where CRDs are learnt from a file | ||
|
|
||
| mod local; | ||
|
|
||
| pub use local::kubeless_watch_gateway_agent_crd; |
Oops, something went wrong.
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.