diff --git a/internal/cmd/events.go b/internal/cmd/events.go index 3676f5c1..64f22881 100644 --- a/internal/cmd/events.go +++ b/internal/cmd/events.go @@ -86,12 +86,12 @@ func retrieveClusterEvents(hvnr havener.Havener) error { continue } - go func() error { - watcher, err := hvnr.Client().CoreV1().Events(namespace).Watch(context.TODO(), metav1.ListOptions{}) - if err != nil { - return wrap.Error(err, "failed to setup event watcher") - } + watcher, err := hvnr.Client().CoreV1().Events(namespace).Watch(context.TODO(), metav1.ListOptions{}) + if err != nil { + return wrap.Error(err, "failed to setup event watcher") + } + go func() { for event := range watcher.ResultChan() { switch event.Type { case watch.Added, watch.Modified: @@ -116,7 +116,6 @@ func retrieveClusterEvents(hvnr havener.Havener) error { } } } - return nil }() } diff --git a/internal/cmd/output_print.go b/internal/cmd/output_print.go index 0721139d..9ed061d6 100644 --- a/internal/cmd/output_print.go +++ b/internal/cmd/output_print.go @@ -60,7 +60,7 @@ func chanWriter(stream string, origin string, c chan OutputMsg) io.Writer { // PrintOutputMessage reads from the given output message channel and prints the // respective messages without any buffering or sorting. -func PrintOutputMessage(messages chan OutputMsg) error { +func PrintOutputMessage(messages chan OutputMsg) { var ( numberOfColors = 64 colors = bunt.RandomTerminalFriendlyColors(numberOfColors) @@ -77,8 +77,6 @@ func PrintOutputMessage(messages chan OutputMsg) error { printMessage(originColors[msg.Origin], msg) } - - return nil } // PrintOutputMessageAsBlock reads from the given output message channel and diff --git a/internal/cmd/pexec.go b/internal/cmd/pexec.go index f3670a41..285d212d 100644 --- a/internal/cmd/pexec.go +++ b/internal/cmd/pexec.go @@ -75,7 +75,7 @@ all pods in all namespaces automatically. `, SilenceUsage: true, SilenceErrors: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) if err != nil { return wrap.Error(err, "unable to get access to cluster") @@ -87,9 +87,9 @@ all pods in all namespaces automatically. func init() { rootCmd.AddCommand(podExecCmd) - viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) - podExecCmd.PersistentFlags().BoolVar(&podExecNoTty, "no-tty", false, "do not allocate pseudo-terminal for command execution") - podExecCmd.PersistentFlags().BoolVar(&podExecBlock, "block", false, "show distributed shell output as block for each pod") + + podExecCmd.Flags().BoolVar(&podExecNoTty, "no-tty", false, "do not allocate pseudo-terminal for command execution") + podExecCmd.Flags().BoolVar(&podExecBlock, "block", false, "show distributed shell output as block for each pod") } func execInClusterPods(hvnr havener.Havener, args []string) error { diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 8b472a7d..5376ef8a 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -119,15 +119,15 @@ func init() { rootCmd.PersistentFlags().Bool("trace", false, "trace output - level 6") // Bind environment variables to CLI flags - viper.BindPFlag("TERMINAL_WIDTH", rootCmd.PersistentFlags().Lookup("terminal-width")) - viper.BindPFlag("TERMINAL_HEIGHT", rootCmd.PersistentFlags().Lookup("terminal-height")) - - viper.BindPFlag("fatal", rootCmd.PersistentFlags().Lookup("fatal")) - viper.BindPFlag("error", rootCmd.PersistentFlags().Lookup("error")) - viper.BindPFlag("warn", rootCmd.PersistentFlags().Lookup("warn")) - viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) - viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")) - viper.BindPFlag("trace", rootCmd.PersistentFlags().Lookup("trace")) + _ = viper.BindPFlag("TERMINAL_WIDTH", rootCmd.PersistentFlags().Lookup("terminal-width")) + _ = viper.BindPFlag("TERMINAL_HEIGHT", rootCmd.PersistentFlags().Lookup("terminal-height")) + + _ = viper.BindPFlag("fatal", rootCmd.PersistentFlags().Lookup("fatal")) + _ = viper.BindPFlag("error", rootCmd.PersistentFlags().Lookup("error")) + _ = viper.BindPFlag("warn", rootCmd.PersistentFlags().Lookup("warn")) + _ = viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) + _ = viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")) + _ = viper.BindPFlag("trace", rootCmd.PersistentFlags().Lookup("trace")) term.FixedTerminalWidth, term.FixedTerminalHeight = viper.GetInt("TERMINAL_WIDTH"), viper.GetInt("TERMINAL_HEIGHT") diff --git a/pkg/havener/kubexec.go b/pkg/havener/kubexec.go index 6c641c7b..07475d30 100644 --- a/pkg/havener/kubexec.go +++ b/pkg/havener/kubexec.go @@ -73,7 +73,7 @@ func (h *Hvnr) PodExec(pod *corev1.Pod, container string, command []string, stdi // https://en.wikipedia.org/wiki/POSIX_terminal_interface#History for a bit more details. if tty { if stateToBeRestored, err := terminal.MakeRaw(0); err == nil { - defer terminal.Restore(0, stateToBeRestored) + defer func() { _ = terminal.Restore(0, stateToBeRestored) }() } } @@ -94,7 +94,7 @@ func (h *Hvnr) NodeExec(node corev1.Node, containerImage string, timeoutSeconds ) // Make sure to stop pod after command execution - defer PurgePod(h.client, namespace, podName, 10, metav1.DeletePropagationForeground) + defer func() { _ = PurgePod(h.client, namespace, podName, 10, metav1.DeletePropagationForeground) }() pod, err := h.preparePodOnNode(node, namespace, podName, containerImage, timeoutSeconds, stdin != nil) if err != nil { @@ -116,9 +116,7 @@ func (h *Hvnr) NodeExec(node corev1.Node, containerImage string, timeoutSeconds func (h *Hvnr) preparePodOnNode(node corev1.Node, namespace string, name string, containerImage string, timeoutSeconds int, useStdin bool) (*corev1.Pod, error) { // Add pod deletion to shutdown sequence list (in case of Ctrl+C exit) - AddShutdownFunction(func() { - PurgePod(h.client, namespace, name, 10, metav1.DeletePropagationBackground) - }) + AddShutdownFunction(func() { _ = PurgePod(h.client, namespace, name, 10, metav1.DeletePropagationBackground) }) // Pod configuration pod := &corev1.Pod{