Search in sources :

Example 1 with Affinity

use of io.fabric8.kubernetes.api.model.Affinity in project syndesis-qe by syndesisio.

the class OperatorValidationSteps method checkAffinity.

@When("^check (affinity|tolerations)( not set)? for (infra|integration) pods$")
public void checkAffinity(String test, String notSet, String method) {
    List<Pod> pods = "infra".equals(method) ? ComponentUtils.getComponentPods().stream().filter(p -> !p.getMetadata().getName().contains("operator")).collect(Collectors.toList()) : OpenShiftUtils.findPodsByPredicates(p -> "integration".equals(p.getMetadata().getLabels().get("syndesis.io/type")));
    for (Pod p : pods) {
        String name = p.getMetadata().getName();
        if ("affinity".equals(test)) {
            Affinity podAffinity = p.getSpec().getAffinity();
            if (notSet == null) {
                assertThat(podAffinity).as(name + ": affinity is null").isNotNull();
                NodeAffinity nodeAffinity = podAffinity.getNodeAffinity();
                assertThat(nodeAffinity).as(name + ": node affinity is null").isNotNull();
                NodeSelector selector = nodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution();
                assertThat(selector).as(name + ": required is null").isNotNull();
                List<NodeSelectorTerm> terms = selector.getNodeSelectorTerms();
                assertThat(terms).as(name + ": node selector is null").isNotNull();
                assertThat(terms).as(name + ": node selector size isn't 1").hasSize(1);
            } else {
                assertThat(podAffinity).isNull();
            }
        } else {
            Optional<Toleration> toleration = p.getSpec().getTolerations().stream().filter(t -> "node.kubernetes.io/network-unavailable".equals(t.getKey())).findAny();
            if (notSet == null) {
                assertThat(toleration).as(name + ": Expected toleration setting is not present").isPresent();
            } else {
                assertThat(toleration).as(name + ": Toleration shouldn't be present").isNotPresent();
            }
        }
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) StringUtils(org.apache.commons.lang3.StringUtils) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) IntegrationsEndpoint(io.syndesis.qe.endpoint.IntegrationsEndpoint) Map(java.util.Map) Addon(io.syndesis.qe.addon.Addon) ZipFile(java.util.zip.ZipFile) Syndesis(io.syndesis.qe.resource.impl.Syndesis) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Affinity(io.fabric8.kubernetes.api.model.Affinity) AccountsDirectory(io.syndesis.qe.account.AccountsDirectory) Set(java.util.Set) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Jaeger(io.syndesis.qe.resource.impl.Jaeger) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) S3BucketNameBuilder(io.syndesis.qe.utils.aws.S3BucketNameBuilder) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) Optional(java.util.Optional) Lazy(org.springframework.context.annotation.Lazy) Pattern(java.util.regex.Pattern) Component(io.syndesis.qe.component.Component) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) SoftAssertions(org.assertj.core.api.SoftAssertions) NodeSelectorTerm(io.fabric8.kubernetes.api.model.NodeSelectorTerm) Then(io.cucumber.java.en.Then) ComponentUtils(io.syndesis.qe.component.ComponentUtils) LocalPortForward(io.fabric8.kubernetes.client.LocalPortForward) HashMap(java.util.HashMap) Yaml(org.yaml.snakeyaml.Yaml) Given(io.cucumber.java.en.Given) DataTable(io.cucumber.datatable.DataTable) Node(io.fabric8.kubernetes.api.model.Node) OutputStream(java.io.OutputStream) PersistentVolumeFluent(io.fabric8.kubernetes.api.model.PersistentVolumeFluent) Endpoints(io.fabric8.kubernetes.api.model.Endpoints) Files(java.nio.file.Files) When(io.cucumber.java.en.When) S3Utils(io.syndesis.qe.utils.aws.S3Utils) FileOutputStream(java.io.FileOutputStream) Pod(io.fabric8.kubernetes.api.model.Pod) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) NodeSelector(io.fabric8.kubernetes.api.model.NodeSelector) Toleration(io.fabric8.kubernetes.api.model.Toleration) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) FileInputStream(java.io.FileInputStream) Account(io.syndesis.qe.account.Account) File(java.io.File) NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) HTTPUtils(io.syndesis.qe.utils.http.HTTPUtils) TestUtils(io.syndesis.qe.utils.TestUtils) Paths(java.nio.file.Paths) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ExternalDatabase(io.syndesis.qe.resource.impl.ExternalDatabase) JSONArray(org.json.JSONArray) InputStream(java.io.InputStream) NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) Pod(io.fabric8.kubernetes.api.model.Pod) Toleration(io.fabric8.kubernetes.api.model.Toleration) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) NodeSelector(io.fabric8.kubernetes.api.model.NodeSelector) NodeSelectorTerm(io.fabric8.kubernetes.api.model.NodeSelectorTerm) When(io.cucumber.java.en.When)

Aggregations

DataTable (io.cucumber.datatable.DataTable)1 Given (io.cucumber.java.en.Given)1 Then (io.cucumber.java.en.Then)1 When (io.cucumber.java.en.When)1 Affinity (io.fabric8.kubernetes.api.model.Affinity)1 DoneablePersistentVolume (io.fabric8.kubernetes.api.model.DoneablePersistentVolume)1 Endpoints (io.fabric8.kubernetes.api.model.Endpoints)1 Node (io.fabric8.kubernetes.api.model.Node)1 NodeAffinity (io.fabric8.kubernetes.api.model.NodeAffinity)1 NodeSelector (io.fabric8.kubernetes.api.model.NodeSelector)1 NodeSelectorTerm (io.fabric8.kubernetes.api.model.NodeSelectorTerm)1 PersistentVolumeFluent (io.fabric8.kubernetes.api.model.PersistentVolumeFluent)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)1 Toleration (io.fabric8.kubernetes.api.model.Toleration)1 LocalPortForward (io.fabric8.kubernetes.client.LocalPortForward)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 Account (io.syndesis.qe.account.Account)1 AccountsDirectory (io.syndesis.qe.account.AccountsDirectory)1