Skip to content

chore: convert k8s-helper to singleton pattern - #2193

Merged
tolusha merged 4 commits into
mainfrom
refactor-k8s-helper-singleton
Sep 9, 2026
Merged

chore: convert k8s-helper to singleton pattern #2193
tolusha merged 4 commits into
mainfrom
refactor-k8s-helper-singleton

Conversation

@tolusha

@tolusha tolusha commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Refactors the k8s-helper package from factory pattern (New()) to singleton pattern (GetInstance()) to ensure consistent initialization across the codebase.

Changes:

  • Rename New()GetInstance()
  • Rename GetClientset()GetClientSet() (capitalization fix)
  • Rename initializeForTesting()InitializeForTesting() (export)
  • Add GetDiscoveryClient() method for discovery API access
  • Add initialization checks with panic guards
  • Add k8shelper.InitializeForTesting() to all test packages
  • Update documentation in .claude/rules/testing.md

The singleton pattern prevents multiple k8s client instances and ensures proper test initialization order across all packages.

Assisted-by: Claude Sonnet 4.6

What does this PR do?

Screenshot/screencast of this PR

What issues does this PR fix or reference?

How to test this PR?

  1. Deploy the operator:

OpenShift

oc create namespace devworkspace-controller
oc apply --server-side -f https://raw.githubusercontent.com/devfile/devworkspace-operator/refs/heads/main/deploy/deployment/openshift/combined.yaml

OPERATOR_IMAGE=<...>
sed 's|quay.io/eclipse/che-operator:next|'${OPERATOR_IMAGE}'|g' deploy/deployment/openshift/combined.yaml | oc apply --server-side -f  -
oc apply --server-side -f deploy/deployment/openshift/org_v2_checluster.yaml
oc wait checluster eclipse-che -n eclipse-che --for=jsonpath='.status.chePhase'=Active   --timeout=120s

on Minikube

./build/scripts/minikube-tests/test-operator-from-sources.sh

Common Test Scenarios

  • Deploy Eclipse Che
  • Start an empty workspace
  • Open terminal and build/run an image
  • Stop a workspace
  • Check operator logs for reconciliation errors or infinite reconciliation loops

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

Refactors the k8s-helper package from factory pattern (`New()`) to
singleton pattern (`GetInstance()`) to ensure consistent initialization
across the codebase.

Changes:
- Rename `New()` → `GetInstance()`
- Rename `GetClientset()` → `GetClientSet()` (capitalization fix)
- Rename `initializeForTesting()` → `InitializeForTesting()` (export)
- Add `GetDiscoveryClient()` method for discovery API access
- Add initialization checks with panic guards
- Add `k8shelper.InitializeForTesting()` to all test packages
- Update documentation in `.claude/rules/testing.md`

The singleton pattern prevents multiple k8s client instances and
ensures proper test initialization order across all packages.

Assisted-by: Claude Sonnet 4.6
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-arm64

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-amd64

@tolusha

tolusha commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi! I'm che-ai-assistant — I help with your pull requests.

I check for new comments every 10m0s, so there may be a short delay before I respond.

Available commands:

  • /che-ai-assistant generate-che-doc — Generate a documentation PR based on this PR's changes
  • /che-ai-assistant ok-pr-review — Run a comprehensive PR review (summary, code review, deep review, impact analysis)
  • /che-ai-assistant ok-pr-readiness — Ensure PR has validation steps
  • /che-ai-assistant check-pr-test-failures — Analyze failing CI checks, identify root causes, and suggest fixes
  • /che-ai-assistant update-che-e2e-tests — Update Eclipse Che e2e tests
  • /che-ai-assistant claude — Run a free-form instruction on this PR
  • /che-ai-assistant help — Show this help message

@tolusha

tolusha commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Warning: IDE/tool configuration files detected

This PR contains changes to files in directories that are typically not intended to be committed:

  • .claude/rules/testing.md

Please verify these changes are intentional.

Signed-off-by: Anatolii Bazko <[email protected]>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-arm64

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-amd64

Signed-off-by: Anatolii Bazko <[email protected]>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-arm64

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-amd64

@tolusha tolusha changed the title chore: convert k8s-helper to singleton pattern chore: convert k8s-helper to singleton pattern Sep 9, 2026
Signed-off-by: Anatolii Bazko <[email protected]>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-arm64

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

New operator image available: quay.io/eclipse/che-operator:pr-2193-amd64

Comment thread pkg/common/k8s-helper/k8s_helper.go
@openshift-ci

openshift-ci Bot commented Sep 9, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rohanKanojia, tolusha

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

@openshift-ci openshift-ci Bot added the lgtm label Sep 9, 2026
@openshift-ci

openshift-ci Bot commented Sep 9, 2026

Copy link
Copy Markdown

@tolusha: The following test 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/v19-devworkspace-happy-path 5bc3526 link true /test v19-devworkspace-happy-path

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.

@tolusha
tolusha merged commit 7fc5d41 into main Sep 9, 2026
20 of 21 checks passed
@tolusha
tolusha deleted the refactor-k8s-helper-singleton branch September 9, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants