Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

check cloud provider cli whether installed on local env #300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion pkg/cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package cmd

import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -31,7 +33,10 @@ func NewAwsCmd(targetReader TargetReader) *cobra.Command {
if !CheckShootIsTargeted(target) {
return errors.New("no shoot targeted")
}

if !CheckToolInstalled("aws") {
fmt.Println("Please go to https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html for how to install aws cli")
os.Exit(2)
}
arguments := "aws " + strings.Join(args[:], " ")
operate("aws", arguments)

Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/az.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package cmd

import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -31,7 +33,10 @@ func NewAzCmd(targetReader TargetReader) *cobra.Command {
if !CheckShootIsTargeted(target) {
return errors.New("no shoot targeted")
}

if !CheckToolInstalled("az") {
fmt.Println("Please go to https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest for how to install az cli")
os.Exit(2)
}
arguments := "az " + strings.Join(args[:], " ")
operate("az", arguments)

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/gcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package cmd

import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -31,6 +33,10 @@ func NewGcloudCmd(targetReader TargetReader) *cobra.Command {
if !CheckShootIsTargeted(target) {
return errors.New("no shoot targeted")
}
if !CheckToolInstalled("gcloud") {
fmt.Println("Please go to https://cloud.google.com/sdk/install for how to install gcloud")
os.Exit(2)
}

arguments := "gcloud " + strings.Join(args[:], " ")
operate("gcp", arguments)
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package cmd

import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -31,7 +33,10 @@ func NewOpenstackCmd(targetReader TargetReader) *cobra.Command {
if !CheckShootIsTargeted(target) {
return errors.New("no shoot targeted")
}

if !CheckToolInstalled("openstack") {
fmt.Println("Please go to https://docs.openstack.org/newton/user-guide/common/cli-install-openstack-command-line-clients.html for how to install openstack cli")
os.Exit(2)
}
arguments := "openstack " + strings.Join(args[:], " ")
operate("openstack", arguments)

Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,13 @@ func GardenctlInfoLog(logMsg string) {
var logger = gardenerlogger.NewLogger("info")
logger.Infof(logMsg)
}

//CheckToolInstalled checks whether cliName is installed on local machine
func CheckToolInstalled(cliName string) bool {
_, err := exec.LookPath(cliName)
if err != nil {
fmt.Println(cliName + " is not installed on your system")
return false
}
return true
}