Skip to content
Merged
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
8 changes: 7 additions & 1 deletion internal/driver/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
labelKagentiInject = "kagenti.io/inject"
labelTenant = "openshell.ai/tenant"
labelKagentiTeam = "kagenti.io/team"
annotationSandboxID = "openshell.io/sandbox-id"
)

// K8sProvisioner implements SandboxProvisioner using the Kubernetes API. It
Expand Down Expand Up @@ -380,10 +381,15 @@ func (p *K8sProvisioner) buildSandboxSpec(sb *pb.DriverSandbox) map[string]inter
podLabels[labelKagentiTeam] = p.cfg.Tenant
}

podAnnotations := map[string]interface{}{
annotationSandboxID: sb.GetId(),
}

return map[string]interface{}{
"podTemplate": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": podLabels,
"labels": podLabels,
"annotations": podAnnotations,
},
"spec": podSpec,
},
Expand Down
24 changes: 24 additions & 0 deletions internal/driver/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,30 @@ func TestBuildSandboxSpec_Labels(t *testing.T) {
}
}

func TestBuildSandboxSpec_Annotations(t *testing.T) {
p := newProvisionerForTest(t)

sb := &pb.DriverSandbox{
Id: "sb-anno-123",
Spec: &pb.DriverSandboxSpec{
Template: &pb.DriverSandboxTemplate{
Image: "img:latest",
},
},
}

spec := p.buildSandboxSpec(sb)
podTemplate := spec["podTemplate"].(map[string]interface{})
meta := podTemplate["metadata"].(map[string]interface{})
annotations, ok := meta["annotations"].(map[string]interface{})
if !ok {
t.Fatal("expected annotations in podTemplate metadata")
}
if annotations[annotationSandboxID] != "sb-anno-123" {
t.Errorf("expected annotation %s=sb-anno-123, got %v", annotationSandboxID, annotations[annotationSandboxID])
}
}

func TestBuildSandboxSpec_TenantLabels(t *testing.T) {
cfg := testConfig()
cfg.Tenant = "team1"
Expand Down
Loading