Skip to content

OCPCLOUD-3513: add a tool to generate manifests-summary#616

Open
hongkailiu wants to merge 1 commit into
openshift:mainfrom
hongkailiu:manifests-summary
Open

OCPCLOUD-3513: add a tool to generate manifests-summary#616
hongkailiu wants to merge 1 commit into
openshift:mainfrom
hongkailiu:manifests-summary

Conversation

@hongkailiu

@hongkailiu hongkailiu commented Jun 17, 2026

Copy link
Copy Markdown
Member

No description provided.

@openshift-ci-robot

openshift-ci-robot commented Jun 17, 2026

Copy link
Copy Markdown

@hongkailiu: This pull request references OCPCLOUD-3513 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

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.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 17, 2026
@openshift-ci openshift-ci Bot requested review from nrb and theobarberbany June 17, 2026 22:59
@openshift-ci

openshift-ci Bot commented Jun 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign enxebre for approval. For more information see the Code Review Process.

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

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a standalone Go CLI tool (generate-manifests-summary) that parses multi-document Kubernetes YAML manifests, extracts resource metadata per document, and writes a per-profile manifests-summary.yaml. The Makefile gains a manifests-summary target wired into the verify workflow. Go module dependencies are updated to promote Kubernetes and YAML libraries to direct requires. The generated openshift/manifests-summary.yaml for the default profile is committed.

Changes

Manifest Summary Generation and Integration

Layer / File(s) Summary
CLI tool: entry point and manifest parsing
openshift/tools/generate-manifests-summary/main.go
Defines CLI flags (--input, --output, --profile), calls run() on startup. parseDocument() validates each decoded PartialObjectMetadata for non-empty kind and Name, mapping fields into ManifestMetadata (including full APIVersion and Namespace). parseManifests() loops through multi-document YAML/JSON input with NewYAMLOrJSONDecoder, aggregating per-document metadata until io.EOF.
CLI tool: orchestration, I/O, and sorting
openshift/tools/generate-manifests-summary/main.go
run() orchestrates the full pipeline: opens input file, parses all manifests, reads existing ManifestsSummary via readExistingSummary(), replaces the named profile with newly parsed manifests sorted by Kind, APIVersion, Namespace, Name via updateSummary(), and writes the result as YAML via writeSummary(). Includes unused parseAPIVersion() helper for group/version splitting.
Build integration: Makefile and Go module dependencies
openshift/Makefile, openshift/tools/go.mod
verify target now depends on new verify-manifests-summary; MAKEFILE_DIR variable and new .PHONY manifests-summary target invoke the CLI tool with Makefile-relative input and output paths. go.mod moves k8s.io/apimachinery, k8s.io/klog/v2, sigs.k8s.io/yaml, and github.com/openshift/cluster-capi-operator/manifests-gen from indirect to direct require block, and demotes k8s.io/client-go to indirect.
Generated default-profile manifest summary
openshift/manifests-summary.yaml
Commits the generated output enumerating 17 resources under the default profile: cluster-scoped ClusterRole/ClusterRoleBinding, four AWS-related CustomResourceDefinition entries, capa-controller-manager Deployment, MutatingWebhookConfiguration, ValidatingWebhookConfiguration, namespace-scoped leader-election Role/RoleBinding, capa-metrics-service, capa-webhook-service, ServiceAccount, ValidatingAdmissionPolicy, and ValidatingAdmissionPolicyBinding.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Ote Binary Stdout Contract ❌ Error The generate-manifests-summary tool uses klog without redirecting output to stderr. klog writes to stdout by default, violating OTE Binary Stdout Contract. klog.Fatal() and klog.InfoS() in main() w... Add klog.LogToStderr(true) after klog.InitFlags(nil) in main() to redirect klog output to stderr, ensuring only intentional output appears on stdout.
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (13 passed)
Check name Status Explanation
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.
Stable And Deterministic Test Names ✅ Passed PR does not add or modify any Ginkgo test files; check for Ginkgo test name stability is not applicable.
Test Structure And Quality ✅ Passed This PR does not contain any Ginkgo test code. The changes are a Makefile update, a manifest YAML data file, a Go CLI tool, and module dependencies—none of which include test code subject to this c...
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests are added in this PR. Changes consist of a CLI tool (main.go), a manifest summary YAML file, and Makefile/module updates—not test files.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR. Changes are limited to a manifest summary generation tool, YAML configuration file, and Makefile updates. Check does not apply.
Topology-Aware Scheduling Compatibility ✅ Passed PR adds only a metadata summary tool and manifest list file for CI verification; no deployment manifests or scheduling constraints are introduced or modified.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR does not add any Ginkgo e2e tests. It adds a manifest generation tool and YAML configuration files for OpenShift cluster API provider. The custom check only applies when new Ginkgo e2e test...
No-Weak-Crypto ✅ Passed PR adds manifest summary tool with no weak crypto (MD5/SHA1/DES/RC4/3DES/Blowfish/ECB), custom crypto implementations, or insecure secret comparisons.
Container-Privileges ✅ Passed No privileged container configurations found. The PR adds utility tooling (Go CLI), a metadata summary file, and Makefile targets with no privileged security settings, SYS_ADMIN capabilities, or ro...
No-Sensitive-Data-In-Logs ✅ Passed The PR's new logging statements only expose non-sensitive data: file paths, manifest counts, profile names, and generic messages. No credentials, tokens, API keys, PII, session IDs, or customer dat...
Title check ✅ Passed The PR title directly matches the primary change: adding a new tool named 'generate-manifests-summary' to create manifest summary files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@hongkailiu

Copy link
Copy Markdown
Member Author

/jira refresh

@openshift-ci-robot

openshift-ci-robot commented Jun 17, 2026

Copy link
Copy Markdown

@hongkailiu: This pull request references OCPCLOUD-3513 which is a valid jira issue.

Details

In response to this:

/jira refresh

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

Actionable comments posted: 3

🤖 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 `@openshift/tools/generate-manifests-summary/main.go`:
- Line 23: The usage example comment on line 23 references an incorrect flag
name `--output`, but the actual flag defined in the code is
`--manifests-summary-file`. Update the comment example to use the correct flag
name `--manifests-summary-file` instead of `--output` to ensure the
documentation accurately reflects how users should invoke the command.
- Around line 65-217: Add comprehensive unit tests for the new parsing and
update functions introduced in this change. Create tests for parseAPIVersion to
verify it correctly splits group and version components including edge cases
with empty strings and various formats. Add tests for parseDocument to validate
it handles missing kind and metadata.name fields with appropriate error
messages. Add tests for parseAllDocuments to verify it correctly decodes
multiple YAML documents and properly reports decode errors with document
indices. Add tests for readExistingSummary to handle missing output files and
invalid YAML content. Add tests for updateSummary to verify that manifests are
sorted deterministically by the correct field order (kind, group, version,
namespace, name) and that the profile is correctly updated in the summary. Add
tests for writeOutput to verify it marshals and writes files correctly. These
tests should cover both success and failure paths to ensure robust error
handling.
- Around line 131-138: The code currently treats missing or empty summary files
as fatal errors in the readExistingSummary function call around line 132, which
crashes on first-run generation when no summary file exists yet. Instead of
calling klog.Fatalf, modify the error handling to gracefully return an empty or
default summary when the file does not exist. Additionally, refactor the run
function to return errors instead of calling klog.Fatalf directly around line
134, allowing the caller to handle errors appropriately. Finally, fix the nil
map assignment issue around lines 185-186 by initializing the map or checking
for nil before attempting to assign values to it.
🪄 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: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 69187914-8b43-496b-9f36-0c44af02a96d

📥 Commits

Reviewing files that changed from the base of the PR and between 77b3287 and c9a72a0.

📒 Files selected for processing (4)
  • openshift/Makefile
  • openshift/manifests-summary.yaml
  • openshift/tools/generate-manifests-summary/main.go
  • openshift/tools/go.mod

Comment thread openshift/tools/generate-manifests-summary/main.go Outdated
Comment thread openshift/tools/generate-manifests-summary/main.go Outdated
Comment thread openshift/tools/generate-manifests-summary/main.go Outdated
@hongkailiu

Copy link
Copy Markdown
Member Author

@hongkailiu hongkailiu changed the title OCPCLOUD-3513: add a tool to generate manifests-summary [wip]OCPCLOUD-3513: add a tool to generate manifests-summary Jun 17, 2026
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 17, 2026
@hongkailiu hongkailiu force-pushed the manifests-summary branch 2 times, most recently from 93e1a7e to f2e3761 Compare June 18, 2026 01:38

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
openshift/tools/generate-manifests-summary/main.go (2)

94-94: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Handle Close() error instead of ignoring it.

defer file.Close() drops the returned error, which violates the Go security guideline and can hide I/O issues.

As per coding guidelines, “Never ignore error returns.”

Proposed fix
-func run(inputPath, outputPath, profileName string) error {
+func run(inputPath, outputPath, profileName string) (err error) {
 	klog.V(1).InfoS("Opening input file", "path", inputPath)
-	file, err := os.Open(inputPath)
+	file, err := os.Open(inputPath)
 	if err != nil {
 		return fmt.Errorf("failed to open input file %q: %w", inputPath, err)
 	}
-	defer file.Close()
+	defer func() {
+		if cerr := file.Close(); cerr != nil && err == nil {
+			err = fmt.Errorf("failed to close input file %q: %w", inputPath, cerr)
+		}
+	}()
🤖 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 `@openshift/tools/generate-manifests-summary/main.go` at line 94, The defer
statement calling file.Close() is ignoring the error returned by the Close()
method, which violates Go security guidelines. To fix this, modify the defer
block to properly handle the error returned by Close(). This typically involves
using a named return variable in the function signature and updating it within
the defer block to capture any close errors, ensuring the error is logged or
propagated rather than silently dropped.

Source: Coding guidelines


66-83: ⚠️ Potential issue | 🟠 Major

Never ignore file close errors; handle empty documents defensively.

The manifest file has no empty YAML docs in practice, so the empty-document issue is defensive rather than critical. However, there is a real Go security issue: line 94 uses defer file.Close() without checking the returned error, which violates the coding guideline "Never ignore error returns" for Go files.

Wrap the Close() call to capture and handle any errors:

 func run(inputPath, outputPath, profileName string) error {
 	klog.V(1).InfoS("Opening input file", "path", inputPath)
 	file, err := os.Open(inputPath)
 	if err != nil {
 		return fmt.Errorf("failed to open input file %q: %w", inputPath, err)
 	}
-	defer file.Close()
+	defer func() {
+		if err := file.Close(); err != nil {
+			klog.V(1).InfoS("Warning: failed to close file", "path", inputPath, "err", err)
+		}
+	}()

Regarding empty documents: the empty-doc handling proposed in the original review is still defensible as a robustness improvement, even though the current manifests contain none.

🤖 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 `@openshift/tools/generate-manifests-summary/main.go` around lines 66 - 83,
Locate the defer file.Close() statement in the function and wrap it to capture
and handle the error return value from Close(). Instead of using defer with an
unchecked Close(), use a proper error handling mechanism to check if Close()
returns an error, and either log it or return it as part of the function's error
handling flow. This ensures compliance with Go's error handling guidelines that
require all error returns to be explicitly checked.
🤖 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.

Outside diff comments:
In `@openshift/tools/generate-manifests-summary/main.go`:
- Line 94: The defer statement calling file.Close() is ignoring the error
returned by the Close() method, which violates Go security guidelines. To fix
this, modify the defer block to properly handle the error returned by Close().
This typically involves using a named return variable in the function signature
and updating it within the defer block to capture any close errors, ensuring the
error is logged or propagated rather than silently dropped.
- Around line 66-83: Locate the defer file.Close() statement in the function and
wrap it to capture and handle the error return value from Close(). Instead of
using defer with an unchecked Close(), use a proper error handling mechanism to
check if Close() returns an error, and either log it or return it as part of the
function's error handling flow. This ensures compliance with Go's error handling
guidelines that require all error returns to be explicitly checked.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8ca13b77-23b7-4831-83d3-5cbe0142ffb8

📥 Commits

Reviewing files that changed from the base of the PR and between fcc6386 and 93e1a7e.

📒 Files selected for processing (2)
  • openshift/manifests-summary.yaml
  • openshift/tools/generate-manifests-summary/main.go
✅ Files skipped from review due to trivial changes (1)
  • openshift/manifests-summary.yaml

@hongkailiu hongkailiu force-pushed the manifests-summary branch 2 times, most recently from 4ddbb25 to b19a734 Compare June 18, 2026 13:42
@hongkailiu hongkailiu changed the title [wip]OCPCLOUD-3513: add a tool to generate manifests-summary OCPCLOUD-3513: add a tool to generate manifests-summary Jun 18, 2026
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2026
Comment on lines +1 to +22
default:
- apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
name: capa-manager-role
- apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
name: capa-manager-rolebinding
- apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
name: awsclustercontrolleridentities.infrastructure.cluster.x-k8s.io
- apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
name: awsclusters.infrastructure.cluster.x-k8s.io
- apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
name: awsmachines.infrastructure.cluster.x-k8s.io
- apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
name: awsmachinetemplates.infrastructure.cluster.x-k8s.io
- apiVersion: apps/v1
kind: Deployment
name: capa-controller-manager

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the output!
But I wonder if we can avoid defining a new go module to do this.
Could we leverage existing tools like yq/jq or similar to generate this? Thanks!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I got the impression that GoLang is alright too.

Moreover, the tools for GoLang are already used in Makefile

.PHONY: update-manifests-gen
update-manifests-gen:
cd tools && go get github.com/openshift/cluster-capi-operator/manifests-gen && go mod tidy && go mod vendor

go get vs go run: what is the difference?

Just to a confirmation before switching.
You want to implement the same function with Shell + yq/jq, correct?

Let me try it and get back to you.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It has go run too.

MANIFESTS_GEN := go run ./vendor/github.com/openshift/cluster-capi-operator/manifests-gen/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Switched to "Shell + yq/jq" implementation.

@hongkailiu hongkailiu Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@hongkailiu hongkailiu force-pushed the manifests-summary branch 3 times, most recently from 1e18671 to 9a976d1 Compare July 7, 2026 22:23
@hongkailiu hongkailiu force-pushed the manifests-summary branch from 9a976d1 to dfa5b4a Compare July 7, 2026 22:24
@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown

@hongkailiu: 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/verify dfa5b4a link true /test verify
ci/prow/e2e-aws-ovn dfa5b4a link true /test e2e-aws-ovn
ci/prow/e2e-hypershift dfa5b4a link true /test e2e-hypershift

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

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.

3 participants