From e7744d1fb59a8bfceef879f5fa3c9901e62b9d76 Mon Sep 17 00:00:00 2001 From: Fran Slot Date: Thu, 28 Dec 2023 10:10:50 +0100 Subject: [PATCH] Moved username cleaning out of k8s. --- .../bootstrap/files/ExecEngineFunctions.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/RAP4/customizations/bootstrap/files/ExecEngineFunctions.php b/RAP4/customizations/bootstrap/files/ExecEngineFunctions.php index 31cd862b..28717875 100644 --- a/RAP4/customizations/bootstrap/files/ExecEngineFunctions.php +++ b/RAP4/customizations/bootstrap/files/ExecEngineFunctions.php @@ -309,6 +309,11 @@ $scriptContent = $scriptContentPairs[0]->tgt()->getId(); $scriptContentForCommandline = base64_encode($scriptContent); + $pattern = '/[\W+]/'; + + $userName=strtolower($userName); + $userName = preg_replace($pattern, '-', $userName); + $deployment = getenv('RAP_DEPLOYMENT'); if ($deployment == 'Kubernetes') { /** Deployed on Kubernetes Cluster @@ -320,16 +325,11 @@ * - run kubectl apply -f "student-manifest-{{student}}.yaml" */ - $pattern = '/[\W+]/'; - - $studentName=strtolower($userName); - $studentName = preg_replace($pattern, '-', $studentName); - $namespace=getenv('RAP_KUBERNETES_NAMESPACE'); $containerImage=getenv('RAP_STUDENT_PROTO_IMAGE'); $hostname=getenv('RAP_HOST_NAME'); - $hostname="{$studentName}.{$hostname}"; + $hostname="{$userName}.{$hostname}"; $suffix=substr($namespace, 3); @@ -337,7 +337,7 @@ $dbSecret="db-secrets{$suffix}"; - $tlsSecret="{$studentName}-tls{$suffix}"; + $tlsSecret="{$userName}-tls{$suffix}"; // Location to save files $relDir = pathinfo($path, PATHINFO_DIRNAME); @@ -350,7 +350,7 @@ throw new Exception("Student manifest template not found for '{$scriptVersionAtom}', workDir: {$workDir}, manifestFile: {$manifestFile}", 500); } // replace {{student}}, {{namespace}} and {{scriptContent}} - $manifest=str_replace("{{student}}", $studentName, $manifest); + $manifest=str_replace("{{student}}", $userName, $manifest); $manifest=str_replace("{{namespace}}", $namespace, $manifest); $manifest=str_replace("{{containerImage}}", $containerImage, $manifest); $manifest=str_replace("{{scriptContent}}", $scriptContentForCommandline, $manifest); @@ -360,7 +360,7 @@ $manifest=str_replace("{{tlsSecret}}", $tlsSecret, $manifest); // Save manifest file - $studentManifestFile="{$workDir}/student-manifest-{$studentName}.yaml"; + $studentManifestFile="{$workDir}/student-manifest-{$userName}.yaml"; file_put_contents($studentManifestFile, $manifest); // Call Kubernetes API to add script