-
Notifications
You must be signed in to change notification settings - Fork 199
/
meta_cleanup.go
86 lines (66 loc) · 1.8 KB
/
meta_cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package config
import (
"fmt"
"regexp"
"strings"
"time"
)
type MetaCleanup struct {
KeepPolicies []*MetaCleanupKeepPolicy
}
type MetaCleanupKeepPolicy struct {
References MetaCleanupKeepPolicyReferences
ImagesPerReference MetaCleanupKeepPolicyImagesPerReference
}
func (p *MetaCleanupKeepPolicy) String() string {
var parts []string
parts = append(parts, fmt.Sprintf("references={%s}", p.References.String()))
imagesPerReferencePart := p.ImagesPerReference.String()
if imagesPerReferencePart != "" {
parts = append(parts, fmt.Sprintf("imagesPerReference={%s}", imagesPerReferencePart))
}
return strings.Join(parts, " ")
}
type MetaCleanupKeepPolicyReferences struct {
TagRegexp *regexp.Regexp
BranchRegexp *regexp.Regexp
Limit *MetaCleanupKeepPolicyLimit
}
func (c *MetaCleanupKeepPolicyReferences) String() string {
var parts []string
if c.TagRegexp != nil {
parts = append(parts, fmt.Sprintf("tag=%s", c.TagRegexp.String()))
} else {
parts = append(parts, fmt.Sprintf("branch=%s", c.BranchRegexp.String()))
}
if c.Limit != nil {
parts = append(parts, fmt.Sprintf("limit={%s}", c.Limit.String()))
}
return strings.Join(parts, " ")
}
type MetaCleanupKeepPolicyImagesPerReference struct {
MetaCleanupKeepPolicyLimit
}
type MetaCleanupKeepPolicyLimit struct {
Last *int
In *time.Duration
Operator *Operator
}
func (c *MetaCleanupKeepPolicyLimit) String() string {
var parts []string
if c.In != nil {
parts = append(parts, fmt.Sprintf("in=%s", c.In.String()))
}
if c.Last != nil {
parts = append(parts, fmt.Sprintf("last=%d", *c.Last))
}
if c.Operator != nil {
parts = append(parts, fmt.Sprintf("operator=%s", *c.Operator))
}
return strings.Join(parts, " ")
}
type Operator string
var (
OrOperator Operator = "Or"
AndOperator Operator = "And"
)