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

Exclude the metrics APIs from resources discovery #2606

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ github.com/Azure/go-autorest v11.7.1+incompatible h1:M2YZIajBBVekV86x0rr1443Lc1F
github.com/Azure/go-autorest v11.7.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
Expand Down
35 changes: 19 additions & 16 deletions pkg/cluster/kubernetes/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"

"github.com/fluxcd/flux/pkg/cluster"
Expand Down Expand Up @@ -208,21 +207,25 @@ func (c *Cluster) getAllowedResourcesBySelector(selector string) (map[string]*ku
listOptions.LabelSelector = selector
}

_, resources, err := c.client.discoveryClient.ServerGroupsAndResources()
if err != nil {
discErr, ok := err.(*discovery.ErrGroupDiscoveryFailed)
if !ok {
return nil, err
}
for gv, e := range discErr.Groups {
if gv.Group == "metrics" || strings.HasSuffix(gv.Group, "metrics.k8s.io") {
// The Metrics API tends to be misconfigured, causing errors.
// We just ignore them, since it doesn't make sense to sync metrics anyways.
continue
}
// Tolerate empty GroupVersions due to e.g. misconfigured custom metrics
if e.Error() != fmt.Sprintf("Got empty response for: %v", gv) {
return nil, err
sgs, err := c.client.discoveryClient.ServerGroups()
if sgs == nil {
return nil, err
}

resources := []*meta_v1.APIResourceList{}
for i := range sgs.Groups {
gv := sgs.Groups[i].PreferredVersion.GroupVersion
// exclude the *.metrics.k8s.io resources to avoid querying the cluster metrics
if sgs.Groups[i].Name != "metrics.k8s.io" && !strings.HasSuffix(sgs.Groups[i].Name, ".metrics.k8s.io") {
squaremo marked this conversation as resolved.
Show resolved Hide resolved
if r, err := c.client.discoveryClient.ServerResourcesForGroupVersion(gv); err == nil {
if r != nil {
resources = append(resources, r)
}
} else {
// ignore errors for resources with empty group version instead of failing to sync
if err.Error() != fmt.Sprintf("Got empty response for: %v", gv) {
return nil, err
}
}
}
}
Expand Down