Documentation
¶
Index ¶
- Constants
- func AgeFilter(object runtime.Object, opts *Options) bool
- func HasExcludedLabel(resourcelabels map[string]string, excludeSelector []string) (bool, error)
- func HasIncludedAge(creationTime metav1.Time, filterOpts *Options) (bool, error)
- func KorLabelFilter(object runtime.Object, opts *Options) bool
- func LabelFilter(object runtime.Object, opts *Options) bool
- type FilterFunc
- type Framework
- type Options
- type Registry
Constants ¶
const ( LabelFilterName = "label" AgeFilterName = "age" KorLabelFilterName = "korlabel" )
Variables ¶
This section is empty.
Functions ¶
func HasExcludedLabel ¶
HasExcludedLabel parses the excluded selector into a label selector object
func HasIncludedAge ¶
HasIncludedAge checks if a resource has an age that matches the included criteria specified by the filter options A resource is considered to have an included age if its age (measured from the last modified time) is within the range specified by older-than and newer-than flags. If older-than or newer-than is zero, no age limit is applied. If both flags are set, an error is returned.
func KorLabelFilter ¶
KorLabelFilter is a filter that filters out resources that are ["kor/used"] != "true"
Types ¶
type FilterFunc ¶
FilterFunc is a filter that is a function If the resource is legal, return true example: deployment.Spec.Replicas > 0; return true meta.GetLabels()["kor/used"] == "true"; return true
type Framework ¶
type Framework interface {
// Run runs all the filters in the framework
// If the resource is legal, return true
Run(opts *Options, disable ...string) (bool, error)
// AddFilter adds a filter to the framework
AddFilter(name string, f FilterFunc) Framework
// SetRegistry sets the registry of the framework
SetRegistry(r Registry) Framework
// SetObject sets the object of the framework
SetObject(object runtime.Object) Framework
// RunFilter runs a filter in the framework
// name not found, return true
RunFilter(name string, opts *Options) (bool, error)
}
Framework is a filter framework
func NewNormalFramework ¶
type Options ¶
type Options struct {
// OlderThan is the minimum age of the resources to be considered unused
OlderThan string
// NewerThan is the maximum age of the resources to be considered unused
NewerThan string
// ExcludeLabels is a label selector to exclude resources with matching labels
// IncludeLabels conflicts with it, and when setting IncludeLabels, ExcludeLabels is ignored and set to empty
ExcludeLabels []string
// IncludeLabels is a label selector to include resources with matching labels
IncludeLabels string
// ExcludeNamespaces is a namespace selector to exclude resources in matching namespaces
// IncludeNamespaces conflicts with it, and when setting IncludeNamespaces, ExcludeNamespaces is ignored and set to empty
ExcludeNamespaces []string
// IncludeNamespaces is a namespace selector to include resources in matching namespaces
IncludeNamespaces []string
// contains filtered or unexported fields
}
Options represents the flags and options for filtering unused Kubernetes resources, such as pods, services, or configmaps. A resource is considered unused if it meets the following conditions:
- Its age (measured from the last modified time) is within the range specified by older-than and newer-than flags. If older-than or newer-than is zero, no age limit is applied. If both flags are set, an error is returned.
- Its size (measured in bytes) is within the range specified by MinSize and MaxSize flags. If MinSize or MaxSize is zero, no size limit is applied.
- It does not have any labels that match the ExcludeLabels flag. The ExcludeLabels flag supports '=', '==', and '!=' operators, and multiple label pairs can be separated by commas. For example, -l key1=value1,key2!=value2.
func NewFilterOptions ¶
func NewFilterOptions() *Options
NewFilterOptions returns a new FilterOptions instance with default values
func (*Options) Namespaces ¶
func (o *Options) Namespaces(clientset kubernetes.Interface) []string
Namespaces returns the namespaces, only called once
type Registry ¶
type Registry map[string]FilterFunc
Registry is a collection of all available filters. The framework uses a
func NewDefaultRegistry ¶
func NewDefaultRegistry() Registry