Skip to content

Refactor e2e tests to reuse Kubernetes clients instead of recreating them #378

@gflarity

Description

@gflarity

What you would like to be added?

Refactor all e2e test code to create Kubernetes clients once at test setup and pass them through the call chain, instead of recreating clients on every YAML apply operation.

Current State:
The e2e test utilities have two patterns for applying YAML resources:

  1. Convenience functions (ApplyYAMLData, ApplyYAMLFile) - Create new dynamic.Interface and meta.RESTMapper clients on every call
  2. Client-based functions (ApplyYAMLDataWithClients, CreateKubernetesClients) - Accept pre-created clients, introduced in PR Support external certificate management for webhooks #344

Proposed Changes:

  1. Add ApplyYAMLFileWithClients() function to operator/e2e/utils/k8s_client.go
  2. Update operator/e2e/tests/setup.go to accept/use clients
  3. Update operator/e2e/setup/kai_scheduler.go to use client-based functions
  4. Update test setup in operator/e2e/tests/*.go to create clients once and pass them through
  5. Mark ApplyYAMLData and ApplyYAMLFile as deprecated

Why is this needed?

The convenience functions recreate Kubernetes clients on every invocation, which:

  • Adds unnecessary overhead (discovery client cache rebuild, REST mapper initialization)
  • Is inconsistent with other e2e utilities that accept clients directly (e.g., ScalePodCliqueSetWithClient)
  • Makes it harder to reason about client lifecycle

Benefits:

  • Improved test performance (fewer client initializations)
  • Consistent patterns across e2e utilities
  • Clearer client lifecycle management
  • Easier to mock clients in unit tests if needed

Metadata

Metadata

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions