Skip to content

Commit

Permalink
Revert "[PLAT-14786] Add support to node_agent install to use bind ip…
Browse files Browse the repository at this point in the history
… and node_external_fqdn"

Summary: This reverts commit b27047d.

Test Plan: na

Reviewers: sneelakantan

Reviewed By: sneelakantan

Subscribers: sneelakantan, yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37724
  • Loading branch information
Vars-07 committed Sep 3, 2024
1 parent 9b4c4b5 commit 9e0c569
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 78 deletions.
88 changes: 47 additions & 41 deletions managed/node-agent/cli/node/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"net"
"node-agent/app/executor"
"node-agent/app/server"
"node-agent/app/task"
Expand Down Expand Up @@ -164,26 +165,28 @@ func configureDisabledEgress(ctx context.Context, cmd *cobra.Command) {
util.ConsoleLogger().Fatalf(ctx, "Unable to store node agent IP - %s", err.Error())
}
nodeIp := config.String(util.NodeIpKey)
bindIp, err := cmd.Flags().GetString("bind_ip")
if err != nil {
util.FileLogger().Infof(ctx, "Unable to get bind IP - %s", err.Error())
util.FileLogger().Infof(ctx, "Using parsed node ip")
bindIp = nodeIp
}
util.FileLogger().Infof(ctx, "Bind IP: %s", bindIp)
// Get the bind IP if it is DNS. It defaults to the DNS if it is not present.
_, err = config.StoreCommandFlagString(
ctx,
cmd,
"bind_ip",
util.NodeBindIpKey,
&bindIp,
true, /* isRequired */
nil, /* validator */
)
if err != nil {
util.ConsoleLogger().
Fatalf(ctx, "Unable to store node agent bind IP - %s", err.Error())
parsedIp := net.ParseIP(nodeIp)
if parsedIp == nil {
// Get the bind IP if it is DNS. It defaults to the DNS if it is not present.
_, err = config.StoreCommandFlagString(
ctx,
cmd,
"bind_ip",
util.NodeBindIpKey,
&nodeIp,
true, /* isRequired */
nil, /* validator */
)
if err != nil {
util.ConsoleLogger().
Fatalf(ctx, "Unable to store node agent bind IP - %s", err.Error())
}
} else {
// Use the node IP as the bind IP.
err = config.Update(util.NodeBindIpKey, nodeIp)
if err != nil {
util.ConsoleLogger().Fatalf(ctx, "Unable to store node agent bind IP - %s", err.Error())
}
}
_, err = config.StoreCommandFlagString(
ctx,
Expand Down Expand Up @@ -297,29 +300,32 @@ func configureEnabledEgress(ctx context.Context, cmd *cobra.Command) {
checkConfigAndUpdate(ctx, util.NodeIpKey, nil, "Node IP")
}
nodeIp := config.String(util.NodeIpKey)
bindIp, err := cmd.Flags().GetString("bind_ip")
if err != nil {
util.FileLogger().Errorf(ctx, "Unable to get bind IP - %s", err.Error())
util.FileLogger().Infof(ctx, "Using node ip")
bindIp = nodeIp
}
util.FileLogger().Infof(ctx, "Bind IP: %s", bindIp)
if silent {
_, err = config.StoreCommandFlagString(
ctx,
cmd,
"bind_ip",
util.NodeBindIpKey,
&bindIp, /* default value */
true, /* isRequired */
nil, /* validator */
)
if err != nil {
util.ConsoleLogger().
Fatalf(ctx, "Unable to store node agent bind IP - %s", err.Error())
parsedIp := net.ParseIP(nodeIp)
if parsedIp == nil {
// Get the bind IP if it is DNS. It defaults to the DNS if it is not present.
if silent {
_, err = config.StoreCommandFlagString(
ctx,
cmd,
"bind_ip",
util.NodeBindIpKey,
&nodeIp,
true, /* isRequired */
nil, /* validator */
)
if err != nil {
util.ConsoleLogger().
Fatalf(ctx, "Unable to store node agent bind IP - %s", err.Error())
}
} else {
checkConfigAndUpdate(ctx, util.NodeBindIpKey, &nodeIp, "Bind IP")
}
} else {
checkConfigAndUpdate(ctx, util.NodeBindIpKey, &bindIp, "Bind IP")
// Use the node IP as the bind IP.
err = config.Update(util.NodeBindIpKey, nodeIp)
if err != nil {
util.ConsoleLogger().Fatalf(ctx, "Unable to store node agent bind IP - %s", err.Error())
}
}
providersHandler := task.NewGetProvidersHandler(apiToken)
// Get Providers from the platform (only on-prem providers displayed)
Expand Down
10 changes: 0 additions & 10 deletions managed/node-agent/resources/node-agent-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ CERT_DIR=""
CUSTOMER_ID=""
NODE_NAME=""
NODE_IP=""
BIND_IP=""
NODE_PORT=""
API_TOKEN=""
PLATFORM_URL=""
Expand Down Expand Up @@ -396,7 +395,6 @@ Options:
Server IP.
-p, --node_port (OPTIONAL for install command)
Server port.
--bind_ip (OPTIONAL if bind_ip is different than node_ip)
--user (REQUIRED only for install_service command)
Username of the installation. A sudo user can install service for a non-sudo user.
--skip_verify_cert (OPTIONAL)
Expand Down Expand Up @@ -546,10 +544,6 @@ main() {
NODE_AGENT_CONFIG_ARGS+=(--disable_egress --id "$NODE_AGENT_ID" --customer_id "$CUSTOMER_ID" \
--cert_dir "$CERT_DIR" --node_name "$NODE_NAME" --node_ip "$NODE_IP" \
--node_port "$NODE_PORT" "${SKIP_VERIFY_CERT:+ "--skip_verify_cert"}")
# if bind ip is provided use that.
if [ -n "$BIND_IP" ]; then
NODE_AGENT_CONFIG_ARGS+=(--bind_ip "$BIND_IP")
fi
fi
setup_node_agent_dir
extract_package
Expand Down Expand Up @@ -665,10 +659,6 @@ while [[ $# -gt 0 ]]; do
NODE_IP=$2
shift
;;
--bind_ip)
BIND_IP=$2
shift
;;
-p|--node_port)
NODE_PORT=$2
shift
Expand Down
1 change: 0 additions & 1 deletion managed/node-agent/resources/node-agent-provision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ yba:
customer_uuid: <customer_uuid>
api_key: <api_key>
node_name: <name>
node_external_fqdn: <ip/dns>
provider:
name: provider_name
region:
Expand Down
1 change: 0 additions & 1 deletion managed/node-agent/resources/ynp/configs/config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ ports = 7000 7100 9000 9100 18018 22 5433 9042 9070 9300 12000 13000
{{ render_section(yba) -}}
tmp_directory = {{ ynp.tmp_directory }}
node_ip = {{ ynp.node_ip }}
bind_ip = {{ ynp.node_ip }}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ def _get_headers(self, token):
}

def _get_provider_url(self, context):
return (f'{context.get("url")}/api/v1/customers/{context.get("customer_uuid")}'
f'/providers?name={context.get("provider_name")}')
return (
f'{context.get("url")}/api/v1/customers/{context.get("customer_uuid")}/providers'
f'?name={context.get("provider_name")}'
)

def _get_instance_type(self, yba_url, customer_uuid, p_uuid, code):
return (f'{yba_url}/api/v1/customers/{customer_uuid}/providers/'
f'{p_uuid}/instance_types/{code}')
return (
f'{yba_url}/api/v1/customers/{customer_uuid}/providers/'
f'{p_uuid}/instance_types/{code}'
)

def _generate_provider_payload(self, context):
# Generates the body for provider payload.
Expand Down Expand Up @@ -106,8 +110,8 @@ def _generate_instance_type_payload(self, context):
'volumeDetailsList': []
}
}
mount_points = context.get('instance_type_mount_points').strip(
"[]").replace("'", "").split(", ")
mount_points = (context.get('instance_type_mount_points')
.strip("[]").replace("'", "").split(", "))
for mp in mount_points:
volume_detail = {
'volumeSizeGB': context.get('instance_type_volume_size'),
Expand All @@ -123,7 +127,7 @@ def _generate_add_node_payload(self, context):
"nodes": [
{
"instanceType": context.get('instance_type_name'),
"ip": context.get('node_external_fqdn'),
"ip": context.get('node_ip'),
"region": context.get('provider_region_name'),
"zone": context.get('provider_region_zone_name'),
"nodeName": context.get("node_name"),
Expand All @@ -146,8 +150,10 @@ def _get_provider(self, context):
def _create_instance_if_not_exists(self, context, provider):
yba_url = context.get('url')
skip_tls_verify = not yba_url.lower().startswith('https')
get_instance_type_url = self._get_instance_type(context.get('url'), context.get(
'customer_uuid'), provider.get('uuid'), context.get('instance_type_name'))
get_instance_type_url = self._get_instance_type(context.get('url'),
context.get('customer_uuid'),
provider.get('uuid'),
context.get('instance_type_name'))

try:
response = requests.get(get_instance_type_url,
Expand All @@ -160,10 +166,11 @@ def _create_instance_if_not_exists(self, context, provider):
except requests.exceptions.HTTPError as http_err:
if response.status_code == 400:
logging.info("Instance type does not exist, creating it.")
instance_data = self._generate_instance_type_payload(context, provider['uuid'])
context['provider_id'] = provider['uuid']
instance_data = self._generate_instance_type_payload(context)

instance_payload_file = os.path.join(
context.get('tmp_directory'), 'create_instance.json')
instance_payload_file = os.path.join(context.get('tmp_directory'),
'create_instance.json')
with open(instance_payload_file, 'w') as f:
json.dump(instance_data, f, indent=4)
else:
Expand Down Expand Up @@ -216,8 +223,8 @@ def render_templates(self, context):
if not region_exists or not zone_exist:
update_provider_data = self._generate_provider_update_payload(
context, provider_data)
update_provider_data_file = os.path.join(
context.get('tmp_directory'), 'update_provider.json')
update_provider_data_file = os.path.join(context.get('tmp_directory'),
'update_provider.json')
with open(update_provider_data_file, 'w') as f:
json.dump(update_provider_data, f, indent=4)
self._create_instance_if_not_exists(context, provider_data)
Expand All @@ -226,13 +233,13 @@ def render_templates(self, context):
else:
logging.info("Generating provider create payload...")
provider_payload = self._generate_provider_payload(context)
provider_payload_file = os.path.join(
context.get('tmp_directory'), 'create_provider.json')
provider_payload_file = os.path.join(context.get('tmp_directory'),
'create_provider.json')
with open(provider_payload_file, 'w') as f:
json.dump(provider_payload, f, indent=4)
instance_create_payload = self._generate_instance_type_payload(context)
instance_payload_file = os.path.join(
context.get('tmp_directory'), 'create_instance.json')
instance_payload_file = os.path.join(context.get('tmp_directory'),
'create_instance.json')
with open(instance_payload_file, 'w') as f:
json.dump(instance_create_payload, f, indent=4)
node_agent_enabled = True
Expand All @@ -243,8 +250,8 @@ def render_templates(self, context):
logging.error(f"Request error: {req_err}")

add_node_payload = self._generate_add_node_payload(context)
add_node_payload_file = os.path.join(context.get(
'tmp_directory'), 'add_node_to_provider.json')
add_node_payload_file = os.path.join(context.get('tmp_directory'),
'add_node_to_provider.json')
with open(add_node_payload_file, 'w') as f:
json.dump(add_node_payload, f, indent=4)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ airgap_flag=""

installer_dir="{{ ynp_dir }}/../../bin"
su - {{ yb_user }} -c "\"$installer_dir/node-agent-installer.sh\" -c install \
-u {{ url }} -t {{ api_key }} --provider_id $provider_id \
--instance_type {{ instance_type_name }} --zone_name {{ provider_region_zone_name }} \
--node_name {{ node_name }} --node_ip {{ node_external_fqdn }} \
--bind_ip {{ bind_ip }} --silent --skip_verify_cert $airgap_flag"
-u {{ url }} -t {{ api_key }} --provider_id $provider_id \
--instance_type {{ instance_type_name }} --region_name {{ provider_region_name }} \
--zone_name {{ provider_region_zone_name }} --node_name {{ node_name }} \
--node_ip {{ node_ip }} --silent --skip_verify_cert $airgap_flag"

loginctl enable-linger {{ yb_user }}
# install node_agent service
Expand All @@ -219,7 +219,7 @@ if test -f "{{ tmp_directory }}/add_node_to_provider.json"; then
# Extract IPs using sed and grep
ips=$(echo "$response_body" | sed -n 's/.*"ip":"\([^"]*\)".*/\1/p')
for ip in $ips; do
if [[ "$ip" == "{{ node_external_fqdn }}" ]]; then
if [[ "$ip" == "{{ node_ip }}" ]]; then
matched=true
break
fi
Expand Down

0 comments on commit 9e0c569

Please sign in to comment.