-
Notifications
You must be signed in to change notification settings - Fork 61
/
prune_types.go
157 lines (132 loc) · 4.82 KB
/
prune_types.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package v1
import (
"context"
"reflect"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// PruneSpec needs to contain the repository information as well as the desired
// retention policies.
type PruneSpec struct {
RunnableSpec `json:",inline"`
// Retention sets how many backups should be kept after a forget and prune
Retention RetentionPolicy `json:"retention,omitempty"`
// KeepJobs amount of jobs to keep for later analysis.
//
// Deprecated: Use FailedJobsHistoryLimit and SuccessfulJobsHistoryLimit respectively.
// +optional
KeepJobs *int `json:"keepJobs,omitempty"`
// FailedJobsHistoryLimit amount of failed jobs to keep for later analysis.
// KeepJobs is used property is not specified.
// +optional
FailedJobsHistoryLimit *int `json:"failedJobsHistoryLimit,omitempty"`
// SuccessfulJobsHistoryLimit amount of successful jobs to keep for later analysis.
// KeepJobs is used property is not specified.
// +optional
SuccessfulJobsHistoryLimit *int `json:"successfulJobsHistoryLimit,omitempty"`
}
type RetentionPolicy struct {
KeepLast int `json:"keepLast,omitempty"`
KeepHourly int `json:"keepHourly,omitempty"`
KeepDaily int `json:"keepDaily,omitempty"`
KeepWeekly int `json:"keepWeekly,omitempty"`
KeepMonthly int `json:"keepMonthly,omitempty"`
KeepYearly int `json:"keepYearly,omitempty"`
KeepTags []string `json:"keepTags,omitempty"`
// Tags is a filter on what tags the policy should be applied
// DO NOT CONFUSE THIS WITH KeepTags OR YOU'LL have a bad time
Tags []string `json:"tags,omitempty"`
// Hostnames is a filter on what hostnames the policy should be applied
Hostnames []string `json:"hostnames,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Schedule Ref",type="string",JSONPath=`.metadata.ownerReferences[?(@.kind == "Schedule")].name`,description="Reference to Schedule"
// +kubebuilder:printcolumn:name="Completion",type="string",JSONPath=`.status.conditions[?(@.type == "Completed")].reason`,description="Status of Completion"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// Prune is the Schema for the prunes API
type Prune struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec PruneSpec `json:"spec,omitempty"`
Status Status `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// PruneList contains a list of Prune
type PruneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Prune `json:"items"`
}
func (p *Prune) GetType() JobType {
return PruneType
}
// GetStatus retrieves the Status property
func (p *Prune) GetStatus() Status {
return p.Status
}
// SetStatus sets the Status property
func (p *Prune) SetStatus(status Status) {
p.Status = status
}
// GetResources returns the resource requirements
func (p *Prune) GetResources() corev1.ResourceRequirements {
return p.Spec.Resources
}
// GetPodSecurityContext returns the pod security context
func (p *Prune) GetPodSecurityContext() *corev1.PodSecurityContext {
return p.Spec.PodSecurityContext
}
// GetActiveDeadlineSeconds implements JobObject
func (p *Prune) GetActiveDeadlineSeconds() *int64 {
return p.Spec.ActiveDeadlineSeconds
}
// GetFailedJobsHistoryLimit returns failed jobs history limit.
// Returns KeepJobs if unspecified.
func (p *Prune) GetFailedJobsHistoryLimit() *int {
if p.Spec.FailedJobsHistoryLimit != nil {
return p.Spec.FailedJobsHistoryLimit
}
return p.Spec.KeepJobs
}
// GetSuccessfulJobsHistoryLimit returns successful jobs history limit.
// Returns KeepJobs if unspecified.
func (p *Prune) GetSuccessfulJobsHistoryLimit() *int {
if p.Spec.SuccessfulJobsHistoryLimit != nil {
return p.Spec.SuccessfulJobsHistoryLimit
}
return p.Spec.KeepJobs
}
func (p *Prune) GetPodConfig(ctx context.Context, c client.Client) (*PodConfig, error) {
if p.Spec.RunnableSpec.PodConfigRef == nil {
return nil, nil
}
return NewPodConfig(ctx, p.Spec.RunnableSpec.PodConfigRef.Name, p.GetNamespace(), c)
}
// GetJobObjects returns a sortable list of jobs
func (p *PruneList) GetJobObjects() JobObjectList {
items := make(JobObjectList, len(p.Items))
for i := range p.Items {
items[i] = &p.Items[i]
}
return items
}
// GetDeepCopy returns a deep copy
func (in *PruneSchedule) GetDeepCopy() ScheduleSpecInterface {
return in.DeepCopy()
}
// GetRunnableSpec returns a pointer to RunnableSpec
func (in *PruneSchedule) GetRunnableSpec() *RunnableSpec {
return &in.RunnableSpec
}
// GetSchedule returns the schedule definition
func (in *PruneSchedule) GetSchedule() ScheduleDefinition {
return in.Schedule
}
func init() {
SchemeBuilder.Register(&Prune{}, &PruneList{})
}
var (
PruneKind = reflect.TypeOf(Prune{}).Name()
)