@@ -30,6 +30,7 @@ import (
3030 "k8s.io/client-go/kubernetes"
3131 "k8s.io/client-go/kubernetes/scheme"
3232 "k8s.io/client-go/rest"
33+ "k8s.io/klog/v2"
3334 "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
3435
3536 "github.com/replicatedhq/troubleshoot/pkg/k8sutil/discovery"
@@ -100,6 +101,7 @@ EMPTY_NAMESPACE_FOUND:
100101}
101102
102103func (c * CollectClusterResources ) Collect (progressChan chan <- interface {}) (CollectorResult , error ) {
104+ klog .V (4 ).Infof ("CollectClusterResources.Collect" )
103105 client , err := kubernetes .NewForConfig (c .ClientConfig )
104106 if err != nil {
105107 return nil , err
@@ -118,16 +120,19 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
118120 var namespaceNames []string
119121 if len (c .Collector .Namespaces ) > 0 {
120122 namespaces , namespaceErrors := getNamespaces (ctx , client , c .Collector .Namespaces )
123+ klog .V (4 ).Infof ("checking for namespaces access: %s" , string (namespaces ))
121124 namespaceNames = c .Collector .Namespaces
122125 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s.json" , constants .CLUSTER_RESOURCES_NAMESPACES )), bytes .NewBuffer (namespaces ))
123126 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_NAMESPACES )), marshalErrors (namespaceErrors ))
124127 } else if c .Namespace != "" {
125128 namespace , namespaceErrors := getNamespace (ctx , client , c .Namespace )
129+ klog .V (4 ).Infof ("checking for namespace access: %s" , string (namespace ))
126130 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s.json" , constants .CLUSTER_RESOURCES_NAMESPACES )), bytes .NewBuffer (namespace ))
127131 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_NAMESPACES )), marshalErrors (namespaceErrors ))
128132 namespaceNames = append (namespaceNames , c .Namespace )
129133 } else {
130134 namespaces , namespaceList , namespaceErrors := getAllNamespaces (ctx , client )
135+ klog .V (4 ).Infof ("checking for all namespaces access: %s" , string (namespaces ))
131136 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s.json" , constants .CLUSTER_RESOURCES_NAMESPACES )), bytes .NewBuffer (namespaces ))
132137 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_NAMESPACES )), marshalErrors (namespaceErrors ))
133138 if namespaceList != nil {
@@ -156,6 +161,7 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
156161 }
157162 }
158163 namespaceNames = filteredNamespaces
164+ klog .V (4 ).Infof ("filtered to namespaceNames %s" , namespaceNames )
159165 }
160166
161167 // pods
@@ -1598,6 +1604,10 @@ func getSelfSubjectRulesReviews(ctx context.Context, client *kubernetes.Clientse
15981604 continue
15991605 }
16001606
1607+ if response .Status .Incomplete == true {
1608+ errorsByNamespace [namespace ] = response .Status .EvaluationError
1609+ }
1610+
16011611 statusByNamespace [namespace ] = response .Status .DeepCopy ()
16021612 }
16031613
@@ -1661,13 +1671,20 @@ func events(ctx context.Context, client *kubernetes.Clientset, namespaces []stri
16611671func canCollectNamespaceResources (status * authorizationv1.SubjectRulesReviewStatus ) bool {
16621672 // This is all very approximate
16631673
1674+ if status .Incomplete && (status .EvaluationError == constants .SELFSUBJECTRULESREVIEW_ERROR_AUTHORIZATION_WEBHOOK_UNSUPPORTED ) {
1675+ klog .V (4 ).Infof ("could not negotiate RBAC because of an unsupported authorizer webhook; try to get resources from this namespace anyway." )
1676+ return true
1677+ }
1678+
1679+ klog .V (4 ).Infof ("canCollectNamespaceResources: %+v" , status )
16641680 for _ , resource := range status .ResourceRules {
16651681 hasGet := false
16661682 for _ , verb := range resource .Verbs {
16671683 if verb == "*" || verb == "get" {
16681684 hasGet = true
16691685 break
16701686 }
1687+ klog .V (4 ).Infof ("resource: %+v hasGet: %t" , resource , hasGet )
16711688 }
16721689
16731690 hasAPI := false
@@ -1676,6 +1693,7 @@ func canCollectNamespaceResources(status *authorizationv1.SubjectRulesReviewStat
16761693 hasAPI = true
16771694 break
16781695 }
1696+ klog .V (4 ).Infof ("group: %+v hasGet: %t" , group , hasAPI )
16791697 }
16801698
16811699 hasPods := false
@@ -1684,6 +1702,7 @@ func canCollectNamespaceResources(status *authorizationv1.SubjectRulesReviewStat
16841702 hasPods = true
16851703 break
16861704 }
1705+ klog .V (4 ).Infof ("resource: %+v hasPods: %t" , resource , hasPods )
16871706 }
16881707
16891708 if hasGet && hasAPI && hasPods {
0 commit comments