-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Added ability to limit the LoadBalancers picked up by chisel-operator #153
Open
bw210343
wants to merge
8
commits into
FyraLabs:main
Choose a base branch
from
bw210343:limit-to-loadbalancerclass
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b818521
Try to fix an issue where cloud-provisioned ExitNodes don't get their…
korewaChino ed0a76e
feat: add funding.json well-known
lleyton e47dfeb
feat: add funding.json well-known to repo
lleyton dcdb88f
Add assignment checks to ExitNode
korewaChino 1f59035
cargo fmt
korewaChino 609334c
remove duplicate key
korewaChino 1599975
Merge pull request #146 from FyraLabs/pr/chart/svcaccname
korewaChino 0fe7a53
Added ability to limit the LoadBalancers picked up by chisel-operator
bw210343 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 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 @@ | ||
https://fyralabs.com/funding.json |
This file contains 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 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 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 @@ | ||
https://fyralabs.com/funding.json |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -16,10 +16,6 @@ | |
There can also be a case where the user creates an exit node manually, | ||
with the provisioner annotation set, in that case chisel operator will | ||
create a cloud resource for that exit node and manages it. | ||
|
||
todo: properly handle all this logic | ||
|
||
todo: use `tracing` and put every operation in a span to make debugging easier | ||
*/ | ||
|
||
use color_eyre::Result; | ||
|
@@ -46,6 +42,8 @@ use std::{collections::BTreeMap, sync::Arc}; | |
use std::time::Duration; | ||
use tracing::{debug, error, info, instrument, warn}; | ||
|
||
use std::env; | ||
|
||
use crate::{ | ||
cloud::Provisioner, | ||
ops::{ | ||
|
@@ -58,6 +56,8 @@ use crate::{deployment::create_owned_deployment, error::ReconcileError}; | |
pub const EXIT_NODE_FINALIZER: &str = "exitnode.chisel-operator.io/finalizer"; | ||
pub const SVCS_FINALIZER: &str = "service.chisel-operator.io/finalizer"; | ||
|
||
// todo: Refactor everything in here into separate functions, then we can write unit tests for them | ||
|
||
// pub fn get_trace_id() -> opentelemetry::trace::TraceId { | ||
// // opentelemetry::Context -> opentelemetry::trace::Span | ||
// use opentelemetry::trace::TraceContextExt as _; | ||
|
@@ -208,7 +208,7 @@ async fn select_exit_node_local( | |
.unwrap_or(false); | ||
|
||
// Is the ExitNode not cloud provisioned or is the status set? | ||
!is_cloud_provisioned || node.status.is_some() | ||
(!is_cloud_provisioned || node.status.is_some()) && !node.is_assigned() | ||
}) | ||
.collect::<Vec<ExitNode>>() | ||
.first() | ||
|
@@ -303,6 +303,13 @@ async fn exit_node_for_service( | |
async fn reconcile_svcs(obj: Arc<Service>, ctx: Arc<Context>) -> Result<Action, ReconcileError> { | ||
// Return if service is not LoadBalancer or if the loadBalancerClass is not blank or set to $OPERATOR_CLASS | ||
|
||
// Check if the REQUIRE_OPERATOR_CLASS environment variable is set | ||
let limit_load_balancer_class; | ||
match env::var("REQUIRE_OPERATOR_CLASS") { | ||
Ok(v) => limit_load_balancer_class = v, | ||
Err(_e) => limit_load_balancer_class = "false".to_string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a bit more elegant by using |
||
} | ||
|
||
// todo: is there anything different need to be done for OpenShift? We use vanilla k8s and k3s/rke2 so we don't know | ||
if obj | ||
.spec | ||
|
@@ -313,7 +320,7 @@ async fn reconcile_svcs(obj: Arc<Service>, ctx: Arc<Context>) -> Result<Action, | |
.spec | ||
.as_ref() | ||
.filter(|spec| { | ||
spec.load_balancer_class.is_none() | ||
(spec.load_balancer_class.is_none() && ( limit_load_balancer_class == "false")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also cast the boolean to a string using |
||
|| spec.load_balancer_class == Some(OPERATOR_CLASS.to_string()) | ||
}) | ||
.is_none() | ||
|
@@ -582,6 +589,7 @@ async fn reconcile_nodes(obj: Arc<ExitNode>, ctx: Arc<Context>) -> Result<Action | |
} | ||
} | ||
|
||
// Find provisioner | ||
let provisioner = find_exit_node_provisioner_from_label( | ||
ctx.clone(), | ||
&obj.namespace().unwrap(), | ||
|
@@ -590,6 +598,7 @@ async fn reconcile_nodes(obj: Arc<ExitNode>, ctx: Arc<Context>) -> Result<Action | |
.await | ||
.ok_or(ReconcileError::CloudProvisionerNotFound)?; | ||
|
||
// Get provisioner API handle | ||
let provisioner_api = provisioner.clone().spec.get_inner(); | ||
|
||
let secret = provisioner | ||
|
@@ -598,6 +607,8 @@ async fn reconcile_nodes(obj: Arc<ExitNode>, ctx: Arc<Context>) -> Result<Action | |
.map_err(|_| crate::error::ReconcileError::CloudProvisionerSecretNotFound)? | ||
.ok_or(ReconcileError::CloudProvisionerSecretNotFound)?; | ||
|
||
debug!(?secret, "Secret"); | ||
|
||
finalizer::finalizer( | ||
&exit_nodes.clone(), | ||
EXIT_NODE_FINALIZER, | ||
|
@@ -607,21 +618,40 @@ async fn reconcile_nodes(obj: Arc<ExitNode>, ctx: Arc<Context>) -> Result<Action | |
{ | ||
Event::Apply(node) => { | ||
let _node = { | ||
let mut pass_secret: Option<k8s_openapi::api::core::v1::Secret> = None; | ||
// if status exists, update, else create | ||
let cloud_resource = if let Some(_status) = node.status.as_ref() { | ||
info!("Updating cloud resource for {}", node.name_any()); | ||
provisioner_api | ||
.update_exit_node(secret.clone(), (*node).clone()) | ||
.await | ||
} else { | ||
// todo: probably update the Provisioner trait to accept a provisioner API handle or | ||
// the provisioner API token *and* then a password secret | ||
// Right now we have the create_exit_node method which returns the password secret alongside the status | ||
|
||
// create cloud resource | ||
info!("Creating cloud resource for {}", node.name_any()); | ||
provisioner_api | ||
|
||
let (resource, new_pass_secret) = provisioner_api | ||
.create_exit_node(secret.clone(), (*node).clone()) | ||
.await | ||
.await?; | ||
pass_secret = Some(new_pass_secret); | ||
Ok(resource) | ||
}; | ||
// TODO: Don't replace the entire status and object, sadly JSON is better here | ||
let exitnode_patch = serde_json::json!({ | ||
"status": cloud_resource? | ||
}); | ||
let exitnode_patch = if let Some(p_secret) = pass_secret { | ||
serde_json::json!({ | ||
"status": cloud_resource?, | ||
"spec": { | ||
"auth": p_secret.name_any(), | ||
} | ||
}) | ||
} else { | ||
serde_json::json!({ | ||
"status": cloud_resource?, | ||
}) | ||
}; | ||
|
||
exit_nodes | ||
.patch_status( | ||
|
This file contains 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
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.
REQUIRE_OPERATOR_CLASS
's envar key should be a const in case the name needs to be changed, so one can easily change them in case it does need to be changed