@@ -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}
0 commit comments