Skip to content

Commit

Permalink
Merge pull request #338 from OctopusDeploy/echo-kubeconfig
Browse files Browse the repository at this point in the history
Echo kubeconfig
  • Loading branch information
mcasperson authored Nov 8, 2018
2 parents b2ec4e5 + 4ae9cbf commit 099a7d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion source/Calamari/Kubernetes/Scripts/KubectlBashContext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ function setup_context {
Octopus_K8S_Client_Cert_Pem_Encoded=$(echo "$Octopus_K8S_Client_Cert_Pem" | base64 -w0)
Octopus_K8S_Client_Cert_Key_Encoded=$(echo "$Octopus_K8S_Client_Cert_Key" | base64 -w0)

set_octopusvariable "${Octopus_K8S_Client_Cert}.PrivateKeyPemBase64" $Octopus_K8S_Client_Cert_Key_Encoded -sensitive

kubectl config set users.octouser.client-certificate-data "$Octopus_K8S_Client_Cert_Pem_Encoded"
kubectl config set users.octouser.client-key-data "$Octopus_K8S_Client_Cert_Key_Encoded"
fi
Expand Down Expand Up @@ -157,8 +159,8 @@ get_kubectl
configure_kubectl_path
setup_context
create_namespace
echo $KUBECONFIG
echo "##octopus[stdout-verbose]"
cat $KUBECONFIG
echo "Invoking target script \"$(get_octopusvariable "OctopusKubernetesTargetScript")\" with $(get_octopusvariable "OctopusKubernetesTargetScriptParameters") parameters"
echo "##octopus[stdout-default]"

Expand Down
15 changes: 11 additions & 4 deletions source/Calamari/Kubernetes/Scripts/KubectlPowershellContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ function SetupContext {
Exit 1
}

& $Kubectl_Exe config set users.octouser.client-certificate-data $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Pem)))
& $Kubectl_Exe config set users.octouser.client-key-data $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Key)))
$K8S_Client_Cert_Key_Encoded = $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Key)))
$K8S_Client_Cert_Pem_Encoded = $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Pem)))

# Don't leak the private key in the logs
Set-OctopusVariable -name "$($K8S_Client_Cert).PrivateKeyPemBase64" -value $K8S_Client_Cert_Key_Encoded -sensitive

& $Kubectl_Exe config set users.octouser.client-certificate-data $K8S_Client_Cert_Pem_Encoded
& $Kubectl_Exe config set users.octouser.client-key-data $K8S_Client_Cert_Key_Encoded
}

if(-not [string]::IsNullOrEmpty($K8S_Server_Cert)) {
Expand Down Expand Up @@ -177,8 +183,9 @@ Write-Host "##octopus[stdout-verbose]"
ConfigureKubeCtlPath
SetupContext
CreateNamespace
Write-Host "##octopus[stdout-default]"

echo "##octopus[stdout-verbose]"
Get-Content $env:KUBECONFIG
Write-Verbose "Invoking target script $OctopusKubernetesTargetScript with $OctopusKubernetesTargetScriptParameters parameters"
echo "##octopus[stdout-default]"

Invoke-Expression ". `"$OctopusKubernetesTargetScript`" $OctopusKubernetesTargetScriptParameters"

0 comments on commit 099a7d3

Please sign in to comment.