io.fabric8.kubernetes.api.model.WeightedPodAffinityTerm Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.WeightedPodAffinityTerm.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testPodAffinityGlobalProperty() { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); LabelSelector labelSelector = new LabelSelector(); labelSelector.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder() .withKey("security") .withOperator("In") .withValues("S1") .build())); PodAffinityTerm podAffinityTerm = new PodAffinityTerm(labelSelector, null, "failure-domain.beta.kubernetes.io/zone"); LabelSelector labelSelector2 = new LabelSelector(); labelSelector2.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder() .withKey("security") .withOperator("In") .withValues("s2") .build())); PodAffinityTerm podAffinityTerm2 = new PodAffinityTerm(labelSelector2, null, "failure-domain.beta.kubernetes.io/zone"); WeightedPodAffinityTerm weightedPodAffinityTerm = new WeightedPodAffinityTerm(podAffinityTerm2, 100); PodAffinity podAffinity = new AffinityBuilder() .withNewPodAffinity() .withRequiredDuringSchedulingIgnoredDuringExecution(podAffinityTerm) .withPreferredDuringSchedulingIgnoredDuringExecution(weightedPodAffinityTerm) .endPodAffinity() .buildPodAffinity(); kubernetesDeployerProperties.setPodAffinity(podAffinity); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodAffinity podAffinityTest = podSpec.getAffinity().getPodAffinity(); assertNotNull("Pod affinity should not be null", podAffinityTest); assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", podAffinityTest.getRequiredDuringSchedulingIgnoredDuringExecution()); assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, podAffinityTest.getPreferredDuringSchedulingIgnoredDuringExecution().size()); }
Example #2
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testPodAntiAffinityGlobalProperty() { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); LabelSelector labelSelector = new LabelSelector(); labelSelector.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder() .withKey("app") .withOperator("In") .withValues("store") .build())); PodAffinityTerm podAffinityTerm = new PodAffinityTerm(labelSelector, null, "kubernetes.io/hostname"); LabelSelector labelSelector2 = new LabelSelector(); labelSelector2.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder() .withKey("security") .withOperator("In") .withValues("s2") .build())); PodAffinityTerm podAffinityTerm2 = new PodAffinityTerm(labelSelector2, null, "failure-domain.beta.kubernetes.io/zone"); WeightedPodAffinityTerm weightedPodAffinityTerm = new WeightedPodAffinityTerm(podAffinityTerm2, 100); PodAntiAffinity podAntiAffinity = new AffinityBuilder() .withNewPodAntiAffinity() .withRequiredDuringSchedulingIgnoredDuringExecution(podAffinityTerm) .withPreferredDuringSchedulingIgnoredDuringExecution(weightedPodAffinityTerm) .endPodAntiAffinity() .buildPodAntiAffinity(); kubernetesDeployerProperties.setPodAntiAffinity(podAntiAffinity); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodAntiAffinity podAntiAffinityTest = podSpec.getAffinity().getPodAntiAffinity(); assertNotNull("Pod anti-affinity should not be null", podAntiAffinityTest); assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", podAntiAffinityTest.getRequiredDuringSchedulingIgnoredDuringExecution()); assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, podAntiAffinityTest.getPreferredDuringSchedulingIgnoredDuringExecution().size()); }
Example #3
Source File: KafkaClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
private void checkStatefulSet(StatefulSet sts, Kafka cm, boolean isOpenShift) { assertThat(sts.getMetadata().getName(), is(KafkaCluster.kafkaClusterName(cluster))); // ... in the same namespace ... assertThat(sts.getMetadata().getNamespace(), is(namespace)); // ... with these labels assertThat(sts.getMetadata().getLabels(), is(expectedLabels())); assertThat(sts.getSpec().getSelector().getMatchLabels(), is(expectedSelectorLabels())); assertThat(sts.getSpec().getTemplate().getSpec().getSchedulerName(), is("default-scheduler")); List<Container> containers = sts.getSpec().getTemplate().getSpec().getContainers(); assertThat(containers.size(), is(2)); // checks on the main Kafka container assertThat(sts.getSpec().getReplicas(), is(new Integer(replicas))); assertThat(sts.getSpec().getPodManagementPolicy(), is(PodManagementPolicy.PARALLEL.toValue())); assertThat(containers.get(0).getImage(), is(image)); assertThat(containers.get(0).getLivenessProbe().getTimeoutSeconds(), is(new Integer(healthTimeout))); assertThat(containers.get(0).getLivenessProbe().getInitialDelaySeconds(), is(new Integer(healthDelay))); assertThat(containers.get(0).getLivenessProbe().getFailureThreshold(), is(new Integer(10))); assertThat(containers.get(0).getLivenessProbe().getSuccessThreshold(), is(new Integer(4))); assertThat(containers.get(0).getLivenessProbe().getPeriodSeconds(), is(new Integer(33))); assertThat(containers.get(0).getReadinessProbe().getTimeoutSeconds(), is(new Integer(healthTimeout))); assertThat(containers.get(0).getReadinessProbe().getInitialDelaySeconds(), is(new Integer(healthDelay))); assertThat(containers.get(0).getReadinessProbe().getFailureThreshold(), is(new Integer(10))); assertThat(containers.get(0).getReadinessProbe().getSuccessThreshold(), is(new Integer(4))); assertThat(containers.get(0).getReadinessProbe().getPeriodSeconds(), is(new Integer(33))); assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaCluster.ENV_VAR_STRIMZI_KAFKA_GC_LOG_ENABLED), is(Boolean.toString(AbstractModel.DEFAULT_JVM_GC_LOGGING_ENABLED))); assertThat(containers.get(0).getVolumeMounts().get(2).getName(), is(KafkaCluster.BROKER_CERTS_VOLUME)); assertThat(containers.get(0).getVolumeMounts().get(2).getMountPath(), is(KafkaCluster.BROKER_CERTS_VOLUME_MOUNT)); assertThat(containers.get(0).getVolumeMounts().get(1).getName(), is(KafkaCluster.CLUSTER_CA_CERTS_VOLUME)); assertThat(containers.get(0).getVolumeMounts().get(1).getMountPath(), is(KafkaCluster.CLUSTER_CA_CERTS_VOLUME_MOUNT)); assertThat(containers.get(0).getVolumeMounts().get(3).getName(), is(KafkaCluster.CLIENT_CA_CERTS_VOLUME)); assertThat(containers.get(0).getVolumeMounts().get(3).getMountPath(), is(KafkaCluster.CLIENT_CA_CERTS_VOLUME_MOUNT)); // checks on the TLS sidecar Container tlsSidecarContainer = containers.get(1); assertThat(tlsSidecarContainer.getImage(), is(image)); assertThat(AbstractModel.containerEnvVars(tlsSidecarContainer).get(KafkaCluster.ENV_VAR_KAFKA_ZOOKEEPER_CONNECT), is(ZookeeperCluster.serviceName(cluster) + ":" + ZookeeperCluster.CLIENT_TLS_PORT)); assertThat(AbstractModel.containerEnvVars(tlsSidecarContainer).get(ModelUtils.TLS_SIDECAR_LOG_LEVEL), is(TlsSidecarLogLevel.NOTICE.toValue())); assertThat(tlsSidecarContainer.getVolumeMounts().get(0).getName(), is(KafkaCluster.BROKER_CERTS_VOLUME)); assertThat(tlsSidecarContainer.getVolumeMounts().get(0).getMountPath(), is(KafkaCluster.TLS_SIDECAR_KAFKA_CERTS_VOLUME_MOUNT)); assertThat(tlsSidecarContainer.getVolumeMounts().get(1).getMountPath(), is(KafkaCluster.TLS_SIDECAR_CLUSTER_CA_CERTS_VOLUME_MOUNT)); assertThat(tlsSidecarContainer.getReadinessProbe().getInitialDelaySeconds(), is(new Integer(tlsHealthDelay))); assertThat(tlsSidecarContainer.getReadinessProbe().getTimeoutSeconds(), is(new Integer(tlsHealthTimeout))); assertThat(tlsSidecarContainer.getLivenessProbe().getInitialDelaySeconds(), is(new Integer(tlsHealthDelay))); assertThat(tlsSidecarContainer.getLivenessProbe().getTimeoutSeconds(), is(new Integer(tlsHealthTimeout))); if (cm.getSpec().getKafka().getRack() != null) { Rack rack = cm.getSpec().getKafka().getRack(); // check that the pod spec contains anti-affinity rules with the right topology key PodSpec podSpec = sts.getSpec().getTemplate().getSpec(); assertThat(podSpec.getAffinity(), is(notNullValue())); assertThat(podSpec.getAffinity().getPodAntiAffinity(), is(notNullValue())); assertThat(podSpec.getAffinity().getPodAntiAffinity().getPreferredDuringSchedulingIgnoredDuringExecution(), is(notNullValue())); List<WeightedPodAffinityTerm> terms = podSpec.getAffinity().getPodAntiAffinity().getPreferredDuringSchedulingIgnoredDuringExecution(); assertThat(terms, is(notNullValue())); assertThat(terms.size() > 0, is(true)); boolean isTopologyKey = terms.stream().anyMatch(term -> term.getPodAffinityTerm().getTopologyKey().equals(rack.getTopologyKey())); assertThat(isTopologyKey, is(true)); // check that pod spec contains the init Kafka container List<Container> initContainers = podSpec.getInitContainers(); assertThat(initContainers, is(notNullValue())); assertThat(initContainers.size() > 0, is(true)); boolean isInitKafka = initContainers.stream().anyMatch(container -> container.getName().equals(KafkaCluster.INIT_NAME)); assertThat(isInitKafka, is(true)); } }