Skip to content

Commit db50ee4

Browse files
committed
Properly fix external host value handling
Ported from stable :3
1 parent 8d7a157 commit db50ee4

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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
@@ -1,6 +1,6 @@
11
[package]
22
name = "chisel-operator"
3-
version = "0.6.0-beta.1"
3+
version = "0.6.0-beta.2"
44
edition = "2021"
55
description = "Chisel tunnel operator for Kubernetes"
66
authors = [

charts/chisel-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ version: 0.1.0
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "v0.6.0-beta.1"
24+
appVersion: "v0.6.0-beta.2"

deploy/crd/exit-node.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ spec:
3434
description: Optional boolean value for whether to make the exit node the default route for the cluster If true, the exit node will be the default route for the cluster default value is false
3535
type: boolean
3636
external_host:
37-
description: Optional real external hostname/IP of exit node If not provided, the host field will be used
37+
description: |-
38+
Optional real external hostname or IP of the exit node.
39+
40+
This field is used to explicitly specify the public-facing endpoint for the exit node. If set to an IP address, it will be used as the `ip` field in the Service's `status.loadBalancer.ingress`, which is what external-dns and other automation will use to create DNS records or inform users of the external endpoint. If set to a DNS name, it will be used as the `hostname` field in the same struct.
41+
42+
This is useful when the exit node is only reachable via a specific external IP or hostname, even if the internal service is routed to a private address. If not provided, the value of the `host` field will be used instead.
3843
nullable: true
3944
type: string
4045
fingerprint:

deploy/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec:
1919
automountServiceAccountToken: true
2020
containers:
2121
- name: chisel-operator
22-
image: ghcr.io/fyralabs/chisel-operator:v0.6.0-beta.1
22+
image: ghcr.io/fyralabs/chisel-operator:v0.6.0-beta.2
2323
env:
2424
- name: RUST_LOG
2525
value: "debug"

src/daemon.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,28 @@ async fn reconcile_svcs(obj: Arc<Service>, ctx: Arc<Context>) -> Result<Action,
466466

467467
let serverside = PatchParams::apply(OPERATOR_MANAGER).validation_strict();
468468

469+
let external_host = node.get_external_host();
470+
471+
// this is kinda hard to read,
472+
// but we do want to properly set up the LoadBalancer status properly
473+
let (ingress_ip, ingress_hostname) = if !external_host.is_empty() {
474+
if external_host.parse::<std::net::IpAddr>().is_ok() {
475+
// If the external host is a valid IP address, use it
476+
(Some(external_host), None)
477+
} else {
478+
// if not an IP address, use it as a hostname
479+
(None, Some(external_host))
480+
}
481+
} else {
482+
// or if we don't have an external hostname configured, just use the IP
483+
(Some(exit_node_ip.clone()), None)
484+
};
485+
469486
svc.status = Some(ServiceStatus {
470487
load_balancer: Some(LoadBalancerStatus {
471488
ingress: Some(vec![LoadBalancerIngress {
472-
ip: Some(exit_node_ip.clone()),
473-
// hostname: Some(node.get_external_host()),
489+
ip: ingress_ip,
490+
hostname: ingress_hostname,
474491
..Default::default()
475492
}]),
476493
}),

src/ops.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ pub fn parse_provisioner_label_value<'a>(
4242
pub struct ExitNodeSpec {
4343
/// Hostname or IP address of the chisel server
4444
pub host: String,
45-
/// Optional real external hostname/IP of exit node
46-
/// If not provided, the host field will be used
45+
/// Optional real external hostname or IP of the exit node.
46+
///
47+
/// This field is used to explicitly specify the public-facing endpoint for the exit node.
48+
/// If set to an IP address, it will be used as the `ip` field in the Service's
49+
/// `status.loadBalancer.ingress`, which is what external-dns and other automation
50+
/// will use to create DNS records or inform users of the external endpoint.
51+
/// If set to a DNS name, it will be used as the `hostname` field in the same struct.
52+
///
53+
/// This is useful when the exit node is only reachable via a specific external IP or
54+
/// hostname, even if the internal service is routed to a private address.
55+
/// If not provided, the value of the `host` field will be used instead.
4756
#[serde(default)]
4857
pub external_host: Option<String>,
4958
/// Control plane port of the chisel server
@@ -85,6 +94,15 @@ impl ExitNode {
8594
}
8695
}
8796

97+
/// returns the external host for use in LoadBalancer Ingress hostname
98+
/// if external_host is set, use that, otherwise use get_host()
99+
pub fn get_external_host(&self) -> String {
100+
self.spec
101+
.external_host
102+
.clone()
103+
.unwrap_or_else(|| self.get_host())
104+
}
105+
88106
/// For cloud provisioning:
89107
///
90108
/// Generates a new secret with the `auth` key containing the auth string for chisel in the same namespace as the ExitNode

0 commit comments

Comments
 (0)