mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +00:00
fix(webhook): remove dead diff code block that panics on nil namespace metadata (#1976)
In userMetadataHandler.OnUpdate the per-request labels/annotations diff is computed twice. The inline block at the top clones oldNs metadata and diffs it against newNs, but its results are immediately shadowed by the `labels, annotations, err := userMetadataForValidation(...)` declaration in the `tnt.Spec.NamespaceOptions \!= nil` branch, which recomputes the same diff (via metadataForValidation) and is the only version actually passed to validateUserMetadata. The inline block is therefore dead code.
It is also a panic: `maps.Clone(oldNs.GetAnnotations())` returns nil for a namespace with no annotations, and the following `annotations[key] = value` then panics with "assignment to entry in nil map" (same with labels).
This happens when using features like NamespaceOptions.AdditionalMetadataList on a namespace that had none.
The dead block and panic was introduced in a6927c5 (#1947).
Signed-off-by: Cyril Jouve <jv.cyril@gmail.com>
This commit is contained in:
@@ -111,39 +111,6 @@ func (h *userMetadataHandler) OnUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
labels := maps.Clone(oldNs.GetLabels())
|
||||
annotations := maps.Clone(oldNs.GetAnnotations())
|
||||
|
||||
for key, value := range newNs.GetLabels() {
|
||||
v, ok := labels[key]
|
||||
if !ok {
|
||||
labels[key] = value
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if v != value {
|
||||
continue
|
||||
}
|
||||
|
||||
delete(labels, key)
|
||||
}
|
||||
|
||||
for key, value := range newNs.GetAnnotations() {
|
||||
v, ok := annotations[key]
|
||||
if !ok {
|
||||
annotations[key] = value
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if v != value {
|
||||
continue
|
||||
}
|
||||
|
||||
delete(annotations, key)
|
||||
}
|
||||
|
||||
if tnt.Spec.NamespaceOptions != nil {
|
||||
labels, annotations, err := userMetadataForValidation(newNs, oldNs, tnt)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user