-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Run k8sgpt as part of hypershift-dump chain #68540
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
Merged
openshift-merge-bot
merged 4 commits into
openshift:master
from
mgencur:test_k8s_gpt_with_hypershift
Sep 23, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ec1ae7
Run k8sgpt as part of hypershift-dump chain
mgencur 6fc0589
Make sure the script doesn't fail if there's no guest cluster
mgencur e7e99f7
Collect hypershift-related namespaces from mgmt cluster
mgencur b9bfd7c
Download k8sgpt binary directly to get latest version
mgencur 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| approvers: | ||
| - csrwng | ||
| - enxebre | ||
| - sjenning | ||
| - LiangquanLi930 | ||
| - bryan-cox | ||
| - jparrill | ||
| - mgencur | ||
| options: {} | ||
| reviewers: | ||
| - csrwng | ||
| - enxebre | ||
| - sjenning | ||
| - LiangquanLi930 | ||
| - bryan-cox | ||
| - jparrill | ||
| - mgencur |
143 changes: 143 additions & 0 deletions
143
ci-operator/step-registry/hypershift/k8sgpt/hypershift-k8sgpt-commands.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,143 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| EXPLAIN="${EXPLAIN:-false}" | ||
| JUNIT_REPORT="${JUNIT_REPORT:-false}" | ||
|
|
||
| OS="$(uname -s)_$(uname -m)" | ||
| K8SGPT_VERSION=${K8SGPT_VERSION:-0.4.25} | ||
| K8SGPT_DIR=${K8SGPT_DIR:-/tmp} | ||
|
|
||
| download_binary(){ | ||
| local url="https://github.com/k8sgpt-ai/k8sgpt/releases/download/v${K8SGPT_VERSION}/k8sgpt_${OS}.tar.gz" | ||
| curl --fail --retry 8 --retry-all-errors -sS -L "${url}" | tar -xzC "${K8SGPT_DIR}/" | ||
| chmod +x "${K8SGPT_DIR}/k8sgpt" | ||
| } | ||
|
|
||
| function set_proxy () { | ||
| if test -s "${SHARED_DIR}/proxy-conf.sh" ; then | ||
| echo "setting the proxy" | ||
| echo "source ${SHARED_DIR}/proxy-conf.sh" | ||
| # shellcheck disable=SC1091 | ||
| source "${SHARED_DIR}/proxy-conf.sh" | ||
| else | ||
| echo "no proxy setting." | ||
| fi | ||
| } | ||
|
|
||
| if [ -f "${SHARED_DIR}/kubeconfig" ] ; then | ||
| export KUBECONFIG=${SHARED_DIR}/kubeconfig | ||
| fi | ||
|
|
||
| set_proxy | ||
|
|
||
| download_binary | ||
|
|
||
| export PATH="${K8SGPT_DIR}:${PATH}" | ||
|
|
||
| k8sgpt version | ||
|
|
||
| explain_arg="" | ||
| if [[ "${EXPLAIN}" == "true" ]]; then | ||
| explain_arg="--explain" | ||
| openai_token=$(cat "/var/run/vault/tests-private-account/openai-token") | ||
| k8sgpt auth add --model gpt-3.5-turbo --backend openai --password "${openai_token}" || true | ||
| fi | ||
|
|
||
| all_filters=(Ingress CronJob Node MutatingWebhookConfiguration Pod Deployment ReplicaSet \ | ||
| ValidatingWebhookConfiguration ConfigMap PersistentVolumeClaim Service StatefulSet) | ||
| # Service and ValidatingWebhookConfiguration filters cause false negatives for hosted clusters. | ||
| # ConfigMap filters cause false positives, reporting unused configmaps. | ||
| excluded_filters=(Service ValidatingWebhookConfiguration ConfigMap) | ||
| active_filters=() | ||
| for filter in "${all_filters[@]}"; do | ||
| if [[ ! ${excluded_filters[*]} =~ ${filter} ]]; then | ||
| active_filters+=("$filter") | ||
| fi | ||
| done | ||
|
|
||
| active_filters_str=$(echo "${active_filters[@]}" | tr ' ' ',') | ||
|
|
||
| common_params=(--output json --anonymize --with-doc "$explain_arg" --filter "$active_filters_str") | ||
|
|
||
| mkdir -p "${ARTIFACT_DIR}/namespaces" "${ARTIFACT_DIR}/hostedcluster" | ||
|
|
||
| CLUSTER_NAME="$(echo -n $PROW_JOB_ID|sha256sum|cut -c-20)" | ||
| HOSTED_CLUSTER_NS=$(oc get hostedcluster -A -ojsonpath='{.items[0].metadata.namespace}') | ||
|
|
||
| mgmt_fail=false | ||
| # Collect only hypershift-related namespaces from the management cluster. | ||
| for namespace in hypershift "${HOSTED_CLUSTER_NS}" "${HOSTED_CLUSTER_NS}-${CLUSTER_NAME}"; do | ||
| mkdir -p "${ARTIFACT_DIR}/namespaces/$namespace" | ||
| # Run the scan on the management cluster | ||
| result_file="${ARTIFACT_DIR}/namespaces/$namespace/result.json" | ||
| k8sgpt --kubeconfig="$KUBECONFIG" analyze --namespace "$namespace" "${common_params[@]}" | \ | ||
| tee "$result_file" || true | ||
| if [[ -f "$result_file" ]]; then | ||
| if ! grep "problems\": 0" "$result_file" &>/dev/null; then | ||
| mgmt_fail=true | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| guest_fail=false | ||
| # Run the scan on the guest cluster | ||
| if [[ -f "${SHARED_DIR}/nested_kubeconfig" ]]; then | ||
| k8sgpt --kubeconfig="${SHARED_DIR}/nested_kubeconfig" analyze "${common_params[@]}" | \ | ||
| tee "${ARTIFACT_DIR}/hostedcluster/result.json" || true | ||
| if ! grep "problems\": 0" "${ARTIFACT_DIR}/hostedcluster/result.json" &>/dev/null; then | ||
| guest_fail=true | ||
| fi | ||
| fi | ||
|
|
||
| # Optionally generate a JUnit report. | ||
| if [[ "${JUNIT_REPORT}" == "false" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| mkdir -p "${ARTIFACT_DIR}/junit" | ||
|
|
||
| testcase_mgmt="<testcase name=\"scanning management cluster\"/>" | ||
| testcase_guest="<testcase name=\"scanning guest cluster\"/>" | ||
|
|
||
| failures=0 | ||
|
|
||
| if [[ "${mgmt_fail}" == "true" ]]; then | ||
| failures=$((failures + 1)) | ||
| result_mgmt="" | ||
| for namespace in hypershift "${HOSTED_CLUSTER_NS}" "${HOSTED_CLUSTER_NS}-${CLUSTER_NAME}"; do | ||
| result_mgmt+=$(cat "${ARTIFACT_DIR}/namespaces/$namespace/result.json") | ||
| done | ||
| testcase_mgmt=$(cat <<EOF | ||
| <testcase name="scanning management cluster"> | ||
| <failure message="">problems detected</failure> | ||
| <system-out> | ||
| ${result_mgmt} | ||
| </system-out> | ||
| </testcase> | ||
| EOF | ||
| ) | ||
| fi | ||
|
|
||
| if [[ "${guest_fail}" == "true" ]]; then | ||
| failures=$((failures + 1)) | ||
| result_guest=$(cat "${ARTIFACT_DIR}/hostedcluster/result.json") | ||
| testcase_guest=$(cat <<EOF | ||
| <testcase name="scanning guest cluster"> | ||
| <failure message="">problems detected</failure> | ||
| <system-out> | ||
| ${result_guest} | ||
| </system-out> | ||
| </testcase> | ||
| EOF | ||
| ) | ||
| fi | ||
|
|
||
| cat <<EOF >"${ARTIFACT_DIR}/junit/k8sgpt-result.xml" | ||
| <testsuite name="hypershift-k8sgpt" tests="2" failures="${failures}"> | ||
| ${testcase_mgmt} | ||
| ${testcase_guest} | ||
| </testsuite> | ||
| EOF | ||
|
|
||
23 changes: 23 additions & 0 deletions
23
ci-operator/step-registry/hypershift/k8sgpt/hypershift-k8sgpt-ref.metadata.json
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,23 @@ | ||
| { | ||
| "path": "hypershift/k8sgpt/hypershift-k8sgpt-ref.yaml", | ||
| "owners": { | ||
| "approvers": [ | ||
| "csrwng", | ||
| "enxebre", | ||
| "sjenning", | ||
| "LiangquanLi930", | ||
| "bryan-cox", | ||
| "jparrill", | ||
| "mgencur" | ||
| ], | ||
| "reviewers": [ | ||
| "csrwng", | ||
| "enxebre", | ||
| "sjenning", | ||
| "LiangquanLi930", | ||
| "bryan-cox", | ||
| "jparrill", | ||
| "mgencur" | ||
| ] | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
ci-operator/step-registry/hypershift/k8sgpt/hypershift-k8sgpt-ref.yaml
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,23 @@ | ||
| ref: | ||
| as: hypershift-k8sgpt | ||
| cli: latest | ||
| env: | ||
| - name: EXPLAIN | ||
| default: "false" | ||
| documentation: "Whether to explain the results by AI." | ||
| - name: JUNIT_REPORT | ||
| default: "false" | ||
| documentation: "Whether to generate a JUnit report." | ||
| grace_period: 10m | ||
| commands: hypershift-k8sgpt-commands.sh | ||
| from: hypershift-operator | ||
| resources: | ||
| requests: | ||
| cpu: 100m | ||
| memory: 100Mi | ||
| credentials: | ||
| - namespace: test-credentials | ||
| name: tests-private-account | ||
| mount_path: /var/run/vault/tests-private-account | ||
| documentation: |- | ||
| Scanning clusters, diagnosing, and triaging issues by calling AI. |
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.
kubevirt presubmit job is failing here