diff --git a/go.sum b/go.sum index cb7ace9e..8819c18b 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -23,7 +22,6 @@ github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8= github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -104,7 +102,6 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -137,9 +134,7 @@ github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.17.3 h1:oJcvKpIb7/8uLpDDtnQuf18xVnwKp8DTD7DQ6gTd/MU= github.com/onsi/ginkgo/v2 v2.17.3/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc= github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= @@ -152,10 +147,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= @@ -163,7 +156,6 @@ github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgY github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= -github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= @@ -286,7 +278,6 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/cmd/events.go b/internal/cmd/events.go index 64f22881..c1af5d3b 100644 --- a/internal/cmd/events.go +++ b/internal/cmd/events.go @@ -22,13 +22,13 @@ package cmd import ( "context" + "fmt" "strings" "time" "github.com/spf13/cobra" "github.com/gonvenience/bunt" - "github.com/gonvenience/wrap" "github.com/homeport/havener/pkg/havener" corev1 "k8s.io/api/core/v1" @@ -55,9 +55,9 @@ var eventsCmd = &cobra.Command{ SilenceUsage: true, SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { - hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) + hvnr, err := havener.NewHavener(havener.WithContext(cmd.Context()), havener.WithKubeConfigPath(kubeConfig)) if err != nil { - return wrap.Error(err, "unable to get access to cluster") + return fmt.Errorf("unable to get access to cluster: %w", err) } return retrieveClusterEvents(hvnr) @@ -73,7 +73,7 @@ func init() { func retrieveClusterEvents(hvnr havener.Havener) error { namespaces, err := havener.ListNamespaces(hvnr.Client()) if err != nil { - return wrap.Error(err, "failed to get a list of namespaces") + return fmt.Errorf("failed to get a list of namespaces: %w", err) } notes := make(chan note) @@ -88,7 +88,7 @@ func retrieveClusterEvents(hvnr havener.Havener) 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") + return fmt.Errorf("failed to setup event watcher: %w", err) } go func() { diff --git a/internal/cmd/logs.go b/internal/cmd/logs.go index 40d94519..2f58977e 100644 --- a/internal/cmd/logs.go +++ b/internal/cmd/logs.go @@ -29,7 +29,6 @@ import ( "github.com/spf13/cobra" "github.com/gonvenience/wait" - "github.com/gonvenience/wrap" "github.com/homeport/havener/pkg/havener" ) @@ -54,9 +53,9 @@ The download includes all deployment YAMLs of the pods and the describe output.` SilenceUsage: true, SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { - hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) + hvnr, err := havener.NewHavener(havener.WithContext(cmd.Context()), havener.WithKubeConfigPath(kubeConfig)) if err != nil { - return wrap.Error(err, "unable to get access to cluster") + return fmt.Errorf("unable to get access to cluster: %w", err) } return retrieveClusterLogs(hvnr) @@ -101,14 +100,13 @@ func retrieveClusterLogs(hvnr havener.Havener) error { case err := <-resultChan: if err != nil { pi.Stop() - return wrap.Error(err, "unable to retrieve logs from pods") + return fmt.Errorf("unable to retrieve logs from pods: %w", err) } case <-time.After(timeout): pi.Stop() - return wrap.Error( + return fmt.Errorf("unable to retrieve logs from pods: %w", fmt.Errorf("download did not finish within configured timeout"), - "unable to retrieve logs from pods", ) } diff --git a/internal/cmd/nexec.go b/internal/cmd/nexec.go index ab45ce41..7877bd6e 100644 --- a/internal/cmd/nexec.go +++ b/internal/cmd/nexec.go @@ -33,7 +33,6 @@ import ( "github.com/gonvenience/bunt" "github.com/gonvenience/term" - "github.com/gonvenience/wrap" "github.com/homeport/havener/pkg/havener" "github.com/spf13/cobra" "k8s.io/client-go/kubernetes" @@ -81,9 +80,9 @@ all nodes automatically. SilenceUsage: true, SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { - hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) + hvnr, err := havener.NewHavener(havener.WithContext(cmd.Context()), havener.WithKubeConfigPath(kubeConfig)) if err != nil { - return wrap.Error(err, "unable to get access to cluster") + return fmt.Errorf("unable to get access to cluster: %w", err) } return execInClusterNodes(hvnr, args) @@ -241,17 +240,15 @@ func lookupNodesByName(client kubernetes.Interface, input string) ([]corev1.Node func availableNodesError(client kubernetes.Interface, title string, fArgs ...interface{}) error { nodes, err := havener.ListNodes(client) if err != nil { - return wrap.Error(err, "failed to list all nodes in cluster") + return fmt.Errorf("failed to list all nodes in cluster: %w", err) } if len(nodes) == 0 { return fmt.Errorf("failed to find any node in cluster") } - return wrap.Errorf( - bunt.Errorf("*list of available nodes:*\n%s\n\nor, use _all_ to target all nodes", - strings.Join(nodes, "\n"), - ), - title, fArgs..., + return fmt.Errorf("%s: %w", + fmt.Sprintf(title, fArgs...), + bunt.Errorf("*list of available nodes:*\n%s\n\nor, use _all_ to target all nodes", strings.Join(nodes, "\n")), ) } diff --git a/internal/cmd/pexec.go b/internal/cmd/pexec.go index 285d212d..5f7de6f9 100644 --- a/internal/cmd/pexec.go +++ b/internal/cmd/pexec.go @@ -32,7 +32,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/gonvenience/term" - "github.com/gonvenience/wrap" "github.com/homeport/havener/pkg/havener" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -75,10 +74,10 @@ all pods in all namespaces automatically. `, SilenceUsage: true, SilenceErrors: true, - RunE: func(_ *cobra.Command, args []string) error { - hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) + RunE: func(cmd *cobra.Command, args []string) error { + hvnr, err := havener.NewHavener(havener.WithContext(cmd.Context()), havener.WithKubeConfigPath(kubeConfig)) if err != nil { - return wrap.Error(err, "unable to get access to cluster") + return fmt.Errorf("unable to get access to cluster: %w", err) } return execInClusterPods(hvnr, args) @@ -300,7 +299,7 @@ func lookupPodsByName(client kubernetes.Interface, input string) (map[*corev1.Po func availablePodsError(client kubernetes.Interface, title string) error { pods, err := havener.ListPods(client) if err != nil { - return wrap.Error(err, "failed to list all pods in cluster") + return fmt.Errorf("failed to list all pods in cluster: %w", err) } podList := []string{} for _, pod := range pods { @@ -313,10 +312,8 @@ func availablePodsError(client kubernetes.Interface, title string) error { } } - return wrap.Error( - fmt.Errorf("> Usage:\npod-exec [flags] \n> List of available pods:\n%s", - strings.Join(podList, "\n"), - ), + return fmt.Errorf("%s: %w", title, + fmt.Errorf("> Usage:\npod-exec [flags] \n> List of available pods:\n%s", strings.Join(podList, "\n")), ) } diff --git a/internal/cmd/top.go b/internal/cmd/top.go index 51ea7f35..0da45e6e 100644 --- a/internal/cmd/top.go +++ b/internal/cmd/top.go @@ -70,7 +70,7 @@ cluster as well as a list per node. topCmdSettings.cycles = 1 } - hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) + hvnr, err := havener.NewHavener(havener.WithContext(cmd.Context()), havener.WithKubeConfigPath(kubeConfig)) if err != nil { return err } diff --git a/internal/cmd/watch.go b/internal/cmd/watch.go index afb835d6..f0454c17 100644 --- a/internal/cmd/watch.go +++ b/internal/cmd/watch.go @@ -48,7 +48,7 @@ var watchCmd = &cobra.Command{ Short: "Watch status of all pods in all namespaces", Long: `Continuesly creates a list of all pods in all namespaces.`, RunE: func(cmd *cobra.Command, args []string) error { - hvnr, err := havener.NewHavener(havener.KubeConfig(kubeConfig)) + hvnr, err := havener.NewHavener(havener.WithContext(cmd.Context()), havener.WithKubeConfigPath(kubeConfig)) if err != nil { return err } diff --git a/pkg/havener/common.go b/pkg/havener/common.go index 93e34621..7ec6efd5 100644 --- a/pkg/havener/common.go +++ b/pkg/havener/common.go @@ -38,7 +38,6 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "github.com/gonvenience/wrap" "gopkg.in/yaml.v3" ) @@ -47,7 +46,7 @@ import ( func KubeConfigDefault() (string, error) { home, err := os.UserHomeDir() if err != nil { - return "", wrap.Error(err, "unable to get home directory") + return "", fmt.Errorf("unable to get home directory: %w", err) } return filepath.Join(home, ".kube", "config"), nil diff --git a/pkg/havener/havener.go b/pkg/havener/havener.go index cbad4327..e3620a17 100644 --- a/pkg/havener/havener.go +++ b/pkg/havener/havener.go @@ -30,12 +30,12 @@ this kind of workload. package havener import ( + "context" "fmt" "io" "os" "time" - "github.com/gonvenience/wrap" "golang.org/x/sync/syncmap" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -73,6 +73,7 @@ func GracefulShutdown() { // Hvnr is the internal handle to consolidate required cluster access variables type Hvnr struct { + ctx context.Context kubeConfigPath string client kubernetes.Interface restconfig *rest.Config @@ -103,12 +104,23 @@ type Havener interface { type Option func(*Hvnr) // KubeConfig is an option to set a specific Kubernetes configuration path +// +// Deprecated: Use WithKubeConfigPath instead func KubeConfig(kubeConfig string) Option { return func(h *Hvnr) { h.kubeConfigPath = kubeConfig } } +func WithKubeConfigPath(kubeConfig string) Option { + return func(h *Hvnr) { h.kubeConfigPath = kubeConfig } +} + +// WithContext is an option to set the context +func WithContext(ctx context.Context) Option { + return func(h *Hvnr) { h.ctx = ctx } +} + // NewHavenerFromFields returns a new Havener handle using the provided // input arguments (use for unit testing only) func NewHavenerFromFields(client kubernetes.Interface, restconfig *rest.Config, clusterName string, kubeConfigPath string) *Hvnr { @@ -127,6 +139,11 @@ func NewHavener(opts ...Option) (hvnr *Hvnr, err error) { opt(hvnr) } + // Set default backgroud context if nothing is set + if hvnr.ctx == nil { + hvnr.ctx = context.Background() + } + // In case `KUBECONFIG` environment variable is set, this will take // precedence over command line flag or default value if value, ok := os.LookupEnv("KUBECONFIG"); ok { @@ -137,18 +154,18 @@ func NewHavener(opts ...Option) (hvnr *Hvnr, err error) { if hvnr.kubeConfigPath == "" { hvnr.kubeConfigPath, err = KubeConfigDefault() if err != nil { - return nil, wrap.Error(err, "failed to look-up default kube config") + return nil, fmt.Errorf("failed to look-up default kube config: %w", err) } } hvnr.client, hvnr.restconfig, err = outOfClusterAuthentication(hvnr.kubeConfigPath) if err != nil { - return nil, wrap.Error(err, "unable to get access to cluster") + return nil, fmt.Errorf("unable to get access to cluster: %w", err) } hvnr.clusterName, err = clusterName(hvnr.kubeConfigPath) if err != nil { - return nil, wrap.Error(err, "unable to get cluster name") + return nil, fmt.Errorf("unable to get cluster name: %w", err) } return hvnr, nil diff --git a/pkg/havener/kubexec.go b/pkg/havener/kubexec.go index 07475d30..a517ef9c 100644 --- a/pkg/havener/kubexec.go +++ b/pkg/havener/kubexec.go @@ -31,7 +31,6 @@ import ( "github.com/gonvenience/term" "github.com/gonvenience/text" - "github.com/gonvenience/wrap" terminal "golang.org/x/term" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" @@ -59,7 +58,7 @@ func (h *Hvnr) PodExec(pod *corev1.Pod, container string, command []string, stdi executor, err := remotecommand.NewSPDYExecutor(h.restconfig, "POST", req.URL()) if err != nil { - return wrap.Error(err, "failed to initialize remote executor") + return fmt.Errorf("failed to initialize remote executor: %w", err) } var tsq *terminalSizeQueue @@ -77,8 +76,8 @@ func (h *Hvnr) PodExec(pod *corev1.Pod, container string, command []string, stdi } } - if err = executor.Stream(remotecommand.StreamOptions{Stdin: stdin, Stdout: stdout, Stderr: stderr, Tty: tty, TerminalSizeQueue: tsq}); err != nil { - return wrap.Errorf(err, "failed to execute command on pod %s, container %s", pod.Name, container) + if err = executor.StreamWithContext(h.ctx, remotecommand.StreamOptions{Stdin: stdin, Stdout: stdout, Stderr: stderr, Tty: tty, TerminalSizeQueue: tsq}); err != nil { + return fmt.Errorf("failed to execute command on pod %s, container %s: %w", pod.Name, container, err) } logf(Verbose, "Successfully executed command.") @@ -135,7 +134,7 @@ func (h *Hvnr) preparePodOnNode(node corev1.Node, namespace string, name string, ImagePullPolicy: corev1.PullIfNotPresent, Stdin: useStdin, SecurityContext: &corev1.SecurityContext{ - Privileged: pointer.BoolPtr(true), + Privileged: pointer.Bool(true), }, }, }, @@ -205,11 +204,11 @@ func (h *Hvnr) waitForPodReadiness(namespace string, pod *corev1.Pod, timeoutSec description = "Unable to provide further details regarding the state of the pod." } - return wrap.Errorf(fmt.Errorf("status of pod at the moment of the timeout:\n\n%s", description), - "Giving up waiting for pod %s in namespace %s to become ready within %s", + return fmt.Errorf("Giving up waiting for pod %s in namespace %s to become ready within %s: %w", pod.Name, pod.Namespace, text.Plural(timeoutSeconds, "second"), + fmt.Errorf("status of pod at the moment of the timeout:\n\n%s", description), ) } } diff --git a/pkg/havener/list.go b/pkg/havener/list.go index 8668b580..6a86ab6a 100644 --- a/pkg/havener/list.go +++ b/pkg/havener/list.go @@ -27,7 +27,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/gonvenience/wrap" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" @@ -185,7 +184,6 @@ func (h *Hvnr) ListConfigMaps(namespaces ...string) (result []*corev1.ConfigMap, // ListCustomResourceDefinition lists all instances of an specific CRD func (h *Hvnr) ListCustomResourceDefinition(crdName string) (result []unstructured.Unstructured, err error) { - var runtimeClassGVR schema.GroupVersionResource _, apiResourceList, err := h.client.Discovery().ServerGroupsAndResources() @@ -198,14 +196,10 @@ func (h *Hvnr) ListCustomResourceDefinition(crdName string) (result []unstructur if crdExist { client, _ := dynamic.NewForConfig(h.restconfig) list, _ := client.Resource(runtimeClassGVR).List(context.TODO(), metav1.ListOptions{}) - - for i := range list.Items { - result = append(result, list.Items[i]) - } - return result, nil + return list.Items, nil } - return result, fmt.Errorf("desired resource %s, was not found", crdName) + return nil, fmt.Errorf("desired resource %s, was not found", crdName) } // ListNodes lists all nodes of the cluster @@ -228,7 +222,7 @@ func ListNodes(client kubernetes.Interface) ([]string, error) { func (h *Hvnr) ListNodes() ([]corev1.Node, error) { nodeList, err := h.client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) if err != nil { - return nil, wrap.Error(err, "failed to get list of nodes") + return nil, fmt.Errorf("failed to get list of nodes: %w", err) } return nodeList.Items, nil @@ -238,7 +232,7 @@ func (h *Hvnr) ListNodes() ([]corev1.Node, error) { func (h *Hvnr) ListNodeNames() ([]string, error) { nodeList, err := h.client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) if err != nil { - return nil, wrap.Error(err, "failed to get list of nodes") + return nil, fmt.Errorf("failed to get list of nodes: %w", err) } result := make([]string, len(nodeList.Items)) diff --git a/pkg/havener/purge.go b/pkg/havener/purge.go index 6555d03b..d527050d 100644 --- a/pkg/havener/purge.go +++ b/pkg/havener/purge.go @@ -24,7 +24,6 @@ import ( "context" "fmt" - "github.com/gonvenience/wrap" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -120,7 +119,7 @@ func PurgeNamespace(kubeClient kubernetes.Interface, namespace string) error { watcher.Stop() case watch.Error: - return wrap.Errorf(err, "failed to watch namespace %s during deletion", namespace) + return fmt.Errorf("failed to watch namespace %s during deletion: %w", namespace, err) } } diff --git a/pkg/havener/top.go b/pkg/havener/top.go index 45c406d8..364b9274 100644 --- a/pkg/havener/top.go +++ b/pkg/havener/top.go @@ -245,9 +245,9 @@ func (h *Hvnr) TopDetails() (*TopDetails, error) { ) if err != nil { - errChan <- wrap.Error( - fmt.Errorf(stderr.String()), + errChan <- fmt.Errorf("%s: %w", err.Error(), + fmt.Errorf(stderr.String()), ) }