Skip to content

Remove unnecessary go dependencies #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ go 1.23.4
require (
github.com/Venafi/vcert/v5 v5.8.1
github.com/cenkalti/backoff/v5 v5.0.2
github.com/d4l3k/messagediff v1.2.1
github.com/fatih/color v1.17.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jetstack/venafi-connection-lib v0.3.2-0.20250305134451-ec1757b9e01b
github.com/maxatome/go-testdeep v1.14.0
github.com/microcosm-cc/bluemonday v1.0.27
github.com/pkg/errors v0.9.1
github.com/pmylund/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.21.0
github.com/spf13/cobra v1.8.1
Expand Down Expand Up @@ -49,6 +46,7 @@ require (
github.com/gorilla/websocket v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sosodev/duration v1.2.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03V
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U=
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -130,8 +128,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/maxatome/go-testdeep v1.14.0 h1:rRlLv1+kI8eOI3OaBXZwb3O7xY3exRzdW5QyX48g9wI=
github.com/maxatome/go-testdeep v1.14.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
13 changes: 6 additions & 7 deletions pkg/client/client_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"k8s.io/client-go/transport"

"github.com/jetstack/preflight/api"
Expand Down Expand Up @@ -188,25 +187,25 @@ func (c *OAuthClient) renewAccessToken(ctx context.Context) error {
payload.Set("password", c.credentials.UserSecret)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, strings.NewReader(payload.Encode()))
if err != nil {
return errors.WithStack(err)
return err
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
version.SetUserAgent(req)

res, err := http.DefaultClient.Do(req)
if err != nil {
return errors.WithStack(err)
return err
}

body, err := io.ReadAll(res.Body)
if err != nil {
return errors.WithStack(err)
return err
}

defer res.Body.Close()

if status := res.StatusCode; status < 200 || status >= 300 {
return errors.Errorf("auth server did not provide an access token: (status %d) %s.", status, string(body))
return fmt.Errorf("auth server did not provide an access token: (status %d) %s.", status, string(body))
}

response := struct {
Expand All @@ -216,11 +215,11 @@ func (c *OAuthClient) renewAccessToken(ctx context.Context) error {

err = json.Unmarshal(body, &response)
if err != nil {
return errors.WithStack(err)
return err
}

if response.ExpiresIn == 0 {
return errors.Errorf("got wrong expiration for access token")
return fmt.Errorf("got wrong expiration for access token")
}

c.accessToken.bearer = response.Bearer
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client_venconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -14,7 +15,6 @@ import (
venapi "github.com/jetstack/venafi-connection-lib/api/v1alpha1"
"github.com/jetstack/venafi-connection-lib/chain/sources/venafi"
"github.com/jetstack/venafi-connection-lib/venafi_client"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down
10 changes: 2 additions & 8 deletions pkg/datagatherer/k8s/cache_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package k8s

import (
"encoding/json"
"testing"
"time"

"github.com/d4l3k/messagediff"
"github.com/go-logr/logr"
"github.com/pmylund/go-cache"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2/ktesting"

Expand Down Expand Up @@ -132,12 +131,7 @@ func TestOnAddCache(t *testing.T) {
t.Errorf("unexpected number of return items found. exp:%+v act:%+v", tc.expected, list)
}

if diff, equal := messagediff.PrettyDiff(tc.expected, list); !equal {
t.Errorf("\n%s", diff)
expectedJSON, _ := json.MarshalIndent(tc.expected, "", " ")
gotJSON, _ := json.MarshalIndent(list, "", " ")
t.Fatalf("unexpected JSON: \ngot \n%s\nwant\n%s", string(gotJSON), expectedJSON)
}
require.Equal(t, tc.expected, list)
})
}
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/datagatherer/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package k8s

import (
"github.com/pkg/errors"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
Expand All @@ -16,12 +15,12 @@ import (
func NewDynamicClient(kubeconfigPath string) (dynamic.Interface, error) {
cfg, err := kubeconfig.LoadRESTConfig(kubeconfigPath)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

cl, err := dynamic.NewForConfig(cfg)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

return cl, nil
Expand All @@ -33,12 +32,12 @@ func NewDynamicClient(kubeconfigPath string) (dynamic.Interface, error) {
func NewDiscoveryClient(kubeconfigPath string) (*discovery.DiscoveryClient, error) {
cfg, err := kubeconfig.LoadRESTConfig(kubeconfigPath)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

return discoveryClient, nil
Expand All @@ -50,12 +49,12 @@ func NewDiscoveryClient(kubeconfigPath string) (*discovery.DiscoveryClient, erro
func NewClientSet(kubeconfigPath string) (kubernetes.Interface, error) {
cfg, err := kubeconfig.LoadRESTConfig(kubeconfigPath)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

clientset, err := kubernetes.NewForConfig(cfg)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

return clientset, nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/datagatherer/k8s/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package k8s

import (
"context"
"errors"
"fmt"
"regexp"
"strings"
"time"

"github.com/pkg/errors"
"github.com/pmylund/go-cache"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -148,7 +148,7 @@ func (c *ConfigDynamic) NewDataGatherer(ctx context.Context) (datagatherer.DataG
if isNativeResource(c.GroupVersionResource) {
clientset, err := NewClientSet(c.KubeConfigPath)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

return c.newDataGathererWithClient(ctx, nil, clientset)
Expand Down Expand Up @@ -348,7 +348,7 @@ func (g *DataGathererDynamic) Fetch() (interface{}, int, error) {
// Redact Secret data
err := redactList(items, g.ExcludeAnnotKeys, g.ExcludeLabelKeys)
if err != nil {
return nil, -1, errors.WithStack(err)
return nil, -1, err
}

// add gathered resources to items
Expand All @@ -363,7 +363,7 @@ func redactList(list []*api.GatheredResource, excludeAnnotKeys, excludeLabelKeys
// Determine the kind of items in case this is a generic 'mixed' list.
gvks, _, err := scheme.Scheme.ObjectKinds(item)
if err != nil {
return errors.WithStack(err)
return err
}

resource := item
Expand Down Expand Up @@ -408,7 +408,7 @@ func redactList(list []*api.GatheredResource, excludeAnnotKeys, excludeLabelKeys
resource := item.(runtime.Object)
gvks, _, err := scheme.Scheme.ObjectKinds(resource)
if err != nil {
return errors.WithStack(err)
return err
}

// During the internal marshal/unmarshal the runtime.Object the metav1.TypeMeta seems to be lost
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kubeconfig

import (
"github.com/pkg/errors"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
Expand All @@ -24,7 +23,7 @@ func LoadRESTConfig(path string) (*rest.Config, error) {
&clientcmd.ConfigOverrides{},
).ClientConfig()
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}

return cfg, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/permissions/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package permissions
import (
"testing"

"github.com/maxatome/go-testdeep/td"
"github.com/stretchr/testify/require"
rbac "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -344,6 +344,6 @@ func TestGenerateAgentRBACManifests(t *testing.T) {
for _, input := range testCases {
got := GenerateAgentRBACManifests(input.dataGatherers)

td.Cmp(t, input.expectedAgentRBACManifests, got)
require.Equal(t, input.expectedAgentRBACManifests, got)
}
}