-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-10009 | feat: Adding taints effect validation to common
- Loading branch information
den-rgb
committed
Jul 31, 2024
1 parent
f7ce367
commit 088d656
Showing
5 changed files
with
151 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package validations | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestValidations(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "MachinePool Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package validations | ||
|
||
import ( | ||
errors "github.com/zgalor/weberr" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func ValidateMachinePoolTaintEffect(effect v1.TaintEffect) error { | ||
switch effect { | ||
case v1.TaintEffectNoExecute, v1.TaintEffectNoSchedule, v1.TaintEffectPreferNoSchedule: | ||
return nil | ||
default: | ||
return errors.BadRequest.UserErrorf("Unrecognized taint effect '%s', "+ | ||
"only the following effects are supported: '%s', '%s', '%s'.", | ||
effect, | ||
v1.TaintEffectNoExecute, v1.TaintEffectNoSchedule, v1.TaintEffectPreferNoSchedule) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package validations | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var _ = Describe("ValidateMachinePoolTaintEffect", func() { | ||
It("should return nil for recognized taint effects", func() { | ||
Expect(ValidateMachinePoolTaintEffect(v1.TaintEffectNoExecute)).To(Succeed()) | ||
Expect(ValidateMachinePoolTaintEffect(v1.TaintEffectNoSchedule)).To(Succeed()) | ||
Expect(ValidateMachinePoolTaintEffect(v1.TaintEffectPreferNoSchedule)).To(Succeed()) | ||
}) | ||
|
||
It("should return an error for unrecognized taint effects", func() { | ||
unrecognizedEffect := v1.TaintEffect("unrecognized") | ||
Expect(ValidateMachinePoolTaintEffect(unrecognizedEffect)).To(MatchError( | ||
MatchRegexp("Unrecognized taint effect 'unrecognized', only the following" + | ||
" effects are supported: 'NoExecute', 'NoSchedule', 'PreferNoSchedule'"))) | ||
}) | ||
}) |