Skip to content

Commit

Permalink
add advertised-addr flag, needed for kubernetes deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
danrusei committed Aug 28, 2024
1 parent f122de3 commit 58c2f08
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ EXPOSE 6650 6651

# Define entrypoint and default command
ENTRYPOINT ["/usr/local/bin/danube-broker"]
CMD ["--config-file", "/etc/danube_broker.yml", "--broker-addr", "0.0.0.0:6650"]
CMD ["--config-file", "/etc/danube_broker.yml", "--broker-addr", "0.0.0.0:6650", "--advertised-addr", "0.0.0.0:6650"]
8 changes: 7 additions & 1 deletion danube-broker/src/danube_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ impl DanubeService {
.await;

// register the local broker to cluster
let advertised_addr = if let Some(advertised_addr) = &self.service_config.advertised_addr {
advertised_addr.to_string()
} else {
self.service_config.broker_addr.clone().to_string()
};

let ttl = 32; // Time to live for the lease in seconds
register_broker(
self.meta_store.clone(),
&self.broker_id.to_string(),
&self.service_config.broker_addr.to_string(),
&advertised_addr,
ttl,
)
.await?;
Expand Down
9 changes: 9 additions & 0 deletions danube-broker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ struct Args {
/// Prometheus Exporter http address (optional, overrides config file)
#[arg(short = 'p', long)]
prom_exporter: Option<String>,

/// Advertised address - fqdn (optional, required for kubernetes deployment)
#[arg(short = 'd', long)]
advertised_addr: Option<String>,
}

#[tokio::main]
Expand All @@ -87,6 +91,11 @@ async fn main() -> Result<()> {
service_config.broker_addr = broker_address;
}

// If "advertised_addr" is provided via command-line args
if let Some(advertised_addr) = args.advertised_addr {
service_config.advertised_addr = Some(advertised_addr)
}

// If `admin_addr` is provided via command-line args, override the value from the config file
if let Some(admin_addr) = args.admin_addr {
let admin_address: SocketAddr = admin_addr.parse().context(format!(
Expand Down
3 changes: 3 additions & 0 deletions danube-broker/src/service_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub(crate) struct ServiceConfiguration {
pub(crate) cluster_name: String,
/// Broker Service address for serving gRPC requests.
pub(crate) broker_addr: std::net::SocketAddr,
/// Broker Advertised address, used for kubernetes deployment
pub(crate) advertised_addr: Option<String>,
/// Admin API address
pub(crate) admin_addr: std::net::SocketAddr,
/// Prometheus exporter address
Expand Down Expand Up @@ -80,6 +82,7 @@ impl TryFrom<LoadConfiguration> for ServiceConfiguration {
Ok(ServiceConfiguration {
cluster_name: config.cluster_name,
broker_addr,
advertised_addr: None,
admin_addr,
prom_exporter,
meta_store_addr,
Expand Down

0 comments on commit 58c2f08

Please sign in to comment.