feat: support environment variable fallback for baremetal BMC credentials (#1289)

Signed-off-by: Aastha-spec-tech <explorethings12345@gmail.com>
Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com>
This commit is contained in:
Aastha-spec-tech
2026-05-14 09:52:42 -04:00
committed by GitHub
co-authored by Paige Patton
parent c9e4cc3254
commit 2628665584
6 changed files with 88 additions and 18 deletions
@@ -0,0 +1,13 @@
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@@ -1,3 +1,16 @@
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import json
import logging
@@ -1,3 +1,16 @@
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import queue
import time
from typing import Tuple
@@ -1,4 +1,4 @@
# Copyright 2025 The Krkn Authors
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@ from krkn.scenario_plugins.node_actions.abstract_node_scenarios import (
abstract_node_scenarios,
)
import logging
import os
import openshift as oc
import pyipmi
import pyipmi.interfaces
@@ -27,8 +28,8 @@ from krkn_lib.utils import get_random_string
class BM:
def __init__(self, bm_info, user, passwd):
self.user = user
self.passwd = passwd
self.user = user if user else os.environ.get("BMC_USER")
self.passwd = passwd if passwd else os.environ.get("BMC_PASSWORD")
self.bm_info = bm_info
def get_node_object(self, node_name):
@@ -98,14 +99,17 @@ class BM:
else:
user = self.user
passwd = self.passwd
if user is None or passwd is None:
if not user or not passwd:
logging.error(
"Missing IPMI BMI user and/or password for baremetal cloud. "
"Please specify either a global or per-machine user and pass"
"Missing IPMI BMC user and/or password for baremetal cloud. "
"Please specify either in the scenario YAML or via "
"BMC_USER/BMC_PASSWORD environment variables."
)
raise RuntimeError(
"Missing IPMI BMI user and/or password for baremetal cloud. "
"Please specify either a global or per-machine user and pass"
"Missing IPMI BMC user and/or password for baremetal cloud. "
"Please specify either in the scenario YAML or via "
"BMC_USER/BMC_PASSWORD environment variables."
)
# Establish connection
@@ -1,3 +1,16 @@
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
node_scenarios:
- actions: # Node chaos scenarios to be injected
- node_stop_start_scenario # Action to run. Supported actions: node_stop, node_restart, node_stop_start etc. Please refer documentation
@@ -10,8 +23,8 @@ node_scenarios:
parallel: False # Run action on label or node name in parallel or sequential, set to true for parallel
cloud_type: bm # Cloud type on which Kubernetes/OpenShift runs.
kube_check: True # Run the kubernetes api calls to see if the node gets to a certain state during the node scenario
bmc_user: <your_bmc_user> # For baremetal (bm) cloud type. The default IPMI username. Optional if specified for all machines
bmc_password: <your_bmc_password> # For baremetal (bm) cloud type. The default IPMI password. Optional if specified for all machines
bmc_user: <your_bmc_user> # The default IPMI username. Optional if BMC_USER env var is set or specified per-machine below.
bmc_password: <your_bmc_password> # The default IPMI password. Optional if BMC_PASSWORD env var is set or specified per-machine below.
bmc_info: # This section is here to specify baremetal per-machine info, so it is optional if there is no per-machine info.
<your_node_name_1>: # The node name for the baremetal machine
bmc_addr: <your_bmc_address_1> # Optional. For baremetal nodes with the IPMI BMC address missing from 'oc get bmh'
+22 -8
View File
@@ -1,4 +1,17 @@
#!/usr/bin/env python3
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
License header linter for krkn source files.
@@ -21,7 +34,7 @@ import sys
from pathlib import Path
LICENSE_HEADER = """\
# Copyright 2025 The Krkn Authors
# Copyright 2026 The Krkn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -36,7 +49,7 @@ LICENSE_HEADER = """\
# limitations under the License."""
# Check for the copyright line only — allows year/author variation
LICENSE_MARKER = "# Copyright 2025 The Krkn Authors"
LICENSE_MARKER = "# Copyright 2026 The Krkn Authors"
REPO_ROOT = Path(__file__).parent.parent
@@ -47,12 +60,13 @@ def is_test_file(path: Path) -> bool:
def collect_source_files() -> list[Path]:
return [
p
for p in REPO_ROOT.rglob("*.py")
if not is_test_file(p)
and not any(part.startswith(".") or part in ("venv", "venv3111", "build", "dist", "__pycache__") for part in p.parts)
]
source_files = []
excluded_dirs = {".git", ".github", "venv", "venv3111", "build", "dist", "__pycache__", "tests", "CI"}
for path in REPO_ROOT.rglob("*.py"):
if not any(part in excluded_dirs or part.startswith(".") for part in path.parts):
if not is_test_file(path):
source_files.append(path)
return source_files
def has_license(path: Path) -> bool: