Skip to content

Commit 8e5b6d7

Browse files
alam0rtahmetb
andauthored
Skip forbidden resources as they are rarely required (#55)
Co-authored-by: Ahmet Alp Balkan <[email protected]>
1 parent 8c32ac5 commit 8e5b6d7

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup Go
1212
uses: actions/setup-go@v1
1313
with:
14-
go-version: '1.20'
14+
go-version-file: 'go.mod'
1515
- name: GoReleaser
1616
uses: goreleaser/goreleaser-action@v1
1717
with:

Diff for: .github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup Go
1313
uses: actions/setup-go@v1
1414
with:
15-
go-version: '1.20'
15+
go-version-file: 'go.mod'
1616
- name: GoReleaser
1717
uses: goreleaser/goreleaser-action@v1
1818
with:

Diff for: cmd/kubectl-tree/query.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package main
22

33
import (
44
"context"
5+
stderrors "errors"
56
"fmt"
67
"sync"
78
"time"
89

10+
"k8s.io/apimachinery/pkg/api/errors"
911
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1012
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1113
"k8s.io/client-go/dynamic"
@@ -33,8 +35,14 @@ func getAllResources(client dynamic.Interface, apis []apiResource, allNs bool) (
3335
klog.V(4).Infof("[query api] start: %s", a.GroupVersionResource())
3436
v, err := queryAPI(client, a, allNs)
3537
if err != nil {
36-
klog.V(4).Infof("[query api] error querying: %s, error=%v", a.GroupVersionResource(), err)
37-
errResult = err
38+
if errors.IsForbidden(err) {
39+
// should not fail the overall process, but print an info message indicating the permission issue
40+
klog.V(4).Infof("[query api] skipping forbidden resource: %s", a.GroupVersionResource())
41+
klog.Infof("cannot query %s (forbidden), omitting from the tree", a.GroupVersionResource().GroupResource())
42+
} else {
43+
klog.V(4).Infof("[query api] error querying: %s, error=%v", a.GroupVersionResource(), err)
44+
errResult = stderrors.Join(errResult, fmt.Errorf("failed to query the %s resources: %w", a.GroupVersionResource(), err))
45+
}
3846
return
3947
}
4048
mu.Lock()

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ahmetb/kubectl-tree
22

3-
go 1.20
3+
go 1.22
44

55
require (
66
github.com/fatih/color v1.15.0

0 commit comments

Comments
 (0)