Skip to content

Commit 44c4ffd

Browse files
authored
(feature): update auto pruning library
update the existing pruning library to implement the new library outlined in the following EP: https://github.com/operator-framework/enhancements/blob/master/enhancements/automatic-resource-pruning.md resolves #101
1 parent d389ad4 commit 44c4ffd

File tree

13 files changed

+1055
-741
lines changed

13 files changed

+1055
-741
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Go 1.x
1717
uses: actions/setup-go@v2
1818
with:
19-
go-version: ^1.17
19+
go-version: 1.17.x
2020
id: go
2121

2222
- name: Check out code into the Go module directory
@@ -50,7 +50,7 @@ jobs:
5050
uses: actions/checkout@v2
5151

5252
- name: Run golangci-lint
53-
uses: golangci/golangci-lint-action@v2
53+
uses: golangci/golangci-lint-action@v3
5454
with:
5555
version: v1.29
5656
args: --timeout 5m

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ require (
3838
github.com/prometheus/common v0.28.0 // indirect
3939
github.com/prometheus/procfs v0.6.0 // indirect
4040
github.com/spf13/pflag v1.0.5 // indirect
41-
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
41+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
4242
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
43-
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
44-
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
43+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
44+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
4545
golang.org/x/text v0.3.7 // indirect
4646
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
4747
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect

go.sum

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,9 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
665665
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
666666
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
667667
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
668-
golang.org/x/net v0.0.0-20210825183410-e898025ed96a h1:bRuuGXV8wwSdGTB+CtJf+FjgO1APK1CoO39T4BN/XBw=
669668
golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
669+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
670+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
670671
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
671672
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
672673
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -764,13 +765,15 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc
764765
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
765766
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
766767
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
767-
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 h1:M69LAlWZCshgp0QSzyDcSsSIejIEeuaCVpmwcKwyLMk=
768768
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
769+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
770+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
769771
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
770772
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
771773
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
772-
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
773774
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
775+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
776+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
774777
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
775778
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
776779
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

prune/maxage.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

prune/maxcount.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

prune/prunables.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2021 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package prune
16+
17+
import (
18+
"sigs.k8s.io/controller-runtime/pkg/client"
19+
20+
batchv1 "k8s.io/api/batch/v1"
21+
corev1 "k8s.io/api/core/v1"
22+
)
23+
24+
// DefaultPodIsPrunable is a default IsPrunableFunc to be used specifically with Pod resources.
25+
// It marks a Pod resource as prunable if it's Status.Phase is "Succeeded"
26+
// This can be overridden by registering your own IsPrunableFunc via the RegisterIsPrunableFunc method
27+
func DefaultPodIsPrunable(obj client.Object) error {
28+
pod := obj.(*corev1.Pod)
29+
if pod.Status.Phase != corev1.PodSucceeded {
30+
return &Unprunable{
31+
Obj: &obj,
32+
Reason: "Pod has not succeeded",
33+
}
34+
}
35+
36+
return nil
37+
}
38+
39+
// DefaultJobIsPrunable is a default IsPrunableFunc to be used specifically with Job resources.
40+
// It marks a Job resource as prunable if it's Status.CompletionTime value is not `nil`, indicating that the Job has completed
41+
// This can be overridden by registering your own IsPrunableFunc via the RegisterIsPrunableFunc method
42+
func DefaultJobIsPrunable(obj client.Object) error {
43+
job := obj.(*batchv1.Job)
44+
if job.Status.CompletionTime == nil {
45+
return &Unprunable{
46+
Obj: &obj,
47+
Reason: "Job has not completed",
48+
}
49+
}
50+
51+
return nil
52+
}

0 commit comments

Comments
 (0)