Skip to content

feat(core): inject managed by label#533

Merged
bzp2010 merged 3 commits into
mainfrom
bzp/feat-managed-by-label
Jul 13, 2026
Merged

feat(core): inject managed by label#533
bzp2010 merged 3 commits into
mainfrom
bzp/feat-managed-by-label

Conversation

@bzp2010

@bzp2010 bzp2010 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Description

Now inject the following label into the synchronized resource:

managed-by = adc

This will help administrators using the UI or Admin API understand that the resource was created and is manage lifecycle by ADC. This implies that you should not modify the resource through any process other than ADC-driven GitOps.

This is a behavior that has changed significantly. When you upgrade to a new version of ADC and then perform synchronization, the label values for all resources will be updated.
If you do not need to inject this label, use --no-managed-by-label to disable this behavior.

If your concern is that this key is the same as the one you're currently using, I suggest using a namespace, such as acme.com/managed-by. This will clearly indicate that the key belongs to your organization's namespace, ensuring there are no conflicts and providing greater clarity. This concept is similar to Kubernetes.

This is enabled only on the CLI; the ADC server does not perform any implicit label injection.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Synced resources now receive a default managed-by=adc label.
    • Added --no-managed-by-label to disable automatic labeling.
    • Diff, sync, ingress sync, lint, and validation workflows respect this setting.
  • Bug Fixes

    • Managed-by labeling now preserves existing non-managed-by labels, and overwrites any conflicting managed-by value.
  • Tests

    • Added coverage for managed-by labeling behavior.
  • Chores

    • Updated TypeScript project reference configuration for the SDK.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI adds a managed-by label option, conditionally labels local resources during configuration loading, forwards the setting through command pipelines, adds coverage, and configures SDK TypeScript project references.

Changes

Managed-by label propagation

Layer / File(s) Summary
Managed-by label option and constants
apps/cli/src/command/helper.ts, apps/cli/src/command/typing.d.ts, apps/cli/src/command/utils.ts
Adds the --no-managed-by-label option, its global boolean property, and shared managed-by=adc constants.
Conditional local resource labeling
apps/cli/src/tasks/load_local.ts, apps/cli/src/command/utils.spec.ts
Adds conditional label injection during local configuration loading and tests label addition, replacement, and preservation.
Command pipeline integration
apps/cli/src/command/{diff,ingress-sync,lint,sync,validate}.command.ts
Passes the managed-by label setting into local configuration loading across command pipelines.

SDK TypeScript project references

Layer / File(s) Summary
SDK TypeScript project wiring
libs/sdk/tsconfig.json, libs/sdk/tsconfig.spec.json
Adds library and specification project references to the SDK TypeScript configurations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLICommand
  participant LoadLocalConfigurationTask
  participant fillLabels
  CLICommand->>LoadLocalConfigurationTask: pass managedByLabel
  LoadLocalConfigurationTask->>fillLabels: apply managed-by=adc when enabled
  fillLabels-->>LoadLocalConfigurationTask: labeled local resources
Loading

Suggested reviewers: guoqqqi, litesun

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning Only unit tests were added for fillLabels; no CLI E2E spec exercises sync/validate/diff with or without --no-managed-by-label. Add an E2E CLI test that drives a real sync/validate flow and asserts managed-by=adc is injected by default and omitted with --no-managed-by-label.
✅ Passed checks (5 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.
Security Check ✅ Passed Reviewed changed CLI/task files; no new logging, auth, storage, or TLS code was added—only managed-by label plumbing and tests.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: injecting the managed-by label.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bzp/feat-managed-by-label

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

@bzp2010 bzp2010 self-assigned this Jul 13, 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.

🧹 Nitpick comments (2)
apps/cli/src/command/utils.spec.ts (1)

259-283: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a case for pre-existing managed-by label overwrite.

Current test covers "no labels" and "different label key" merge cases but not a resource that already sets its own managed-by value, which is the scenario most likely to surprise users given fillLabels's overwrite semantics.

🤖 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 `@apps/cli/src/command/utils.spec.ts` around lines 259 - 283, Add a test case
alongside the existing fillLabels test that gives a service or consumer an
existing managed-by label with a different value, then verifies fillLabels
overwrites it with MANAGED_BY_LABEL_VALUE while preserving other labels and
resources.
apps/cli/src/tasks/load_local.ts (1)

110-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing title on the new task.

Every other task in this pipeline (load, merge, resolve vars, filter, label-selector) declares a title for Listr rendering; this one doesn't, which will show a blank/undefined step in the CLI output.

♻️ Proposed fix
         {
+          title: 'Label resources as managed by ADC',
           enabled: managedByLabel,
           task: async () => {
             fillLabels(ctx.local, {
               [MANAGED_BY_LABEL_KEY]: MANAGED_BY_LABEL_VALUE,
             });
           },
         },
🤖 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 `@apps/cli/src/tasks/load_local.ts` around lines 110 - 117, Add a descriptive
title to the task object that invokes fillLabels in the local loading pipeline,
matching the title pattern used by the neighboring load, merge,
variable-resolution, and filter tasks so Listr renders a named step.
🤖 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.

Nitpick comments:
In `@apps/cli/src/command/utils.spec.ts`:
- Around line 259-283: Add a test case alongside the existing fillLabels test
that gives a service or consumer an existing managed-by label with a different
value, then verifies fillLabels overwrites it with MANAGED_BY_LABEL_VALUE while
preserving other labels and resources.

In `@apps/cli/src/tasks/load_local.ts`:
- Around line 110-117: Add a descriptive title to the task object that invokes
fillLabels in the local loading pipeline, matching the title pattern used by the
neighboring load, merge, variable-resolution, and filter tasks so Listr renders
a named step.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b85ab589-457e-4816-b0d3-40671fed5553

📥 Commits

Reviewing files that changed from the base of the PR and between 06d3943 and c3e27a8.

📒 Files selected for processing (12)
  • apps/cli/src/command/diff.command.ts
  • apps/cli/src/command/helper.ts
  • apps/cli/src/command/ingress-sync.command.ts
  • apps/cli/src/command/lint.command.ts
  • apps/cli/src/command/sync.command.ts
  • apps/cli/src/command/typing.d.ts
  • apps/cli/src/command/utils.spec.ts
  • apps/cli/src/command/utils.ts
  • apps/cli/src/command/validate.command.ts
  • apps/cli/src/tasks/load_local.ts
  • libs/sdk/tsconfig.json
  • libs/sdk/tsconfig.spec.json

@bzp2010 bzp2010 added test/api7 Trigger the API7 test on the PR test/apisix-standalone Trigger the APISIX standalone test on the PR labels Jul 13, 2026
@bzp2010
bzp2010 merged commit b72f153 into main Jul 13, 2026
95 checks passed
@bzp2010
bzp2010 deleted the bzp/feat-managed-by-label branch July 13, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test/api7 Trigger the API7 test on the PR test/apisix-standalone Trigger the APISIX standalone test on the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants