...

Source file src/sigs.k8s.io/cli-utils/pkg/kstatus/watcher/object_filter.go

Documentation: sigs.k8s.io/cli-utils/pkg/kstatus/watcher

     1  // Copyright 2022 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package watcher
     5  
     6  import (
     7  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     8  	"sigs.k8s.io/cli-utils/pkg/object"
     9  )
    10  
    11  // ObjectFilter allows for filtering objects.
    12  type ObjectFilter interface {
    13  	// Filter returns true if the object should be skipped.
    14  	Filter(obj *unstructured.Unstructured) bool
    15  }
    16  
    17  // AllowListObjectFilter filters objects not in the allow list.
    18  // AllowListObjectFilter implements ObjectFilter.
    19  type AllowListObjectFilter struct {
    20  	AllowList object.ObjMetadataSet
    21  }
    22  
    23  var _ ObjectFilter = &AllowListObjectFilter{}
    24  
    25  // Filter returns true if the object should be skipped, because it is NOT in the
    26  // AllowList.
    27  func (f *AllowListObjectFilter) Filter(obj *unstructured.Unstructured) bool {
    28  	id := object.UnstructuredToObjMetadata(obj)
    29  	return !f.AllowList.Contains(id)
    30  }
    31  

View as plain text