From 1ea8a2da392873d56a1c6d728ea8ef48aa951e4d Mon Sep 17 00:00:00 2001 From: Greg Cusack Date: Tue, 30 Jul 2024 16:22:28 -0700 Subject: [PATCH] set correct rpc address (#63) --- src/kubernetes.rs | 22 +++++++++++++++------- src/startup_scripts.rs | 14 +++++++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/kubernetes.rs b/src/kubernetes.rs index 135b01f..8f8a9e6 100644 --- a/src/kubernetes.rs +++ b/src/kubernetes.rs @@ -260,6 +260,8 @@ impl<'a> Kubernetes<'a> { if self.metrics.is_some() { env_vars.push(self.get_metrics_env_var_secret()) } + env_vars.push(self.set_namespace_environment_variable()); + env_vars.append(&mut self.set_load_balancer_environment_variables()); let accounts_volume = Some(vec![Volume { name: "bootstrap-accounts-volume".into(), @@ -473,13 +475,16 @@ impl<'a> Kubernetes<'a> { } } + fn set_namespace_environment_variable(&self) -> EnvVar { + k8s_helpers::create_environment_variable( + "NAMESPACE".to_string(), + None, + Some("metadata.namespace".to_string()), + ) + } + fn set_non_bootstrap_environment_variables(&self) -> Vec { vec![ - k8s_helpers::create_environment_variable( - "NAMESPACE".to_string(), - None, - Some("metadata.namespace".to_string()), - ), k8s_helpers::create_environment_variable( "BOOTSTRAP_RPC_ADDRESS".to_string(), Some("bootstrap-validator-service.$(NAMESPACE).svc.cluster.local:8899".to_string()), @@ -567,10 +572,11 @@ impl<'a> Kubernetes<'a> { label_selector: &BTreeMap, validator_index: usize, ) -> Result> { - let mut env_vars = self.set_non_bootstrap_environment_variables(); + let mut env_vars = vec![self.set_namespace_environment_variable()]; if self.metrics.is_some() { env_vars.push(self.get_metrics_env_var_secret()) } + env_vars.append(&mut self.set_non_bootstrap_environment_variables()); env_vars.append(&mut self.set_load_balancer_environment_variables()); let accounts_volume = Some(vec![Volume { @@ -643,6 +649,7 @@ impl<'a> Kubernetes<'a> { }), ..Default::default() }]; + env_vars.push(self.set_namespace_environment_variable()); env_vars.append(&mut self.set_non_bootstrap_environment_variables()); env_vars.append(&mut self.set_load_balancer_environment_variables()); @@ -707,10 +714,11 @@ impl<'a> Kubernetes<'a> { label_selector: &BTreeMap, client_index: usize, ) -> Result> { - let mut env_vars = self.set_non_bootstrap_environment_variables(); + let mut env_vars = vec![self.set_namespace_environment_variable()]; if self.metrics.is_some() { env_vars.push(self.get_metrics_env_var_secret()) } + env_vars.append(&mut self.set_non_bootstrap_environment_variables()); env_vars.append(&mut self.set_load_balancer_environment_variables()); let accounts_volume = Some(vec![Volume { diff --git a/src/startup_scripts.rs b/src/startup_scripts.rs index 146c37b..236c150 100644 --- a/src/startup_scripts.rs +++ b/src/startup_scripts.rs @@ -172,6 +172,8 @@ for arg in "${args[@]}"; do echo "$arg" done +solana config set -u "http://$LOAD_BALANCER_RPC_ADDRESS" + pid= kill_node() { # Note: do not echo anything from this function to ensure $pid is actually @@ -510,6 +512,8 @@ RETRY_DELAY=5 # Load balancer RPC URL LOAD_BALANCER_RPC_URL="http://$LOAD_BALANCER_RPC_ADDRESS" +solana config set -u $LOAD_BALANCER_RPC_URL + # Identity file IDENTITY_FILE=$identity @@ -560,12 +564,12 @@ run_solana_command() { } setup_validator() { - if ! run_solana_command "solana -u $LOAD_BALANCER_RPC_URL airdrop $node_sol $IDENTITY_FILE" "Airdrop"; then + if ! run_solana_command "solana airdrop $node_sol $IDENTITY_FILE" "Airdrop"; then echo "Aidrop command failed." exit 1 fi - if ! run_solana_command "solana -u $LOAD_BALANCER_RPC_URL create-vote-account --allow-unsafe-authorized-withdrawer validator-accounts/vote.json $IDENTITY_FILE $IDENTITY_FILE -k $IDENTITY_FILE --commission $commission" "Create Vote Account"; then + if ! run_solana_command "solana create-vote-account --allow-unsafe-authorized-withdrawer validator-accounts/vote.json $IDENTITY_FILE $IDENTITY_FILE -k $IDENTITY_FILE --commission $commission" "Create Vote Account"; then if $vote_account_already_exists; then echo "Vote account already exists. Skipping remaining commands." else @@ -579,7 +583,7 @@ setup_validator() { run_delegate_stake() { echo "stake sol for account: $stake_sol" - if ! run_solana_command "solana -u $LOAD_BALANCER_RPC_URL create-stake-account validator-accounts/stake.json $stake_sol -k $IDENTITY_FILE" "Create Stake Account"; then + if ! run_solana_command "solana create-stake-account validator-accounts/stake.json $stake_sol -k $IDENTITY_FILE" "Create Stake Account"; then if $stake_account_already_exists; then echo "Stake account already exists. Skipping remaining commands." else @@ -591,14 +595,14 @@ run_delegate_stake() { if [ "$stake_account_already_exists" != true ]; then echo "stake account does not exist. so lets deligate" - if ! run_solana_command "solana -u $LOAD_BALANCER_RPC_URL delegate-stake validator-accounts/stake.json validator-accounts/vote.json --force -k $IDENTITY_FILE" "Delegate Stake"; then + if ! run_solana_command "solana delegate-stake validator-accounts/stake.json validator-accounts/vote.json --force -k $IDENTITY_FILE" "Delegate Stake"; then echo "Delegate stake command failed." exit 1 fi echo "delegated stake" fi - solana --url $LOAD_BALANCER_RPC_URL --keypair $IDENTITY_FILE stake-account validator-accounts/stake.json + solana --keypair $IDENTITY_FILE stake-account validator-accounts/stake.json } echo "get airdrop and create vote account"