diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f793692..4836460 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: '1.23' + go-version-file: 'go.mod' - name: GoReleaser uses: goreleaser/goreleaser-action@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 405a86d..7bf08bb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v1 with: - go-version: '1.23' + go-version-file: 'go.mod' - name: GoReleaser uses: goreleaser/goreleaser-action@v1 with: diff --git a/cmd/kubectl-tree/query.go b/cmd/kubectl-tree/query.go index 0591d2c..3e9517b 100644 --- a/cmd/kubectl-tree/query.go +++ b/cmd/kubectl-tree/query.go @@ -2,10 +2,12 @@ package main import ( "context" + stderrors "errors" "fmt" "sync" "time" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/client-go/dynamic" @@ -33,8 +35,14 @@ func getAllResources(client dynamic.Interface, apis []apiResource, allNs bool) ( klog.V(4).Infof("[query api] start: %s", a.GroupVersionResource()) v, err := queryAPI(client, a, allNs) if err != nil { - klog.V(4).Infof("[query api] error querying: %s, error=%v", a.GroupVersionResource(), err) - errResult = err + if errors.IsForbidden(err) { + // should not fail the overall process, but print an info message indicating the permission issue + klog.V(4).Infof("[query api] skipping forbidden resource: %s", a.GroupVersionResource()) + klog.Infof("cannot query %s (forbidden), omitting from the tree", a.GroupVersionResource().GroupResource()) + } else { + klog.V(4).Infof("[query api] error querying: %s, error=%v", a.GroupVersionResource(), err) + errResult = stderrors.Join(errResult, fmt.Errorf("failed to query the %s resources: %w", a.GroupVersionResource(), err)) + } return } mu.Lock() diff --git a/go.mod b/go.mod index fd52224..8e9884c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ahmetb/kubectl-tree -go 1.20 +go 1.22 require ( github.com/fatih/color v1.15.0