Skip to content

Added built-in api group list for CRD check#136

Merged
stillalearner merged 1 commit into
migtools:mainfrom
stillalearner:add_crd_list
Mar 31, 2026
Merged

Added built-in api group list for CRD check#136
stillalearner merged 1 commit into
migtools:mainfrom
stillalearner:add_crd_list

Conversation

@stillalearner

@stillalearner stillalearner commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Description

What’s added

  • Introduced a new API-group classification package:
    • apigroups/builtin.go
    • apigroups/builtin_test.go

New exported behavior

  • Added apigroups.IsDefaultBuiltinAPIGroup(group string) bool as the shared source of truth for default built-in group detection used by CRD export filtering.
  • Default behavior includes:
    • Known in-tree Kubernetes API groups
    • Common platform

Summary by CodeRabbit

  • New Features

    • Enhanced system to recognize and classify built-in Kubernetes and OpenShift API groups, including support for OpenShift-specific group patterns.
  • Tests

    • Added comprehensive test coverage for API group classification across various group types and patterns.

@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request introduces a new utility function in the apigroups package that checks whether a given Kubernetes API group is a default built-in group. The implementation includes a map of known in-tree API groups and an exported function that performs lookups against this set, supplemented by suffix matching for OpenShift groups. Comprehensive table-driven tests validate the function across multiple API group scenarios.

Changes

Cohort / File(s) Summary
API Group Classification
apigroups/builtin.go
Defines builtinK8sAPIGroups map containing in-tree Kubernetes and OpenShift API groups; exports IsDefaultBuiltinAPIGroup() function that returns true for known built-in groups or groups ending with .openshift.io, otherwise false.
Function Tests
apigroups/builtin_test.go
Table-driven test TestIsDefaultBuiltinAPIGroup validates the classification function across eight test cases including empty string, standard Kubernetes groups, OpenShift groups, and non-built-in domains.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A map of groups, so neat and tidy,
Builtin checks from Monday to Friday,
OpenShift friends with .io delight,
API groups sorted just right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a built-in API group list for CRD checking, which matches the new apigroups/builtin.go file and IsDefaultBuiltinAPIGroup function introduced in the changeset.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
apigroups/builtin.go (1)

5-6: Consider clarifying the comment to reflect the actual scope of included groups.

The comment states "in-tree Kubernetes API groups" but the map also includes CoreOS groups (operators.coreos.com, packages.operators.coreos.com, monitoring.coreos.com) which are not strictly in-tree Kubernetes. A more accurate description would help maintainers understand what belongs here.

📝 Suggested comment clarification
-// builtinK8sAPIGroups lists in-tree Kubernetes API groups that are not backed by
-// user-defined CRDs. Extend when new first-party groups appear.
+// builtinK8sAPIGroups lists in-tree Kubernetes API groups plus well-known
+// platform groups (e.g., CoreOS/OLM) that are not backed by user-defined CRDs.
+// Extend when new first-party or platform groups appear.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apigroups/builtin.go` around lines 5 - 6, The comment above the
builtinK8sAPIGroups map is misleading because it says "in-tree Kubernetes API
groups" while the map (builtinK8sAPIGroups) includes non-in-tree groups such as
operators.coreos.com, packages.operators.coreos.com, and monitoring.coreos.com;
update the comment in apigroups/builtin.go to accurately describe the map's
scope (e.g., "first-party and commonly bundled API groups not backed by
user-defined CRDs" or note inclusion of CoreOS/operator groups) so maintainers
know why those entries are present and when to extend the map.
apigroups/builtin_test.go (2)

9-18: Consider adding an edge case for suffix-matching boundary.

The .openshift.io suffix check could be validated with a negative case where the substring appears but not as a suffix (e.g., "openshift.io.example.com"). This would confirm the suffix logic works correctly.

📝 Suggested additional test case
 		{"example.com", false},
 		{"widgets.example.com", false},
+		{"openshift.io.example.com", false}, // contains but doesn't end with .openshift.io
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apigroups/builtin_test.go` around lines 9 - 18, Add a negative boundary test
to the existing test table literal that verifies suffix-only matching: include
an entry like {"openshift.io.example.com", false} (or
{"something.openshift.io.example.com", false}) alongside the other cases so the
suffix-check logic is exercised when ".openshift.io" appears as an internal
substring but not as the domain suffix.

10-10: Use a descriptive subtest name for the empty-string case.

When tt.group is "", the subtest name becomes empty, leading to less readable test output (Go will generate a name like #00). Consider adding a name field to the test struct for clarity.

📝 Suggested improvement for test readability
 func TestIsDefaultBuiltinAPIGroup(t *testing.T) {
 	tests := []struct {
+		name  string
 		group string
 		want  bool
 	}{
-		{"", true},
-		{"apps", true},
-		{"rbac.authorization.k8s.io", true},
-		{"operators.coreos.com", true},
-		{"route.openshift.io", true},
-		{"config.openshift.io", true},
-		{"example.com", false},
-		{"widgets.example.com", false},
+		{"empty (core)", "", true},
+		{"apps", "apps", true},
+		{"rbac.authorization.k8s.io", "rbac.authorization.k8s.io", true},
+		{"operators.coreos.com", "operators.coreos.com", true},
+		{"route.openshift.io", "route.openshift.io", true},
+		{"config.openshift.io", "config.openshift.io", true},
+		{"example.com", "example.com", false},
+		{"widgets.example.com", "widgets.example.com", false},
 	}

 	for _, tt := range tests {
-		t.Run(tt.group, func(t *testing.T) {
+		t.Run(tt.name, func(t *testing.T) {
 			if got := IsDefaultBuiltinAPIGroup(tt.group); got != tt.want {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apigroups/builtin_test.go` at line 10, The subtest for the empty-group case
uses tt.group as the test name which is empty; add a descriptive name field to
the test case struct (e.g., add "name string" alongside "group string, expected
bool") and replace uses of tt.group for t.Run with tt.name so the case {"",
true} becomes something like {name: "empty-group", group: "", expected: true};
update the test table (in apigroups/builtin_test.go) and change t.Run(tt.name,
...) to improve readability while leaving the test logic (functions that
reference tt.group) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apigroups/builtin_test.go`:
- Around line 9-18: Add a negative boundary test to the existing test table
literal that verifies suffix-only matching: include an entry like
{"openshift.io.example.com", false} (or {"something.openshift.io.example.com",
false}) alongside the other cases so the suffix-check logic is exercised when
".openshift.io" appears as an internal substring but not as the domain suffix.
- Line 10: The subtest for the empty-group case uses tt.group as the test name
which is empty; add a descriptive name field to the test case struct (e.g., add
"name string" alongside "group string, expected bool") and replace uses of
tt.group for t.Run with tt.name so the case {"", true} becomes something like
{name: "empty-group", group: "", expected: true}; update the test table (in
apigroups/builtin_test.go) and change t.Run(tt.name, ...) to improve readability
while leaving the test logic (functions that reference tt.group) unchanged.

In `@apigroups/builtin.go`:
- Around line 5-6: The comment above the builtinK8sAPIGroups map is misleading
because it says "in-tree Kubernetes API groups" while the map
(builtinK8sAPIGroups) includes non-in-tree groups such as operators.coreos.com,
packages.operators.coreos.com, and monitoring.coreos.com; update the comment in
apigroups/builtin.go to accurately describe the map's scope (e.g., "first-party
and commonly bundled API groups not backed by user-defined CRDs" or note
inclusion of CoreOS/operator groups) so maintainers know why those entries are
present and when to extend the map.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3395f007-c062-42d0-b2b8-6751f23e5dfc

📥 Commits

Reviewing files that changed from the base of the PR and between b620e71 and 2b81645.

📒 Files selected for processing (2)
  • apigroups/builtin.go
  • apigroups/builtin_test.go

@stillalearner stillalearner merged commit 536e4ec into migtools:main Mar 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants