Skip to content

Commit

Permalink
Eun script
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-kiefer committed Nov 9, 2023
1 parent 0333831 commit 31839cb
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions testdata/00-Scripts/Initialize-Testset.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# .SYNOPSIS
# Runs a script on a cluster DB. Clears the DB and uses DB-Migration-Tooling beforehand. No Previous data are kept.
param(
[Parameter(Mandatory)]$DBScriptPath
)
Set-Variable -Option Constant -Name DBParamSecret -Value 'db-params'
Set-Variable -Option Constant -Name SPSHSecret -Value 'spsh-config'
Set-Variable -Option Constant -Name ScriptConfigMap -Value 'test-data-config-map'

function Test-Secret
{
param(
$secretName
)
if (kubectl get secret $secretName)
{
return $true;
}
return $false;
}

Push-Location
try
{
if (-Not(Test-Path -IsValid -PathType Leaf $DBScriptPath))
{
throw "Could not find DB-Script $DBScriptPath"
}
if ($null -eq (Get-Command "kubectl" -ErrorAction SilentlyContinue))
{
throw new "Could not find kubectl"
}

if (-Not(Test-Secret $DBParamSecret))
{
throw "Secret: $DBParamSecret not in cluster"
}

if (-Not(Test-Secret $SPSHSecret))
{
throw "Secret: $SPSHSecret not in cluster"
}

kubectl delete --ignore-not-found configmap $ScriptConfigMap | Out-Null


kubectl create configmap test-data-config-map --from-file $DBScriptPath | Out-Null
$jobName = (kubectl apply -f apply_to_cluster.yaml -o 'template={{.metadata.name}}')
try
{
if (kubectl wait job $jobName --for 'condition=complete' --timeout=30s)
{
kubectl logs --all-containers --prefix --selector "job-name=$jobName" --tail=-1 | Write-Error
throw "Job did not complete in 30 seconds"
}
kubectl logs --all-containers --prefix --selector job-name=$jobName | Out-Host
}
finally
{
#kubectl delete job $jobName
}

}
finally
{
Pop-Location
}

0 comments on commit 31839cb

Please sign in to comment.