Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
Remove unused return types.

Ignore errors that are not required to be checked.
  • Loading branch information
HeavyWombat committed Oct 18, 2022
1 parent f190ec2 commit bfa5946
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
11 changes: 5 additions & 6 deletions internal/cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -116,7 +116,6 @@ func retrieveClusterEvents(hvnr havener.Havener) error {
}
}
}
return nil
}()
}

Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/output_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/pexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 3 additions & 5 deletions pkg/havener/kubexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }()
}
}

Expand All @@ -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 {
Expand All @@ -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{
Expand Down

0 comments on commit bfa5946

Please sign in to comment.