Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved username cleaning out of k8s. #345

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
18 changes: 9 additions & 9 deletions RAP4/customizations/bootstrap/files/ExecEngineFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -320,24 +325,19 @@
* - 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);

$dbName="rap-db{$suffix}";

$dbSecret="db-secrets{$suffix}";

$tlsSecret="{$studentName}-tls{$suffix}";
$tlsSecret="{$userName}-tls{$suffix}";

// Location to save files
$relDir = pathinfo($path, PATHINFO_DIRNAME);
Expand All @@ -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);
Expand All @@ -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
Expand Down