Documentation
¶
Index ¶
- Constants
- Variables
- func GetEnvValueAsInt(envKey string, defaultValue int) (int, error)
- func MatchLabels(labels map[string]string, labelSelector string) bool
- type EnforcedConfigLevel
- type GlobalConfig
- type HistoryLimiter
- type HistoryLimiterResourceFuncs
- type NamespaceSpec
- type PrunerConfig
- type PrunerFieldType
- type PrunerResourceType
- type ResourceSpec
- type SelectorSpec
- type TTLHandler
- type TTLResourceFuncs
Constants ¶
const ( // PrunerResourceTypePipelineRun represents the resource type for a PipelineRun in the pruner. PrunerResourceTypePipelineRun PrunerResourceType = "pipelineRun" // PrunerResourceTypeTaskRun represents the resource type for a TaskRun in the pruner. PrunerResourceTypeTaskRun PrunerResourceType = "taskRun" // PrunerFieldTypeTTLSecondsAfterFinished represents the field type for the TTL (Time-to-Live) in seconds after the resource is finished. PrunerFieldTypeTTLSecondsAfterFinished PrunerFieldType = "ttlSecondsAfterFinished" // PrunerFieldTypeSuccessfulHistoryLimit represents the field type for the successful history limit of a resource. PrunerFieldTypeSuccessfulHistoryLimit PrunerFieldType = "successfulHistoryLimit" // PrunerFieldTypeFailedHistoryLimit represents the field type for the failed history limit of a resource. PrunerFieldTypeFailedHistoryLimit PrunerFieldType = "failedHistoryLimit" // EnforcedConfigLevelGlobal represents the cluster-wide config level for pruner. EnforcedConfigLevelGlobal EnforcedConfigLevel = "global" // EnforcedConfigLevelNamespace represents the namespace config level for pruner. EnforcedConfigLevelNamespace EnforcedConfigLevel = "namespace" // EnforcedConfigLevelResource represents the resource-level config for pruner. EnforcedConfigLevelResource EnforcedConfigLevel = "resource" )
const ( // EnvSystemNamespace is the environment variable name used to define the system namespace // it is used for setting the namespace where pruner-related resources are managed EnvSystemNamespace = "SYSTEM_NAMESPACE" // EnvTTLConcurrentWorkersPipelineRun is the environment variable name // used to specify the count of concurrent workers in action to prune pipelineruns EnvTTLConcurrentWorkersPipelineRun = "TTL_CONCURRENT_WORKERS_PIPELINE_RUN" // EnvTTLConcurrentWorkersTaskRun is the environment variable name // used to specify the count of concurrent workers in action to prune taskruns EnvTTLConcurrentWorkersTaskRun = "TTL_CONCURRENT_WORKERS_TASK_RUN" // LabelPipelineName represents the label key in a pipeline run's metadata, // where its value corresponds to the name of the pipeline LabelPipelineName = "tekton.dev/pipeline" // LabelPipelineRunName represents the label key in a pipeline run's metadata, // where its value corresponds to the name of the pipeline run LabelPipelineRunName = "tekton.dev/pipelineRun" // LabelTaskName represents the label key in a task run's metadata, // where its value corresponds to the name of the task LabelTaskName = "tekton.dev/task" // LabelTaskRunName represents the label key in a task run's metadata, // where its value corresponds to the name of the task run LabelTaskRunName = "tekton.dev/taskRun" // KindPipelineRun represents the kind value of pipelineRun custom resource KindPipelineRun = "PipelineRun" // KindTaskRun represents the kind value of taskRun custom resource KindTaskRun = "TaskRun" // AnnotationTTLSecondsAfterFinished represents the annotation key // that stores the ttlSecondsAfterFinished value for the resource. AnnotationTTLSecondsAfterFinished = "pruner.tekton.dev/ttlSecondsAfterFinished" // AnnotationResourceNameLabelKey represents the annotation key // that stores the label key value used to uniquely identify the resource. AnnotationResourceNameLabelKey = "pruner.tekton.dev/resourceNameLabelKey" // AnnotationSuccessfulHistoryLimit represents the annotation key // that stores the successfulHistoryLimit value for the resource. AnnotationSuccessfulHistoryLimit = "pruner.tekton.dev/successfulHistoryLimit" // AnnotationFailedHistoryLimit represents the annotation key // that stores the failedHistoryLimit value for the resource. AnnotationFailedHistoryLimit = "pruner.tekton.dev/failedHistoryLimit" // AnnotationHistoryLimitCheckProcessed represents the annotation key // that indicates whether history limit checks have been processed for the resource. AnnotationHistoryLimitCheckProcessed = "pruner.tekton.dev/historyLimitCheckProcessed" // PrunerConfigMapName represents the name of the config map // that holds the cluster-wide pruner configuration data PrunerConfigMapName = "tekton-pruner-default-spec" // PrunerGlobalConfigKey represents the key name // used to fetch the cluster-wide pruner configuration data PrunerGlobalConfigKey = "global-config" // DefaultTTLConcurrentWorkersPipelineRun represents // number of workers in the PipelineRun controller DefaultTTLConcurrentWorkersPipelineRun = int(5) // DefaultTTLConcurrentWorkersTaskRun represents // number of workers in the TaskRun controller DefaultTTLConcurrentWorkersTaskRun = int(5) // DefaultGCInterval represents // interval in seconds for the periodic cleanup i.e garbage collector to run DefaultPeriodicCleanupIntervalSeconds = 600 // 10 minutes // DefaultWorkerCountForNamespaceCleanup represents the number of workers to be used // for cleaning up resources in a namespace concurrently DefaultWorkerCountForNamespaceCleanup = 5 // DefaultHistoryLimit represents the default history limit for successful and failed resources DefaultHistoryLimit = 100 )
const ( // NoTTL represents a TTL value that indicates no TTL should be applied NoTTL = "-1" // DefaultTTL represents the default TTL duration if none is specified DefaultTTL = 0 )
Variables ¶
var ( // PrunerConfigStore is the singleton instance to store pruner config PrunerConfigStore = prunerConfigStore{/* contains filtered or unexported fields */} )
Functions ¶
func GetEnvValueAsInt ¶
GetEnvValueAsInt fetches the value of an environment variable and converts it to an integer if the environment variable is not set or if the conversion fails, it returns a default value
Types ¶
type EnforcedConfigLevel ¶
type EnforcedConfigLevel string
EnforcedConfigLevel is a string type to manage the different override levels allowed for Pruner config
type GlobalConfig ¶
type GlobalConfig struct {
PrunerConfig `yaml:",inline"`
Namespaces map[string]NamespaceSpec `yaml:"namespaces" json:"namespaces"`
}
type HistoryLimiter ¶
type HistoryLimiter struct {
// contains filtered or unexported fields
}
HistoryLimiter is a struct that encapsulates functionality for managing resources with history limits. It uses the HistoryLimiterResourceFuncs interface to interact with different types of resources
func NewHistoryLimiter ¶
func NewHistoryLimiter(resourceFn HistoryLimiterResourceFuncs) (*HistoryLimiter, error)
NewHistoryLimiter creates a new instance of HistoryLimiter, ensuring that the provided HistoryLimiterResourceFuncs interface is not nil
func (*HistoryLimiter) DoFailedResourceCleanup ¶
func (*HistoryLimiter) DoSuccessfulResourceCleanup ¶
func (*HistoryLimiter) ProcessEvent ¶
ProcessEvent processes an event for a given resource and performs cleanup based on its status. The method checks if the resource is in a deletion state, whether it has already been processed, and if it's in a completed state. Depending on the resource's completion status, it will either trigger cleanup for successful or failed resources
type HistoryLimiterResourceFuncs ¶
type HistoryLimiterResourceFuncs interface {
Type() string
Get(ctx context.Context, namespace, name string) (metav1.Object, error)
Update(ctx context.Context, resource metav1.Object) error
Patch(ctx context.Context, namespace, name string, patchBytes []byte) error
Delete(ctx context.Context, namespace, name string) error
List(ctx context.Context, namespace, label string) ([]metav1.Object, error)
GetFailedHistoryLimitCount(namespace, name string, selectors SelectorSpec) (*int32, string)
GetSuccessHistoryLimitCount(namespace, name string, selectors SelectorSpec) (*int32, string)
IsSuccessful(resource metav1.Object) bool
IsFailed(resource metav1.Object) bool
IsCompleted(resource metav1.Object) bool
GetDefaultLabelKey() string
GetEnforcedConfigLevel(namespace, name string, selectors SelectorSpec) EnforcedConfigLevel
}
HistoryLimiterResourceFuncs defines a set of methods that operate on resources with history limit capabilities.
type NamespaceSpec ¶
type NamespaceSpec struct {
PrunerConfig `yaml:",inline"`
PipelineRuns []ResourceSpec `yaml:"pipelineRuns"`
TaskRuns []ResourceSpec `yaml:"taskRuns"`
}
NamespaceSpec is used to hold the pruning config of a specific namespace and its resources
type PrunerConfig ¶
type PrunerConfig struct {
// EnforcedConfigLevel allowed values: global, namespace, resource (default: resource)
EnforcedConfigLevel *EnforcedConfigLevel `yaml:"enforcedConfigLevel" json:"enforcedConfigLevel"`
TTLSecondsAfterFinished *int32 `yaml:"ttlSecondsAfterFinished" json:"ttlSecondsAfterFinished"`
SuccessfulHistoryLimit *int32 `yaml:"successfulHistoryLimit" json:"successfulHistoryLimit"`
FailedHistoryLimit *int32 `yaml:"failedHistoryLimit" json:"failedHistoryLimit"`
HistoryLimit *int32 `yaml:"historyLimit" json:"historyLimit"`
}
PrunerConfig used to hold the cluster-wide pruning config as well as namespace specific pruning config
func (*PrunerConfig) SetDefaults ¶
func (pc *PrunerConfig) SetDefaults()
type PrunerFieldType ¶
type PrunerFieldType string
PrunerFieldType is a string type used to represent different configuration types for pruner
type PrunerResourceType ¶
type PrunerResourceType string
PrunerResourceType is a string type used to represent different types of resources that the pruner manages
type ResourceSpec ¶
type ResourceSpec struct {
Name string `yaml:"name"` // Exact name of the parent Pipeline or Task
Selector []SelectorSpec `yaml:"selector,omitempty"` // Supports selection based on labels and annotations. If Name is given, Name taskes precedence
PrunerConfig `yaml:",inline"`
}
ResourceSpec is used to hold the config of a specific resource
type SelectorSpec ¶
type SelectorSpec struct {
// Match by labels or Annotations. If both are specified, Annotations will take priority.
MatchLabels map[string]string `yaml:"matchLabels,omitempty"`
MatchAnnotations map[string]string `yaml:"matchAnnotations,omitempty"`
}
SelectorSpec allows specifying selectors for matching resources like PipelineRun or TaskRun
type TTLHandler ¶
type TTLHandler struct {
// contains filtered or unexported fields
}
TTLHandler is responsible for managing resources with a Time-To-Live (TTL) configuration
func NewTTLHandler ¶
func NewTTLHandler(clock clockUtil.Clock, resourceFn TTLResourceFuncs) (*TTLHandler, error)
NewTTLHandler creates a new instance of TTLHandler, which is responsible for managing resources with a Time-To-Live (TTL) configuration and initializes a TTLHandler with the provided clock and resource function interface.
func (*TTLHandler) ProcessEvent ¶
ProcessEvent handles an event for a resource by processing its TTL-based actions. It evaluates the resource's state, checks whether it should be cleaned up, and updates the TTL annotation if needed
type TTLResourceFuncs ¶
type TTLResourceFuncs interface {
Type() string
Get(ctx context.Context, namespace, name string) (metav1.Object, error)
Delete(ctx context.Context, namespace, name string) error
Patch(ctx context.Context, namespace, name string, patchBytes []byte) error
Update(ctx context.Context, resource metav1.Object) error
IsCompleted(resource metav1.Object) bool
GetCompletionTime(resource metav1.Object) (metav1.Time, error)
Ignore(resource metav1.Object) bool
GetTTLSecondsAfterFinished(namespace, name string, selectors SelectorSpec) (*int32, string)
GetDefaultLabelKey() string
GetEnforcedConfigLevel(namespace, name string, selectors SelectorSpec) EnforcedConfigLevel
}
TTLResourceFuncs defines the set of functions that should be implemented for resources that are subject to Time-To-Live (TTL) management, including determining whether a resource is completed, updating or deleting the resource, and handling the TTL (time-to-live) after the resource is finished