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 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.

@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

Walkthrough

Framework initialization in main.go is refactored to separate cluster-independent setup (initFrameworkDefaults) from cluster-dependent setup (initFrameworkCluster). This removes the unconditional KUBECONFIG requirement for early commands and defers cluster configuration validation to when it is actually needed.

Changes

Cohort / File(s) Summary
Framework Initialization Refactor
openshift-tests/ccm-aws-tests/main.go
Splits initialization into two phases: initFrameworkDefaults() called at startup (without KUBECONFIG requirement, preserves AWS region handling), and initFrameworkCluster() invoked via specs.AddBeforeAll() (enforces KUBECONFIG availability with specific error messaging).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Ote Binary Stdout Contract ❌ Error PR violates OTE Binary Stdout Contract by calling framework.AfterReadingAllFlags() during startup, which writes directly to os.Stdout via Output variable, corrupting JSON output for info/list tests commands. Redirect Output variable to stderr before calling AfterReadingAllFlags() in initFrameworkDefaults(), or defer the call only when running tests, not during discovery.
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.
Stable And Deterministic Test Names ❓ Inconclusive Verification of Ginkgo test definitions for dynamic values in titles requires direct repository access and inspection of test files. Access the openshift-tests/ccm-aws-tests directory and examine all test files for dynamic values in It(), Describe(), Context(), or When() constructs.
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Test Structure And Quality ✅ Passed PR modifies only framework initialization in main.go; actual test specifications in test files remain unchanged.
Microshift Test Compatibility ✅ Passed This PR refactors the initialization framework in main.go by splitting functions. No new Ginkgo e2e test declarations are added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR refactors test framework initialization without adding new Ginkgo e2e tests; actual tests are imported from external packages and existing codebase includes SNO topology exclusions.
Topology-Aware Scheduling Compatibility ✅ Passed This pull request refactors Go test framework initialization code and does not introduce deployment manifests, operator code, or scheduling constraints.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed New Ginkgo e2e tests for NLB security groups do not contain IPv4 assumptions, IPv4-only logic, or external connectivity requirements.
Title check ✅ Passed The title accurately summarizes the main change: splitting framework initialization to defer KUBECONFIG requirements so tests can be discovered/listed without cluster access.
✨ 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

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 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
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 2, 2026

@petr-muller: all tests passed!

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.

@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.

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