From aaff1c8964dbc6f9564b6c0a3f1fb9c2e2f94d49 Mon Sep 17 00:00:00 2001 From: chenk Date: Sun, 7 Jul 2024 12:40:08 +0300 Subject: [PATCH 1/2] fix: ignore nodes when listing permission is not allowed Signed-off-by: chenk --- pkg/k8s/k8s.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 6938b85..87de944 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -14,6 +14,7 @@ import ( "github.com/opencontainers/go-digest" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" k8sapierror "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -480,8 +481,9 @@ func GetContainer(hex string, imageName containerimage.Reference) (bom.Container func (c *cluster) CollectNodes(components []bom.Component) ([]bom.NodeInfo, error) { nodes, err := c.clientset.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return []bom.NodeInfo{}, err + if errors.IsNotFound(err) || errors.IsForbidden(err) { + slog.Error("Unable to list node resources", "error", err) + return []bom.NodeInfo{}, nil } nodesInfo := make([]bom.NodeInfo, 0) for _, node := range nodes.Items { From 40fe9dd9134d524ab3a88d737251260f9dbae36c Mon Sep 17 00:00:00 2001 From: chenk Date: Sun, 7 Jul 2024 12:46:32 +0300 Subject: [PATCH 2/2] fix: ignore nodes when listing permission is not allowed Signed-off-by: chenk --- pkg/k8s/k8s.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 87de944..58cc49c 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -481,9 +481,12 @@ func GetContainer(hex string, imageName containerimage.Reference) (bom.Container func (c *cluster) CollectNodes(components []bom.Component) ([]bom.NodeInfo, error) { nodes, err := c.clientset.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) - if errors.IsNotFound(err) || errors.IsForbidden(err) { - slog.Error("Unable to list node resources", "error", err) - return []bom.NodeInfo{}, nil + if err != nil { + if errors.IsNotFound(err) || errors.IsForbidden(err) { + slog.Error("Unable to list node resources", "error", err) + return []bom.NodeInfo{}, nil + } + return nil, err } nodesInfo := make([]bom.NodeInfo, 0) for _, node := range nodes.Items {