@@ -111,7 +111,9 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath *
111
111
}
112
112
}
113
113
bv := semver.Version {}
114
- if spec .BinaryVersion != "" {
114
+ if spec .BinaryVersion == "" {
115
+ allErrs = append (allErrs , field .Required (fldPath .Child ("binaryVersion" ), "" ))
116
+ } else {
115
117
var err error
116
118
bv , err = semver .Parse (spec .BinaryVersion )
117
119
if err != nil {
@@ -124,29 +126,18 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath *
124
126
allErrs = append (allErrs , field .Invalid (fld , spec .BinaryVersion , "must be greater than or equal to `emulationVersion`" ))
125
127
}
126
128
127
- if len (spec .PreferredStrategies ) > 0 {
128
- for i , strategy := range spec .PreferredStrategies {
129
- fld := fldPath .Child ("preferredStrategies" ).Index (i )
130
-
131
- strategySeen := make (map [coordination.CoordinatedLeaseStrategy ]bool )
132
- if _ , ok := strategySeen [strategy ]; ok {
133
- allErrs = append (allErrs , field .Duplicate (fld , strategy ))
134
- } else {
135
- strategySeen [strategy ] = true
136
- }
137
-
138
- if strategy == coordination .OldestEmulationVersion {
139
- zeroVersion := semver.Version {}
140
- if bv .EQ (zeroVersion ) {
141
- allErrs = append (allErrs , field .Required (fldPath .Child ("binaryVersion" ), "must be specified when `strategy` is 'OldestEmulationVersion'" ))
142
- }
143
- if ev .EQ (zeroVersion ) {
144
- allErrs = append (allErrs , field .Required (fldPath .Child ("emulationVersion" ), "must be specified when `strategy` is 'OldestEmulationVersion'" ))
145
- }
129
+ if spec .Strategy == "" {
130
+ allErrs = append (allErrs , field .Required (fldPath .Child ("strategy" ), "" ))
131
+ } else {
132
+ fld := fldPath .Child ("strategy" )
133
+ if spec .Strategy == coordination .OldestEmulationVersion {
134
+ zeroVersion := semver.Version {}
135
+ if ev .EQ (zeroVersion ) {
136
+ allErrs = append (allErrs , field .Required (fldPath .Child ("emulationVersion" ), "must be specified when `strategy` is 'OldestEmulationVersion'" ))
146
137
}
147
-
148
- allErrs = append (allErrs , ValidateCoordinatedLeaseStrategy (strategy , fld )... )
149
138
}
139
+
140
+ allErrs = append (allErrs , ValidateCoordinatedLeaseStrategy (spec .Strategy , fld )... )
150
141
}
151
142
// spec.PingTime is a MicroTime and doesn't need further validation
152
143
// spec.RenewTime is a MicroTime and doesn't need further validation
0 commit comments