Search in sources :

Example 41 with OrderedProperties

use of io.strimzi.operator.common.model.OrderedProperties in project strimzi-kafka-operator by strimzi.

the class TestConfigurationWithoutDefaults method testNonEmptyConfigurationString.

@ParallelTest
public void testNonEmptyConfigurationString() {
    String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR;
    OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa");
    AbstractConfiguration config = new TestConfiguration(configuration);
    assertThat(config.asOrderedProperties(), is(expectedConfiguration));
}
Also used : OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 42 with OrderedProperties

use of io.strimzi.operator.common.model.OrderedProperties in project strimzi-kafka-operator by strimzi.

the class TestConfigurationWithoutDefaults method testConfigurationStringWithForbiddenKeysInUpperCase.

@ParallelTest
public void testConfigurationStringWithForbiddenKeysInUpperCase() {
    String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR + "FORBIDDEN.OPTION=ddd" + LINE_SEPARATOR;
    OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa");
    AbstractConfiguration config = new TestConfiguration(configuration);
    assertThat(config.asOrderedProperties(), is(expectedConfiguration));
}
Also used : OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 43 with OrderedProperties

use of io.strimzi.operator.common.model.OrderedProperties in project strimzi-kafka-operator by strimzi.

the class TestConfigurationWithoutDefaults method testConfigurationStringWithForbiddenKeys.

@ParallelTest
public void testConfigurationStringWithForbiddenKeys() {
    String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR + "forbidden.option=ddd" + LINE_SEPARATOR;
    OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa");
    AbstractConfiguration config = new TestConfiguration(configuration);
    assertThat(config.asOrderedProperties(), is(expectedConfiguration));
}
Also used : OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 44 with OrderedProperties

use of io.strimzi.operator.common.model.OrderedProperties in project strimzi-kafka-operator by strimzi.

the class TestConfigurationWithoutDefaults method testJsonWithForbiddenKeysPrefix.

@ParallelTest
public void testJsonWithForbiddenKeysPrefix() {
    JsonObject configuration = new JsonObject().put("var1", "aaa").put("var2", "bbb").put("var3", "ccc").put("forbidden.option.first", "ddd").put("forbidden.option.second", "ddd");
    OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa");
    AbstractConfiguration config = new TestConfiguration(configuration);
    assertThat(config.asOrderedProperties(), is(expectedConfiguration));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 45 with OrderedProperties

use of io.strimzi.operator.common.model.OrderedProperties in project strimzi-kafka-operator by strimzi.

the class ZookeeperPodSetTest method testPodSet.

@ParallelTest
public void testPodSet() {
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, KAFKA, VERSIONS);
    StrimziPodSet ps = zc.generatePodSet(3, true, null, null, Map.of());
    assertThat(ps.getMetadata().getName(), is(KafkaResources.zookeeperStatefulSetName(CLUSTER)));
    assertThat(ps.getMetadata().getLabels().entrySet().containsAll(zc.getLabelsWithStrimziName(zc.getName(), null).toMap().entrySet()), is(true));
    assertThat(ps.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_STORAGE), is(ModelUtils.encodeStorageToJson(new PersistentClaimStorageBuilder().withSize("100Gi").withDeleteClaim(false).build())));
    assertThat(ps.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(ps.getMetadata().getOwnerReferences().get(0), is(zc.createOwnerReference()));
    assertThat(ps.getSpec().getSelector().getMatchLabels(), is(zc.getSelectorLabels().toMap()));
    assertThat(ps.getSpec().getPods().size(), is(3));
    // We need to loop through the pods to make sure they have the right values
    List<Pod> pods = PodSetUtils.mapsToPods(ps.getSpec().getPods());
    for (Pod pod : pods) {
        assertThat(pod.getMetadata().getLabels().entrySet().containsAll(zc.getLabelsWithStrimziNameAndPodName(zc.getName(), pod.getMetadata().getName(), null).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(zc.getName()).toMap().entrySet()), is(true));
        assertThat(pod.getMetadata().getAnnotations().size(), is(1));
        assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
        assertThat(pod.getSpec().getHostname(), is(pod.getMetadata().getName()));
        assertThat(pod.getSpec().getSubdomain(), is(zc.getHeadlessServiceName()));
        assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
        assertThat(pod.getSpec().getTerminationGracePeriodSeconds(), is(30L));
        assertThat(pod.getSpec().getVolumes().stream().filter(volume -> volume.getName().equalsIgnoreCase("strimzi-tmp")).findFirst().orElse(null).getEmptyDir().getSizeLimit(), is(new Quantity(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_SIZE)));
        assertThat(pod.getSpec().getContainers().size(), is(1));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds(), is(15));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds(), is(15));
        assertThat(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(ZookeeperCluster.ENV_VAR_STRIMZI_KAFKA_GC_LOG_ENABLED), is(Boolean.toString(AbstractModel.DEFAULT_JVM_GC_LOGGING_ENABLED)));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is(AbstractModel.VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/var/lib/zookeeper"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getName(), is("zookeeper-metrics-and-logging"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getMountPath(), is("/opt/kafka/custom-config/"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getName(), is(ZookeeperCluster.ZOOKEEPER_NODE_CERTIFICATES_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getMountPath(), is(ZookeeperCluster.ZOOKEEPER_NODE_CERTIFICATES_VOLUME_MOUNT));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getName(), is(ZookeeperCluster.ZOOKEEPER_CLUSTER_CA_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getMountPath(), is(ZookeeperCluster.ZOOKEEPER_CLUSTER_CA_VOLUME_MOUNT));
        // Config
        OrderedProperties expectedConfig = new OrderedProperties().addMapPairs(ZookeeperConfiguration.DEFAULTS);
        OrderedProperties actual = new OrderedProperties().addStringPairs(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(ZookeeperCluster.ENV_VAR_ZOOKEEPER_CONFIGURATION));
        assertThat(actual, is(expectedConfig));
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) SecurityContextBuilder(io.fabric8.kubernetes.api.model.SecurityContextBuilder) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Collections.singletonMap(java.util.Collections.singletonMap) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PodRevision(io.strimzi.operator.cluster.operator.resource.PodRevision) Affinity(io.fabric8.kubernetes.api.model.Affinity) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Probe(io.strimzi.api.kafka.model.Probe) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) Pod(io.fabric8.kubernetes.api.model.Pod) Toleration(io.fabric8.kubernetes.api.model.Toleration) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) List(java.util.List) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

OrderedProperties (io.strimzi.operator.common.model.OrderedProperties)46 ParallelTest (io.strimzi.test.annotations.ParallelTest)24 Map (java.util.Map)20 Reconciliation (io.strimzi.operator.common.Reconciliation)16 JsonObject (io.vertx.core.json.JsonObject)16 ArrayList (java.util.ArrayList)14 List (java.util.List)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)12 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)12 Collections (java.util.Collections)10 Collections.emptyMap (java.util.Collections.emptyMap)10 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 HostAlias (io.fabric8.kubernetes.api.model.HostAlias)8 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 PodSecurityContextBuilder (io.fabric8.kubernetes.api.model.PodSecurityContextBuilder)8 Quantity (io.fabric8.kubernetes.api.model.Quantity)8 Secret (io.fabric8.kubernetes.api.model.Secret)8 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)8