Skip to content

Commit 099a7d3

Browse files
authored
Merge pull request #338 from OctopusDeploy/echo-kubeconfig
Echo kubeconfig
2 parents b2ec4e5 + 4ae9cbf commit 099a7d3

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

source/Calamari/Kubernetes/Scripts/KubectlBashContext.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ function setup_context {
7575
Octopus_K8S_Client_Cert_Pem_Encoded=$(echo "$Octopus_K8S_Client_Cert_Pem" | base64 -w0)
7676
Octopus_K8S_Client_Cert_Key_Encoded=$(echo "$Octopus_K8S_Client_Cert_Key" | base64 -w0)
7777

78+
set_octopusvariable "${Octopus_K8S_Client_Cert}.PrivateKeyPemBase64" $Octopus_K8S_Client_Cert_Key_Encoded -sensitive
79+
7880
kubectl config set users.octouser.client-certificate-data "$Octopus_K8S_Client_Cert_Pem_Encoded"
7981
kubectl config set users.octouser.client-key-data "$Octopus_K8S_Client_Cert_Key_Encoded"
8082
fi
@@ -157,8 +159,8 @@ get_kubectl
157159
configure_kubectl_path
158160
setup_context
159161
create_namespace
160-
echo $KUBECONFIG
161162
echo "##octopus[stdout-verbose]"
163+
cat $KUBECONFIG
162164
echo "Invoking target script \"$(get_octopusvariable "OctopusKubernetesTargetScript")\" with $(get_octopusvariable "OctopusKubernetesTargetScriptParameters") parameters"
163165
echo "##octopus[stdout-default]"
164166

source/Calamari/Kubernetes/Scripts/KubectlPowershellContext.ps1

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ function SetupContext {
7878
Exit 1
7979
}
8080

81-
& $Kubectl_Exe config set users.octouser.client-certificate-data $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Pem)))
82-
& $Kubectl_Exe config set users.octouser.client-key-data $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Key)))
81+
$K8S_Client_Cert_Key_Encoded = $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Key)))
82+
$K8S_Client_Cert_Pem_Encoded = $([Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($K8S_Client_Cert_Pem)))
83+
84+
# Don't leak the private key in the logs
85+
Set-OctopusVariable -name "$($K8S_Client_Cert).PrivateKeyPemBase64" -value $K8S_Client_Cert_Key_Encoded -sensitive
86+
87+
& $Kubectl_Exe config set users.octouser.client-certificate-data $K8S_Client_Cert_Pem_Encoded
88+
& $Kubectl_Exe config set users.octouser.client-key-data $K8S_Client_Cert_Key_Encoded
8389
}
8490

8591
if(-not [string]::IsNullOrEmpty($K8S_Server_Cert)) {
@@ -177,8 +183,9 @@ Write-Host "##octopus[stdout-verbose]"
177183
ConfigureKubeCtlPath
178184
SetupContext
179185
CreateNamespace
180-
Write-Host "##octopus[stdout-default]"
181-
186+
echo "##octopus[stdout-verbose]"
187+
Get-Content $env:KUBECONFIG
182188
Write-Verbose "Invoking target script $OctopusKubernetesTargetScript with $OctopusKubernetesTargetScriptParameters parameters"
189+
echo "##octopus[stdout-default]"
183190

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

0 commit comments

Comments
 (0)