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));
}
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));
}
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);
});
});
}
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);
});
}
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));
}
Aggregations