Skip to content

[BUG] KRT FilterObjectName ignores namespace in collectionReader.fetchObject()#2587

Description

@ekam-walia

馃搵 Prerequisites

  • I have searched the existing issues to avoid creating a duplicate
  • By submitting this issue, you agree to follow our Code of Conduct
  • I am using the latest version of the software
  • I have tried to clear cache/cookies or used incognito mode (if ui-related)
  • I can consistently reproduce this issue

馃幆 Affected Service(s)

Multiple services / System-wide issue

馃殾 Impact/Severity

Minor inconvenience

馃悰 Bug Description

The collectionReader.fetchObject() function in the controller is using krt.FilterObjectName(key) to fetch objects, but passing a NamespacedName (which contains both namespace and name). The filter only checks the name, ignoring the namespace.

Location

go/core/v2/controller/collection_reader.go - fetchObject() function

   func (r collectionReader) fetchObject[T controllers.ComparableObject](collection krt.Collection[T], key types.NamespacedName, resource schema.GroupResource) (T, error) {
   	object := krt.FetchOne(r.ctx, collection, krt.FilterObjectName(key))
   	// ...
   }

Problem

krt.FilterObjectName() only filters by object name, not by namespace. This means:

  • If two namespaces have objects with the same name, the wrong object could be fetched
  • The namespace part of the NamespacedName is completely ignored
  • This can cause incorrect configurations to be loaded at runtime

Solution

Filter by both namespace AND name:

   func (r collectionReader) fetchObject[T controllers.ComparableObject](collection krt.Collection[T], key types.NamespacedName, resource schema.GroupResource) (T, error) {
   	object := krt.FetchOne(r.ctx, collection, krt.FilterNamespace(key.Namespace), krt.FilterName(key.Name))
   	if object == nil {
   		var zero T
   		return zero, apierrors.NewNotFound(resource, key.Name)
   	}
   	return *object, nil
   }

Alternatively, if KRT provides a combined filter:

   object := krt.FetchOne(r.ctx, collection, krt.FilterNamespacedName(key))

馃 Expected Behavior

No response

馃摫 Actual Behavior

No response

馃捇 Environment

No response

馃敡 CLI Bug Report

No response

馃攳 Additional Context

This affects resource lookups across all KRT collections:

  • AgentTemplates
  • ModelConfigs
  • RemoteMCPServers
  • ConfigMaps
  • Secrets
  • WorkerPools

Any code relying on collectionReader.Get() may fetch incorrect objects.

馃搵 Logs

馃摲 Screenshots

No response

馃檵 Are you willing to contribute?

  • I am willing to submit a PR to fix this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions