Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Continue when k8s returns Forbidden when getting resources of resourc… #1620

Merged
merged 1 commit into from
Dec 31, 2018
Merged
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
30 changes: 24 additions & 6 deletions cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,18 @@ func (c *Cluster) AllControllers(namespace string) (res []cluster.Controller, er
for kind, resourceKind := range resourceKinds {
podControllers, err := resourceKind.getPodControllers(c, ns.Name)
if err != nil {
if se, ok := err.(*apierrors.StatusError); ok && se.ErrStatus.Reason == meta_v1.StatusReasonNotFound {
// Kind not supported by API server, skip
continue
if se, ok := err.(*apierrors.StatusError); ok {
switch (se.ErrStatus.Reason) {
case meta_v1.StatusReasonNotFound:
// Kind not supported by API server, skip
continue
case meta_v1.StatusReasonForbidden:
// K8s can return forbidden instead of not found for non super admins
c.logger.Log("warning", "not allowed to list resources", "err", err)
continue
default:
return nil, err
}
} else {
return nil, err
}
Expand Down Expand Up @@ -281,9 +290,18 @@ func (c *Cluster) Export() ([]byte, error) {
for _, resourceKind := range resourceKinds {
podControllers, err := resourceKind.getPodControllers(c, ns.Name)
if err != nil {
if se, ok := err.(*apierrors.StatusError); ok && se.ErrStatus.Reason == meta_v1.StatusReasonNotFound {
// Kind not supported by API server, skip
continue
if se, ok := err.(*apierrors.StatusError); ok {
switch (se.ErrStatus.Reason) {
case meta_v1.StatusReasonNotFound:
// Kind not supported by API server, skip
continue
case meta_v1.StatusReasonForbidden:
// K8s can return forbidden instead of not found for non super admins
c.logger.Log("warning", "not allowed to list resources", "err", err)
continue
default:
return nil, err
}
} else {
return nil, err
}
Expand Down