Skip to content

Commit 5b7523d

Browse files
committed
test connection after cloud login, remove failed release log
1 parent 7e6532c commit 5b7523d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
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 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
@@ -352,6 +352,7 @@ var ciReleaseDeployCmd = &cobra.Command{
352352
else
353353
true
354354
fi
355+
rm -f helm-output.log
355356
}
356357
357358
trap show_failing_pods ERR
@@ -420,6 +421,7 @@ var ciReleaseDeployCmd = &cobra.Command{
420421
echo "$statefulsets" | xargs -n 1 kubectl rollout status statefulset -n "$NAMESPACE" --timeout 5m
421422
fi
422423
kubectl get deployment -n "$NAMESPACE" -l "release=${RELEASE_NAME}" -o name | xargs -n 1 kubectl rollout status -n "$NAMESPACE" --timeout 5m
424+
rm -f helm-output.log
423425
`,
424426
releaseName, chartName, chartRepository, chartVersionOverride,
425427
siltaEnvironmentName, branchname,
@@ -611,6 +613,7 @@ var ciReleaseDeployCmd = &cobra.Command{
611613
else
612614
true
613615
fi
616+
rm -f helm-output.log
614617
}
615618
616619
trap show_failing_pods ERR
@@ -683,6 +686,7 @@ var ciReleaseDeployCmd = &cobra.Command{
683686
echo "$statefulsets" | xargs -n 1 kubectl rollout status statefulset -n "$NAMESPACE" --timeout 5m
684687
fi
685688
kubectl get deployment -n "$NAMESPACE" -l "release=${RELEASE_NAME}" -o name | xargs -n 1 kubectl rollout status -n "$NAMESPACE" --timeout 5m
689+
rm -f helm-output.log
686690
`,
687691
releaseName, chartName, chartRepository, chartVersionOverride,
688692
siltaEnvironmentName, branchname,

0 commit comments

Comments
 (0)