Skip to content

Commit

Permalink
adds auto-prune per namespace
Browse files Browse the repository at this point in the history
This adds auto-pruning of taskrun and pipeline run per namespace
configured specifically.
adding unique schedule create a new cronjob in the annotated
namespace.
The default behaviour will persist, on top of it now user can
annotate a namespace with unique pruning configuration.
If user configures a unique schedule value by annotating a ns
a new cron job in that namespace will be created.

Auto puring is now enabled by default for default configurations
from tektonconfig.

Annotations introduced with this pr
 - "operator.tekton.dev/prune.skip"
 - "operator.tekton.dev/prune.resources"
 - "operator.tekton.dev/prune.resources.pipelineNames"
 - "operator.tekton.dev/prune.resources.taskNames"
 - "operator.tekton.dev/prune.keep"
 - "operator.tekton.dev/prune.keepsince"
 - "operator.tekton.dev/prune.schedule"

Signed-off-by: Pradeep Kumar <[email protected]>
  • Loading branch information
pradeepitm12 committed Sep 16, 2021
1 parent 0467af4 commit 4bbafef
Show file tree
Hide file tree
Showing 16 changed files with 526 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ metadata:
spec:
profile: all
targetNamespace: tekton-pipelines
pruner:
resources:
- pipelinerun
- taskrun
keep: 2
schedule: "0 8 * * *"
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ metadata:
spec:
profile: basic
targetNamespace: tekton-pipelines
pruner:
resources:
- pipelinerun
- taskrun
keep: 2
schedule: "0 8 * * *"
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ metadata:
spec:
profile: lite
targetNamespace: tekton-pipelines
pruner:
resources:
- pipelinerun
- taskrun
keep: 2
schedule: "0 8 * * *"
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ spec:
value: "true"
- name: pipelineTemplates
value: "true"
pruner:
resources:
- pipelinerun
- taskrun
keep: 2
schedule: "0 8 * * *"
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ metadata:
spec:
profile: basic
targetNamespace: openshift-pipelines
pruner:
resources:
- pipelinerun
- taskrun
keep: 2
schedule: "0 8 * * *"
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ metadata:
spec:
profile: lite
targetNamespace: openshift-pipelines
pruner:
resources:
- pipelinerun
- taskrun
keep: 2
schedule: "0 8 * * *"
5 changes: 5 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ type Prune struct {
Resources []string `json:"resources,omitempty"`
// The number of resource to keep
// You dont want to delete all the pipelinerun/taskrun's by a cron
// +optional
Keep *uint `json:"keep,omitempty"`
// KeepSince keeps the resources younger than the specified value
// Its value is taken in minutes
// +optional
KeepSince *uint `json:"keep-since,omitempty"`
// How frequent pruning should happen
Schedule string `json:"schedule,omitempty"`
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/apis/operator/v1alpha1/tektonconfig_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ func (p Prune) validate() *apis.FieldError {
errs = errs.Also(apis.ErrMissingField("spec.pruner.resources"))
}

if p.Keep == nil {
errs = errs.Also(apis.ErrMissingField("spec.pruner.keep"))
} else if *p.Keep == 0 {
if p.Keep == nil && p.KeepSince == nil {
errs = errs.Also(apis.ErrMissingOneOf("spec.pruner.keep", "spec.pruner.keep-since"))
} else if p.Keep != nil && *p.Keep == 0 {
errs = errs.Also(apis.ErrInvalidValue(*p.Keep, "spec.pruner.keep"))
} else if p.KeepSince != nil && *p.KeepSince == 0 {
errs = errs.Also(apis.ErrInvalidValue(*p.Keep, "spec.pruner.keep-since"))
}

if p.Schedule == "" {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bbafef

Please sign in to comment.