Skip to content

Remove hard dependency on OCP CRDs #1157

Merged
openshift-merge-bot[bot] merged 8 commits into
redhat-developer:masterfrom
anandrkskd:remove-OCP-hard-dependency
Jun 1, 2026
Merged

Remove hard dependency on OCP CRDs #1157
openshift-merge-bot[bot] merged 8 commits into
redhat-developer:masterfrom
anandrkskd:remove-OCP-hard-dependency

Conversation

@anandrkskd
Copy link
Copy Markdown
Contributor

@anandrkskd anandrkskd commented May 25, 2026

assisted-by: claude-code
What type of PR is this?

/kind enhancement

What does this PR do / why we need it:
Before this change, Openshift GitOps uses Routes and other Openshift specific tests as hard dependency. This PR removes this hard dependency that willl allow users to run gitops-operator on non OCP clusters. This PR also adds a check to see if promethus (monitoring.coreos.com) is present, if not it skips.

Have you updated the necessary documentation?

  • Documentation update is required by this PR.
  • Documentation has been updated.

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/GITOPS-9812

Test acceptance criteria:

  • Unit Test
  • E2E Test

How to test changes / Special notes to the reviewer:

  • start a any k8s cluster, create argocd namespace
  • run make target
make install run
cat <<EOF | kubectl apply -f -
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
  name: test
  namespace: argocd
spec: {}
EOF
  • check logs if any openshift api cause failure

@openshift-ci openshift-ci Bot added the kind/enhancement New feature or request label May 25, 2026
@openshift-ci openshift-ci Bot requested review from chetan-rns and jgwest May 25, 2026 13:03
@anandrkskd anandrkskd marked this pull request as draft May 25, 2026 13:43
Comment thread controllers/util/util.go Outdated
Comment thread controllers/gitopsservice_controller.go Outdated
Comment thread controllers/argocd_metrics_controller.go Outdated
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
…able

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
assisted-by: claude-code for code,planning

remove duplicate import, add checks before gitopsService and other OCP specific controller

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
@anandrkskd anandrkskd force-pushed the remove-OCP-hard-dependency branch from f4b2f01 to ae67f3e Compare May 26, 2026 10:10
@anandrkskd anandrkskd marked this pull request as ready for review May 26, 2026 15:40
@openshift-ci openshift-ci Bot requested review from trdoyle81 and varshab1210 May 26, 2026 15:41
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 5fe7d167-e842-45aa-9832-1880d6e67260

📥 Commits

Reviewing files that changed from the base of the PR and between 21318ad and 405a81e.

📒 Files selected for processing (1)
  • controllers/util/util.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Cluster inspection failures now log as errors to prevent proceeding with incomplete API discovery.
  • New Features

    • Platform-specific APIs and related components are registered only when detected; unsupported APIs are skipped with informational logs.
    • Controllers that depend on route or monitoring APIs are enabled conditionally at runtime.
  • Tests

    • Test suite gains helpers to simulate API/platform discovery states for more reliable testing.

Walkthrough

Runtime API discovery was expanded; cmd/main now logs discovery failures as errors and conditionally registers OpenShift-related schemes and controllers only when their APIs are detected. Controllers and cleanup logic skip OpenShift-specific behavior when APIs are absent; test helpers and TestMain allow overriding discovery flags in tests.

Changes

Conditional OpenShift API Support

Layer / File(s) Summary
API discovery and accessors
controllers/util/util.go
Adds multi-API runtime discovery, package-level booleans, updated InspectCluster flow, and new Is* accessors for OpenShift cluster, Route, Monitoring, Template, Apps, OAuth, and OLM.
Test helpers to override discovery
controllers/util/test_util.go, controllers/gitopsservice_controller_test.go
Adds test-only setter functions to force discovery flags and a TestMain that sets discovery state for the test suite; specific tests save/restore prior route state.
Main manager: conditional scheme registration and controllers
cmd/main.go
Logs InspectCluster() failures at error level; registers OpenShift-related schemes and sets up ReconcileGitopsService, ReconcileArgoCDRoute, and ArgoCDMetricsReconciler only when corresponding util.Is* checks are true; failures during registration still exit via registerComponentOrExit.
Controller conditional wiring and cleanup
controllers/gitopsservice_controller.go, controllers/argocd_controller.go
GitopsService controller registers Route ownership and performs KAM Route cleanup only when Route API is present; ArgoCDRoute setup returns early when Route API absent.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Remove hard dependency on OCP CRDs' clearly and concisely describes the main objective of the changeset: eliminating hard dependencies on OpenShift-specific APIs/CRDs to support non-OCP clusters.
Description check ✅ Passed The description directly addresses the changeset, explaining the removal of hard dependencies on OpenShift-specific CRDs (Routes, monitoring APIs), the addition of runtime checks, testing instructions, and references the corresponding JIRA issue GITOPS-9812.
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.

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


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.

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/main.go`:
- Around line 135-137: The startup currently logs but continues when
util.InspectCluster() returns an error; change this to fail fast so the operator
doesn't run partially broken: after detecting err from util.InspectCluster(),
log the error with setupLog.Error(err, "unable to inspect cluster") and then
immediately terminate (e.g., call os.Exit(1) or log.Fatal/panic) instead of
continuing startup so discovery failures are explicit; update the error handling
in the main function where util.InspectCluster() is called.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 5e966c53-53fe-4bda-828a-eabe196177c9

📥 Commits

Reviewing files that changed from the base of the PR and between 3b6fb22 and 6d7e429.

📒 Files selected for processing (5)
  • cmd/main.go
  • controllers/gitopsservice_controller.go
  • controllers/gitopsservice_controller_test.go
  • controllers/util/test_util.go
  • controllers/util/util.go

Comment thread cmd/main.go
…, keep the check and register pattern same for all conditional api registration

assisted-by: claude-code for code,planning
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controllers/util/util.go`:
- Around line 92-105: InspectCluster currently returns early when
openShiftClusterFound is false which prevents verifyMonitoringAPI from running
and leaves monitoringAPIFound unset; remove the early return (or explicitly call
verifyMonitoringAPI before returning) so verifyMonitoringAPI always runs
regardless of openShiftClusterFound, ensuring monitoringAPIFound is discovered
and cmd/main.go can register the monitoring scheme/controller; update
InspectCluster (and references to openShiftClusterFound/monitoringAPIFound) so
only OpenShift-specific checks (eg. verifyRouteAPI, verifyConsoleAPI,
verifyTemplateAPI) are skipped when not OpenShift, while verifyMonitoringAPI
always executes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 9ad0319d-98d7-42c1-8d27-a55343b68534

📥 Commits

Reviewing files that changed from the base of the PR and between 6d7e429 and 6fbf537.

📒 Files selected for processing (6)
  • cmd/main.go
  • controllers/argocd_controller.go
  • controllers/gitopsservice_controller.go
  • controllers/gitopsservice_controller_test.go
  • controllers/util/test_util.go
  • controllers/util/util.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • controllers/gitopsservice_controller_test.go

Comment thread controllers/util/util.go Outdated
Comment thread cmd/main.go Outdated
Comment thread cmd/main.go Outdated
Copy link
Copy Markdown
Member

@anandf anandf left a comment

Choose a reason for hiding this comment

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

posted few minor comments. Otherwise looks good to me.

@svghadi svghadi mentioned this pull request May 29, 2026
4 tasks
remove non openshift check before config.openshift.io api check to make sure CRDs are not skipped, and not gate gitopsservice

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controllers/util/util.go`:
- Around line 97-103: The early returns after calling verifyConfigAPI() and when
configAPIFound is false are discarding previously collected errors in errs;
update the control flow in the block around verifyConfigAPI(), configAPIFound
and errs so that you append verifyConfigAPI()'s error to errs and then return
the aggregated errs slice (or a combined error) instead of returning the raw
err, and similarly when configAPIFound is false return errs (or a combined
error) rather than nil; locate the logic using verifyConfigAPI(), the errs
variable and configAPIFound to implement returning the accumulated errors
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 2bdef35b-f154-4bf9-bc96-6aede3fddc0a

📥 Commits

Reviewing files that changed from the base of the PR and between 6fbf537 and 21318ad.

📒 Files selected for processing (4)
  • cmd/main.go
  • controllers/gitopsservice_controller_test.go
  • controllers/util/test_util.go
  • controllers/util/util.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • controllers/util/test_util.go
  • controllers/gitopsservice_controller_test.go

Comment thread controllers/util/util.go
Comment on lines +97 to +103
if err := verifyConfigAPI(); err != nil {
errs = append(errs, err)
return err
}
if !configAPIFound {
return nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Both early-return paths discard accumulated errors.

On Line 98 the error is appended to errs but Line 99 returns the raw err, dropping any OLM/Monitoring failures. Likewise Line 102 returns nil on non-OpenShift clusters, silently swallowing genuine OLM/Monitoring discovery errors collected at Line 90-95. Return the aggregated errs instead.

Suggested fix
 	if err := verifyConfigAPI(); err != nil {
 		errs = append(errs, err)
-		return err
+		return stderrors.Join(errs...)
 	}
 	if !configAPIFound {
-		return nil
+		return stderrors.Join(errs...)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err := verifyConfigAPI(); err != nil {
errs = append(errs, err)
return err
}
if !configAPIFound {
return nil
}
if err := verifyConfigAPI(); err != nil {
errs = append(errs, err)
return stderrors.Join(errs...)
}
if !configAPIFound {
return stderrors.Join(errs...)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controllers/util/util.go` around lines 97 - 103, The early returns after
calling verifyConfigAPI() and when configAPIFound is false are discarding
previously collected errors in errs; update the control flow in the block around
verifyConfigAPI(), configAPIFound and errs so that you append
verifyConfigAPI()'s error to errs and then return the aggregated errs slice (or
a combined error) instead of returning the raw err, and similarly when
configAPIFound is false return errs (or a combined error) rather than nil;
locate the logic using verifyConfigAPI(), the errs variable and configAPIFound
to implement returning the accumulated errors consistently.

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
@anandrkskd
Copy link
Copy Markdown
Contributor Author

/retest

Copy link
Copy Markdown
Member

@svghadi svghadi left a comment

Choose a reason for hiding this comment

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

/lgtm

@anandrkskd
Copy link
Copy Markdown
Contributor Author

/retest

Copy link
Copy Markdown
Member

@anandf anandf left a comment

Choose a reason for hiding this comment

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

LGTM

@svghadi
Copy link
Copy Markdown
Member

svghadi commented Jun 1, 2026

/approve

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 1, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: svghadi

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 label Jun 1, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit d4b8418 into redhat-developer:master Jun 1, 2026
17 checks passed
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.

3 participants