...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "github.com/robfig/cron/v3"
20 corev1 "k8s.io/api/core/v1"
21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22 )
23
24 const KindSchedule = "Schedule"
25
26
27
28
29 type Schedule struct {
30 metav1.TypeMeta `json:",inline"`
31 metav1.ObjectMeta `json:"metadata,omitempty"`
32
33 Spec ScheduleSpec `json:"spec"`
34
35
36 Status ScheduleStatus `json:"status,omitempty"`
37 }
38
39 type ConcurrencyPolicy string
40
41 var (
42 ForbidConcurrent ConcurrencyPolicy = "Forbid"
43 AllowConcurrent ConcurrencyPolicy = "Allow"
44 )
45
46 func (c ConcurrencyPolicy) IsForbid() bool {
47 return c == ForbidConcurrent || c == ""
48 }
49
50 func (c ConcurrencyPolicy) IsAllow() bool {
51 return c == AllowConcurrent
52 }
53
54
55 type ScheduleSpec struct {
56 Schedule string `json:"schedule"`
57
58
59
60
61
62 StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds"`
63
64
65
66
67 ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy"`
68
69
70
71 HistoryLimit int `json:"historyLimit,omitempty"`
72
73 Type ScheduleTemplateType `json:"type"`
74
75 ScheduleItem `json:",inline"`
76 }
77
78
79 type ScheduleStatus struct {
80
81 Active []corev1.ObjectReference `json:"active,omitempty"`
82
83
84
85 LastScheduleTime metav1.Time `json:"time,omitempty"`
86 }
87
88 type ScheduleTemplateType string
89
90 func (in *Schedule) IsPaused() bool {
91 if in.Annotations == nil || in.Annotations[PauseAnnotationKey] != "true" {
92 return false
93 }
94 return true
95 }
96
97
98
99
100 type ScheduleList struct {
101 metav1.TypeMeta `json:",inline"`
102 metav1.ListMeta `json:"metadata,omitempty"`
103 Items []Schedule `json:"items"`
104 }
105
106 func (in *ScheduleList) GetItems() []GenericChaos {
107 var result []GenericChaos
108 for _, item := range in.Items {
109 item := item
110 result = append(result, &item)
111 }
112 return result
113 }
114
115 func (in *ScheduleList) DeepCopyList() GenericChaosList {
116 return in.DeepCopy()
117 }
118
119 var StandardCronParser = cron.NewParser(
120 cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
121 )
122
123 func init() {
124 SchemeBuilder.Register(&Schedule{})
125 SchemeBuilder.Register(&ScheduleList{})
126 }
127