Skip to content

Feature cms api operator#2463

Open
a932846905 wants to merge 18 commits into
openkruise:masterfrom
a932846905:feature-cms-api-operator
Open

Feature cms api operator#2463
a932846905 wants to merge 18 commits into
openkruise:masterfrom
a932846905:feature-cms-api-operator

Conversation

@a932846905

Copy link
Copy Markdown
Contributor

Ⅰ. Describe what this PR does

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how to verify it

Ⅳ. Special notes for reviews

chrisdeng added 2 commits May 21, 2026 14:42
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Copilot AI review requested due to automatic review settings May 21, 2026 07:31
@kruise-bot
kruise-bot requested review from furykerry and zmberg May 21, 2026 07:31
@kruise-bot

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 zmberg for approval by writing /assign @zmberg in a comment. For more information see:The Kubernetes 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

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

Pull request overview

This PR introduces a new ConfigMapSet API + controller + webhooks to manage configuration rollouts to Pods, including Pod-side injection of a reload sidecar and update coordination via annotations.

Changes:

  • Add ConfigMapSet CRD/API types, controller reconciliation logic, and RBAC wiring.
  • Add mutating/validating admission webhooks for ConfigMapSet, plus Pod mutation logic to inject volumes/sidecar and initialize revision annotations.
  • Generate/update clientset/informers/listers and add unit tests around conflict detection and validation behavior.

Reviewed changes

Copilot reviewed 21 out of 33 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
pkg/webhook/pod/mutating/pod_create_update_handler.go Inject ConfigMapSet volumes/sidecar and set revision annotations on Pod create
pkg/webhook/pod/mutating/configmapset_mutating_test.go Unit tests for Pod-side conflict/name logic and annotation initialization
pkg/webhook/configmapset/validating/webhooks.go Register ConfigMapSet validating webhook
pkg/webhook/configmapset/validating/configmapset_create_update_handler.go Validate ConfigMapSet spec, conflicts, history limit semantics
pkg/webhook/configmapset/validating/configmapset_create_update_handler_test.go Unit tests for ConfigMapSet validating webhook logic
pkg/webhook/configmapset/validating/configmapset_conflicts.go Cross-ConfigMapSet conflict detection (overlapping selectors)
pkg/webhook/configmapset/mutating/webhooks.go Register ConfigMapSet mutating webhook
pkg/webhook/configmapset/mutating/configmapset_create_update_handler.go Defaulting webhook for ConfigMapSet
pkg/webhook/add_configmapset.go Wire ConfigMapSet webhooks into webhook server
pkg/controller/controllers.go Register ConfigMapSet controller with manager
pkg/controller/configmapset/configmapset_utils.go Shared helpers for annotation keys, pod matching, grouping
pkg/controller/configmapset/configmapset_utils_test.go Tests for utils helpers (pod matching, readiness, CMS matching)
pkg/controller/configmapset/configmapset_event_handler.go Event handlers for ConfigMapSet/Pod enqueueing
pkg/controller/configmapset/configmapset_controller.go Core controller reconcile loop, revision hub management, pod update strategy
pkg/controller/configmapset/configmapset_controller_test.go Tests for hash, distribution logic, pod update prioritization, container name resolution
pkg/client/listers/apps/v1alpha1/expansion_generated.go Add ConfigMapSet lister expansions
pkg/client/listers/apps/v1alpha1/configmapset.go Generated ConfigMapSet lister
pkg/client/informers/externalversions/generic.go Wire generic informer lookup for ConfigMapSets
pkg/client/informers/externalversions/apps/v1alpha1/interface.go Add ConfigMapSets informer accessor
pkg/client/informers/externalversions/apps/v1alpha1/configmapset.go Generated ConfigMapSet informer
pkg/client/clientset/versioned/typed/apps/v1alpha1/generated_expansion.go Add ConfigMapSet client expansion hook
pkg/client/clientset/versioned/typed/apps/v1alpha1/fake/fake_configmapset.go Generated fake ConfigMapSet client
pkg/client/clientset/versioned/typed/apps/v1alpha1/fake/fake_apps_client.go Expose fake ConfigMapSets() accessor
pkg/client/clientset/versioned/typed/apps/v1alpha1/configmapset.go Generated typed ConfigMapSet client
pkg/client/clientset/versioned/typed/apps/v1alpha1/apps_client.go Expose ConfigMapSets() accessor
apis/apps/v1alpha1/configmapset_types.go New ConfigMapSet API types
apis/apps/v1alpha1/zz_generated.deepcopy.go Generated deepcopy for new API types
apis/apps/defaults/v1alpha1.go Add ConfigMapSet defaulting
config/crd/bases/apps.kruise.io_configmapsets.yaml Add ConfigMapSet CRD manifest
config/webhook/manifests.yaml Register ConfigMapSet mutating/validating webhooks
config/rbac/role.yaml Grant RBAC for configmapsets + status
go.mod Add indirect deps needed by tests
go.sum Lock new indirect deps
Files not reviewed (11)
  • apis/apps/v1alpha1/zz_generated.deepcopy.go: Language not supported
  • pkg/client/clientset/versioned/typed/apps/v1alpha1/apps_client.go: Language not supported
  • pkg/client/clientset/versioned/typed/apps/v1alpha1/configmapset.go: Language not supported
  • pkg/client/clientset/versioned/typed/apps/v1alpha1/fake/fake_apps_client.go: Language not supported
  • pkg/client/clientset/versioned/typed/apps/v1alpha1/fake/fake_configmapset.go: Language not supported
  • pkg/client/clientset/versioned/typed/apps/v1alpha1/generated_expansion.go: Language not supported
  • pkg/client/informers/externalversions/apps/v1alpha1/configmapset.go: Language not supported
  • pkg/client/informers/externalversions/apps/v1alpha1/interface.go: Language not supported
  • pkg/client/informers/externalversions/generic.go: Language not supported
  • pkg/client/listers/apps/v1alpha1/configmapset.go: Language not supported
  • pkg/client/listers/apps/v1alpha1/expansion_generated.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/webhook/pod/mutating/pod_create_update_handler.go Outdated
Comment thread pkg/webhook/pod/mutating/pod_create_update_handler.go Outdated
Comment thread pkg/webhook/pod/mutating/pod_create_update_handler.go
Comment thread apis/apps/defaults/v1alpha1.go
Comment thread pkg/controller/configmapset/configmapset_controller.go Outdated
Comment thread pkg/controller/configmapset/configmapset_controller.go Outdated
Comment thread pkg/controller/configmapset/configmapset_utils.go Outdated
Comment thread pkg/webhook/configmapset/validating/configmapset_conflicts.go
Comment thread pkg/webhook/configmapset/validating/configmapset_create_update_handler.go Outdated
Comment thread pkg/controller/configmapset/configmapset_controller.go Fixed
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.40403% with 1233 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.64%. Comparing base (749e8f2) to head (512e744).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
...controller/configmapset/configmapset_controller.go 16.83% 571 Missing and 7 partials ⚠️
.../webhook/pod/mutating/pod_create_update_handler.go 21.79% 239 Missing and 5 partials ⚠️
pkg/controller/configmapset/configmapset_utils.go 18.27% 155 Missing and 6 partials ⚠️
...t/validating/configmapset_create_update_handler.go 54.43% 92 Missing and 21 partials ⚠️
...troller/configmapset/configmapset_event_handler.go 0.00% 55 Missing ⚠️
.../configmapset/validating/configmapset_conflicts.go 0.00% 52 Missing ⚠️
...set/mutating/configmapset_create_update_handler.go 0.00% 18 Missing ⚠️
pkg/webhook/configmapset/validating/webhooks.go 0.00% 5 Missing ⚠️
pkg/webhook/add_configmapset.go 0.00% 3 Missing ⚠️
pkg/webhook/configmapset/mutating/webhooks.go 0.00% 3 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2463      +/-   ##
==========================================
- Coverage   48.77%   47.64%   -1.14%     
==========================================
  Files         324      334      +10     
  Lines       27928    29701    +1773     
==========================================
+ Hits        13623    14151     +528     
- Misses      12775    13942    +1167     
- Partials     1530     1608      +78     
Flag Coverage Δ
unittests 47.64% <22.40%> (-1.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

chrisdeng added 10 commits May 21, 2026 15:51
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>

@ABNER-1 ABNER-1 left a comment

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.

Re-review (2026-05-25)

Thanks for the fixes! I can see the following issues from the previous review have been addressed:

  • md5.New().Sum() → fixed to md5.Sum()
  • GetMatchedPods nil check order → fixed
  • SetDefaultsConfigMapSet nil pointer → fixed
  • ✅ Selector/Data now enforced as required in validating webhook
  • ✅ Health check script extracted to a helper function with proper path parameterization

However, a few issues remain — one Critical and several Medium/Low items.

}
for _, pod := range pods.Items {
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}})
}

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.

[Critical] Event handler enqueues the wrong resource.

configMapSetEventHandler.handle() adds Pod NamespacedNames to the work queue, but Reconcile() expects to receive ConfigMapSet NamespacedNames. This means ConfigMapSet spec changes (create/update/delete) will never trigger reconciliation of the ConfigMapSet itself.

The podEventHandler.handle() correctly enqueues CMS names (line 120), so this handler should simply enqueue the CMS:

func (e *configMapSetEventHandler) handle(cms *appsv1alpha1.ConfigMapSet, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
	q.Add(reconcile.Request{NamespacedName: types.NamespacedName{Namespace: cms.Namespace, Name: cms.Name}})
}

Note: since you're already watching ConfigMapSet with handler.TypedEnqueueRequestForObject (in add()), this custom configMapSetEventHandler may actually be redundant — the built-in handler already enqueues the CMS on create/update/delete. You could consider removing configMapSetEventHandler entirely and relying on the built-in watcher.

}
return fmt.Errorf("create ConfigMap %s/%s: %v", cmNamespace, cmName, err)
}
return fmt.Errorf("failed to get ConfigMap: %v", err)

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.

[High] Error returned on successful creation.

After successfully creating the hub ConfigMap, this line returns:

return fmt.Errorf("create ConfigMap %s/%s: %v", cmNamespace, cmName, err)

At this point err is nil (the Create call succeeded). This causes RetryOnConflict to unnecessarily retry.

Suggested fix — return a sentinel or restructure:

if err = r.Create(ctx, newCM); err != nil {
	return fmt.Errorf("failed to create ConfigMap %s/%s: %v", cmNamespace, cmName, err)
}
// ConfigMap just created, re-fetch to continue with revision append
cm = newCM

"k8s.io/utils/ptr"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"

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.

[Medium] Duplicate import aliases.

Both corev1 "k8s.io/api/core/v1" and v1 "k8s.io/api/core/v1" are imported. Please unify to a single alias — recommend corev1 per project convention.

"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/fieldpath"
"k8s.io/utils/pointer"

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.

[Medium] Deprecated + redundant package.

"k8s.io/utils/pointer" (line 49) is deprecated and you already import "k8s.io/utils/ptr" (line 34). Please remove the pointer import and use ptr.To() throughout.

func (p *podEventHandler) Delete(ctx context.Context, evt event.TypedDeleteEvent[*v1.Pod], q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
//obj := evt.Object.(*corev1.Pod)
//e.handle(obj, q)
}

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.

[Low] Dead code.

The Delete handler body is commented out. Either implement the delete handling logic (e.g., enqueue the CMS for status update when a matched Pod is deleted) or remove the commented code to keep the codebase clean.

"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/fieldpath"

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.

[Low] Potentially unused import.

"k8s.io/kubernetes/pkg/fieldpath" — is this actually used? If not, please remove to pass go vet.

@kruise-bot

Copy link
Copy Markdown

@a932846905: PR needs rebase.

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/test-infra repository.

chrisdeng added 6 commits June 5, 2026 18:46
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Signed-off-by: chrisdeng <chrisdeng@futunn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants