@@ -13,6 +13,12 @@ import (
1313 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414)
1515
16+ // ToNamespace converts a workspace name to its Kubernetes namespace
17+ var ToNamespace = sgs .WorkspaceToNamespace
18+
19+ // FromNamespace converts a Kubernetes namespace to workspace name (strips ws- prefix)
20+ var FromNamespace = sgs .NamespaceToWorkspace
21+
1622// WorkspaceInfo represents information about an SGS workspace
1723type WorkspaceInfo struct {
1824 Name string
@@ -58,7 +64,7 @@ func List(ctx context.Context, c *client.Client) ([]WorkspaceInfo, error) {
5864 }
5965
6066 info := & WorkspaceInfo {
61- Name : ns .Name ,
67+ Name : FromNamespace ( ns .Name ) ,
6268 }
6369
6470 // Parse node selector annotation for node group
@@ -105,9 +111,12 @@ func List(ctx context.Context, c *client.Client) ([]WorkspaceInfo, error) {
105111
106112// Get returns information about a specific workspace
107113func Get (ctx context.Context , c * client.Client , name string ) (* WorkspaceInfo , error ) {
114+ // Convert workspace name to K8s namespace (add ws- prefix)
115+ nsName := ToNamespace (name )
116+
108117 // Get namespace with retry
109118 ns , err := client .RetryWithContext (ctx , func () (* corev1.Namespace , error ) {
110- return c .Clientset .CoreV1 ().Namespaces ().Get (ctx , name , metav1.GetOptions {})
119+ return c .Clientset .CoreV1 ().Namespaces ().Get (ctx , nsName , metav1.GetOptions {})
111120 })
112121 if err != nil {
113122 return nil , fmt .Errorf ("workspace not found: %s" , name )
@@ -120,14 +129,14 @@ func Get(ctx context.Context, c *client.Client, name string) (*WorkspaceInfo, er
120129
121130 // Try to access resource quotas to verify permission (with retry)
122131 quotas , err := client .RetryWithContext (ctx , func () (* corev1.ResourceQuotaList , error ) {
123- return c .Clientset .CoreV1 ().ResourceQuotas (name ).List (ctx , metav1.ListOptions {})
132+ return c .Clientset .CoreV1 ().ResourceQuotas (nsName ).List (ctx , metav1.ListOptions {})
124133 })
125134 if err != nil {
126135 return nil , fmt .Errorf ("access denied to workspace: %s" , name )
127136 }
128137
129138 info := & WorkspaceInfo {
130- Name : name ,
139+ Name : FromNamespace ( nsName ), // Use name without prefix
131140 }
132141
133142 // Parse node selector annotation
@@ -160,7 +169,8 @@ func GetCurrent(ctx context.Context, c *client.Client) (*WorkspaceInfo, error) {
160169
161170// Exists checks if a workspace exists (but doesn't check permission)
162171func Exists (ctx context.Context , c * client.Client , name string ) bool {
163- ns , err := c .Clientset .CoreV1 ().Namespaces ().Get (ctx , name , metav1.GetOptions {})
172+ nsName := ToNamespace (name ) // Add ws- prefix for K8s API
173+ ns , err := c .Clientset .CoreV1 ().Namespaces ().Get (ctx , nsName , metav1.GetOptions {})
164174 if err != nil {
165175 return false
166176 }
0 commit comments