Merge pull request #61 from Azure/jose/spinner

spinner: Ensure there are no logs/prints between Start and Stop
This commit is contained in:
Jose Blanquicet 2024-02-07 17:55:04 +01:00 коммит произвёл GitHub
Родитель 76393e0b49 44df752576
Коммит 34574f2c68
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 19 добавлений и 7 удалений

Просмотреть файл

@ -15,6 +15,7 @@ import (
var connCheckCmd = &cobra.Command{
Use: "check-apiserver-connectivity",
Short: "Check connectivity between the nodes and the Kubernetes API Server",
Args: cobra.NoArgs,
RunE: connCheckCmdRun,
SilenceUsage: true,
}
@ -26,7 +27,6 @@ func init() {
}
func connCheckCmdRun(cmd *cobra.Command, args []string) error {
utils.DefaultSpinner.Start()
cred, err := utils.GetCredentials()
if err != nil {
return fmt.Errorf("failed to authenticate: %w", err)
@ -53,7 +53,7 @@ func connCheckCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("couldn't parse stdout of response message:\n%s", res.Stdout)
}
if ret != 0 {
fmt.Printf("\nConnectivity check: failed with returned value %d: %s\n",
fmt.Printf("Connectivity check: failed with returned value %d: %s\n",
ret, res.Stderr)
// Force the binary to return an exit code != 0 (forwarding command's
@ -61,7 +61,6 @@ func connCheckCmdRun(cmd *cobra.Command, args []string) error {
os.Exit(ret)
}
utils.DefaultSpinner.Stop()
fmt.Println("Connectivity check: succeeded")
return nil

Просмотреть файл

@ -21,6 +21,7 @@ var configCmd = &cobra.Command{
var showConfigCmd = &cobra.Command{
Use: "show",
Short: "Show the configuration",
Args: cobra.NoArgs,
RunE: showConfigCmdRun,
SilenceUsage: true,
}
@ -35,6 +36,7 @@ var useNodeCmd = &cobra.Command{
var unsetCurrentNodeCmd = &cobra.Command{
Use: "unset-current-node",
Short: "Unset the current node in the configuration",
Args: cobra.NoArgs,
RunE: unsetCurrentNodeCmdRun,
SilenceUsage: true,
}
@ -49,6 +51,7 @@ var unsetNodeCmd = &cobra.Command{
var unsetAllCmd = &cobra.Command{
Use: "unset-all",
Short: "Unset all nodes in the configuration",
Args: cobra.NoArgs,
RunE: unsetAllCmdRun,
SilenceUsage: true,
}
@ -122,20 +125,27 @@ func importCmdCommand() *cobra.Command {
var clusterName string
virtualMachineScaleSetVMs := func() (map[string]*utils.VirtualMachineScaleSetVM, error) {
utils.DefaultSpinner.Start()
utils.DefaultSpinner.Suffix = " Importing..."
if subscriptionID != "" && resourceGroup != "" && clusterName != "" {
vms, err := utils.VirtualMachineScaleSetVMsViaAzureAPI(subscriptionID, resourceGroup, clusterName)
utils.DefaultSpinner.Stop()
if err != nil {
return nil, fmt.Errorf("getting VMSS VMs via Azure API: %w", err)
}
return vms, nil
}
vms, err := utils.VirtualMachineScaleSetVMsViaKubeconfig()
utils.DefaultSpinner.Stop()
if err != nil {
logrus.Warn("Could not get VMSS VMs via Kubernetes API")
logrus.Warnf("Please provide '--%s', '--%s' and '--%s' flags to get VMSS VMs via Azure API",
utils.SubscriptionIDKey, utils.ResourceGroupKey, utils.ClusterNameKey)
return nil, fmt.Errorf("getting VMSS VMs via Kuberntes API: %w", err)
}
return vms, nil
}
@ -147,9 +157,8 @@ func importCmdCommand() *cobra.Command {
"In case of Azure API, you need to provide '--%s', '--%s' and '--%s' flags.",
utils.SubscriptionIDKey, utils.ResourceGroupKey, utils.ClusterNameKey),
SilenceUsage: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
utils.DefaultSpinner.Start()
defer utils.DefaultSpinner.Stop()
vms, err := virtualMachineScaleSetVMs()
if err != nil {
return err

Просмотреть файл

@ -54,7 +54,6 @@ func init() {
}
func runCommandCmdRun(cmd *cobra.Command, args []string) error {
utils.DefaultSpinner.Start()
cred, err := utils.GetCredentials()
if err != nil {
return fmt.Errorf("authenticating: %w", err)
@ -75,7 +74,6 @@ func runCommandCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("running command: %w", err)
}
utils.DefaultSpinner.Stop()
fmt.Fprintf(os.Stderr, "%s", res.Stderr)
fmt.Fprintf(os.Stdout, "%s", res.Stdout)
return nil

Просмотреть файл

@ -273,13 +273,18 @@ func RunCommand(
os.Exit(1)
}()
DefaultSpinner.Start()
DefaultSpinner.Suffix = " Running..."
poller, err := client.BeginRunCommand(ctx, vm.NodeResourceGroup,
vm.VMScaleSet, vm.InstanceID, runCommand, nil)
if err != nil {
DefaultSpinner.Stop()
return nil, fmt.Errorf("begin running command: %w", err)
}
res, err := poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{Frequency: pollingFreq})
DefaultSpinner.Stop()
if err != nil {
return nil, fmt.Errorf("polling command response: %w", err)
}

Просмотреть файл

@ -19,6 +19,7 @@ func init() {
var versionCmd = &cobra.Command{
Use: "version",
Short: "Show version",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
},