-
Notifications
You must be signed in to change notification settings - Fork 1.5k
OCPBUGS-63472: detect manual network config and set --copy-network installer arg #10414
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
Open
rwsu
wants to merge
1
commit into
openshift:main
Choose a base branch
from
rwsu:OCPBUGS-63472
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.
+778
−549
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
data/data/agent/files/usr/local/bin/agent-set-host-copy-network-arg.sh
This file contains hidden or 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,83 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| # shellcheck disable=SC1091 | ||
| source "common.sh" | ||
|
|
||
| NM_CONNECTIONS_DIR="/etc/NetworkManager/system-connections" | ||
|
|
||
| # Check for manually-created keyfiles, excluding those auto-generated by nm-initrd-generator. | ||
| # nm-initrd-generator creates keyfiles for DHCP during boot; these should not trigger | ||
| # --copy-network since they were not manually configured by the user. | ||
| # We additionally filter by the presence of a [connection] section to ensure we only | ||
| # act on valid NM keyfiles. NetworkManager may leave stray files (e.g. empty temp files) | ||
| # in the directory that lack the nm-initrd-generator marker but are not valid connections. | ||
| manual_keyfiles=$(find "$NM_CONNECTIONS_DIR" -maxdepth 1 -type f -print0 2>/dev/null | \ | ||
| xargs -r -0 grep -lZ "^\\[connection\\]" 2>/dev/null | \ | ||
| xargs -r -0 grep -LZ "org.freedesktop.NetworkManager.origin=nm-initrd-generator" 2>/dev/null | \ | ||
| tr '\0' '\n' || true) | ||
|
|
||
| if [ -z "$manual_keyfiles" ]; then | ||
| echo "No manually-created network keyfiles found in $NM_CONNECTIONS_DIR, skipping" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Found manually-created network keyfiles in $NM_CONNECTIONS_DIR, will set --copy-network for this host" | ||
| echo "$manual_keyfiles" | ||
|
|
||
| # Query INFRA_ENV_ID dynamically from the API on all nodes - this avoids relying on | ||
| # rendezvous-host.env which only has INFRA_ENV_ID on the rendezvous node. | ||
| # Retry indefinitely until the API is available and the infra-env is registered. | ||
| INFRA_ENV_ID="" | ||
| until [ -n "$INFRA_ENV_ID" ] && [ "$INFRA_ENV_ID" != "null" ]; do | ||
| INFRA_ENV_ID=$(curl_assisted_service "/infra-envs" GET 2>/dev/null | jq -r '.[0].id' 2>/dev/null) || true | ||
| if [ -z "$INFRA_ENV_ID" ] || [ "$INFRA_ENV_ID" = "null" ]; then | ||
| echo "Waiting for assisted-service and infra-env to be available..." | ||
| sleep 5 | ||
| fi | ||
| done | ||
| echo "Got INFRA_ENV_ID: $INFRA_ENV_ID" | ||
|
|
||
| # Get local MAC addresses (lowercase, skip loopback). These are used to match | ||
| # this host against the inventory reported by the agent to assisted-service, | ||
| # since assisted-service identifies hosts by their interface MAC addresses. | ||
| local_macs=$(ip link show | awk '/link\/ether/{print tolower($2)}') | ||
| if [ -z "$local_macs" ]; then | ||
| echo "ERROR: No ethernet interfaces found, cannot identify host in assisted-service" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Poll until this host appears in assisted-service (agent.service has registered it, | ||
| # but it may take a moment before the host is visible in the API) | ||
| host_id="" | ||
| until [ -n "$host_id" ]; do | ||
| for mac in $local_macs; do | ||
| host_id=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" GET 2>/dev/null | \ | ||
| jq -r --arg mac "$mac" ' | ||
| .[] | | ||
| select(.inventory != null and .inventory != "") | | ||
| select( | ||
| .inventory | fromjson | .interfaces // [] | | ||
| map(.mac_address | ascii_downcase) | | ||
| index($mac) != null | ||
| ) | | ||
| .id | ||
| ' 2>/dev/null | head -1) || true | ||
| [ -n "$host_id" ] && break | ||
| done | ||
|
|
||
| if [ -z "$host_id" ]; then | ||
| echo "Host not yet found in assisted-service, retrying..." | ||
| sleep 5 | ||
| fi | ||
| done | ||
|
|
||
| echo "Setting --copy-network installer arg for host ${host_id}" | ||
| http_code=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts/${host_id}/installer-args" PATCH \ | ||
| --data '{"args":["--copy-network"]}' \ | ||
| -o /dev/null -w "%{http_code}") | ||
| if [[ "$http_code" != "201" ]]; then | ||
| echo "ERROR: Failed to set --copy-network for host ${host_id}, HTTP status: ${http_code}" | ||
| exit 1 | ||
| fi | ||
| echo "Successfully set --copy-network for host ${host_id}" | ||
13 changes: 13 additions & 0 deletions
13
data/data/agent/systemd/units/agent-set-host-copy-network-arg.service
This file contains hidden or 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,13 @@ | ||
| [Unit] | ||
| Description=Set --copy-network installer arg if manual network config was detected | ||
| After=agent.service | ||
| Before=start-cluster-installation.service agent-add-node.service | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| RemainAfterExit=true | ||
| EnvironmentFile=/etc/assisted/rendezvous-host.env | ||
| ExecStart=/usr/local/bin/agent-set-host-copy-network-arg.sh | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
This file contains hidden or 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
Oops, something went wrong.
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.
Do not select infra-env by
.[0].id.Line 33 assumes the first infra-env belongs to this host. In environments with multiple infra-envs (notably add-nodes/unconfigured flows), this can patch the wrong host or wait forever in later host lookup.
Suggested fix (resolve host across infra-envs, then patch the matched one)
📝 Committable suggestion
🤖 Prompt for AI Agents