Skip to content

Commit d960d10

Browse files
authored
Merge pull request #73 from wunderio/feature/cloud-login-test
test connection after cloud login, remove failed release log
2 parents 43eaf98 + 8989e0e commit d960d10

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

cmd/ciCloudLogin.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ var cloudLoginCmd = &cobra.Command{
4848
- "--aks-tenant-id" flag or "AKS_TENANT_ID" environment variable
4949
- "--aks-sp-app-id" flag or "AKS_SP_APP_ID" environment variable
5050
- "--aks-sp-password" flag or "AKS_SP_PASSWORD" environment variable
51+
52+
After login, the connection is tested by running "kubectl can-i get pods" command,
53+
disable with "--test-connection=false" flag.
5154
`,
5255
Run: func(cmd *cobra.Command, args []string) {
5356

@@ -77,7 +80,7 @@ var cloudLoginCmd = &cobra.Command{
7780
}
7881

7982
// Environment value fallback
80-
if useEnv == true {
83+
if useEnv {
8184
if len(clusterName) == 0 {
8285
clusterName = os.Getenv("CLUSTER_NAME")
8386
}
@@ -267,7 +270,7 @@ var cloudLoginCmd = &cobra.Command{
267270

268271
// Execute login commands
269272
if command != "" {
270-
if debug == true {
273+
if debug {
271274
fmt.Printf("Command (not executed): %s\n", command)
272275
} else {
273276
out, err := exec.Command("bash", "-c", command).CombinedOutput()
@@ -278,6 +281,20 @@ var cloudLoginCmd = &cobra.Command{
278281
fmt.Printf("%s\n", out)
279282
}
280283
}
284+
285+
// Test connection
286+
testConnection, _ := cmd.Flags().GetBool("test-connection")
287+
if testConnection {
288+
if !debug {
289+
command = "kubectl auth can-i get pods"
290+
_, err := exec.Command("bash", "-c", command).CombinedOutput()
291+
if err != nil {
292+
log.Fatal("Error: ", err)
293+
}
294+
} else {
295+
fmt.Printf("Command (not executed): %s\n", command)
296+
}
297+
}
281298
},
282299
}
283300

@@ -299,4 +316,5 @@ func init() {
299316
cloudLoginCmd.Flags().String("aks-tenant-id", "", "Azure Services tenant id")
300317
cloudLoginCmd.Flags().String("aks-sp-app-id", "", "Azure Services servicePrincipal app id")
301318
cloudLoginCmd.Flags().String("aks-sp-password", "", "Azure Services servicePrincipal password")
319+
cloudLoginCmd.Flags().Bool("test-connection", true, "Test connection after login")
302320
}

cmd/ciReleaseDeploy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ var ciReleaseDeployCmd = &cobra.Command{
353353
else
354354
true
355355
fi
356+
rm -f helm-output.log
356357
}
357358
358359
trap show_failing_pods ERR
@@ -421,6 +422,7 @@ var ciReleaseDeployCmd = &cobra.Command{
421422
echo "$statefulsets" | xargs -n 1 kubectl rollout status statefulset -n "$NAMESPACE" --timeout 5m
422423
fi
423424
kubectl get deployment -n "$NAMESPACE" -l "release=${RELEASE_NAME}" -o name | xargs -n 1 kubectl rollout status -n "$NAMESPACE" --timeout 5m
425+
rm -f helm-output.log
424426
`,
425427
releaseName, chartName, chartRepository, chartVersionOverride,
426428
siltaEnvironmentName, branchname,
@@ -612,6 +614,7 @@ var ciReleaseDeployCmd = &cobra.Command{
612614
else
613615
true
614616
fi
617+
rm -f helm-output.log
615618
}
616619
617620
trap show_failing_pods ERR
@@ -684,6 +687,7 @@ var ciReleaseDeployCmd = &cobra.Command{
684687
echo "$statefulsets" | xargs -n 1 kubectl rollout status statefulset -n "$NAMESPACE" --timeout 5m
685688
fi
686689
kubectl get deployment -n "$NAMESPACE" -l "release=${RELEASE_NAME}" -o name | xargs -n 1 kubectl rollout status -n "$NAMESPACE" --timeout 5m
690+
rm -f helm-output.log
687691
`,
688692
releaseName, chartName, chartRepository, chartVersionOverride,
689693
siltaEnvironmentName, branchname,

tests/cloud_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ func TestCloudLoginCmd(t *testing.T) {
1414
// Custom kubeconfig
1515
command := "cloud login --kubeconfig `echo \"TEST\" | base64` --kubeconfigpath tmpkubeconfig --debug; cat tmpkubeconfig; rm tmpkubeconfig"
1616
environment := []string{}
17-
testString := "TEST\n"
17+
testString := `Command (not executed):
18+
TEST
19+
`
1820
CliExecTest(t, command, environment, testString, true)
1921

2022
// Custom kubeconfig as env variable
@@ -23,7 +25,9 @@ func TestCloudLoginCmd(t *testing.T) {
2325
// echo "TEST2" | base64 => "VEVTVDIK"
2426
"KUBECTL_CONFIG=VEVTVDIK",
2527
}
26-
testString = "TEST2\n"
28+
testString = `Command (not executed):
29+
TEST2
30+
`
2731
CliExecTest(t, command, environment, testString, true)
2832

2933
// TODO: test gcp, aws and aks

tests/release_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func TestReleaseDeployCmd(t *testing.T) {
197197
else
198198
true
199199
fi
200+
rm -f helm-output.log
200201
}
201202
202203
trap show_failing_pods ERR
@@ -308,6 +309,7 @@ func TestReleaseDeployCmd(t *testing.T) {
308309
else
309310
true
310311
fi
312+
rm -f helm-output.log
311313
}
312314
313315
trap show_failing_pods ERR

0 commit comments

Comments
 (0)