Skip to content

Commit

Permalink
Exclude metrics.k8s.io from watch (argoproj#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Feb 15, 2019
1 parent 83bcf46 commit d9a395f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions util/kube/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k KubectlCmd) GetAPIResources(config *rest.Config) ([]*metav1.APIResourceL
func (k KubectlCmd) GetResources(config *rest.Config, namespace string) ([]*unstructured.Unstructured, error) {

listSupported := func(groupVersion string, apiResource *metav1.APIResource) bool {
return isSupportedVerb(apiResource, listVerb) && !isExcludedResourceGroup(*apiResource)
return isSupportedVerb(apiResource, listVerb) && !isExcludedResourceGroup(apiResource.Group)
}
apiResIfs, err := filterAPIResources(config, listSupported, namespace)
if err != nil {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (k KubectlCmd) WatchResources(
namespace string,
) (chan watch.Event, error) {
watchSupported := func(groupVersion string, apiResource *metav1.APIResource) bool {
return isSupportedVerb(apiResource, watchVerb) && !isExcludedResourceGroup(*apiResource)
return isSupportedVerb(apiResource, watchVerb) && !isExcludedResourceGroup(apiResource.Group)
}
log.Infof("Start watching for resources changes with in cluster %s", config.Host)
apiResIfs, err := filterAPIResources(config, watchSupported, namespace)
Expand Down
13 changes: 10 additions & 3 deletions util/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,15 @@ func IsCRD(obj *unstructured.Unstructured) bool {
return IsCRDGroupVersionKind(obj.GroupVersionKind())
}

func isExcludedResourceGroup(resource metav1.APIResource) bool {
return false
// excludedAPIGroups is a list of groups that we do not care to monitor
var excludedAPIGroups = map[string]bool{
"events.k8s.io": true,
"metrics.k8s.io": true,
}

func isExcludedResourceGroup(group string) bool {
_, ok := excludedAPIGroups[group]
return ok
}

type apiResourceInterface struct {
Expand Down Expand Up @@ -280,7 +287,7 @@ func filterAPIResources(config *rest.Config, filter filterFunc, namespace string
if err != nil {
gv = schema.GroupVersion{}
}
if gv.Group == "events.k8s.io" {
if isExcludedResourceGroup(gv.Group) {
continue
}
for _, apiResource := range apiResourcesList.APIResources {
Expand Down

0 comments on commit d9a395f

Please sign in to comment.