Skip to content

Commit 193ff75

Browse files
ChrisJBurnsclaude
andcommitted
Use compound (kind, name) listMapKey on ReferencingWorkloads
The original review of this PR flagged that +listMapKey=name alone is insufficient: two workloads of different kinds that share a name (an MCPServer "foo" and a VirtualMCPServer "foo") would collide under merge-patch semantics, with the second-applied entry silently overwriting the first. Adding +listMapKey=kind makes the map key the (kind, name) pair so cross-kind name reuse stays distinct. Limited to MCPAuthzConfig here. The two sibling controllers (MCPOIDCConfig, MCPExternalAuthConfig) share the same WorkloadReference type and have the same listMapKey=name asymmetry — filed as a parity follow-up rather than expanding this PR's scope. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent ee44449 commit 193ff75

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

cmd/thv-operator/api/v1beta1/mcpauthzconfig_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ type MCPAuthzConfigStatus struct {
6464
ReferenceCount int32 `json:"referenceCount,omitempty"`
6565

6666
// ReferencingWorkloads is a list of workload resources that reference this MCPAuthzConfig.
67-
// Each entry identifies the workload by kind and name.
67+
// Each entry identifies the workload by kind and name. The map key is the
68+
// (kind, name) pair so two workloads of different kinds that share a name
69+
// (e.g., an MCPServer "foo" and a VirtualMCPServer "foo") are distinct
70+
// entries rather than colliding under merge-patch semantics.
6871
// +listType=map
72+
// +listMapKey=kind
6973
// +listMapKey=name
7074
// +optional
7175
ReferencingWorkloads []WorkloadReference `json:"referencingWorkloads,omitempty"`

deploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_mcpauthzconfigs.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ spec:
163163
referencingWorkloads:
164164
description: |-
165165
ReferencingWorkloads is a list of workload resources that reference this MCPAuthzConfig.
166-
Each entry identifies the workload by kind and name.
166+
Each entry identifies the workload by kind and name. The map key is the
167+
(kind, name) pair so two workloads of different kinds that share a name
168+
(e.g., an MCPServer "foo" and a VirtualMCPServer "foo") are distinct
169+
entries rather than colliding under merge-patch semantics.
167170
items:
168171
description: |-
169172
WorkloadReference identifies a workload that references a shared configuration resource.
@@ -186,6 +189,7 @@ spec:
186189
type: object
187190
type: array
188191
x-kubernetes-list-map-keys:
192+
- kind
189193
- name
190194
x-kubernetes-list-type: map
191195
type: object
@@ -338,7 +342,10 @@ spec:
338342
referencingWorkloads:
339343
description: |-
340344
ReferencingWorkloads is a list of workload resources that reference this MCPAuthzConfig.
341-
Each entry identifies the workload by kind and name.
345+
Each entry identifies the workload by kind and name. The map key is the
346+
(kind, name) pair so two workloads of different kinds that share a name
347+
(e.g., an MCPServer "foo" and a VirtualMCPServer "foo") are distinct
348+
entries rather than colliding under merge-patch semantics.
342349
items:
343350
description: |-
344351
WorkloadReference identifies a workload that references a shared configuration resource.
@@ -361,6 +368,7 @@ spec:
361368
type: object
362369
type: array
363370
x-kubernetes-list-map-keys:
371+
- kind
364372
- name
365373
x-kubernetes-list-type: map
366374
type: object

deploy/charts/operator-crds/templates/toolhive.stacklok.dev_mcpauthzconfigs.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ spec:
166166
referencingWorkloads:
167167
description: |-
168168
ReferencingWorkloads is a list of workload resources that reference this MCPAuthzConfig.
169-
Each entry identifies the workload by kind and name.
169+
Each entry identifies the workload by kind and name. The map key is the
170+
(kind, name) pair so two workloads of different kinds that share a name
171+
(e.g., an MCPServer "foo" and a VirtualMCPServer "foo") are distinct
172+
entries rather than colliding under merge-patch semantics.
170173
items:
171174
description: |-
172175
WorkloadReference identifies a workload that references a shared configuration resource.
@@ -189,6 +192,7 @@ spec:
189192
type: object
190193
type: array
191194
x-kubernetes-list-map-keys:
195+
- kind
192196
- name
193197
x-kubernetes-list-type: map
194198
type: object
@@ -341,7 +345,10 @@ spec:
341345
referencingWorkloads:
342346
description: |-
343347
ReferencingWorkloads is a list of workload resources that reference this MCPAuthzConfig.
344-
Each entry identifies the workload by kind and name.
348+
Each entry identifies the workload by kind and name. The map key is the
349+
(kind, name) pair so two workloads of different kinds that share a name
350+
(e.g., an MCPServer "foo" and a VirtualMCPServer "foo") are distinct
351+
entries rather than colliding under merge-patch semantics.
345352
items:
346353
description: |-
347354
WorkloadReference identifies a workload that references a shared configuration resource.
@@ -364,6 +371,7 @@ spec:
364371
type: object
365372
type: array
366373
x-kubernetes-list-map-keys:
374+
- kind
367375
- name
368376
x-kubernetes-list-type: map
369377
type: object

docs/operator/crd-api.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)