Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test connection after cloud login, remove failed release log #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions cmd/ciCloudLogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var cloudLoginCmd = &cobra.Command{
- "--aks-tenant-id" flag or "AKS_TENANT_ID" environment variable
- "--aks-sp-app-id" flag or "AKS_SP_APP_ID" environment variable
- "--aks-sp-password" flag or "AKS_SP_PASSWORD" environment variable

After login, the connection is tested by running "kubectl can-i get pods" command,
disable with "--test-connection=false" flag.
`,
Run: func(cmd *cobra.Command, args []string) {

Expand Down Expand Up @@ -77,7 +80,7 @@ var cloudLoginCmd = &cobra.Command{
}

// Environment value fallback
if useEnv == true {
if useEnv {
if len(clusterName) == 0 {
clusterName = os.Getenv("CLUSTER_NAME")
}
Expand Down Expand Up @@ -267,7 +270,7 @@ var cloudLoginCmd = &cobra.Command{

// Execute login commands
if command != "" {
if debug == true {
if debug {
fmt.Printf("Command (not executed): %s\n", command)
} else {
out, err := exec.Command("bash", "-c", command).CombinedOutput()
Expand All @@ -278,6 +281,20 @@ var cloudLoginCmd = &cobra.Command{
fmt.Printf("%s\n", out)
}
}

// Test connection
testConnection, _ := cmd.Flags().GetBool("test-connection")
if testConnection {
if !debug {
command = "kubectl can-i get pods"
_, err := exec.Command("bash", "-c", command).CombinedOutput()
if err != nil {
log.Fatal("Error: ", err)
}
} else {
fmt.Printf("Command (not executed): %s\n", command)
}
}
},
}

Expand All @@ -299,4 +316,5 @@ func init() {
cloudLoginCmd.Flags().String("aks-tenant-id", "", "Azure Services tenant id")
cloudLoginCmd.Flags().String("aks-sp-app-id", "", "Azure Services servicePrincipal app id")
cloudLoginCmd.Flags().String("aks-sp-password", "", "Azure Services servicePrincipal password")
cloudLoginCmd.Flags().Bool("test-connection", true, "Test connection after login")
}
4 changes: 4 additions & 0 deletions cmd/ciReleaseDeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ var ciReleaseDeployCmd = &cobra.Command{
else
true
fi
rm -f helm-output.log
}

trap show_failing_pods ERR
Expand Down Expand Up @@ -420,6 +421,7 @@ var ciReleaseDeployCmd = &cobra.Command{
echo "$statefulsets" | xargs -n 1 kubectl rollout status statefulset -n "$NAMESPACE" --timeout 5m
fi
kubectl get deployment -n "$NAMESPACE" -l "release=${RELEASE_NAME}" -o name | xargs -n 1 kubectl rollout status -n "$NAMESPACE" --timeout 5m
rm -f helm-output.log
`,
releaseName, chartName, chartRepository, chartVersionOverride,
siltaEnvironmentName, branchname,
Expand Down Expand Up @@ -611,6 +613,7 @@ var ciReleaseDeployCmd = &cobra.Command{
else
true
fi
rm -f helm-output.log
}

trap show_failing_pods ERR
Expand Down Expand Up @@ -683,6 +686,7 @@ var ciReleaseDeployCmd = &cobra.Command{
echo "$statefulsets" | xargs -n 1 kubectl rollout status statefulset -n "$NAMESPACE" --timeout 5m
fi
kubectl get deployment -n "$NAMESPACE" -l "release=${RELEASE_NAME}" -o name | xargs -n 1 kubectl rollout status -n "$NAMESPACE" --timeout 5m
rm -f helm-output.log
`,
releaseName, chartName, chartRepository, chartVersionOverride,
siltaEnvironmentName, branchname,
Expand Down
Loading