@@ -132,10 +132,10 @@ export async function deeplinkConnect(
132132
133133 try {
134134 let connectionType = 'sm_dl'
135- if ( domain === '' && eksClusterArn ) {
135+ if ( ! domain && eksClusterArn && workspaceName && namespace ) {
136136 const { accountId, region, clusterName } = parseEKSClusterArn ( eksClusterArn )
137137 connectionType = 'sm_hp'
138- session = ` ${ workspaceName } _ ${ namespace } _ ${ clusterName } _ ${ region } _ ${ accountId } `
138+ session = createValidK8sSession ( workspaceName , namespace , clusterName , region , accountId )
139139 }
140140 const remoteEnv = await prepareDevEnvConnection (
141141 connectionIdentifier ,
@@ -192,6 +192,38 @@ function parseEKSClusterArn(eksClusterArn: string): { accountId: string; region:
192192 return { accountId, region, clusterName }
193193}
194194
195+ /**
196+ * Validates and sanitizes session names for Kubernetes DNS label compliance
197+ */
198+ function createValidK8sSession (
199+ workspaceName : string ,
200+ namespace : string ,
201+ clusterName : string ,
202+ region : string ,
203+ accountId : string
204+ ) : string {
205+ const sanitize = ( str : string ) : string =>
206+ str
207+ . toLowerCase ( )
208+ . replace ( / [ ^ a - z 0 - 9 - ] / g, '-' )
209+ . replace ( / ^ - + | - + $ / g, '' )
210+ . substring ( 0 , 15 )
211+
212+ const components = [ workspaceName , namespace , clusterName , region , accountId ]
213+ . map ( sanitize )
214+ . filter ( ( c ) => c . length > 0 )
215+
216+ const session = components . join ( '_' ) . substring ( 0 , 63 )
217+ return session . replace ( / ^ - + | - + $ / g, '' ) || 'session'
218+ }
219+
220+ /**
221+ * Validates if a string meets K8s DNS label requirements
222+ */
223+ function isValidK8sLabel ( label : string ) : boolean {
224+ return / ^ [ a - z 0 - 9 ] ( [ a - z 0 - 9 - ] { 0 , 61 } [ a - z 0 - 9 ] ) ? $ / . test ( label )
225+ }
226+
195227export async function stopSpace (
196228 node : SagemakerSpaceNode | SagemakerUnifiedStudioSpaceNode ,
197229 ctx : vscode . ExtensionContext ,
0 commit comments