Skip to content

NO-JIRA: cache kube client instance#30997

Open
jcmoraisjr wants to merge 1 commit intoopenshift:mainfrom
jcmoraisjr:cache-kube-client
Open

NO-JIRA: cache kube client instance#30997
jcmoraisjr wants to merge 1 commit intoopenshift:mainfrom
jcmoraisjr:cache-kube-client

Conversation

@jcmoraisjr
Copy link
Copy Markdown
Member

oc client is a generic acessor for all the OpenShift API clients, as well as the typed kubernetes.Interface client. However the acessor for those clients require reading the configuration file from disk and parsing it again. This not only uses more processing, but also more IO, increasing the chance for an IO failure.

This update is caching the clients used during the tests, so converting lots of IO and config parsing into a single one per test.

oc client is a generic acessor for all the OpenShift API clients, as
well as the typed kubernetes.Interface client. However the acessor for
those clients require reading the configuration file from disk and
parsing it again. This not only uses more processing, but also more IO,
increasing the chance for an IO failure.

This update is caching the clients used during the tests, so converting
lots of IO and config parsing into a single one per test.
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@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 10, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@jcmoraisjr: This pull request explicitly references no jira issue.

Details

In response to this:

oc client is a generic acessor for all the OpenShift API clients, as well as the typed kubernetes.Interface client. However the acessor for those clients require reading the configuration file from disk and parsing it again. This not only uses more processing, but also more IO, increasing the chance for an IO failure.

This update is caching the clients used during the tests, so converting lots of IO and config parsing into a single one per test.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Walkthrough

These changes refactor two test configuration management files to optimize Kubernetes API client usage by introducing cached client instances. Both files eliminate repeated calls to client initialization methods by storing references to kubeClient and route clients, and the createNamedRoute function signature is updated to accept a route client interface instead of a full CLI object.

Changes

Cohort / File(s) Summary
Client caching optimization
test/extended/router/config_manager.go
Introduced cached kubeClient variable initialized from oc.AdminKubeClient() to replace repeated client initialization calls. Updated helper functions to use the shared client for CRUD operations on role bindings, config maps, services, and pods.
Route client interface refactoring
test/extended/router/config_manager_ingress.go
Added kubeClient and routeClient fields to routeStackBuilder struct, initialized in constructor. Updated createNamedRoute() function signature to accept routev1client.Interface instead of *exutil.CLI. Modified methods to use cached clients for Kubernetes and route operations, replacing direct oc.AdminKubeClient() and oc.AsAdmin() calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@openshift-ci openshift-ci bot requested review from Thealisyed and gcs278 April 10, 2026 11:52
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 10, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jcmoraisjr

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 10, 2026
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)
test/extended/router/config_manager.go (1)

787-793: Consider using a cached client for consistency.

This helper function creates a new kubeClient via oc.AdminKubeClient() on each invocation. While this function is only called once per test (not in loops), passing the cached kubeClient from the suite scope would maintain consistency with the overall caching strategy.

♻️ Optional: Accept cached client as parameter
-func createExecPod(oc *exutil.CLI) (execPod *corev1.Pod, done func()) {
-	kubeClient := oc.AdminKubeClient()
+func createExecPod(kubeClient kubernetes.Interface, oc *exutil.CLI) (execPod *corev1.Pod, done func()) {
 	ns := oc.KubeFramework().Namespace.Name
 	execPod = exutil.CreateExecPodOrFail(kubeClient, ns, "execpod")
 	return execPod, func() {
 		kubeClient.CoreV1().Pods(ns).Delete(context.Background(), execPod.Name, *metav1.NewDeleteOptions(1))
 	}
 }

Then update call sites:

-execPod, doneExecPod := createExecPod(oc)
+execPod, doneExecPod := createExecPod(kubeClient, oc)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/extended/router/config_manager.go` around lines 787 - 793, The
createExecPod helper currently calls oc.AdminKubeClient() internally which
bypasses the suite-level cached client; change createExecPod to accept a
pre-created kube client (e.g., client := oc.AdminKubeClient() passed in) or
accept the cached client as an argument and use that instead of calling
oc.AdminKubeClient() inside createExecPod, update all call sites that invoke
createExecPod to pass the cached kubeClient, and keep the returned execPod and
done() behavior the same (references: createExecPod, oc.AdminKubeClient,
execPod, done func).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/extended/router/config_manager.go`:
- Around line 787-793: The createExecPod helper currently calls
oc.AdminKubeClient() internally which bypasses the suite-level cached client;
change createExecPod to accept a pre-created kube client (e.g., client :=
oc.AdminKubeClient() passed in) or accept the cached client as an argument and
use that instead of calling oc.AdminKubeClient() inside createExecPod, update
all call sites that invoke createExecPod to pass the cached kubeClient, and keep
the returned execPod and done() behavior the same (references: createExecPod,
oc.AdminKubeClient, execPod, done func).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 76501e72-ed1d-4b53-846f-22bcc1ad27b8

📥 Commits

Reviewing files that changed from the base of the PR and between 7da3e1c and c9fe49c.

📒 Files selected for processing (2)
  • test/extended/router/config_manager.go
  • test/extended/router/config_manager_ingress.go

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 10, 2026

@jcmoraisjr: 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/e2e-gcp-ovn c9fe49c link true /test e2e-gcp-ovn
ci/prow/e2e-vsphere-ovn-upi c9fe49c link true /test e2e-vsphere-ovn-upi

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

approved Indicates a PR has been approved by an approver from all required OWNERS files. 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