Search in sources :

Example 1 with Toleration

use of io.stackgres.common.crd.Toleration in project stackgres by ongres.

the class ClusterConstraintValidatorTest method validToleration_shouldPass.

@Test
void validToleration_shouldPass() throws ValidationFailed {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
    review.getRequest().getObject().getSpec().getPod().getScheduling().setTolerations(new ArrayList<>());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().add(new Toleration());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setKey("test");
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Toleration(io.stackgres.common.crd.Toleration) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Toleration

use of io.stackgres.common.crd.Toleration in project stackgres by ongres.

the class ClusterConstraintValidatorTest method invalidTolerationOperator_shouldFail.

@Test
void invalidTolerationOperator_shouldFail() {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
    review.getRequest().getObject().getSpec().getPod().getScheduling().setTolerations(new ArrayList<>());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().add(new Toleration());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setKey("test");
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setOperator("NotExists");
    checkErrorCause(Toleration.class, "spec.pod.scheduling.tolerations[0].operator", "isOperatorValid", review, AssertTrue.class);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Toleration(io.stackgres.common.crd.Toleration) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Toleration

use of io.stackgres.common.crd.Toleration in project stackgres by ongres.

the class ClusterConstraintValidatorTest method validTolerationKeyEmpty_shouldPass.

@Test
void validTolerationKeyEmpty_shouldPass() throws ValidationFailed {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
    review.getRequest().getObject().getSpec().getPod().getScheduling().setTolerations(new ArrayList<>());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().add(new Toleration());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setKey("");
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setOperator("Exists");
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Toleration(io.stackgres.common.crd.Toleration) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Toleration

use of io.stackgres.common.crd.Toleration in project stackgres by ongres.

the class ClusterConstraintValidatorTest method givenTolerationsSetAndEffectNoExecute_shouldPass.

@Test
void givenTolerationsSetAndEffectNoExecute_shouldPass() throws ValidationFailed {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
    review.getRequest().getObject().getSpec().getPod().getScheduling().setTolerations(new ArrayList<>());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().add(new Toleration());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setKey("test");
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setTolerationSeconds(100L);
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setEffect("NoExecute");
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Toleration(io.stackgres.common.crd.Toleration) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Toleration

use of io.stackgres.common.crd.Toleration in project stackgres by ongres.

the class ClusterConstraintValidatorTest method givenTolerationsSetAndEffectOtherThanNoExecute_shouldFail.

@Test
void givenTolerationsSetAndEffectOtherThanNoExecute_shouldFail() {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
    review.getRequest().getObject().getSpec().getPod().getScheduling().setTolerations(new ArrayList<>());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().add(new Toleration());
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setKey("test");
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setTolerationSeconds(100L);
    review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setEffect(new Random().nextBoolean() ? "NoSchedule" : "PreferNoSchedule");
    checkErrorCause(Toleration.class, "spec.pod.scheduling.tolerations[0].effect", "isEffectNoExecuteIfTolerationIsSet", review, AssertTrue.class);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Random(java.util.Random) Toleration(io.stackgres.common.crd.Toleration) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Toleration (io.stackgres.common.crd.Toleration)7 StackGresClusterPodScheduling (io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling)7 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)7 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)7 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Random (java.util.Random)1