Skip to content

Add Labels to GSM Bundle - #5347

Open
psalajova wants to merge 1 commit into
openshift:mainfrom
psalajova:add-labels-field-to-bundles
Open

Add Labels to GSM Bundle#5347
psalajova wants to merge 1 commit into
openshift:mainfrom
psalajova:add-labels-field-to-bundles

Conversation

@psalajova

@psalajova psalajova commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Adds a labels field to GSM bundle definitions in gsm-config.yaml, allowing bundles with sync_to_cluster: true to attach custom Kubernetes labels to the secrets they create on clusters.

This is needed for the Vault-to-GSM migration (https://redhat.atlassian.net/browse/DPTP-4893). Some Vault secrets currently use secretsync/target-labels metadata (#5189) to set labels on synced K8s secrets -- most notably argocd.argoproj.io/secret-type:cluster for ArgoCD cluster secret discovery. Without this field, those secrets would lose their labels after migration to GSM.

Example of such bundle in gsm-config.yaml

  bundles:
    - name: gitops-cluster-build04
      sync_to_cluster: true
      labels:
        - "argocd.argoproj.io/secret-type:cluster"
      gsm_secrets:
        - collection: test-platform-infra
          group: gitops-cluster-build04
      targets:
        - cluster: build04
          namespace: openshift-gitops

Intended workflow is:

  1. Secret data lives in GSM (Google Secret Manager)
  2. ci-secret-bootstrap runs as a periodic job, reads gsm-config.yaml
  3. For bundles with sync_to_cluster: true, it fetches the secret data from GSM and creates/updates K8s Secrets on the target clusters
  4. If the bundle has labels, those labels are set on the resulting K8s Secret's ObjectMeta.Labels (alongside the existing dptp.openshift.io/requester: ci-secret-bootstrap label)
  5. Controllers like ArgoCD that discover secrets by label (e.g. argocd.argoproj.io/secret-type: cluster) find them automatically

Summary

GSM bundle definitions can now include Kubernetes Secret labels.

When sync_to_cluster: true, ci-secret-bootstrap applies valid configured labels to generated or updated Secrets. It retains the existing bootstrap label and ignores invalid labels.

GSMBundle preserves labels during cluster-group expansion and ${CLUSTER} substitution. Validation rejects malformed labels and the reserved DPTPRequesterLabel key.

This enables migrated Vault secrets, including ArgoCD cluster secrets, to be discovered automatically by Kubernetes controllers.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 13c99078-cc81-4713-80c3-a6343fca29ad

📥 Commits

Reviewing files that changed from the base of the PR and between 1688c69 and 0abb04b.

⛔ Files ignored due to path filters (1)
  • pkg/api/zz_generated.deepcopy.go is excluded by !**/zz_generated*
📒 Files selected for processing (5)
  • cmd/ci-secret-bootstrap/main.go
  • cmd/ci-secret-bootstrap/main_test.go
  • pkg/api/constant.go
  • pkg/api/gsm.go
  • pkg/api/gsm_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/release (manual)
  • openshift/ci-docs (manual)
  • openshift/release-controller (manual)
  • openshift/ci-chat-bot (manual)
🚧 Files skipped from review as they are similar to previous changes (5)
  • cmd/ci-secret-bootstrap/main_test.go
  • pkg/api/gsm_test.go
  • pkg/api/constant.go
  • pkg/api/gsm.go
  • cmd/ci-secret-bootstrap/main.go

📝 Walkthrough

Walkthrough

GSM bundles now support validated labels. Labels remain during cluster expansion and are applied to generated Kubernetes Secrets with the default requester label.

Changes

GSM label propagation

Layer / File(s) Summary
Label contract and bundle validation
pkg/api/constant.go, pkg/api/gsm.go, pkg/api/gsm_test.go
GSMBundle accepts optional labels. ParseLabel validates key:value entries. Validation rejects malformed labels and the reserved DPTPRequesterLabel key.
Bundle expansion
pkg/api/gsm.go, pkg/api/gsm_test.go
Cluster-group expansion and ${CLUSTER} substitution preserve bundle labels.
Generated Secret label application
cmd/ci-secret-bootstrap/main.go, cmd/ci-secret-bootstrap/main_test.go
The bootstrapper parses user labels and applies valid bundle labels with the default requester label. Tests verify Secret metadata, type, and token data.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: hector-vido, pruan-rht

🚥 Pre-merge checks | ✅ 15 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Go Error Handling ⚠️ Warning Error from api.ParseLabel() is silently ignored at line 1554 of main.go using err == nil without logging or justification, violating error handling patterns used elsewhere in the PR. Either handle the error by returning it or logging it, or add a comment justifying the silent ignore. Consider consistency with the validation in pkg/api/gsm.go line 454-458.
Test Coverage For New Features ⚠️ Warning The PR adds pure public ParseLabel, but no corresponding TestParseLabel exists; current tests cover callers only and omit direct invalid-value and trimming cases. Add a table-driven TestParseLabel covering valid parsing, whitespace, missing colon, invalid key, invalid value, and first-colon handling.
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding labels to GSM bundles.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 All newly added test names are stable and deterministic. Seven test cases use static, descriptive names without dynamic values: "bundle with labels", "resolved bundle doesn't drop labels", "${CLUST...
Test Structure And Quality ✅ Passed The changed tests use Go's testing package, not Ginkgo. They use t.Run and diagnostic t.Fatalf calls, with no cluster waits or resource lifecycle requiring cleanup.
Microshift Test Compatibility ✅ Passed This PR adds no new Ginkgo e2e tests. All changes are to unit tests using standard Go testing package or non-test code (main.go, gsm.go, constant.go). The MicroShift Test Compatibility check applie...
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR adds only standard Go unit tests using the testing package. No Ginkgo e2e tests are added, so the SNO compatibility check does not apply.
Topology-Aware Scheduling Compatibility ✅ Passed This PR adds label support to GSM bundle definitions and applies those labels to K8s Secrets. No deployment manifests, scheduling constraints, affinity rules, or topology-related configurations are...
Ote Binary Stdout Contract ✅ Passed The OTE Binary Stdout Contract check does not apply to this PR. ci-secret-bootstrap is a standard CLI tool, not an OTE binary. It has no OTE/Ginkgo imports, does not output test data to stdout, a...
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests were added in this pull request. All test files use standard Go testing framework (testing.T), not Ginkgo patterns.
No-Weak-Crypto ✅ Passed PR adds label support to GSM bundles using standard Kubernetes label validation; no weak crypto (MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB), custom crypto implementations, or non-constant-time secre...
Container-Privileges ✅ Passed The PR changes only Go source and tests; it adds no container or Kubernetes manifests and introduces no privileged, host namespace, SYS_ADMIN, or privilege-escalation settings.
No-Sensitive-Data-In-Logs ✅ Passed The production diff adds no logging of secret payloads, tokens, credentials, or PII; existing logs retain only secret names, keys, and metadata.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci
openshift-ci Bot requested review from hector-vido and pruan-rht July 31, 2026 10:41
@openshift-ci

openshift-ci Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: psalajova

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 Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 31, 2026

@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

🧹 Nitpick comments (1)
pkg/api/gsm.go (1)

36-36: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document GSMBundle.Labels.

Add a Go doc comment for this exported API field. State the key:value syntax and that labels apply to generated Secrets.

🤖 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 `@pkg/api/gsm.go` at line 36, Add a Go doc comment immediately above the
exported GSMBundle.Labels field, documenting that labels use key:value syntax
and are applied to generated Secrets.

Source: Coding guidelines

🤖 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/ci-secret-bootstrap/main.go`:
- Around line 1553-1558: Update bundle validation to reject configured labels
using the reserved api.DPTPRequesterLabel key, preventing bundles from
overriding the bootstrap requester label. In the label merge near the labels map
and bundle.Labels loop, assign api.DPTPRequesterLabel to
api.CISecretBootstrapName after processing all configured labels as a defensive
safeguard. Add a test covering the reserved-key collision and confirming the
bootstrap requester value is preserved.

In `@pkg/api/gsm_test.go`:
- Around line 740-783: Update the expectedConfig for the “resolved bundle
doesn't drop labels” test case to retain the managed-clusters ClusterGroups
entry from the input GSMConfig, while preserving the expanded Targets and Labels
assertions.

In `@pkg/api/gsm.go`:
- Around line 453-458: Update GSMConfig.Validate() to split each bundle label
into exactly one key and value, then validate the key with
validation.IsQualifiedName and the value with validation.IsValidLabelValue,
rejecting empty or malformed components such as :cluster, bad key:value, and
key:bad:value before Secret creation. Add table-driven tests covering invalid
label keys and values.

---

Nitpick comments:
In `@pkg/api/gsm.go`:
- Line 36: Add a Go doc comment immediately above the exported GSMBundle.Labels
field, documenting that labels use key:value syntax and are applied to generated
Secrets.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 9bd0648f-1b5e-4c99-a4a5-e3dcd4b6b922

📥 Commits

Reviewing files that changed from the base of the PR and between 7b3feca and 467ad2e.

⛔ Files ignored due to path filters (1)
  • pkg/api/zz_generated.deepcopy.go is excluded by !**/zz_generated*
📒 Files selected for processing (4)
  • cmd/ci-secret-bootstrap/main.go
  • cmd/ci-secret-bootstrap/main_test.go
  • pkg/api/gsm.go
  • pkg/api/gsm_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/release (manual)
  • openshift/ci-docs (manual)
  • openshift/release-controller (manual)
  • openshift/ci-chat-bot (manual)

Comment thread cmd/ci-secret-bootstrap/main.go Outdated
Comment thread pkg/api/gsm_test.go
Comment thread pkg/api/gsm.go
@psalajova
psalajova force-pushed the add-labels-field-to-bundles branch from 467ad2e to 1089aeb Compare July 31, 2026 12:39

@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: 2

🤖 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 `@pkg/api/constant.go`:
- Around line 45-57: Update validateBundle to track each parsed label key and
return a configuration error when a duplicate key appears, before Secret
generation runs. Keep ParseLabel’s per-entry validation unchanged and preserve
labels assignment only for validated, unique keys.
- Around line 43-45: The exported ParseLabel documentation should describe the
label parameter, both returned key and value strings, and the whitespace
behavior while preserving its validation summary. Also update the relevant
labels field documentation in openshift/ci-docs to mention the exact key:value
syntax.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 50e0f87a-e9f7-4267-ab0c-6ab435313cba

📥 Commits

Reviewing files that changed from the base of the PR and between 467ad2e and 1089aeb.

⛔ Files ignored due to path filters (1)
  • pkg/api/zz_generated.deepcopy.go is excluded by !**/zz_generated*
📒 Files selected for processing (5)
  • cmd/ci-secret-bootstrap/main.go
  • cmd/ci-secret-bootstrap/main_test.go
  • pkg/api/constant.go
  • pkg/api/gsm.go
  • pkg/api/gsm_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/release (manual)
  • openshift/ci-docs (manual)
  • openshift/release-controller (manual)
  • openshift/ci-chat-bot (manual)
🚧 Files skipped from review as they are similar to previous changes (4)
  • pkg/api/gsm_test.go
  • pkg/api/gsm.go
  • cmd/ci-secret-bootstrap/main.go
  • cmd/ci-secret-bootstrap/main_test.go

Comment thread pkg/api/constant.go Outdated
Comment thread pkg/api/constant.go
@psalajova
psalajova force-pushed the add-labels-field-to-bundles branch from 1089aeb to 1688c69 Compare July 31, 2026 12:54
@psalajova
psalajova force-pushed the add-labels-field-to-bundles branch from 1688c69 to 0abb04b Compare July 31, 2026 13:57
@openshift-ci

openshift-ci Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@psalajova: 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/integration 0abb04b link true /test integration

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

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant