Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions internal/runtime/translation/kagent/kagent_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,8 @@ func (t *translator) translateAgentConfigMap(agent *api.Agent) (*corev1.ConfigMa
}

// AgentConfigMapName returns the ConfigMap name for an agent
func AgentConfigMapName(name, version, deploymentID string) string {
base := fmt.Sprintf("%s-mcp-config", name)
if version != "" {
base = fmt.Sprintf("%s-%s-mcp-config", name, version)
}
return sanitizeK8sName(nameWithDeploymentID(base, deploymentID))
func AgentConfigMapName(name, _, _ string) string {
return sanitizeK8sName(fmt.Sprintf("%s-mcp-config", name))
}

func buildRemoteMCPURL(scheme, host string, port uint32, path string) string {
Expand All @@ -430,20 +426,16 @@ func buildRemoteMCPURL(scheme, host string, port uint32, path string) string {
return fmt.Sprintf("%s://%s:%d%s", scheme, host, port, path)
}

func AgentResourceName(name, version, deploymentID string) string {
base := name
if version != "" {
base = fmt.Sprintf("%s-%s", name, version)
}
return sanitizeK8sName(nameWithDeploymentID(base, deploymentID))
func AgentResourceName(name, _, _ string) string {
return sanitizeK8sName(name)
}

func RemoteMCPResourceName(name, deploymentID string) string {
return sanitizeK8sName(nameWithDeploymentID(name, deploymentID))
func RemoteMCPResourceName(name, _ string) string {
return sanitizeK8sName(name)
}

func MCPServerResourceName(name, deploymentID string) string {
return sanitizeK8sName(nameWithDeploymentID(name, deploymentID))
func MCPServerResourceName(name, _ string) string {
return sanitizeK8sName(name)
}

func deploymentManagedLabels(deploymentID string) map[string]string {
Expand All @@ -465,13 +457,6 @@ func deploymentManagedAnnotations(deploymentID string) map[string]string {
}
}

func nameWithDeploymentID(base, deploymentID string) string {
if deploymentID == "" {
return base
}
return fmt.Sprintf("%s-%s", base, deploymentID)
}

// sanitizeK8sName sanitizes a string to a valid Kubernetes name
func sanitizeK8sName(value string) string {
value = strings.ToLower(value)
Expand Down
45 changes: 18 additions & 27 deletions internal/runtime/translation/kagent/kagent_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestTranslateRuntimeConfig_AgentOnly(t *testing.T) {
}

agent := config.Kubernetes.Agents[0]
if agent.Name != "test-agent-v1" {
t.Errorf("Expected agent name test-agent-v1, got %s", agent.Name)
if agent.Name != "test-agent" {
t.Errorf("Expected agent name test-agent, got %s", agent.Name)
}

// Verify no config maps or volumes for simple agent
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestTranslateRuntimeConfig_AgentWithMCPServers(t *testing.T) {
}

cm := config.Kubernetes.ConfigMaps[0]
expectedCMName := "test-agent-v1-mcp-config"
expectedCMName := "test-agent-mcp-config"
if cm.Name != expectedCMName {
t.Errorf("Expected ConfigMap name %s, got %s", expectedCMName, cm.Name)
}
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestTranslateRuntimeConfig_DeploymentIDMetadataAndNaming(t *testing.T) {
t.Fatalf("expected 1 agent, got %d", len(config.Kubernetes.Agents))
}
agent := config.Kubernetes.Agents[0]
if agent.Name != "demo-agent-1-0-0-dep-agent-123" {
if agent.Name != "demo-agent" {
t.Fatalf("unexpected agent name: %s", agent.Name)
}
if got := agent.Labels[DeploymentIDLabelKey]; got != "dep-agent-123" {
Expand All @@ -497,7 +497,7 @@ func TestTranslateRuntimeConfig_DeploymentIDMetadataAndNaming(t *testing.T) {
t.Fatalf("expected 1 configmap, got %d", len(config.Kubernetes.ConfigMaps))
}
configMap := config.Kubernetes.ConfigMaps[0]
if configMap.Name != "demo-agent-1-0-0-mcp-config-dep-agent-123" {
if configMap.Name != "demo-agent-mcp-config" {
t.Fatalf("unexpected configmap name: %s", configMap.Name)
}
if got := configMap.Labels[DeploymentIDLabelKey]; got != "dep-agent-123" {
Expand All @@ -508,7 +508,7 @@ func TestTranslateRuntimeConfig_DeploymentIDMetadataAndNaming(t *testing.T) {
t.Fatalf("expected 1 remote mcp server, got %d", len(config.Kubernetes.RemoteMCPServers))
}
remote := config.Kubernetes.RemoteMCPServers[0]
if remote.Name != "demo-mcp-dep-mcp-123" {
if remote.Name != "demo-mcp" {
t.Fatalf("unexpected remote mcp name: %s", remote.Name)
}
if got := remote.Labels[DeploymentIDLabelKey]; got != "dep-mcp-123" {
Expand Down Expand Up @@ -749,7 +749,7 @@ func TestTranslateRuntimeConfig_AgentWithSkills(t *testing.T) {
}
}

func TestTranslateRuntimeConfig_DuplicateArtifactIdentityUsesDistinctDeploymentScopedNames(t *testing.T) {
func TestTranslateRuntimeConfig_SameAgentNameProducesSameCRDName(t *testing.T) {
translator := NewTranslator()
ctx := context.Background()

Expand Down Expand Up @@ -794,29 +794,20 @@ func TestTranslateRuntimeConfig_DuplicateArtifactIdentityUsesDistinctDeploymentS
if len(config.Kubernetes.Agents) != 2 {
t.Fatalf("expected 2 agents, got %d", len(config.Kubernetes.Agents))
}
if len(config.Kubernetes.ConfigMaps) != 2 {
t.Fatalf("expected 2 configmaps, got %d", len(config.Kubernetes.ConfigMaps))
}

agentNames := map[string]struct{}{}
for _, agent := range config.Kubernetes.Agents {
agentNames[agent.Name] = struct{}{}
}
if _, ok := agentNames["com-example-planner-1-0-0-dep-old"]; !ok {
t.Fatalf("missing deployment-scoped agent name for dep-old: %v", agentNames)
}
if _, ok := agentNames["com-example-planner-1-0-0-dep-new"]; !ok {
t.Fatalf("missing deployment-scoped agent name for dep-new: %v", agentNames)
// Both agents share the same name (derived from agent name only, not deployment ID)
expectedName := "com-example-planner"
for i, agent := range config.Kubernetes.Agents {
if agent.Name != expectedName {
t.Errorf("agent[%d] name = %q, want %q", i, agent.Name, expectedName)
}
}

configMapNames := map[string]struct{}{}
for _, cm := range config.Kubernetes.ConfigMaps {
configMapNames[cm.Name] = struct{}{}
}
if _, ok := configMapNames["com-example-planner-1-0-0-mcp-config-dep-old"]; !ok {
t.Fatalf("missing deployment-scoped configmap name for dep-old: %v", configMapNames)
// Deployment IDs are tracked via labels, not resource names
if got := config.Kubernetes.Agents[0].Labels[DeploymentIDLabelKey]; got != "dep-old" {
t.Errorf("agent[0] deployment-id label = %q, want %q", got, "dep-old")
}
if _, ok := configMapNames["com-example-planner-1-0-0-mcp-config-dep-new"]; !ok {
t.Fatalf("missing deployment-scoped configmap name for dep-new: %v", configMapNames)
if got := config.Kubernetes.Agents[1].Labels[DeploymentIDLabelKey]; got != "dep-new" {
t.Errorf("agent[1] deployment-id label = %q, want %q", got, "dep-new")
}
}
Loading