@@ -17,14 +17,8 @@ limitations under the License.
17
17
package pkg
18
18
19
19
import (
20
- "fmt"
21
- "time"
22
-
23
20
corev1 "k8s.io/api/core/v1"
24
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
- "k8s.io/apimachinery/pkg/runtime"
26
- "sigs.k8s.io/controller-runtime/pkg/webhook"
27
- "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
28
22
)
29
23
30
24
// ChaosPodSpec defines the desired state of ChaosPod
@@ -62,61 +56,6 @@ type ChaosPodList struct {
62
56
Items []ChaosPod `json:"items"`
63
57
}
64
58
65
- // +kubebuilder:webhook:path=/validate-chaosapps-metamagical-io-v1-chaospod,mutating=false,failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=vchaospod.kb.io
66
-
67
- var _ webhook.Validator = & ChaosPod {}
68
-
69
- // ValidateCreate implements webhookutil.validator so a webhook will be registered for the type
70
- func (c * ChaosPod ) ValidateCreate () (admission.Warnings , error ) {
71
- log .Info ("validate create" , "name" , c .Name )
72
-
73
- if c .Spec .NextStop .Before (& metav1.Time {Time : time .Now ()}) {
74
- return nil , fmt .Errorf (".spec.nextStop must be later than current time" )
75
- }
76
- return nil , nil
77
- }
78
-
79
- // ValidateUpdate implements webhookutil.validator so a webhook will be registered for the type
80
- func (c * ChaosPod ) ValidateUpdate (old runtime.Object ) (admission.Warnings , error ) {
81
- log .Info ("validate update" , "name" , c .Name )
82
-
83
- if c .Spec .NextStop .Before (& metav1.Time {Time : time .Now ()}) {
84
- return nil , fmt .Errorf (".spec.nextStop must be later than current time" )
85
- }
86
-
87
- oldC , ok := old .(* ChaosPod )
88
- if ! ok {
89
- return nil , fmt .Errorf ("expect old object to be a %T instead of %T" , oldC , old )
90
- }
91
- if c .Spec .NextStop .After (oldC .Spec .NextStop .Add (time .Hour )) {
92
- return nil , fmt .Errorf ("it is not allowed to delay.spec.nextStop for more than 1 hour" )
93
- }
94
- return nil , nil
95
- }
96
-
97
- // ValidateDelete implements webhookutil.validator so a webhook will be registered for the type
98
- func (c * ChaosPod ) ValidateDelete () (admission.Warnings , error ) {
99
- log .Info ("validate delete" , "name" , c .Name )
100
-
101
- if c .Spec .NextStop .Before (& metav1.Time {Time : time .Now ()}) {
102
- return nil , fmt .Errorf (".spec.nextStop must be later than current time" )
103
- }
104
- return nil , nil
105
- }
106
-
107
- // +kubebuilder:webhook:path=/mutate-chaosapps-metamagical-io-v1-chaospod,mutating=true,failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=mchaospod.kb.io
108
-
109
- var _ webhook.Defaulter = & ChaosPod {}
110
-
111
- // Default implements webhookutil.defaulter so a webhook will be registered for the type
112
- func (c * ChaosPod ) Default () {
113
- log .Info ("default" , "name" , c .Name )
114
-
115
- if c .Spec .NextStop .Before (& metav1.Time {Time : time .Now ()}) {
116
- c .Spec .NextStop = metav1.Time {Time : time .Now ().Add (time .Minute )}
117
- }
118
- }
119
-
120
59
func init () {
121
60
SchemeBuilder .Register (& ChaosPod {}, & ChaosPodList {})
122
61
}
0 commit comments