Skip to content

Commit

Permalink
fix: remove check for empty value, operator is equal (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru authored Mar 2, 2024
1 parent 3e74bfa commit be42c60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
8 changes: 2 additions & 6 deletions pkg/utils/validator/clusterresourceplacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,8 @@ func validateTolerations(tolerations []placementv1beta1.Toleration) error {
if toleration.Key == "" {
allErr = append(allErr, fmt.Errorf(invalidTolerationErrFmt, toleration, "toleration key cannot be empty, when operator is Equal"))
}
if toleration.Value == "" {
allErr = append(allErr, fmt.Errorf(invalidTolerationErrFmt, toleration, "toleration value cannot be empty, when operator is Equal"))
} else {
for _, msg := range validation.IsValidLabelValue(toleration.Value) {
allErr = append(allErr, fmt.Errorf(invalidTolerationValueErrFmt, toleration, msg))
}
for _, msg := range validation.IsValidLabelValue(toleration.Value) {
allErr = append(allErr, fmt.Errorf(invalidTolerationValueErrFmt, toleration, msg))
}
}
if tolerationMap[toleration] {
Expand Down
19 changes: 9 additions & 10 deletions pkg/utils/validator/clusterresourceplacement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,39 +1064,38 @@ func TestValidateTolerations(t *testing.T) {
},
wantErr: false,
},
"invalid toleration, key is empty, operator is Equal": {
"valid toleration, value is empty, operator is Equal": {
tolerations: []placementv1beta1.Toleration{
{
Key: "key1",
Operator: corev1.TolerationOpEqual,
Value: "value1",
Effect: corev1.TaintEffectNoSchedule,
},
},
wantErr: true,
wantErrMsg: "toleration key cannot be empty, when operator is Equal",
wantErr: false,
},
"invalid toleration, key is invalid, operator is Equal": {
"invalid toleration, key is empty, operator is Equal": {
tolerations: []placementv1beta1.Toleration{
{
Key: "key:123*",
Operator: corev1.TolerationOpEqual,
Value: "value1",
Effect: corev1.TaintEffectNoSchedule,
},
},
wantErr: true,
wantErrMsg: "name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character",
wantErrMsg: "toleration key cannot be empty, when operator is Equal",
},
"invalid toleration, value is empty, operator is Equal": {
"invalid toleration, key is invalid, operator is Equal": {
tolerations: []placementv1beta1.Toleration{
{
Key: "key1",
Key: "key:123*",
Operator: corev1.TolerationOpEqual,
Value: "value1",
Effect: corev1.TaintEffectNoSchedule,
},
},
wantErr: true,
wantErrMsg: "toleration value cannot be empty, when operator is Equal",
wantErrMsg: "name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character",
},
"invalid toleration, value is invalid, operator is Equal": {
tolerations: []placementv1beta1.Toleration{
Expand Down

0 comments on commit be42c60

Please sign in to comment.