Skip to content

NO-JIRA: feat: add ssh-node target for quick SSH access to cluster nodes#55

Open
clobrano wants to merge 1 commit intoopenshift-eng:mainfrom
clobrano:feature/simplify-ssh-into-node
Open

NO-JIRA: feat: add ssh-node target for quick SSH access to cluster nodes#55
clobrano wants to merge 1 commit intoopenshift-eng:mainfrom
clobrano:feature/simplify-ssh-into-node

Conversation

@clobrano
Copy link
Contributor

@clobrano clobrano commented Mar 12, 2026

Add 'make ssh-node' command to simplify SSH access to cluster nodes.

Usage:
make ssh-node node=master-0 # Interactive SSH session
make ssh-node node=1 # SSH to master-1
make ssh-node node=0 cmd='pcs status' # Run command and return

Features:

  • Supports multiple node name formats (master-0, master_0, node0, 0)
  • Handles known_hosts issues from cluster redeploys
  • Uses ProxyJump through the hypervisor automatically

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 12, 2026
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 12, 2026
@openshift-ci
Copy link

openshift-ci bot commented Mar 12, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci-robot
Copy link

@clobrano: This pull request explicitly references no jira issue.

Details

In response to this:

Add 'make ssh-node' command to simplify SSH access to cluster nodes.

Usage:
make ssh-node master-0 # Interactive SSH session
make ssh-node 1 # SSH to master-1
make ssh-node 0 'pcs status' # Run command and return

Features:

  • Supports multiple node name formats (master-0, master_0, node0, 0)
  • Handles known_hosts issues from cluster redeploys
  • Uses ProxyJump through the hypervisor automatically

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link

openshift-ci bot commented Mar 12, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clobrano

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2026
@clobrano clobrano force-pushed the feature/simplify-ssh-into-node branch from 68a1e2e to 9ac5588 Compare March 12, 2026 08:57
Add 'make ssh-node' command to simplify SSH access to cluster nodes.

Usage:
  make ssh-node node=master-0               # Interactive SSH session
  make ssh-node node=1                      # SSH to master-1
  make ssh-node node=0 cmd='pcs status'     # Run command and return

Features:
- Supports multiple node name formats (master-0, master_0, node0, 0)
- Handles known_hosts issues from cluster redeploys
- Uses ProxyJump through the hypervisor automatically
@clobrano clobrano force-pushed the feature/simplify-ssh-into-node branch from 9ac5588 to 3c99bea Compare March 12, 2026 08:58
@clobrano clobrano marked this pull request as ready for review March 12, 2026 08:59
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 12, 2026
@openshift-ci openshift-ci bot requested review from fonta-rh and qJkee March 12, 2026 08:59
Copy link
Contributor

@fonta-rh fonta-rh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! For attacking both nodes, ad hoc ansible like this works well:
ansible -a "sudo podman inspect sushy-tools" cluster_vms -i openshift-clusters/inventory.ini

But adapting it work constantly on a single node was a pain, so this is a great addition!

Out of the review comments, I only think the unreachable echos are necessary, the rest is just nitpicking

@@ -0,0 +1,92 @@
#!/bin/bash

set -euo pipefail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to make a few lines of helpful errors unreachable, I'll point them out below

# Extract node IP from inventory
NODE_IP=$(grep -E "master_0|master_1" "${INVENTORY_FILE}" | grep "${NODE_PATTERN}" | grep -oP "ansible_host='\\K[^']+")

if [[ -z "${NODE_IP}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be unreachable: if line 55 grep doesn't find anything, it will have exit code 1 and script should exit.

Adding "|| true" to the command on 55 should be enough, we're checking for content of grep output anyway

# Extract hypervisor info from inventory
HYPERVISOR=$(grep -E "^[^#]*@" "${INVENTORY_FILE}" | head -1 | awk '{print $1}')

if [[ -z "${HYPERVISOR}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be unreachable: if line 64 grep doesn't find anything, it will have exit code 1 and script should exit

fi

# Extract hypervisor info from inventory
HYPERVISOR=$(grep -E "^[^#]*@" "${INVENTORY_FILE}" | head -1 | awk '{print $1}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great to parse the ProxyJump, but it might also hit the @ in "ansible_ssh_common_args" if the inventory were ordered differently, so although it works with the current inventory structure, it's a bit fragile.
Claude suggests parsing just in the metal_machine subsection
HYPERVISOR=$(awk '/^\[metal_machine\]/{found=1;next} /^\[/{found=0} found && /@/{print $1; exit}' "${INVENTORY_FILE}")

@echo " make ssh-node node=1 cmd=\"sudo pcs status\""
@exit 1
endif
@./openshift-clusters/scripts/ssh-node.sh $(node) $(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the $(cmd) might be expanded as an "empty" argument to make if it's not provided. To allow for no command safely, might need something like this:

@./openshift-clusters/scripts/ssh-node.sh $(node) $(if $(cmd),$(cmd))

esac

# Extract node IP from inventory
NODE_IP=$(grep -E "master_0|master_1" "${INVENTORY_FILE}" | grep "${NODE_PATTERN}" | grep -oP "ansible_host='\\K[^']+")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this'll happen, but maybe we need to parse for the full word (master_0 or master_1, as this will match master10, master100, and also things like ostest_master_10)

Suggestion might be changing grep -E to grep -W to parse only full words

SSH_OPTS=(
-o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null
-o LogLevel=ERROR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to WARN to make debugging easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants