Skip to content

Commit 99120be

Browse files
authored
Remove deprecated fields tag_filter, allow_tagged, and repo (#93)
These fields have been deprecated for a long time. This removes them in preparation for a 1.0 release.
1 parent 0ae9d25 commit 99120be

File tree

5 files changed

+27
-175
lines changed

5 files changed

+27
-175
lines changed

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,6 @@ The payload is expected to be JSON with the following fields:
9898
and create a dedicated service account that has granular permissions on a
9999
subset of repositories.
100100

101-
- `tag_filter` (_Deprecated_) - This option is deprecated and only exists to
102-
maintain backwards compatibility with some existing broken behavior. You
103-
should not use it. If specified, any image where **the first tag** matches
104-
this given regular expression will be deleted. The image will not be deleted
105-
if other tags match the regular expression. The regular expressions are parsed
106-
according to the [Go regexp package][go-re].
107-
108-
- `allow_tagged` (_Deprecated_) - This option is deprecated and has no effect.
109-
By default, GCR Cleaner will not delete tagged images. To delete tagged
110-
images, specify `tag_filter_any` or `tag_filter_all`. Specifying either of
111-
these will enable deletion by tag.
112-
113101

114102
## Permissions
115103

cmd/gcr-cleaner-cli/main.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ var (
5151
tagFilterAll = flag.String("tag-filter-all", "", "Delete images where all tags match this regular expression")
5252
keepPtr = flag.Int("keep", 0, "Minimum to keep")
5353
dryRunPtr = flag.Bool("dry-run", false, "Do a noop on delete api call")
54-
55-
// tagFilterPtr and allow-tagged are deprecated
56-
// TODO(sethvargo): remove before 1.0.0
57-
allowTaggedPtr = flag.Bool("allow-tagged", false, "DEPRECATED: Delete tagged images")
58-
tagFilterFirstPtr = flag.String("tag-filter", "", "DEPRECATED: Tags pattern to clean")
5954
)
6055

6156
func main() {
@@ -115,14 +110,7 @@ func realMain(ctx context.Context, logger *gcrcleaner.Logger) error {
115110
}
116111
sort.Strings(repos)
117112

118-
if *allowTaggedPtr {
119-
fmt.Fprintf(stderr, "DEPRECATION: -allow-tagged is deprecated, specifying any tags will enable deleting of tagged images\n")
120-
}
121-
if *tagFilterFirstPtr != "" {
122-
fmt.Fprintf(stderr, "DEPRECATION: -tag-filter is deprecated, use -tag-filter-any or -tag-filter-all instead\n")
123-
}
124-
125-
tagFilter, err := gcrcleaner.BuildTagFilter(*tagFilterFirstPtr, *tagFilterAny, *tagFilterAll)
113+
tagFilter, err := gcrcleaner.BuildTagFilter(*tagFilterAny, *tagFilterAll)
126114
if err != nil {
127115
return fmt.Errorf("failed to parse tag filter: %w", err)
128116
}

pkg/gcrcleaner/filter.go

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,13 @@ type TagFilter interface {
2929
// BuildTagFilter builds and compiles a new tag filter for the given inputs. All
3030
// inputs are strings to be compiled to regular expressions and are mutually
3131
// exclusive.
32-
func BuildTagFilter(first, any, all string) (TagFilter, error) {
32+
func BuildTagFilter(any, all string) (TagFilter, error) {
3333
// Ensure only one tag filter type is given.
34-
if (first != "" && any != "") || (first != "" && all != "") || (any != "" && all != "") {
34+
if any != "" && all != "" {
3535
return nil, fmt.Errorf("only one tag filter type may be specified")
3636
}
3737

3838
switch {
39-
case first != "":
40-
re, err := regexp.Compile(first)
41-
if err != nil {
42-
return nil, fmt.Errorf("failed to compile tag_filter regular expression %q: %w", first, err)
43-
}
44-
return &TagFilterFirst{re}, nil
4539
case any != "":
4640
re, err := regexp.Compile(any)
4741
if err != nil {
@@ -56,7 +50,7 @@ func BuildTagFilter(first, any, all string) (TagFilter, error) {
5650
return &TagFilterAll{re}, nil
5751
default:
5852
// If no filters were provided, return the null filter which just returns
59-
// false for all matches. This preserves the "allow_tagged" behavior.
53+
// false for all matches.
6054
return &TagFilterNull{}, nil
6155
}
6256
}
@@ -74,27 +68,6 @@ func (f *TagFilterNull) Name() string {
7468
return "(none)"
7569
}
7670

77-
var _ TagFilter = (*TagFilterFirst)(nil)
78-
79-
// TagFilterFirst filters based on the first item in the list. If the list is
80-
// empty or if the first item does not match the regex, it returns false.
81-
type TagFilterFirst struct {
82-
re *regexp.Regexp
83-
}
84-
85-
func (f *TagFilterFirst) Name() string {
86-
return fmt.Sprintf("first(%s)", f.re.String())
87-
}
88-
89-
func (f *TagFilterFirst) Matches(tags []string) bool {
90-
if len(tags) < 1 || f.re == nil {
91-
return false
92-
}
93-
return f.re.MatchString(tags[0])
94-
}
95-
96-
var _ TagFilter = (*TagFilterAny)(nil)
97-
9871
// TagFilterAny filters based on the entire list. If any tag in the list
9972
// matches, it returns true. If no tags match, it returns false.
10073
type TagFilterAny struct {

pkg/gcrcleaner/filter_test.go

Lines changed: 21 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,34 @@ func TestBuildTagFilter(t *testing.T) {
2424
t.Parallel()
2525

2626
cases := []struct {
27-
name string
28-
first, any, all string
29-
err bool
30-
exp reflect.Type
27+
name string
28+
any, all string
29+
err bool
30+
exp reflect.Type
3131
}{
3232
{
33-
name: "empty",
34-
first: "",
35-
any: "",
36-
all: "",
37-
exp: reflect.TypeOf(&TagFilterNull{}),
33+
name: "empty",
34+
any: "",
35+
all: "",
36+
exp: reflect.TypeOf(&TagFilterNull{}),
3837
},
3938
{
40-
name: "first_any",
41-
first: "a",
42-
any: "b",
43-
all: "",
44-
err: true,
39+
name: "any_all",
40+
any: "b",
41+
all: "c",
42+
err: true,
4543
},
4644
{
47-
name: "first_all",
48-
first: "a",
49-
any: "",
50-
all: "c",
51-
err: true,
45+
name: "any",
46+
any: "a",
47+
all: "",
48+
exp: reflect.TypeOf(&TagFilterAny{}),
5249
},
5350
{
54-
name: "any_all",
55-
first: "",
56-
any: "b",
57-
all: "c",
58-
err: true,
59-
},
60-
{
61-
name: "first",
62-
first: "a",
63-
any: "",
64-
all: "",
65-
exp: reflect.TypeOf(&TagFilterFirst{}),
66-
},
67-
{
68-
name: "any",
69-
first: "",
70-
any: "a",
71-
all: "",
72-
exp: reflect.TypeOf(&TagFilterAny{}),
73-
},
74-
{
75-
name: "all",
76-
first: "",
77-
any: "",
78-
all: "a",
79-
exp: reflect.TypeOf(&TagFilterAll{}),
51+
name: "all",
52+
any: "",
53+
all: "a",
54+
exp: reflect.TypeOf(&TagFilterAll{}),
8055
},
8156
}
8257

@@ -86,7 +61,7 @@ func TestBuildTagFilter(t *testing.T) {
8661
t.Run(tc.name, func(t *testing.T) {
8762
t.Parallel()
8863

89-
f, err := BuildTagFilter(tc.first, tc.any, tc.all)
64+
f, err := BuildTagFilter(tc.any, tc.all)
9065
if (err != nil) != tc.err {
9166
t.Fatal(err)
9267
}
@@ -97,55 +72,6 @@ func TestBuildTagFilter(t *testing.T) {
9772
}
9873
}
9974

100-
func TestTagFilterFirst_Matches(t *testing.T) {
101-
t.Parallel()
102-
103-
cases := []struct {
104-
name string
105-
re *regexp.Regexp
106-
tags []string
107-
exp bool
108-
}{
109-
{
110-
name: "empty_re",
111-
re: nil,
112-
tags: nil,
113-
exp: false,
114-
},
115-
{
116-
name: "empty_tags",
117-
re: regexp.MustCompile(`.*`),
118-
tags: nil,
119-
exp: false,
120-
},
121-
{
122-
name: "matches_first",
123-
re: regexp.MustCompile(`.*`),
124-
tags: []string{"tag1", "tag2"},
125-
exp: true,
126-
},
127-
{
128-
name: "doesnt_match_second",
129-
re: regexp.MustCompile(`^tag2$`),
130-
tags: []string{"tag1", "tag2"},
131-
exp: false,
132-
},
133-
}
134-
135-
for _, tc := range cases {
136-
tc := tc
137-
138-
t.Run(tc.name, func(t *testing.T) {
139-
t.Parallel()
140-
141-
f := &TagFilterFirst{re: tc.re}
142-
if got, want := f.Matches(tc.tags), tc.exp; got != want {
143-
t.Errorf("expected %q matches %q to be %t", tc.re, tc.tags, want)
144-
}
145-
})
146-
}
147-
}
148-
14975
func TestTagFilterAny_Matches(t *testing.T) {
15076
t.Parallel()
15177

pkg/gcrcleaner/server.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (s *Server) clean(ctx context.Context, r io.ReadCloser) (map[string][]strin
143143
}
144144

145145
since := time.Now().UTC().Add(sub)
146-
tagFilter, err := BuildTagFilter(p.TagFilterFirst, p.TagFilterAny, p.TagFilterAll)
146+
tagFilter, err := BuildTagFilter(p.TagFilterAny, p.TagFilterAll)
147147
if err != nil {
148148
return nil, http.StatusBadRequest, fmt.Errorf("failed to build tag filter: %w", err)
149149
}
@@ -155,16 +155,12 @@ func (s *Server) clean(ctx context.Context, r io.ReadCloser) (map[string][]strin
155155
repos = append(repos, t)
156156
}
157157
}
158-
if t := strings.TrimSpace(p.Repo); t != "" {
159-
s.logger.Warn("specifying \"repo\" is deprecated - switch to \"repos\"")
160-
repos = append(repos, t)
161-
}
162158
if p.Recursive {
163159
s.logger.Debug("gathering child repositories recursively")
164160

165161
allRepos, err := s.cleaner.ListChildRepositories(ctx, repos)
166162
if err != nil {
167-
return nil, http.StatusBadRequest, fmt.Errorf("failed to list child repositories for %q: %w", p.Repo, err)
163+
return nil, http.StatusBadRequest, fmt.Errorf("failed to list child repositories: %w", err)
168164
}
169165
s.logger.Debug("recursively listed child repositories",
170166
"in", repos,
@@ -218,11 +214,6 @@ func (s *Server) handleError(w http.ResponseWriter, err error, status int) {
218214

219215
// Payload is the expected incoming payload format.
220216
type Payload struct {
221-
// Repo is the name of the repo to clean.
222-
//
223-
// Deprecated: Use Repos instead.
224-
Repo string `json:"repo"`
225-
226217
// Repos is the list of repositories to clean.
227218
Repos sortedStringSlice `json:"repos"`
228219

@@ -251,20 +242,6 @@ type Payload struct {
251242

252243
// Recursive enables cleaning all child repositories.
253244
Recursive bool `json:"recursive"`
254-
255-
// TagFilterFirst is the tags pattern to be allowed removing. If specified, any
256-
// images where the first tag matches the given regular expression will be
257-
// deleted.
258-
//
259-
// Deprecated: Use tag_filter_all or tag_filter_any instead.
260-
TagFilterFirst string `json:"tag_filter"`
261-
262-
// AllowTagged is a Boolean value determine if tagged images are allowed to be
263-
// deleted.
264-
//
265-
// Deprecated: Use tag_filter_all or tag_filter_any instead. Setting either of
266-
// these values enables deleting tagged images.
267-
AllowTagged bool `json:"allow_tagged"`
268245
}
269246

270247
type pubsubMessage struct {

0 commit comments

Comments
 (0)