Skip to content

Fix kubeadmin password printed with trailing newline in openshift and hypershift flows (fixes #891) - #896

Open
shivampwm2020 wants to merge 2 commits into
karmab:mainfrom
shivampwm2020:fix/891-hypershift-kubeadmin-password-newline
Open

shivampwm2020 wants to merge 2 commits into
karmab:mainfrom
shivampwm2020:fix/891-hypershift-kubeadmin-password-newline

Conversation

@shivampwm2020

Copy link
Copy Markdown

Problem

When creating a hypershift cluster (see the linked Actions run in the issue), the final log shows the kubeadmin password with a literal \n appended:

INFO Login to the console with user: "kubeadmin", and password: "HCbHn-2nrLS-PVNsG-Mn8hn\n"

Same behavior for standard openshift clusters (kcli create cluster --type openshift), because kcli prints the same password with info2.

Root cause

  • kvirt/cluster/openshift/__init__.py reads <clusterdir>/auth/kubeadmin-password with open(...).read() and no stripping, at both the normal (line ~1588) and async_install (line ~1783) paths. The openshift-installer writes that file with a trailing newline, so every message kcli prints carries it.
  • In the hypershift flow (kvirt/cluster/hypershift/__init__.py), kcli itself creates <clusterdir>/auth/kubeadmin-password from the stdout of oc extract -n <ns> secret/<cluster>-kubeadmin-password --to=-, which also ends with a newline. When openshift-install wait-for install-complete later reads it from that clusterdir, the password is rendered with a trailing \n.

Fix

  • kvirt/cluster/openshift/__init__.py: strip both reads (.read().strip()).
  • kvirt/cluster/hypershift/__init__.py: strip the secret output before writing kubeadmin-password to disk.

Testing

  • Added tests/test_kubeadmin_password.py (stdlib-only, runs with python3 -m unittest): asserts both openshift reads use .strip(), asserts the hypershift secret write strips, and an end-to-end content test.
  • Local repro confirmed: writing C5337-...\n (simulated oc extract stdout) to the file and reading it reproduces the trailing \n; after the fix the value is clean.
  • python3 -m unittest tests.test_kubeadmin_password → 3 tests, OK.

Shivam Maurya added 2 commits October 15, 2026 00:52
… and add tests

kcli writes <clusterdir>/auth/kubeadmin-password from 'oc extract' stdout,
which ends with a newline, so openshift-install --dir=<clusterdir> later
prints the password with a literal \n (karmab#891). Strip it when
extracting the secret, and cover both openshift read sites plus the
hypershift write with a regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant