Skip to content

TRT-2652: Allow info and list tests commands to work without KUBECONFIG#458

Open
petr-muller wants to merge 1 commit intoopenshift:mainfrom
petr-muller:fix-info-without-kubeconfig
Open

TRT-2652: Allow info and list tests commands to work without KUBECONFIG#458
petr-muller wants to merge 1 commit intoopenshift:mainfrom
petr-muller:fix-info-without-kubeconfig

Conversation

@petr-muller
Copy link
Copy Markdown
Member

@petr-muller petr-muller commented Apr 30, 2026

Summary

Split initFrameworkForTests() into two functions:

  • initFrameworkDefaults() — sets cluster-independent framework defaults (provider, flags, OS distro). Runs at startup, no KUBECONFIG needed.
  • initFrameworkCluster() — loads kubeconfig, sets host, calls AfterReadingAllFlags. Deferred to AddBeforeAll, only runs when tests are actually executed.

This enables workflows that need to discover or list tests from ccm-aws-tests without a live cluster connection, such as the openshift-tests list all-tests command being added in openshift/origin#31105.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Test framework init split into cluster-independent startup and deferred cluster-dependent setup.
    • Test discovery and non-cluster commands (e.g., info/list) run without cluster credentials, reducing startup noise.
    • Startup redirects framework output to stderr to keep stdout clean for command output.
    • Temporary placeholder host used to avoid warnings when no kubeconfig is present.
    • AWS region from environment variables continues to be applied.

@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 Apr 30, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 73e7eea8-5445-4f7d-89c0-6e50fbc64c8a

📥 Commits

Reviewing files that changed from the base of the PR and between 0ca8c7c and d2ea9fa.

📒 Files selected for processing (1)
  • openshift-tests/ccm-aws-tests/main.go

Walkthrough

Startup initialization in main.go is split: cluster-independent defaults are set early via initFrameworkDefaults(), and cluster-dependent kubeconfig/host setup is deferred to initFrameworkCluster() run in a BeforeAll hook, removing the upfront KUBECONFIG requirement.

Changes

Framework Initialization Refactor

Layer / File(s) Summary
Startup / Defaults
openshift-tests/ccm-aws-tests/main.go
Add initFrameworkDefaults() called at program start to set cluster-independent testContext fields, derive CloudConfig from AWS env vars, set placeholder testContext.Host, and redirect framework.Output to stderr.
Framework Flag Handling
openshift-tests/ccm-aws-tests/main.go
Call framework.AfterReadingAllFlags(testContext) early from defaults so test discovery can run without cluster access.
Deferred Cluster Init / Hook
openshift-tests/ccm-aws-tests/main.go
Replace prior upfront initFrameworkForTests() usage with specs.AddBeforeAll invoking initFrameworkCluster(), which requires KUBECONFIG, loads kubeconfig non-interactively, sets testContext.Host, and returns errors handled by panicking with a cluster-config message.
Removed Flow
openshift-tests/ccm-aws-tests/main.go
Eliminate the previous single-path initFrameworkForTests() startup call that required KUBECONFIG before flag processing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Ipv6 And Disconnected Network Test Compatibility ❓ Inconclusive No result was produced after verification. Marking as INCONCLUSIVE. Re-run the check or adjust instructions to produce a final result.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: refactoring to allow info and list test commands to work without KUBECONFIG, which directly reflects the core objective of deferring cluster-dependent initialization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All Ginkgo test names are stable. The one fmt.Sprintf usage only interpolates compile-time constants, producing a fixed deterministic test name. No dynamic information in test names.
Test Structure And Quality ✅ Passed PR refactors framework initialization only. Does not add or modify Ginkgo test code (It blocks, Describe blocks). Custom check for test quality is not applicable.
Microshift Test Compatibility ✅ Passed This PR does not add any new Ginkgo e2e tests. It only refactors the test framework initialization in main.go, splitting test setup into two phases. The check is not applicable to this PR.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR does not add any new Ginkgo e2e tests. It refactors test framework initialization code only, splitting it into two functions. The check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR only modifies test code with topology-aware exclusions. No new deployment manifests or scheduling constraints are introduced by this refactoring.
Ote Binary Stdout Contract ✅ Passed All framework messages redirected to stderr. Placeholder Host prevents in-cluster detection. No fmt.Print* or os.Stdout writes. Logrus logging defaults to stderr.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@petr-muller
Copy link
Copy Markdown
Member Author

/test all

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign damdo for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
openshift-tests/ccm-aws-tests/main.go (1)

159-185: Harden initFrameworkCluster() with an explicit sync.Once guard for defense in depth.

The framework.AfterReadingAllFlags() call has multiple non-idempotent side effects (image initialization, gomega configuration, spec validation, token generation). While currently guarded by OneTimeTask semantics in AddBeforeAll, making this function explicitly one-time idempotent will prevent regressions if additional call paths are introduced in the future.

The proposed refactoring also improves KUBECONFIG validation with strings.TrimSpace() to handle whitespace-only edge cases.

♻️ Proposed hardening
 import (
 	"context"
 	"fmt"
 	"os"
 	"path/filepath"
+	"sync"
 	"strings"
@@
 var (
 	// testContext is the global test context that is used to store the test configuration.
 	testContext = &framework.TestContext
+	initFrameworkClusterOnce sync.Once
+	initFrameworkClusterErr  error
 )
@@
 func initFrameworkCluster() error {
-	if len(os.Getenv("KUBECONFIG")) == 0 {
-		return fmt.Errorf("KUBECONFIG is empty. Set the KUBECONFIG environment variable")
-	}
-
-	// Load kube client config and set the host variable for kubectl
-	testContext.KubeConfig = os.Getenv("KUBECONFIG")
-	clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
-		&clientcmd.ClientConfigLoadingRules{
-			ExplicitPath: testContext.KubeConfig,
-		},
-		&clientcmd.ConfigOverrides{},
-	)
-	cfg, err := clientConfig.ClientConfig()
-	if err != nil {
-		return fmt.Errorf("failed to get client config: %w", err)
-	}
-	testContext.Host = cfg.Host
-
-	// After reading all flags, this will configure the test context, and needs to be
-	// called once by framework to avoid re-configuring the test context, and leading
-	// to issues in Ginkgo phases (PhaseBuildTopLevel, PhaseBuildTree, PhaseRun),
-	// such as: 'cannot clone suite after tree has been built'
-	framework.AfterReadingAllFlags(testContext)
-
-	return nil
+	initFrameworkClusterOnce.Do(func() {
+		if len(strings.TrimSpace(os.Getenv("KUBECONFIG"))) == 0 {
+			initFrameworkClusterErr = fmt.Errorf("KUBECONFIG is empty. Set the KUBECONFIG environment variable")
+			return
+		}
+
+		// Load kube client config and set the host variable for kubectl
+		testContext.KubeConfig = os.Getenv("KUBECONFIG")
+		clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
+			&clientcmd.ClientConfigLoadingRules{
+				ExplicitPath: testContext.KubeConfig,
+			},
+			&clientcmd.ConfigOverrides{},
+		)
+		cfg, err := clientConfig.ClientConfig()
+		if err != nil {
+			initFrameworkClusterErr = fmt.Errorf("failed to get client config: %w", err)
+			return
+		}
+		testContext.Host = cfg.Host
+
+		framework.AfterReadingAllFlags(testContext)
+	})
+	return initFrameworkClusterErr
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openshift-tests/ccm-aws-tests/main.go` around lines 159 - 185, Wrap the
non-idempotent setup in initFrameworkCluster() with a sync.Once to ensure
framework.AfterReadingAllFlags(testContext) is executed only once even if
initFrameworkCluster() is called multiple times; also tighten KUBECONFIG
validation by using strings.TrimSpace(os.Getenv("KUBECONFIG")) and treat
empty/whitespace-only values as invalid (return error). Locate the calls to
testContext.KubeConfig, clientcmd.NewNonInteractiveDeferredLoadingClientConfig,
and framework.AfterReadingAllFlags to implement the sync.Once guard and updated
validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openshift-tests/ccm-aws-tests/main.go`:
- Around line 159-185: Wrap the non-idempotent setup in initFrameworkCluster()
with a sync.Once to ensure framework.AfterReadingAllFlags(testContext) is
executed only once even if initFrameworkCluster() is called multiple times; also
tighten KUBECONFIG validation by using
strings.TrimSpace(os.Getenv("KUBECONFIG")) and treat empty/whitespace-only
values as invalid (return error). Locate the calls to testContext.KubeConfig,
clientcmd.NewNonInteractiveDeferredLoadingClientConfig, and
framework.AfterReadingAllFlags to implement the sync.Once guard and updated
validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e1830bbc-23a8-4392-baec-1ed802784f6f

📥 Commits

Reviewing files that changed from the base of the PR and between abc2b83 and 50ed490.

📒 Files selected for processing (1)
  • openshift-tests/ccm-aws-tests/main.go

@petr-muller petr-muller changed the title Allow info and list tests commands to work without KUBECONFIG NO-JIRA: Allow info and list tests commands to work without KUBECONFIG Apr 30, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 30, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@petr-muller: This pull request explicitly references no jira issue.

Details

In response to this:

Summary

Split initFrameworkForTests() into two functions:

  • initFrameworkDefaults() — sets cluster-independent framework defaults (provider, flags, OS distro). Runs at startup, no KUBECONFIG needed.
  • initFrameworkCluster() — loads kubeconfig, sets host, calls AfterReadingAllFlags. Deferred to AddBeforeAll, only runs when tests are actually executed.

This enables workflows that need to discover or list tests from ccm-aws-tests without a live cluster connection, such as the openshift-tests list all-tests command being added in openshift/origin#31105.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
  • Improved test framework initialization by separating cluster-independent defaults from cluster-dependent setup. Tests no longer require KUBECONFIG upfront; configuration is deferred until cluster access is needed. AWS region handling via environment variables remains functional.

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.

@petr-muller petr-muller marked this pull request as ready for review April 30, 2026 22:07
@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 Apr 30, 2026
@openshift-ci openshift-ci Bot requested review from mdbooth and nrb April 30, 2026 22:08
@petr-muller petr-muller marked this pull request as draft April 30, 2026 22:09
@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 Apr 30, 2026
@petr-muller
Copy link
Copy Markdown
Member Author

/uncc @mdbooth @nrb

@openshift-ci openshift-ci Bot removed request for mdbooth and nrb April 30, 2026 22:10
@petr-muller
Copy link
Copy Markdown
Member Author

/test all

@petr-muller petr-muller force-pushed the fix-info-without-kubeconfig branch from 50ed490 to 66a64ba Compare May 1, 2026 09:43
@petr-muller
Copy link
Copy Markdown
Member Author

/test all

@petr-muller
Copy link
Copy Markdown
Member Author

/test unit

@petr-muller
Copy link
Copy Markdown
Member Author

/test e2e-aws-ovn

@petr-muller petr-muller marked this pull request as ready for review May 2, 2026 00:32
@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 May 2, 2026
@openshift-ci openshift-ci Bot requested review from RadekManak and nrb May 2, 2026 00:32
@petr-muller petr-muller changed the title NO-JIRA: Allow info and list tests commands to work without KUBECONFIG TRT-2652: Allow info and list tests commands to work without KUBECONFIG May 4, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented May 4, 2026

@petr-muller: This pull request references TRT-2652 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

Split initFrameworkForTests() into two functions:

  • initFrameworkDefaults() — sets cluster-independent framework defaults (provider, flags, OS distro). Runs at startup, no KUBECONFIG needed.
  • initFrameworkCluster() — loads kubeconfig, sets host, calls AfterReadingAllFlags. Deferred to AddBeforeAll, only runs when tests are actually executed.

This enables workflows that need to discover or list tests from ccm-aws-tests without a live cluster connection, such as the openshift-tests list all-tests command being added in openshift/origin#31105.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
  • Test framework initialization split into cluster-independent defaults and deferred cluster-dependent setup.
  • Tests no longer require cluster credentials up front; cluster access is configured only when needed.
  • AWS region from environment variables continues to be applied to test configuration.

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.

@petr-muller petr-muller force-pushed the fix-info-without-kubeconfig branch from 66a64ba to 0ca8c7c Compare May 7, 2026 20:23
Split initFrameworkForTests() into initFrameworkDefaults() (runs at
startup without KUBECONFIG) and initFrameworkCluster() (deferred to
AddBeforeAll, requires KUBECONFIG). This enables workflows that need
to discover or list tests without a live cluster connection, such as
the openshift-tests "list all-tests" command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@petr-muller petr-muller force-pushed the fix-info-without-kubeconfig branch from 0ca8c7c to d2ea9fa Compare May 7, 2026 20:36
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 7, 2026

@petr-muller: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/images d2ea9fa link true /test images
ci/prow/e2e-aws-ovn d2ea9fa link true /test e2e-aws-ovn
ci/prow/e2e-aws-ovn-upgrade d2ea9fa link true /test e2e-aws-ovn-upgrade
ci/prow/level0-clusterinfra-azure-ipi-proxy-tests d2ea9fa link false /test level0-clusterinfra-azure-ipi-proxy-tests

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

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.

2 participants