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

Commit

Permalink
Add certmanager's webhook to excluded groups list
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Jan 15, 2020
1 parent a144686 commit 57802b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/cluster/kubernetes/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ func (r *kuberesource) GetGCMark() string {
return r.obj.GetLabels()[gcMarkLabel]
}

var excludedGroups = []string{"metrics.k8s.io", "webhook.certmanager.k8s.io"}

func (c *Cluster) getAllowedResourcesBySelector(selector string) (map[string]*kuberesource, error) {
listOptions := meta_v1.ListOptions{}
if selector != "" {
Expand All @@ -215,8 +217,16 @@ func (c *Cluster) getAllowedResourcesBySelector(selector string) (map[string]*ku
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") {

excluded := false
for _, exg := range excludedGroups {
if strings.HasSuffix(sgs.Groups[i].Name, exg) {
excluded = true
break
}
}

if !excluded {
if r, err := c.client.discoveryClient.ServerResourcesForGroupVersion(gv); err == nil {
if r != nil {
resources = append(resources, r)
Expand Down
5 changes: 5 additions & 0 deletions pkg/cluster/kubernetes/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ func TestSyncTolerateMetricsErrors(t *testing.T) {
fakeClient.Resources = []*metav1.APIResourceList{{GroupVersion: "custom.metrics.k8s.io/v1"}}
err = kube.Sync(cluster.SyncSet{})
assert.NoError(t, err)

kube.client.discoveryClient.(*cachedDiscovery).CachedDiscoveryInterface.Invalidate()
fakeClient.Resources = []*metav1.APIResourceList{{GroupVersion: "webhook.certmanager.k8s.io/v1beta1"}}
err = kube.Sync(cluster.SyncSet{})
assert.NoError(t, err)
}

func TestSync(t *testing.T) {
Expand Down

0 comments on commit 57802b0

Please sign in to comment.