Search in sources :

Example 6 with StackGresClusterSpecAnnotations

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations in project stackgres by ongres.

the class ClusterAnnotationDecoratorTest method pods_shouldHavePodAnnotationsAndAllResourcesAnnotations.

@Test
void pods_shouldHavePodAnnotationsAndAllResourcesAnnotations() {
    String allResourceAnnotationKey = StringUtil.generateRandom(8);
    String allResourceAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().setPod(null);
    defaultCluster.getSpec().setPostgresServices(null);
    defaultCluster.getSpec().getMetadata().setAnnotations(new StackGresClusterSpecAnnotations());
    defaultCluster.getSpec().getMetadata().getAnnotations().setAllResources(ImmutableMap.of(allResourceAnnotationKey, allResourceAnnotationValue));
    String podAnnotationKey = StringUtil.generateRandom(8);
    String podAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().getMetadata().getAnnotations().setClusterPods(Map.of(podAnnotationKey, podAnnotationValue));
    annotationDecorator.decorate(context, resources);
    Map<String, String> expected = Map.of(allResourceAnnotationKey, allResourceAnnotationValue, podAnnotationKey, podAnnotationValue);
    resources.stream().filter(r -> r.getKind().equals("Pod")).forEach(resource -> checkVersionableResourceAnnotations(resource, expected));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) StackGresContext(io.stackgres.common.StackGresContext) BeforeEach(org.junit.jupiter.api.BeforeEach) StackGresProperty(io.stackgres.common.StackGresProperty) Mock(org.mockito.Mock) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StringUtil(io.stackgres.common.StringUtil) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) CronJob(io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob) ClusterAnnotationDecorator(io.stackgres.operator.conciliation.factory.cluster.ClusterAnnotationDecorator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) Mockito.when(org.mockito.Mockito.when) JobTemplateSpec(io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec) Truth.assertThat(com.google.common.truth.Truth.assertThat) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) JsonUtil(io.stackgres.testutil.JsonUtil) Test(org.junit.jupiter.api.Test) List(java.util.List) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PatroniUtil(io.stackgres.common.PatroniUtil) Optional(java.util.Optional) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) Test(org.junit.jupiter.api.Test)

Example 7 with StackGresClusterSpecAnnotations

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations in project stackgres by ongres.

the class ClusterAnnotationDecoratorTest method replicaServices_shouldHaveReplicaServiceAnnotations.

@Test
void replicaServices_shouldHaveReplicaServiceAnnotations() {
    defaultCluster.getSpec().getMetadata().setAnnotations(new StackGresClusterSpecAnnotations());
    String replicaAnnotationKey = StringUtil.generateRandom(8);
    String replicaAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().getMetadata().getAnnotations().setReplicasService(Map.of(replicaAnnotationKey, replicaAnnotationValue));
    String serviceAnnotationKey = StringUtil.generateRandom(8);
    String serviceAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().setPod(null);
    defaultCluster.getSpec().getPostgresServices().setPrimary(null);
    defaultCluster.getSpec().getMetadata().getAnnotations().setServices(Map.of(serviceAnnotationKey, serviceAnnotationValue));
    annotationDecorator.decorate(context, resources);
    Map<String, String> expected = Map.of(replicaAnnotationKey, replicaAnnotationValue, serviceAnnotationKey, serviceAnnotationValue);
    resources.stream().filter(r -> r.getKind().equals("Service")).filter(r -> r.getMetadata().getName().endsWith(PatroniUtil.READ_ONLY_SERVICE)).forEach(resource -> checkResourceAnnotations(resource, expected));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) StackGresContext(io.stackgres.common.StackGresContext) BeforeEach(org.junit.jupiter.api.BeforeEach) StackGresProperty(io.stackgres.common.StackGresProperty) Mock(org.mockito.Mock) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StringUtil(io.stackgres.common.StringUtil) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) CronJob(io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob) ClusterAnnotationDecorator(io.stackgres.operator.conciliation.factory.cluster.ClusterAnnotationDecorator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) Mockito.when(org.mockito.Mockito.when) JobTemplateSpec(io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec) Truth.assertThat(com.google.common.truth.Truth.assertThat) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) JsonUtil(io.stackgres.testutil.JsonUtil) Test(org.junit.jupiter.api.Test) List(java.util.List) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PatroniUtil(io.stackgres.common.PatroniUtil) Optional(java.util.Optional) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) Test(org.junit.jupiter.api.Test)

Example 8 with StackGresClusterSpecAnnotations

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations in project stackgres by ongres.

the class ClusterAnnotationDecoratorTest method allResourcesAnnotations_shouldBePresentInStatefulSetPersistenVolumeClaims.

@Test
void allResourcesAnnotations_shouldBePresentInStatefulSetPersistenVolumeClaims() {
    String allResourceAnnotationKey = StringUtil.generateRandom(8);
    String allResourceAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().setPod(null);
    defaultCluster.getSpec().setPostgresServices(null);
    defaultCluster.getSpec().getMetadata().setAnnotations(new StackGresClusterSpecAnnotations());
    defaultCluster.getSpec().getMetadata().getAnnotations().setAllResources(ImmutableMap.of(allResourceAnnotationKey, allResourceAnnotationValue));
    annotationDecorator.decorate(context, resources);
    Map<String, String> expected = Map.of(allResourceAnnotationKey, allResourceAnnotationValue);
    resources.stream().filter(r -> r.getKind().equals("StatefulSet")).forEach(resource -> {
        StatefulSet statefulSet = (StatefulSet) resource;
        statefulSet.getSpec().getVolumeClaimTemplates().forEach(template -> {
            checkResourceAnnotations(template, expected);
        });
    });
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) StackGresContext(io.stackgres.common.StackGresContext) BeforeEach(org.junit.jupiter.api.BeforeEach) StackGresProperty(io.stackgres.common.StackGresProperty) Mock(org.mockito.Mock) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StringUtil(io.stackgres.common.StringUtil) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) CronJob(io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob) ClusterAnnotationDecorator(io.stackgres.operator.conciliation.factory.cluster.ClusterAnnotationDecorator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) Mockito.when(org.mockito.Mockito.when) JobTemplateSpec(io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec) Truth.assertThat(com.google.common.truth.Truth.assertThat) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) JsonUtil(io.stackgres.testutil.JsonUtil) Test(org.junit.jupiter.api.Test) List(java.util.List) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PatroniUtil(io.stackgres.common.PatroniUtil) Optional(java.util.Optional) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.jupiter.api.Test)

Example 9 with StackGresClusterSpecAnnotations

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations in project stackgres by ongres.

the class ClusterAnnotationDecoratorTest method podsAnnotations_shouldBePresentInStatefulSetPodTemplates.

@Test
void podsAnnotations_shouldBePresentInStatefulSetPodTemplates() {
    String allResourceAnnotationKey = "AllResource-" + StringUtil.generateRandom(8);
    String allResourceAnnotationValue = "AllResource-" + StringUtil.generateRandom(8);
    defaultCluster.getSpec().setPod(null);
    defaultCluster.getSpec().setPostgresServices(null);
    defaultCluster.getSpec().getMetadata().setAnnotations(new StackGresClusterSpecAnnotations());
    defaultCluster.getSpec().getMetadata().getAnnotations().setAllResources(Map.of(allResourceAnnotationKey, allResourceAnnotationValue));
    String podAnnotationKey = "Pod-" + StringUtil.generateRandom(8);
    String podAnnotationValue = "Pod-" + StringUtil.generateRandom(8);
    defaultCluster.getSpec().getMetadata().getAnnotations().setClusterPods(Map.of(podAnnotationKey, podAnnotationValue));
    annotationDecorator.decorate(context, resources);
    Map<String, String> expectedSts = Map.of(allResourceAnnotationKey, allResourceAnnotationValue);
    Map<String, String> expectedPod = Map.of(allResourceAnnotationKey, allResourceAnnotationValue, podAnnotationKey, podAnnotationValue);
    resources.stream().filter(r -> r.getKind().equals("StatefulSet")).forEach(resource -> {
        checkResourceAnnotations(resource, expectedSts);
        StatefulSet statefulSet = (StatefulSet) resource;
        checkResourceAnnotations(statefulSet.getSpec().getTemplate(), expectedPod);
    });
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) StackGresContext(io.stackgres.common.StackGresContext) BeforeEach(org.junit.jupiter.api.BeforeEach) StackGresProperty(io.stackgres.common.StackGresProperty) Mock(org.mockito.Mock) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StringUtil(io.stackgres.common.StringUtil) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) CronJob(io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob) ClusterAnnotationDecorator(io.stackgres.operator.conciliation.factory.cluster.ClusterAnnotationDecorator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) Mockito.when(org.mockito.Mockito.when) JobTemplateSpec(io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec) Truth.assertThat(com.google.common.truth.Truth.assertThat) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) JsonUtil(io.stackgres.testutil.JsonUtil) Test(org.junit.jupiter.api.Test) List(java.util.List) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PatroniUtil(io.stackgres.common.PatroniUtil) Optional(java.util.Optional) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.jupiter.api.Test)

Example 10 with StackGresClusterSpecAnnotations

use of io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations in project stackgres by ongres.

the class ClusterAnnotationDecoratorTest method services_shouldHaveServicesAnnotationsAndAllResourcesAnnotations.

@Test
void services_shouldHaveServicesAnnotationsAndAllResourcesAnnotations() {
    String allResourceAnnotationKey = StringUtil.generateRandom(8);
    String allResourceAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().setPod(null);
    defaultCluster.getSpec().setPostgresServices(null);
    defaultCluster.getSpec().getMetadata().setAnnotations(new StackGresClusterSpecAnnotations());
    defaultCluster.getSpec().getMetadata().getAnnotations().setAllResources(Map.of(allResourceAnnotationKey, allResourceAnnotationValue));
    String serviceAnnotationKey = StringUtil.generateRandom(8);
    String serviceAnnotationValue = StringUtil.generateRandom(8);
    defaultCluster.getSpec().getMetadata().getAnnotations().setServices(Map.of(serviceAnnotationKey, serviceAnnotationValue));
    annotationDecorator.decorate(context, resources);
    Map<String, String> expected = Map.of(allResourceAnnotationKey, allResourceAnnotationValue, serviceAnnotationKey, serviceAnnotationValue);
    resources.stream().filter(r -> r.getKind().equals("Service")).forEach(resource -> checkResourceAnnotations(resource, expected));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) StackGresContext(io.stackgres.common.StackGresContext) BeforeEach(org.junit.jupiter.api.BeforeEach) StackGresProperty(io.stackgres.common.StackGresProperty) Mock(org.mockito.Mock) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StringUtil(io.stackgres.common.StringUtil) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) CronJob(io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob) ClusterAnnotationDecorator(io.stackgres.operator.conciliation.factory.cluster.ClusterAnnotationDecorator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) Mockito.when(org.mockito.Mockito.when) JobTemplateSpec(io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec) Truth.assertThat(com.google.common.truth.Truth.assertThat) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) JsonUtil(io.stackgres.testutil.JsonUtil) Test(org.junit.jupiter.api.Test) List(java.util.List) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PatroniUtil(io.stackgres.common.PatroniUtil) Optional(java.util.Optional) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterSpecAnnotations (io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations)15 Test (org.junit.jupiter.api.Test)10 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)9 CronJob (io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob)9 JobTemplateSpec (io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec)9 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Truth.assertThat (com.google.common.truth.Truth.assertThat)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)8 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)8 PatroniUtil (io.stackgres.common.PatroniUtil)8 StackGresContext (io.stackgres.common.StackGresContext)8 StackGresProperty (io.stackgres.common.StackGresProperty)8 StringUtil (io.stackgres.common.StringUtil)8 StackGresClusterContext (io.stackgres.operator.conciliation.cluster.StackGresClusterContext)8 ClusterAnnotationDecorator (io.stackgres.operator.conciliation.factory.cluster.ClusterAnnotationDecorator)8 JsonUtil (io.stackgres.testutil.JsonUtil)8 List (java.util.List)8 Map (java.util.Map)8