Skip to content

Commit 92f1e78

Browse files
ChrisJBurnsclaude
andcommitted
Reuse shared WorkloadReference type from MCPOIDCConfig
Remove duplicate WorkloadReference definition from mcptelemetryconfig_types.go and use the shared type already defined in mcpoidcconfig_types.go. Drop the Namespace field (cross-namespace refs are not supported) to match the shared type's schema. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ebac7e9 commit 92f1e78

6 files changed

Lines changed: 65 additions & 61 deletions

File tree

cmd/thv-operator/api/v1alpha1/mcptelemetryconfig_types.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,6 @@ type MCPTelemetryConfigSpec struct {
9595
Prometheus *PrometheusConfig `json:"prometheus,omitempty"`
9696
}
9797

98-
// WorkloadReference identifies a Kubernetes workload that references a shared config resource.
99-
type WorkloadReference struct {
100-
// Kind is the resource kind (e.g., "MCPServer")
101-
Kind string `json:"kind"`
102-
103-
// Namespace is the resource namespace
104-
Namespace string `json:"namespace"`
105-
106-
// Name is the resource name
107-
Name string `json:"name"`
108-
}
109-
11098
// MCPTelemetryConfigStatus defines the observed state of MCPTelemetryConfig
11199
type MCPTelemetryConfigStatus struct {
112100
// Conditions represent the latest available observations of the MCPTelemetryConfig's state

cmd/thv-operator/controllers/mcptelemetryconfig_controller.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (r *MCPTelemetryConfigReconciler) handleDeletion(
196196
if len(referencingWorkloads) > 0 {
197197
names := make([]string, 0, len(referencingWorkloads))
198198
for _, ref := range referencingWorkloads {
199-
names = append(names, fmt.Sprintf("%s/%s", ref.Namespace, ref.Name))
199+
names = append(names, fmt.Sprintf("%s/%s", ref.Kind, ref.Name))
200200
}
201201
msg := fmt.Sprintf("cannot delete: still referenced by MCPServer(s): %v", names)
202202
logger.Info(msg, "telemetryConfig", telemetryConfig.Name)
@@ -239,19 +239,12 @@ func (r *MCPTelemetryConfigReconciler) findReferencingWorkloads(
239239
if server.Spec.TelemetryConfigRef != nil &&
240240
server.Spec.TelemetryConfigRef.Name == telemetryConfig.Name {
241241
refs = append(refs, mcpv1alpha1.WorkloadReference{
242-
Kind: "MCPServer",
243-
Namespace: server.Namespace,
244-
Name: server.Name,
242+
Kind: "MCPServer",
243+
Name: server.Name,
245244
})
246245
}
247246
}
248247
slices.SortFunc(refs, func(a, b mcpv1alpha1.WorkloadReference) int {
249-
if a.Namespace != b.Namespace {
250-
if a.Namespace < b.Namespace {
251-
return -1
252-
}
253-
return 1
254-
}
255248
if a.Name < b.Name {
256249
return -1
257250
}
@@ -266,6 +259,6 @@ func (r *MCPTelemetryConfigReconciler) findReferencingWorkloads(
266259
// workloadRefsEqual compares two WorkloadReference slices for equality.
267260
func workloadRefsEqual(a, b []mcpv1alpha1.WorkloadReference) bool {
268261
return slices.EqualFunc(a, b, func(x, y mcpv1alpha1.WorkloadReference) bool {
269-
return x.Kind == y.Kind && x.Namespace == y.Namespace && x.Name == y.Name
262+
return x.Kind == y.Kind && x.Name == y.Name
270263
})
271264
}

cmd/thv-operator/controllers/mcptelemetryconfig_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ func TestMCPTelemetryConfigReconciler_ReferenceTracking(t *testing.T) {
704704

705705
// ReferencingWorkloads should list server-a and server-b (sorted), but not server-c
706706
assert.Equal(t, []mcpv1alpha1.WorkloadReference{
707-
{Kind: "MCPServer", Namespace: "default", Name: "server-a"},
708-
{Kind: "MCPServer", Namespace: "default", Name: "server-b"},
707+
{Kind: "MCPServer", Name: "server-a"},
708+
{Kind: "MCPServer", Name: "server-b"},
709709
}, updated.Status.ReferencingWorkloads)
710710
}
711711

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,24 @@ spec:
250250
description: ReferencingWorkloads lists workloads that reference this
251251
MCPTelemetryConfig
252252
items:
253-
description: WorkloadReference identifies a Kubernetes workload
254-
that references a shared config resource.
253+
description: |-
254+
WorkloadReference identifies a workload that references a shared configuration resource.
255+
Namespace is implicit — cross-namespace references are not supported.
255256
properties:
256257
kind:
257-
description: Kind is the resource kind (e.g., "MCPServer")
258+
description: Kind is the type of workload resource
259+
enum:
260+
- MCPServer
261+
- VirtualMCPServer
262+
- MCPRemoteProxy
258263
type: string
259264
name:
260-
description: Name is the resource name
261-
type: string
262-
namespace:
263-
description: Namespace is the resource namespace
265+
description: Name is the name of the workload resource
266+
minLength: 1
264267
type: string
265268
required:
266269
- kind
267270
- name
268-
- namespace
269271
type: object
270272
type: array
271273
type: object

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,24 @@ spec:
253253
description: ReferencingWorkloads lists workloads that reference this
254254
MCPTelemetryConfig
255255
items:
256-
description: WorkloadReference identifies a Kubernetes workload
257-
that references a shared config resource.
256+
description: |-
257+
WorkloadReference identifies a workload that references a shared configuration resource.
258+
Namespace is implicit — cross-namespace references are not supported.
258259
properties:
259260
kind:
260-
description: Kind is the resource kind (e.g., "MCPServer")
261+
description: Kind is the type of workload resource
262+
enum:
263+
- MCPServer
264+
- VirtualMCPServer
265+
- MCPRemoteProxy
261266
type: string
262267
name:
263-
description: Name is the resource name
264-
type: string
265-
namespace:
266-
description: Namespace is the resource namespace
268+
description: Name is the name of the workload resource
269+
minLength: 1
267270
type: string
268271
required:
269272
- kind
270273
- name
271-
- namespace
272274
type: object
273275
type: array
274276
type: object

docs/operator/crd-api.md

Lines changed: 39 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)