Skip to content

Commit b0241fc

Browse files
authored
Merge pull request #70 from AdvH039/verbose-flag-set-logLvl
Verbose flag controls log level
2 parents 886d5f4 + f120496 commit b0241fc

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

cmd/check-apiserver-connectivity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func connCheckCmdRun(cmd *cobra.Command, args []string) error {
4141
// command will try to contact the API server to get the Kubernetes version
4242
// it is running. Use only the return value of the command, tough.
4343
command := "kubectl --kubeconfig /var/lib/kubelet/kubeconfig version > /dev/null; echo -n $?"
44-
res, err := utils.RunCommand(cmd.Context(), cred, vm, &command, commonFlags.Verbose, nil, utils.OutputTruncateTail)
44+
res, err := utils.RunCommand(cmd.Context(), cred, vm, &command, nil, utils.OutputTruncateTail)
4545
if err != nil {
4646
return fmt.Errorf("failed to run command that checks connectivity: %w", err)
4747
}

cmd/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ var importCmd = importCmdCommand()
6868

6969
func init() {
7070
utils.AddCommonFlags(configCmd, &commonFlags)
71+
72+
if commonFlags.Verbose {
73+
logrus.SetLevel(logrus.DebugLevel)
74+
}
7175
rootCmd.AddCommand(configCmd)
7276

7377
configCmd.AddCommand(showConfigCmd, useNodeCmd, unsetCurrentNodeCmd, unsetNodeCmd, unsetAllCmd, setNodeCmd, importCmd)

cmd/run-command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func runCommandCmdRun(cmd *cobra.Command, args []string) error {
6969
outputTruncate = utils.OutputTruncateHead
7070
}
7171

72-
res, err := utils.RunCommand(cmd.Context(), cred, vm, &command, commonFlags.Verbose, &timeout, outputTruncate)
72+
res, err := utils.RunCommand(cmd.Context(), cred, vm, &command, &timeout, outputTruncate)
7373
if err != nil {
7474
return fmt.Errorf("running command: %w", err)
7575
}

cmd/utils/vmss.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ func RunCommand(
223223
cred azcore.TokenCredential,
224224
vm *VirtualMachineScaleSetVM,
225225
command *string,
226-
verbose bool,
227226
timeout *int,
228227
outputTruncate OutputTruncate,
229228
) (
@@ -257,11 +256,8 @@ func RunCommand(
257256
Script: script,
258257
}
259258

260-
if verbose {
261-
b, _ := json.MarshalIndent(vm, "", " ")
262-
fmt.Printf("Command: %s\nVirtual Machine Scale Set VM:\n%s\n\n", *command, string(b))
263-
}
264-
259+
b, _ := json.MarshalIndent(vm, "", " ")
260+
log.Debugf("Command: %s\nVirtual Machine Scale Set VM:\n%s\n\n", *command, string(b))
265261
s := make(chan os.Signal, 1)
266262
signal.Notify(s, os.Interrupt, syscall.SIGTERM)
267263
go func() {
@@ -289,11 +285,8 @@ func RunCommand(
289285
return nil, fmt.Errorf("polling command response: %w", err)
290286
}
291287

292-
if verbose {
293-
b, _ := json.MarshalIndent(res, "", " ")
294-
fmt.Printf("\nResponse:\n%s\n", string(b))
295-
}
296-
288+
b, _ = json.MarshalIndent(res, "", " ")
289+
log.Debugf("\nResponse:\n%s\n", string(b))
297290
// TODO: Is it possible to have multiple values after using PollUntilDone()?
298291
if len(res.Value) == 0 || res.Value[0] == nil {
299292
return nil, errors.New("no response received after command execution")

0 commit comments

Comments
 (0)