config

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
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"
)
View Source
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"

	// PrunerNamespaceConfigMapName represents the name of the config map
	// that holds the namespace-level pruner configuration data
	PrunerNamespaceConfigMapName = "tekton-pruner-namespace-spec"

	// PrunerGlobalConfigKey represents the key name
	// used to fetch the cluster-wide pruner configuration data
	PrunerGlobalConfigKey = "global-config"

	// PrunerNamespaceConfigKey represents the key name
	// used to fetch the namespace-level pruner configuration data
	PrunerNamespaceConfigKey = "ns-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

	// MaxTTLSecondsAfterFinished represents the maximum TTL in seconds that can be set
	// when no explicit global limit is defined. This is 30 days (2,592,000 seconds)
	MaxTTLSecondsAfterFinished = 2592000

	// MaxHistoryLimit represents the maximum history limit that can be set
	// when no explicit global limit is defined for history-based retention
	MaxHistoryLimit = 100
)
View Source
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

View Source
var (
	// PrunerConfigStore is the singleton instance to store pruner config
	PrunerConfigStore = prunerConfigStore{
		// contains filtered or unexported fields
	}
)

Functions

func GetEnvValueAsInt

func GetEnvValueAsInt(envKey string, defaultValue int) (int, error)

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

func MatchLabels

func MatchLabels(labels map[string]string, labelSelector string) bool

Helper function to match labels against label selector

func ValidateConfigMap added in v0.3.0

func ValidateConfigMap(cm *corev1.ConfigMap) error

func ValidateConfigMapWithGlobal added in v0.3.0

func ValidateConfigMapWithGlobal(cm *corev1.ConfigMap, globalConfigMap *corev1.ConfigMap) error

ValidateConfigMapWithGlobal validates a ConfigMap with optional global config for limit enforcement If globalConfigMap is provided and cm is a namespace-level config, it validates that namespace limits do not exceed global limits

func ValidateGlobalConfig added in v0.3.3

func ValidateGlobalConfig(globalConfig *GlobalConfig) error

ValidateGlobalConfig validates a GlobalConfig struct directly without ConfigMap conversion This is a convenience function for validating global config and all nested namespace configs without the overhead of serialization/deserialization through ConfigMaps.

Use this function when you have a GlobalConfig struct and want to validate it directly, for example when validating configuration from operator CRDs or other non-ConfigMap sources.

For ConfigMap-based validation, use ValidateConfigMap or ValidateConfigMapWithGlobal instead.

func ValidateNamespaceSpec added in v0.3.3

func ValidateNamespaceSpec(namespaceSpec *NamespaceSpec, namespace string, globalConfig *GlobalConfig) error

ValidateNamespaceSpec validates a NamespaceSpec struct directly without ConfigMap conversion This function validates namespace-level configuration against optional global limits.

Parameters:

  • namespaceSpec: The namespace configuration to validate
  • namespace: The namespace name (used for error messages)
  • globalConfig: Optional global config for limit enforcement (can be nil)

Use this function when you have a NamespaceSpec struct and want to validate it directly, for example when validating configuration from operator CRDs or other non-ConfigMap sources.

For ConfigMap-based validation, use ValidateConfigMapWithGlobal instead.

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,omitempty" json:",inline,omitempty"` // Global root-level defaults
	Namespaces   map[string]NamespaceSpec                            `yaml:"namespaces,omitempty" json:"namespaces,omitempty"` // Per-namespace defaults (selectors ignored)
}

GlobalConfig represents the global ConfigMap (tekton-pruner-default-spec) Root-level fields are defaults; Namespaces map is for per-namespace defaults NOTE: Selector support (PipelineRuns/TaskRuns arrays) is IGNORED in global ConfigMap

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 (hl *HistoryLimiter) DoFailedResourceCleanup(ctx context.Context, resource metav1.Object) error

func (*HistoryLimiter) DoSuccessfulResourceCleanup

func (hl *HistoryLimiter) DoSuccessfulResourceCleanup(ctx context.Context, resource metav1.Object) error

func (*HistoryLimiter) ProcessEvent

func (hl *HistoryLimiter) ProcessEvent(ctx context.Context, resource metav1.Object) error

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
	GetMatchingSelector(namespace, name string, selectors SelectorSpec) *SelectorSpec
}

HistoryLimiterResourceFuncs defines a set of methods that operate on resources with history limit capabilities.

type NamespaceSpec

type NamespaceSpec struct {
	PrunerConfig `yaml:",inline,omitempty" json:",inline,omitempty"` // Root-level defaults
	PipelineRuns []ResourceSpec                                      `yaml:"pipelineRuns,omitempty" json:"pipelineRuns,omitempty"` // Selector-based configs (namespace ConfigMap only)
	TaskRuns     []ResourceSpec                                      `yaml:"taskRuns,omitempty" json:"taskRuns,omitempty"`         // Selector-based configs (namespace ConfigMap only)
}

NamespaceSpec is used to hold the pruning config of a specific namespace and its resources Used in both global ConfigMap (tekton-pruner-default-spec) and namespace ConfigMap (tekton-pruner-namespace-spec) Selector support (PipelineRuns/TaskRuns arrays) ONLY works in namespace ConfigMaps

type PrunerConfig

type PrunerConfig struct {
	// EnforcedConfigLevel allowed values: global, namespace (default: namespace)
	EnforcedConfigLevel     *EnforcedConfigLevel `yaml:"enforcedConfigLevel,omitempty" json:"enforcedConfigLevel,omitempty"`
	TTLSecondsAfterFinished *int32               `yaml:"ttlSecondsAfterFinished,omitempty" json:"ttlSecondsAfterFinished,omitempty"`
	SuccessfulHistoryLimit  *int32               `yaml:"successfulHistoryLimit,omitempty" json:"successfulHistoryLimit,omitempty"`
	FailedHistoryLimit      *int32               `yaml:"failedHistoryLimit,omitempty" json:"failedHistoryLimit,omitempty"`
	HistoryLimit            *int32               `yaml:"historyLimit,omitempty" json:"historyLimit,omitempty"`
}

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,omitempty" json:"name,omitempty"`         // Exact name of the parent Pipeline or Task
	Selector     []SelectorSpec `yaml:"selector,omitempty" json:"selector,omitempty"` // Supports selection based on labels and annotations. If Name is given, Name takes precedence
	PrunerConfig `yaml:",inline,omitempty" json:",inline,omitempty"`
}

ResourceSpec is used to hold the config of a specific resource Only used in namespace-level ConfigMaps (tekton-pruner-namespace-spec), NOT in global ConfigMaps

type SelectorSpec

type SelectorSpec struct {
	// Match by labels AND annotations. If both are specified, BOTH must match (AND logic)
	MatchLabels      map[string]string `yaml:"matchLabels,omitempty" json:"matchLabels,omitempty"`
	MatchAnnotations map[string]string `yaml:"matchAnnotations,omitempty" json:"matchAnnotations,omitempty"`
}

SelectorSpec allows specifying selectors for matching resources like PipelineRun or TaskRun Only applicable in namespace-level ConfigMaps, NOT in global ConfigMaps

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

func (th *TTLHandler) ProcessEvent(ctx context.Context, resource metav1.Object) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL