@@ -18,18 +18,18 @@ package v1alpha1
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"net/url"
22
23
23
- "github.com/aws/aws-sdk-go/service/sqs"
24
-
25
24
"k8s.io/apimachinery/pkg/util/sets"
26
25
27
26
"knative.dev/pkg/apis"
28
27
)
29
28
30
- var (
31
- // https://github.com/aws/aws-sdk-go/blob/v1.38.55/service/sqs/api.go#L3966-L3994
32
- knownSQSAttributeNames = sets .NewString (sqs .MessageSystemAttributeName_Values ()... )
29
+ var knownActions = sets .NewString (
30
+ Actions .CordonAndDrain ,
31
+ Actions .Cordon ,
32
+ Actions .NoAction ,
33
33
)
34
34
35
35
func (t * Terminator ) Validate (_ context.Context ) (errs * apis.FieldError ) {
@@ -43,6 +43,7 @@ func (t *TerminatorSpec) validate() (errs *apis.FieldError) {
43
43
return errs .Also (
44
44
t .validateMatchLabels ().ViaField ("matchLabels" ),
45
45
t .SQS .validate ().ViaField ("sqs" ),
46
+ t .Events .validate ().ViaField ("events" ),
46
47
)
47
48
}
48
49
@@ -61,3 +62,19 @@ func (s *SQSSpec) validate() (errs *apis.FieldError) {
61
62
}
62
63
return errs
63
64
}
65
+
66
+ func (e * EventsSpec ) validate () (errs * apis.FieldError ) {
67
+ errMsg := fmt .Sprintf ("must be one of %s" , knownActions .List ())
68
+ for name , value := range map [string ]string {
69
+ "autoScalingTermination" : e .AutoScalingTermination ,
70
+ "rebalanceRecommendation" : e .RebalanceRecommendation ,
71
+ "scheduledChange" : e .ScheduledChange ,
72
+ "spotInterruption" : e .SpotInterruption ,
73
+ "stateChange" : e .StateChange ,
74
+ } {
75
+ if ! knownActions .Has (value ) {
76
+ errs = errs .Also (apis .ErrInvalidValue (value , name , errMsg ))
77
+ }
78
+ }
79
+ return errs
80
+ }
0 commit comments