Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 100
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: 100
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: 100
schedule: "0 8 * * *"
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ spec:
params:
- name: createRbacResource
value: "true"
pruner:
resources:
- pipelinerun
- taskrun
keep: 100
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: 100
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: 100
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 @@ -53,7 +53,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
11 changes: 8 additions & 3 deletions pkg/apis/operator/v1alpha1/tektonconfig_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ 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.ErrMultipleOneOf("spec.pruner.keep", "spec.pruner.keep-since"))
}
if p.Keep == nil && p.KeepSince == nil {
errs = errs.Also(apis.ErrMissingOneOf("spec.pruner.keep", "spec.pruner.keep-since"))
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to error here, we can run tkn pr delete command without either keep or keepSince, couldn't we. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so can we remove this check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this check is required here, in the current approach without keep/keep-since we will have to use all flag, which will delete all the tr/prs in that namespace.
But soon(upcoming releases) we will support keep and keep-since both together.

} 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
29 changes: 26 additions & 3 deletions pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func Test_ValidateTektonConfig_InvalidPruningResource(t *testing.T) {
}

err := tc.Validate(context.TODO())
assert.Equal(t, "invalid value: task: spec.pruner.resources[0]\nmissing field(s): spec.pruner.keep, spec.pruner.schedule", err.Error())
assert.Equal(t, "expected exactly one, got neither: spec.pruner.keep, spec.pruner.keep-since\ninvalid value: task: spec.pruner.resources[0]\nmissing field(s): spec.pruner.schedule", err.Error())
}

func Test_ValidateTektonConfig_MissingKeepSchedule(t *testing.T) {
func Test_ValidateTektonConfig_MissingKeepKeepsinceSchedule(t *testing.T) {

tc := &TektonConfig{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -121,7 +121,30 @@ func Test_ValidateTektonConfig_MissingKeepSchedule(t *testing.T) {
}

err := tc.Validate(context.TODO())
assert.Equal(t, "missing field(s): spec.pruner.keep, spec.pruner.schedule", err.Error())
assert.Equal(t, "expected exactly one, got neither: spec.pruner.keep, spec.pruner.keep-since\nmissing field(s): spec.pruner.schedule", err.Error())
}

func Test_ValidateTektonConfig_MissingSchedule(t *testing.T) {
keep := uint(2)
tc := &TektonConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: TektonConfigSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
},
Profile: "all",
Pruner: Prune{
Keep: &keep,
Resources: []string{"taskrun"},
},
},
}

err := tc.Validate(context.TODO())
assert.Equal(t, "missing field(s): spec.pruner.schedule", err.Error())
}

func Test_ValidateTektonConfig_InvalidAddonParam(t *testing.T) {
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