From c580cff065ff01e56f08cdba73b0fc42c7454995 Mon Sep 17 00:00:00 2001 From: Matteo Melli Date: Fri, 15 Dec 2023 21:37:57 +0100 Subject: [PATCH 01/27] fix: SGScript status is corrupted for SGShardedCluster --- ?/.redhat/anonymousId | 1 - .../StackGresShardedClusterForCitusUtil.java | 71 ++++++++++++++++++- ...tractStatefulSetReconciliationHandler.java | 6 +- .../cluster/ScriptsConfigMutator.java | 4 +- ...rStatefulSetReconciliationHandlerTest.java | 2 +- .../cluster/ScriptsConfigMutatorTest.java | 20 ++++++ .../java/io/stackgres/testutil/JsonUtil.java | 15 ++++ 7 files changed, 111 insertions(+), 8 deletions(-) delete mode 100644 ?/.redhat/anonymousId diff --git a/?/.redhat/anonymousId b/?/.redhat/anonymousId deleted file mode 100644 index b12cd9af80..0000000000 --- a/?/.redhat/anonymousId +++ /dev/null @@ -1 +0,0 @@ -c93a885b-ce4e-4df8-9cc1-7f90b5a37d5e \ No newline at end of file diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java index ccd8898f53..6906f71d1a 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java @@ -15,6 +15,7 @@ import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.stackgres.common.ManagedSqlUtil; import io.stackgres.common.StackGresShardedClusterUtil; import io.stackgres.common.crd.SecretKeySelector; import io.stackgres.common.crd.postgres.service.StackGresPostgresService; @@ -25,6 +26,10 @@ import io.stackgres.common.crd.sgcluster.StackGresClusterCredentials; import io.stackgres.common.crd.sgcluster.StackGresClusterExtensionBuilder; import io.stackgres.common.crd.sgcluster.StackGresClusterInitialDataBuilder; +import io.stackgres.common.crd.sgcluster.StackGresClusterManagedScriptEntry; +import io.stackgres.common.crd.sgcluster.StackGresClusterManagedScriptEntryBuilder; +import io.stackgres.common.crd.sgcluster.StackGresClusterManagedSql; +import io.stackgres.common.crd.sgcluster.StackGresClusterManagedSqlBuilder; import io.stackgres.common.crd.sgcluster.StackGresClusterPatroni; import io.stackgres.common.crd.sgcluster.StackGresClusterPatroniConfig; import io.stackgres.common.crd.sgcluster.StackGresClusterPatroniCredentials; @@ -140,7 +145,7 @@ static StackGresCluster getShardsCluster(StackGresShardedCluster cluster, int in index)) .findFirst() .ifPresent(specOverride -> setClusterSpecFromShardOverrides( - specOverride, spec, index + 1)); + cluster, specOverride, spec, index + 1)); StackGresCluster shardsCluster = new StackGresCluster(); shardsCluster.setMetadata(new ObjectMeta()); shardsCluster.getMetadata().setNamespace(cluster.getMetadata().getNamespace()); @@ -180,6 +185,7 @@ private static void setClusterSpecFromShardedCluster( setConfigurationsPatroniInitialConfig(cluster, spec, index); setMetadata(cluster, spec, index); setInitialData(cluster, spec, index); + setManagedSql(cluster, spec, index); spec.setDistributedLogs(cluster.getSpec().getDistributedLogs()); spec.setPrometheusAutobind(cluster.getSpec().getPrometheusAutobind()); spec.setNonProductionOptions(cluster.getSpec().getNonProductionOptions()); @@ -409,8 +415,48 @@ private static void setInitialData( } } + private static void setManagedSql( + StackGresShardedCluster cluster, + StackGresClusterSpec spec, + int index) { + final String defaultScript = ManagedSqlUtil.defaultName(getClusterName(cluster, index)); + spec.setManagedSql(new StackGresClusterManagedSqlBuilder(spec.getManagedSql()) + .withScripts( + Optional.ofNullable(spec.getManagedSql()) + .map(StackGresClusterManagedSql::getScripts) + .map(scripts -> Seq + .of(new StackGresClusterManagedScriptEntryBuilder() + .withId(getLastId(spec) + 1) + .withSgScript(defaultScript) + .build()) + .filter(script -> scripts.stream() + .map(StackGresClusterManagedScriptEntry::getSgScript) + .noneMatch(defaultScript::equals)) + .append(scripts) + .toList()) + .orElse(List + .of(new StackGresClusterManagedScriptEntryBuilder() + .withId(0) + .withSgScript(defaultScript) + .build()))) + .build()); + } + + private static Integer getLastId(StackGresClusterSpec spec) { + return Optional.of(spec) + .map(StackGresClusterSpec::getManagedSql) + .map(StackGresClusterManagedSql::getScripts) + .stream() + .flatMap(List::stream) + .map(StackGresClusterManagedScriptEntry::getId) + .reduce(-1, (last, id) -> id == null || last >= id ? last : id, (u, v) -> v); + } + private static void setClusterSpecFromShardOverrides( - StackGresShardedClusterShard specOverride, StackGresClusterSpec spec, int index) { + StackGresShardedCluster cluster, + StackGresShardedClusterShard specOverride, + StackGresClusterSpec spec, + int index) { if (specOverride.getConfigurationsForShards() != null) { if (specOverride.getConfigurationsForShards().getSgPostgresConfig() != null) { spec.getConfigurations().setSgPostgresConfig( @@ -431,7 +477,26 @@ private static void setClusterSpecFromShardOverrides( spec.setReplication(specOverride.getReplicationForShards()); } if (specOverride.getManagedSql() != null) { - spec.setManagedSql(specOverride.getManagedSql()); + final String defaultScript = ManagedSqlUtil.defaultName(getClusterName(cluster, index)); + spec.setManagedSql(new StackGresClusterManagedSqlBuilder(specOverride.getManagedSql()) + .withScripts( + Optional.ofNullable(specOverride.getManagedSql().getScripts()) + .map(scripts -> Seq + .of(new StackGresClusterManagedScriptEntryBuilder() + .withId(getLastId(specOverride) + 1) + .withSgScript(defaultScript) + .build()) + .filter(script -> scripts.stream() + .map(StackGresClusterManagedScriptEntry::getSgScript) + .noneMatch(defaultScript::equals)) + .append(scripts) + .toList()) + .orElse(List + .of(new StackGresClusterManagedScriptEntryBuilder() + .withId(0) + .withSgScript(defaultScript) + .build()))) + .build()); } if (specOverride.getMetadata() != null) { if (spec.getMetadata() == null) { diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractStatefulSetReconciliationHandler.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractStatefulSetReconciliationHandler.java index 70e652df16..720a4ba65d 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractStatefulSetReconciliationHandler.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractStatefulSetReconciliationHandler.java @@ -105,7 +105,7 @@ public AbstractStatefulSetReconciliationHandler() { @Override public HasMetadata create(T context, HasMetadata resource) { - return concileSts(context, resource, (c, sts) -> updateStatefulSet(c, sts)); + return concileSts(context, resource, (c, sts) -> createStatefulSet(c, sts)); } @Override @@ -136,6 +136,10 @@ private StatefulSet safeCast(HasMetadata resource) { return (StatefulSet) resource; } + private StatefulSet createStatefulSet(T context, StatefulSet requiredSts) { + return (StatefulSet) handler.create(context, requiredSts); + } + private StatefulSet updateStatefulSet(T context, StatefulSet requiredSts) { try { return (StatefulSet) handler.patch(context, requiredSts, null); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutator.java index 4f1bd6141a..585b922921 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutator.java @@ -68,10 +68,10 @@ private void addDefaultScripts(StackGresCluster resource) { resource.getStatus().getManagedSql().setScripts(new ArrayList<>()); } resource.getStatus().getManagedSql().getScripts() - .removeIf(entry -> Objects.equals(0, entry.getId())); + .removeIf(entry -> Objects.equals(lastId + 1, entry.getId())); resource.getStatus().getManagedSql().getScripts() .add(0, new StackGresClusterManagedScriptEntryStatus()); - resource.getStatus().getManagedSql().getScripts().get(0).setId(0); + resource.getStatus().getManagedSql().getScripts().get(0).setId(lastId + 1); } private void fillRequiredFields(StackGresCluster resource) { diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/cluster/ClusterStatefulSetReconciliationHandlerTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/cluster/ClusterStatefulSetReconciliationHandlerTest.java index f350f0a78e..fc3bdf6cc4 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/cluster/ClusterStatefulSetReconciliationHandlerTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/cluster/ClusterStatefulSetReconciliationHandlerTest.java @@ -146,7 +146,7 @@ void createResource_shouldValidateTheResourceType() { @Test void createResource_shouldCreateTheResource() { - when(defaultHandler.patch(any(), any(StatefulSet.class), any())) + when(defaultHandler.create(any(), any(StatefulSet.class))) .thenReturn(requiredStatefulSet); HasMetadata sts = handler.create(cluster, requiredStatefulSet); diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutatorTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutatorTest.java index b942ff59fb..607f498f2c 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutatorTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/mutation/cluster/ScriptsConfigMutatorTest.java @@ -282,4 +282,24 @@ void updateClusterRemovingAnEntry_shouldRemoveItsStatus() { JsonUtil.toJson(result)); } + @Test + void updateClusterWithDefaultRemovedWithDifferentId_shouldAddDefaultAndResetStatus() { + StackGresClusterReview review = AdmissionReviewFixtures.cluster() + .loadUpdateWithManagedSql().get(); + + review.getRequest().getObject().getStatus().getManagedSql().getScripts().get(0).setId(4); + StackGresCluster expected = JsonUtil.copy(review.getRequest().getObject()); + review.getRequest().getObject().getSpec().getManagedSql().getScripts().remove(0); + expected.getSpec().getManagedSql().getScripts().get(0).setId(4); + expected.getStatus().getManagedSql().getScripts().get(0).setId(4); + JsonNode expectedCluster = JsonUtil.toJson(expected); + + StackGresCluster result = mutator.mutate( + review, JsonUtil.copy(review.getRequest().getObject())); + + JsonUtil.assertJsonEquals( + expectedCluster, + JsonUtil.toJson(result)); + } + } diff --git a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/JsonUtil.java b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/JsonUtil.java index 757e163676..f2089b33d1 100644 --- a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/JsonUtil.java +++ b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/JsonUtil.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import junit.framework.AssertionFailedError; import org.json.JSONException; import org.skyscreamer.jsonassert.JSONAssert; @@ -29,10 +30,24 @@ private static JsonMapper createJsonMapper() { .build(); } + private static final YAMLMapper YAML_MAPPER = createYamlMapper(); + + private static YAMLMapper createYamlMapper() { + return YAMLMapper.builder() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS) + .build(); + } + public static JsonMapper jsonMapper() { return JSON_MAPPER; } + public static YAMLMapper yamlMapper() { + return YAML_MAPPER; + } + public static JsonNode toJson(Object object) { return JSON_MAPPER.valueToTree(object); } From b1c53d5414d6115e8c86e708bf1cc7d64fcb101a Mon Sep 17 00:00:00 2001 From: Matteo Melli Date: Mon, 18 Dec 2023 09:43:22 +0100 Subject: [PATCH 02/27] chore: set versions-1.6.properties as versions.properties from branch main-1.6 --- .../main/resources/versions-1.6.properties | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stackgres-k8s/src/common/src/main/resources/versions-1.6.properties b/stackgres-k8s/src/common/src/main/resources/versions-1.6.properties index 4763fc7a59..6245f5da19 100644 --- a/stackgres-k8s/src/common/src/main/resources/versions-1.6.properties +++ b/stackgres-k8s/src/common/src/main/resources/versions-1.6.properties @@ -1,10 +1,10 @@ -patroni=2.1.4-build-6.17,3.0.2-build-6.22,3.2.0-build-6.28 -postgresql=12.9-build-6.17,12.10-build-6.17,12.11-build-6.17,12.12-build-6.17,12.13-build-6.28,12.14-build-6.28,12.15-build-6.28,12.16-build-6.28,13.5-build-6.17,13.6-build-6.17,13.7-build-6.22,13.8-build-6.22,13.9-build-6.28,13.10-build-6.28,13.11-build-6.28,13.12-build-6.28,14.1-build-6.17,14.2-build-6.17,14.3-build-6.22,14.4-build-6.22,14.5-build-6.22,14.6-build-6.28,14.7-build-6.28,14.8-build-6.28,14.9-build-6.28,15.0-build-6.22,15.1-build-6.28,15.2-build-6.28,15.3-build-6.28,15.4-build-6.28,16.0-build-6.28 -babelfish=13.6-build-6.17,13.9-build-6.28,14.3-build-6.17,14.7-build-6.28,15.3-build-6.28 -envoy=1.24.12-build-6.28 -pgbouncer=1.21.0-build-6.28 -prometheus-postgres-exporter=0.12.1-build-6.28 -fluentbit=1.9.9-build-6.28 -fluentd=1.15.3-build-6.28 -kubectl=1.28.2-build-6.28,1.25.14-build-6.28,1.22.17-build-6.28,1.19.16-build-6.28 -babelfish-compass=2023.10-build-6.28 +patroni=2.1.4-build-6.17,3.0.2-build-6.22,3.2.0-build-6.29 +postgresql=12.9-build-6.17,12.10-build-6.17,12.11-build-6.17,12.12-build-6.17,12.13-build-6.29,12.14-build-6.29,12.15-build-6.29,12.16-build-6.29,12.17-build-6.29,13.5-build-6.17,13.6-build-6.17,13.7-build-6.22,13.8-build-6.22,13.9-build-6.29,13.10-build-6.29,13.11-build-6.29,13.12-build-6.29,13.13-build-6.29,14.1-build-6.17,14.2-build-6.17,14.3-build-6.22,14.4-build-6.22,14.5-build-6.22,14.6-build-6.29,14.7-build-6.29,14.8-build-6.29,14.9-build-6.29,14.10-build-6.29,15.0-build-6.22,15.1-build-6.29,15.2-build-6.29,15.3-build-6.29,15.4-build-6.29,15.5-build-6.29,16.0-build-6.29,16.1-build-6.29 +babelfish=13.6-build-6.17,13.9-build-6.29,14.3-build-6.17,14.7-build-6.29,15.3-build-6.29 +envoy=1.24.12-build-6.29 +pgbouncer=1.21.0-build-6.29 +prometheus-postgres-exporter=0.12.1-build-6.29 +fluentbit=1.9.9-build-6.29 +fluentd=1.15.3-build-6.29 +kubectl=1.28.2-build-6.29,1.25.14-build-6.29,1.22.17-build-6.29,1.19.16-build-6.29 +babelfish-compass=2023.10-build-6.29 From 870472fe9df497a4b9b94ef8bfc174e6785045ee Mon Sep 17 00:00:00 2001 From: Matteo Melli Date: Tue, 19 Dec 2023 13:21:42 +0100 Subject: [PATCH 03/27] fix: native image require fixing CRD schema before updating --- .../templates/operator-cluster-role.yaml | 1 + .../ProxiedKubernetesClientProducer.java | 8 ++ .../stackgres/operator/app/CrdInstaller.java | 78 ++++++++++++++----- .../operator/app/CrdInstallerTest.java | 8 +- 4 files changed, 74 insertions(+), 21 deletions(-) diff --git a/stackgres-k8s/install/helm/stackgres-operator/templates/operator-cluster-role.yaml b/stackgres-k8s/install/helm/stackgres-operator/templates/operator-cluster-role.yaml index a30214fb00..95b896370f 100644 --- a/stackgres-k8s/install/helm/stackgres-operator/templates/operator-cluster-role.yaml +++ b/stackgres-k8s/install/helm/stackgres-operator/templates/operator-cluster-role.yaml @@ -198,5 +198,6 @@ rules: - sgscripts.stackgres.io verbs: - patch + - update {{- end }} {{- end }} diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/kubernetesclient/ProxiedKubernetesClientProducer.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/kubernetesclient/ProxiedKubernetesClientProducer.java index 826afaab4b..1ad4b64b7d 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/kubernetesclient/ProxiedKubernetesClientProducer.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/kubernetesclient/ProxiedKubernetesClientProducer.java @@ -42,6 +42,10 @@ public ProxiedKubernetesClientProducer( new KubernetesClientInvocationHandler(client)); } + public KubernetesClient getClient() { + return client; + } + @Produces public KubernetesClient create() { return proxyClient; @@ -65,6 +69,10 @@ public KubernetesClientInvocationHandler(KubernetesClient client) { this.client = client; } + public KubernetesClient getClient() { + return client; + } + @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("close".equals(method.getName())) { diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java index bb32f3c66a..27d5e0f77f 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java @@ -5,6 +5,7 @@ package io.stackgres.operator.app; +import java.lang.reflect.Proxy; import java.util.List; import java.util.Optional; import java.util.function.Predicate; @@ -16,12 +17,14 @@ import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext; +import io.fabric8.kubernetes.client.impl.BaseClient; import io.stackgres.common.CrdLoader; import io.stackgres.common.StackGresVersion; import io.stackgres.common.YamlMapperProvider; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs; import io.stackgres.common.crd.sgshardedcluster.StackGresShardedCluster; +import io.stackgres.common.kubernetesclient.ProxiedKubernetesClientProducer.KubernetesClientInvocationHandler; import io.stackgres.common.resource.ResourceFinder; import io.stackgres.common.resource.ResourceWriter; import jakarta.enterprise.context.ApplicationScoped; @@ -103,23 +106,6 @@ public void installCustomResourceDefinitions() { .forEach(this::installCrd); } - private CustomResourceDefinition fixCrd(CustomResourceDefinition crd) { - crd.getSpec().getVersions() - .forEach(crdVersion -> fixOpenApiProps(crdVersion.getSchema().getOpenAPIV3Schema())); - return crd; - } - - private void fixOpenApiProps(JSONSchemaProps props) { - if (props == null) { - return; - } - props.setDependencies(null); - props.getDefinitions().values().forEach(this::fixOpenApiProps); - if (props.getItems() != null) { - fixOpenApiProps(props.getItems().getSchema()); - } - } - protected void installCrd(@NotNull CustomResourceDefinition currentCrd) { String name = currentCrd.getMetadata().getName(); LOGGER.info("Installing CRD " + name); @@ -133,13 +119,34 @@ protected void installCrd(@NotNull CustomResourceDefinition currentCrd) { upgradeCrd(currentCrd, installedCrd); } updateAlreadyInstalledVersions(currentCrd, installedCrd); - crdResourceWriter.update(installedCrd); + crdResourceWriter.update(installedCrd, foundCrd -> { + fixCrd(installedCrd); + foundCrd.setSpec(installedCrd.getSpec()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Updating CRD:\n{}", + serializeToJsonAsKubernetesClient(foundCrd)); + } + }); } else { LOGGER.info("CRD {} is not present, installing it", name); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Creating CRD:\n{}", serializeToJsonAsKubernetesClient(currentCrd)); + } crdResourceWriter.create(currentCrd); } } + private String serializeToJsonAsKubernetesClient(CustomResourceDefinition foundCrd) { + try { + return BaseClient.class.cast( + KubernetesClientInvocationHandler.class.cast( + Proxy.getInvocationHandler(client)).getClient()) + .getKubernetesSerialization().asJson(foundCrd); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + private void updateAlreadyInstalledVersions(CustomResourceDefinition currentCrd, CustomResourceDefinition installedCrd) { installedCrd.getSpec().getVersions().forEach(installedVersion -> { @@ -164,7 +171,14 @@ private void upgradeCrd( CustomResourceDefinition installedCrd) { disableStorageVersions(installedCrd); addNewSchemaVersions(currentCrd, installedCrd); - crdResourceWriter.update(installedCrd); + crdResourceWriter.update(installedCrd, foundCrd -> { + fixCrd(installedCrd); + foundCrd.setSpec(installedCrd.getSpec()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Updating CRD:\n{}", + serializeToJsonAsKubernetesClient(foundCrd)); + } + }); } private void disableStorageVersions(CustomResourceDefinition installedCrd) { @@ -219,4 +233,30 @@ protected void checkCrd(@NotNull CustomResourceDefinition currentCrd) { } } + private CustomResourceDefinition fixCrd(CustomResourceDefinition crd) { + crd.getSpec().getVersions() + .forEach(crdVersion -> fixOpenApiProps( + "openAPIV3Schema", + crdVersion.getSchema().getOpenAPIV3Schema())); + return crd; + } + + private void fixOpenApiProps(String key, JSONSchemaProps props) { + LOGGER.trace("Inspecting key {}", key); + if (props == null) { + return; + } + if (props.getDependencies() != null) { + LOGGER.trace("Setting dependencies null for key {}", key); + props.setDependencies(null); + } + props.getProperties().entrySet().forEach(e -> fixOpenApiProps( + key + "." + e.getKey(), e.getValue())); + props.getDefinitions().entrySet().forEach(e -> fixOpenApiProps( + key + "." + e.getKey(), e.getValue())); + if (props.getItems() != null) { + fixOpenApiProps(key + "[]", props.getItems().getSchema()); + } + } + } diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/CrdInstallerTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/CrdInstallerTest.java index ff833d3530..90cfb45659 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/CrdInstallerTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/CrdInstallerTest.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Consumer; import io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder; import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList; @@ -33,6 +34,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; @@ -176,13 +178,15 @@ void installCrd_shouldPatchTheResourceIfExists() { .thenAnswer((Answer>) invocation -> Optional .of(crdLoader.getCrd(definition.getSpec().getNames().getKind()))); - when(customResourceDefinitionWriter.update(any(CustomResourceDefinition.class))) + when(customResourceDefinitionWriter.update(any(CustomResourceDefinition.class), + Mockito.>any())) .thenReturn(definition); crdInstaller.installCrd(definition); verify(customResourceDefinitionFinder).findByName(definition.getMetadata().getName()); - verify(customResourceDefinitionWriter).update(any(CustomResourceDefinition.class)); + verify(customResourceDefinitionWriter).update(any(CustomResourceDefinition.class), + Mockito.>any()); } } From cdc18d50af61b621d12ccef22b099c65dea68eac Mon Sep 17 00:00:00 2001 From: Matteo Melli Date: Wed, 20 Dec 2023 00:23:23 +0100 Subject: [PATCH 04/27] chore: skip building swagger for restapi after tests --- stackgres-k8s/ci/build/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/stackgres-k8s/ci/build/config.yml b/stackgres-k8s/ci/build/config.yml index df680980c4..ad91a01764 100644 --- a/stackgres-k8s/ci/build/config.yml +++ b/stackgres-k8s/ci/build/config.yml @@ -134,8 +134,6 @@ modules: - sh stackgres-k8s/ci/build/redact-version.sh api-web sources: - stackgres-k8s/src/api-web/src/test - post_build_commands: - - 'sh $SHELL_XTRACE stackgres-k8s/src/api-web/src/main/swagger/build.sh' artifacts: - stackgres-k8s/src/api-web/target jobs-java: From 5c2e5f81e3d009ba834ee313e082a88b47429cea Mon Sep 17 00:00:00 2001 From: Matteo Melli Date: Wed, 20 Dec 2023 11:56:58 +0100 Subject: [PATCH 05/27] e2e: try to fix subtle ARM bug with calico --- stackgres-k8s/e2e/envs/kind | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stackgres-k8s/e2e/envs/kind b/stackgres-k8s/e2e/envs/kind index 4a519ef175..54ae6f5a76 100755 --- a/stackgres-k8s/e2e/envs/kind +++ b/stackgres-k8s/e2e/envs/kind @@ -318,14 +318,14 @@ EOF echo "Setting up calico for kind..." until kubectl get node --template '{{ if (index .items 0).spec.podCIDR }}true{{ end }}' | grep -q 'true' do - sleep 1 + sleep 3 done K8S_POD_CIDR="$(kubectl get node --template '{{ (index .items 0).spec.podCIDR }}')" if [ "$(echo "$K8S_VERSION" | tr . '\n' | head -n 2 | xargs -I @ printf '%05d' @)" \ -ge "$(echo "1.22" | tr . '\n' | xargs -I @ printf '%05d' @)" ] then - kubectl create -f https://docs.projectcalico.org/archive/v3.24/manifests/tigera-operator.yaml - kubectl create -f https://docs.projectcalico.org/archive/v3.24/manifests/custom-resources.yaml + kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.4/manifests/tigera-operator.yaml + kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.4/manifests/custom-resources.yaml kubectl patch installations.operator.tigera.io default --type json \ -p '[{"op":"replace","path":"/spec/calicoNetwork/ipPools/0/cidr","value":"'"$K8S_POD_CIDR"'"}]' else From 4ab4cf9f778b8d64ba951760796c6b15f6cc8083 Mon Sep 17 00:00:00 2001 From: Matteo Melli Date: Wed, 20 Dec 2023 13:22:03 +0100 Subject: [PATCH 06/27] fix: PostgresStatDto was not annotated properly for native image --- .../io/stackgres/apiweb/dto/pgstat/PostgresStatDto.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/pgstat/PostgresStatDto.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/pgstat/PostgresStatDto.java index 99c928e2c0..722db1cfa6 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/pgstat/PostgresStatDto.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/pgstat/PostgresStatDto.java @@ -7,4 +7,12 @@ import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.quarkus.runtime.annotations.RegisterForReflection; +import io.stackgres.apiweb.dto.ResourceClassForDto; +import io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_DEFAULT) +@ResourceClassForDto(StackGresPostgresConfig.class) public record PostgresStatDto(int resultSetIndex, List fields) { } From 951c60d31e690b3cbdd23f290da2392aeb8ff04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Wed, 29 Nov 2023 12:56:58 +0100 Subject: [PATCH 07/27] chore: Follow slf4j best practices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../AbstractClusterStatsDtoFinder.java | 2 +- .../ClusterExtensionReconciliator.java | 4 ++-- .../PatroniStandbyHistoryReconciliator.java | 3 +-- .../controller/PostgresSslReconciliator.java | 2 +- .../common/validation/ValidationUtil.java | 3 +-- .../DistributedLogsClusterReconciliator.java | 3 +-- ...DistributedLogsExtensionReconciliator.java | 4 ++-- .../dbops/AbstractRestartStateHandler.java | 23 +++++++++---------- .../io/stackgres/jobs/dbops/MutinyUtil.java | 2 +- .../MinorVersionUpgradeJob.java | 2 +- .../reconciliation/ReconciliationCycle.java | 17 +++++++------- .../resource/WatcherMonitor.java | 6 ++--- .../stackgres/operator/app/CrdInstaller.java | 2 +- .../app/DefaultOperatorBootstrap.java | 2 +- .../conciliation/AbstractConciliator.java | 14 +++-------- .../dbops/DbOpsStatusManager.java | 3 +-- .../ShardedDbOpsStatusManager.java | 3 +-- .../conversion/ConversionResource.java | 2 +- .../java/io/stackgres/operator/ItHelper.java | 19 ++++++++------- .../operator/KubernetesOperatorRunner.java | 2 +- .../app/MockKubernetesClientFactory.java | 2 +- 21 files changed, 52 insertions(+), 68 deletions(-) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/resource/AbstractClusterStatsDtoFinder.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/resource/AbstractClusterStatsDtoFinder.java index fb4b0a0294..dfa698cb92 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/resource/AbstractClusterStatsDtoFinder.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/resource/AbstractClusterStatsDtoFinder.java @@ -110,7 +110,7 @@ protected ImmutableMap getPodStats(Pod pod) { LOGGER.debug("An error accurred while retrieving stats for pod {}.{}: {}", pod.getMetadata().getNamespace(), pod.getMetadata().getName(), - ex.getMessage()); + ex.getMessage(), ex); return ImmutableMap.of(); } } diff --git a/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/ClusterExtensionReconciliator.java b/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/ClusterExtensionReconciliator.java index cf3c166f07..350c6fd9d1 100644 --- a/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/ClusterExtensionReconciliator.java +++ b/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/ClusterExtensionReconciliator.java @@ -64,7 +64,7 @@ protected void onUninstallException(KubernetesClient client, StackGresCluster cl eventController.sendEvent(ClusterControllerEventReason.CLUSTER_CONTROLLER_ERROR, message + ": " + ex.getMessage(), cluster, client); } catch (Exception rex) { - LOGGER.error("Failed sending event while reconciling extension " + extension, rex); + LOGGER.error("Failed sending event while reconciling extension {}", extension, rex); } } @@ -84,7 +84,7 @@ protected void onInstallException(KubernetesClient client, StackGresCluster clus eventController.sendEvent(ClusterControllerEventReason.CLUSTER_CONTROLLER_ERROR, message + ": " + ex.getMessage(), cluster, client); } catch (Exception rex) { - LOGGER.error("Failed sending event while reconciling extension " + extension, rex); + LOGGER.error("Failed sending event while reconciling extension {}", extension, rex); } } diff --git a/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PatroniStandbyHistoryReconciliator.java b/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PatroniStandbyHistoryReconciliator.java index 538f9005aa..e3e612b7cf 100644 --- a/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PatroniStandbyHistoryReconciliator.java +++ b/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PatroniStandbyHistoryReconciliator.java @@ -72,8 +72,7 @@ public ReconciliationResult reconcile(KubernetesClient client, ClusterCont try { reconcileBootstrappedStandbyLeaderWithAntHistory(context); } catch (Exception ex) { - LOGGER.error("An error occurred while" - + " reconciling patroni history for standby cluster", ex); + LOGGER.error("An error occurred while reconciling patroni history for standby cluster", ex); try { eventController.sendEvent(ClusterControllerEventReason.CLUSTER_CONTROLLER_ERROR, "An error occurred while reconciling patroni history for standby cluster: " diff --git a/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PostgresSslReconciliator.java b/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PostgresSslReconciliator.java index d7320837ce..deb9e69c79 100644 --- a/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PostgresSslReconciliator.java +++ b/stackgres-k8s/src/cluster-controller/src/main/java/io/stackgres/cluster/controller/PostgresSslReconciliator.java @@ -114,7 +114,7 @@ private void reconcilePostgresSsl(KubernetesClient client, StackGresClusterConte try { PatroniCommandUtil.reloadPatroniConfig(); } catch (Exception ex) { - LOGGER.warn("Was not able to reload Patroni, will try later if needed: " + ex.getMessage()); + LOGGER.warn("Was not able to reload Patroni, will try later if needed: {}", ex.getMessage(), ex); } LOGGER.info("SSL config updated"); eventController.sendEvent(ClusterPatroniConfigEventReason.CLUSTER_PATRONI_CONFIG_UPDATED, diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/validation/ValidationUtil.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/validation/ValidationUtil.java index e38759202e..fa2757cf7c 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/validation/ValidationUtil.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/validation/ValidationUtil.java @@ -53,8 +53,7 @@ private static String replacePropertyPathWithJsonProperties( (u, v) -> v) .v1().toString(); } catch (Exception ex) { - LOGGER.warn("Can not translate path " + propertyPath + " using @JsonProperty annotations", - ex); + LOGGER.warn("Can not translate path {} using @JsonProperty annotations", propertyPath, ex); return propertyPath; } } diff --git a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java index 3f73f2db6e..5cff58dec8 100644 --- a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java +++ b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java @@ -196,8 +196,7 @@ private void handleException(KubernetesClient client, StackGresDistributedLogs d DistributedLogsControllerEventReason.DISTRIBUTEDLOGS_CONTROLLER_ERROR, message + ": " + ex.getMessage(), distributedLogs, client); } catch (RuntimeException rex) { - LOGGER.error("Failed sending event while reconciling cluster " - + cluster.getNamespace() + "." + cluster.getName(), rex); + LOGGER.error("Failed sending event while reconciling cluster {}.{}", cluster.getNamespace(), cluster.getName(), rex); } } diff --git a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsExtensionReconciliator.java b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsExtensionReconciliator.java index d11292346c..1f80bf188b 100644 --- a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsExtensionReconciliator.java +++ b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsExtensionReconciliator.java @@ -65,7 +65,7 @@ protected void onUninstallException(KubernetesClient client, StackGresCluster cl DistributedLogsControllerEventReason.DISTRIBUTEDLOGS_CONTROLLER_ERROR, message + ": " + ex.getMessage(), cluster, client); } catch (Exception rex) { - LOGGER.error("Failed sending event while reconciling extension " + extension, rex); + LOGGER.error("Failed sending event while reconciling extension {}", extension, rex); } } @@ -86,7 +86,7 @@ protected void onInstallException(KubernetesClient client, StackGresCluster clus DistributedLogsControllerEventReason.DISTRIBUTEDLOGS_CONTROLLER_ERROR, message + ": " + ex.getMessage(), cluster, client); } catch (Exception rex) { - LOGGER.error("Failed sending event while reconciling extension " + extension, rex); + LOGGER.error("Failed sending event while reconciling extension {}", extension, rex); } } diff --git a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/AbstractRestartStateHandler.java b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/AbstractRestartStateHandler.java index 9a4e9b47c2..e9a5cd6e98 100644 --- a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/AbstractRestartStateHandler.java +++ b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/AbstractRestartStateHandler.java @@ -53,8 +53,7 @@ public abstract class AbstractRestartStateHandler implements ClusterRestartStateHandler { - private static final Logger LOGGER = LoggerFactory - .getLogger(ClusterRestartStateHandler.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRestartStateHandler.class); @Inject ClusterRestart clusterRestart; @@ -364,30 +363,30 @@ protected ClusterRestartState buildClusterRestartState(StackGresDbOps dbOps, Function.identity(), pod -> getPodRestartReasons(cluster, statefulSet, pod))); - LOGGER.info("Operation: " + operation.toString()); - LOGGER.info("Restart method: " + method.toString()); - LOGGER.info("Only pending restart: " + onlyPendingRestart); - LOGGER.info("Found cluster pods: " + clusterPods.stream() + LOGGER.info("Operation: {}", operation.toString()); + LOGGER.info("Restart method: {}", method.toString()); + LOGGER.info("Only pending restart: {}", onlyPendingRestart); + LOGGER.info("Found cluster pods: {}", clusterPods.stream() .map(HasMetadata::getMetadata) .map(ObjectMeta::getName) .collect(Collectors.joining(" "))); - LOGGER.info("Primary instance: " + primaryInstance.getMetadata().getName()); - LOGGER.info("Initial pods: " + initialInstances.stream() + LOGGER.info("Primary instance: {}", primaryInstance.getMetadata().getName()); + LOGGER.info("Initial pods: {}", initialInstances.stream() .map(HasMetadata::getMetadata) .map(ObjectMeta::getName) .collect(Collectors.joining(" "))); - LOGGER.info("Already restarted pods: " + restartedInstances.stream() + LOGGER.info("Already restarted pods: {}", restartedInstances.stream() .map(HasMetadata::getMetadata) .map(ObjectMeta::getName) .collect(Collectors.joining(" "))); - LOGGER.info("Restart reasons: " + podRestartReasonsMap.entrySet().stream() + LOGGER.info("Restart reasons: {}", podRestartReasonsMap.entrySet().stream() .map(e -> e.getKey().getMetadata().getName() + ":" + e.getValue().getReasons() .stream().map(Enum::name).collect(Collectors.joining(","))) .collect(Collectors.joining(" "))); - LOGGER.info("Switchover initialized: " + Optional.of(restartStatus) + LOGGER.info("Switchover initialized: {}", Optional.of(restartStatus) .map(DbOpsRestartStatus::getSwitchoverInitiated) .orElse("no")); - LOGGER.info("Switchover finalized: " + Optional.of(restartStatus) + LOGGER.info("Switchover finalized: {}", Optional.of(restartStatus) .map(DbOpsRestartStatus::getSwitchoverFinalized) .orElse("no")); diff --git a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/MutinyUtil.java b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/MutinyUtil.java index b486490a75..74703517fd 100644 --- a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/MutinyUtil.java +++ b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/MutinyUtil.java @@ -22,7 +22,7 @@ public interface MutinyUtil { static Throwable logOnFailureToRetry(Throwable ex, String message, Object...args) { LOGGER.warn(MessageFormatter.arrayFormat("Transient failure " + message + ": {}", - Seq.of(args).append(ex.getMessage()).toArray()).getMessage()); + Seq.of(args).append(ex.getMessage()).toArray()).getMessage(), ex); return ex; } diff --git a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java index dc707fd8c2..98288244c0 100644 --- a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java +++ b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java @@ -31,7 +31,7 @@ @DatabaseOperation("minorVersionUpgrade") public class MinorVersionUpgradeJob implements DatabaseOperationJob { - private static final Logger LOGGER = LoggerFactory.getLogger(SecurityUpgradeJob.class); + private static final Logger LOGGER = LoggerFactory.getLogger(MinorVersionUpgradeJob.class); @Inject CustomResourceFinder clusterFinder; diff --git a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationCycle.java b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationCycle.java index 860246a3d3..b6a1e5ca3f 100644 --- a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationCycle.java +++ b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationCycle.java @@ -102,7 +102,7 @@ private void reconciliationCycleLoop() { } reconciliationCycle(existingContextResources); } catch (Exception ex) { - logger.error(name + " reconciliation cycle loop was interrupted", ex); + logger.error("{} reconciliation cycle loop was interrupted", name, ex); } } logger.info("{} reconciliation cycle loop stopped", name); @@ -134,12 +134,11 @@ public synchronized ReconciliationCycleResult reconciliationCycle( .toList(); } } catch (RuntimeException ex) { - logger.error(cycleName + " failed", ex); + logger.error("{} failed", cycleName, ex); try { onError(ex); } catch (RuntimeException rex) { - logger.error(cycleName - + " failed sending event while retrieving reconciliation cycle contexts", rex); + logger.error("{} failed sending event while retrieving reconciliation cycle contexts", cycleName, rex); } return new ReconciliationCycleResult<>(ex); } @@ -197,24 +196,24 @@ public synchronized ReconciliationCycleResult reconciliationCycle( } } catch (Exception ex) { contextExceptions.put(exisitingContextResource, ex); - logger.error(cycleName + " failed reconciling " + contextId, ex); + logger.error("{} failed reconciling {}", cycleName, contextId, ex); try { onConfigError(context, exisitingContextResource, ex); } catch (RuntimeException rex) { - logger.error(cycleName + " failed sending event while reconciling " + contextId, rex); + logger.error("{} failed sending event while reconciling {}", cycleName, contextId, rex); } } } - logger.trace(cycleName + " ended successfully"); + logger.trace("{} ended successfully", cycleName); return new ReconciliationCycleResult<>( existingContextResourcesBuilder.build(), contextExceptions.build()); } catch (RuntimeException ex) { - logger.error(cycleName + " failed", ex); + logger.error("{} failed", cycleName, ex); try { onError(ex); } catch (RuntimeException rex) { - logger.error(cycleName + " failed sending event while running reconciliation cycle", rex); + logger.error("{} failed sending event while running reconciliation cycle", cycleName, rex); } return new ReconciliationCycleResult<>(ex); } diff --git a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/WatcherMonitor.java b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/WatcherMonitor.java index 4016d7b7fa..4c0bb89adc 100644 --- a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/WatcherMonitor.java +++ b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/WatcherMonitor.java @@ -71,7 +71,7 @@ private void tryCreateWatcher() { createWatcher(); break; } catch (Exception ex) { - LOGGER.warn("An error occurred while creating watcher " + name, ex); + LOGGER.warn("An error occurred while creating watcher {}", name, ex); try { Thread.sleep(backoffSleepDuration.apply(attempts++).toMillis()); } catch (InterruptedException iex) { @@ -104,7 +104,7 @@ private synchronized void closeWatcher() { watcher.close(); } } catch (Exception ex) { - LOGGER.warn("Error while closing watcher " + name, ex); + LOGGER.warn("Error while closing watcher {}", name, ex); } } @@ -121,7 +121,7 @@ public void eventReceived(Watcher.Action action, T resource) { @Override public void watcherError(WatcherException ex) { - LOGGER.warn("An error occurred in watcher " + name, ex); + LOGGER.warn("An error occurred in watcher {}", name, ex); onWatcherClosed(); } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java index 27d5e0f77f..be573c3262 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java @@ -108,7 +108,7 @@ public void installCustomResourceDefinitions() { protected void installCrd(@NotNull CustomResourceDefinition currentCrd) { String name = currentCrd.getMetadata().getName(); - LOGGER.info("Installing CRD " + name); + LOGGER.info("Installing CRD {}", name); Optional installedCrdOpt = crdResourceFinder .findByName(name); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorBootstrap.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorBootstrap.java index c4e0f2a615..a7c92d45f2 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorBootstrap.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorBootstrap.java @@ -18,7 +18,7 @@ @ApplicationScoped public class DefaultOperatorBootstrap implements OperatorBootstrap { - private static final Logger LOGGER = LoggerFactory.getLogger(OperatorBootstrap.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultOperatorBootstrap.class); private final KubernetesClient client; private final ConfigInstaller configInstaller; diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java index 22b7ed7789..dc386ef06e 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java @@ -106,9 +106,7 @@ public ReconciliationResult evalReconciliationState(T config) { .anyMatch(deployedResourceKey::equals)) .toList(); if (!deployedOtherOwnerRequiredResources.isEmpty()) { - LOGGER.warn("Following resources are required but already exists in the cluster and are" - + " owned by another resource: {}", - deployedOtherOwnerRequiredResources.stream() + LOGGER.warn("Following resources are required but already exists in the cluster and are owned by another resource: {}", deployedOtherOwnerRequiredResources.stream() .map(resourceKey -> resourceKey.kind() + " " + resourceKey.namespace() + "." + resourceKey.name()) @@ -159,19 +157,13 @@ private void cleanupNonGarbageCollectedResources( throw ex; } })) { - LOGGER.warn("Proceding to delete following required resource that already exists" - + " in the cluster but was not garbage collected due to a bug (see" - + " https://github.com/kubernetes/kubernetes/issues/120960): {}", - resource.getKind() + LOGGER.warn("Proceding to delete following required resource that already exists in the cluster but was not garbage collected due to a bug (see https://github.com/kubernetes/kubernetes/issues/120960): {}", resource.getKind() + " " + resource.getMetadata().getNamespace() + "." + resource.getMetadata().getName()); try { client.resource(resource).delete(); } catch (KubernetesClientException ex) { - LOGGER.warn("Error while trying to remove ungarbaged resource " - + resource.getKind() - + " " + resource.getMetadata().getNamespace() - + "." + resource.getMetadata().getName(), ex); + LOGGER.warn("Error while trying to remove ungarbaged resource {} {}.{}", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName(), ex); } } }); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java index 09a2b76d73..0453c9e65f 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java @@ -83,8 +83,7 @@ public StackGresDbOps refreshCondition(StackGresDbOps source) { } if (isJobFailedAndStatusNotUpdated) { - LOGGER.debug("DbOps {} failed since the job failed but status condition" - + " is neither completed or failed", getDbOpsId(source)); + LOGGER.debug("DbOps {} failed since the job failed but status condition is neither completed or failed", getDbOpsId(source)); updateCondition(getFalseRunning(), source); updateCondition(getFalseCompleted(), source); updateCondition(getFailedDueToUnexpectedFailure(), source); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java index d6af2a680f..858a9c6d14 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java @@ -83,8 +83,7 @@ public StackGresShardedDbOps refreshCondition(StackGresShardedDbOps source) { } if (isJobFailedAndStatusNotUpdated) { - LOGGER.debug("ShardedDbOps {} failed since the job failed but status condition" - + " is neither completed or failed", getShardedDbOpsId(source)); + LOGGER.debug("ShardedDbOps {} failed since the job failed but status condition is neither completed or failed", getShardedDbOpsId(source)); updateCondition(getFalseRunning(), source); updateCondition(getFalseCompleted(), source); updateCondition(getFailedDueToUnexpectedFailure(), source); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conversion/ConversionResource.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conversion/ConversionResource.java index 45d8da8ff5..91189d2395 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conversion/ConversionResource.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conversion/ConversionResource.java @@ -44,7 +44,7 @@ default ConversionReviewResponse convert( String errorMessage = Optional.ofNullable(ex.getMessage()).orElse("null"); - LOGGER.error("Cannot proceed with request " + uid + ", cause: " + errorMessage); + LOGGER.error("Cannot proceed with request {}, cause: {}", uid, errorMessage); Status result = new StatusBuilder() .withStatus("Failed") diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java index 2cdc0086be..e0d7b9d45a 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java @@ -118,7 +118,7 @@ public static void copyResources(Container k8s) throws Exception { public static String generateOperatorNamespace(Container k8s) throws Exception { return k8s.execute("sh", "/resources/e2e/e2e", "generate_operator_namespace") .filter(ItHelper.EXCLUDE_TTY_WARNING) - .peek(line -> LOGGER.info("Generated operator namespace: " + line)) + .peek(line -> LOGGER.info("Generated operator namespace: {}", line)) .collect(Collectors.joining()); } @@ -129,7 +129,7 @@ public static void resetKind(Container k8s, String namespace) throws Exception { if (Optional.ofNullable(System.getenv("K8S_REUSE")) .map(Boolean::parseBoolean) .orElse(true)) { - LOGGER.info("Reusing " + E2E_ENV); + LOGGER.info("Reusing {}", E2E_ENV); k8s.copyIn(new ByteArrayInputStream( ("cd /resources/e2e\n" + E2E_ENVVARS + "\n" @@ -173,7 +173,7 @@ public static void resetKind(Container k8s, String namespace) throws Exception { "/resources/e2e/target/" + file, Paths.get("target/certs", file)))); return; } - LOGGER.info("Restarting " + E2E_ENV); + LOGGER.info("Restarting {}", E2E_ENV); k8s.copyIn(new ByteArrayInputStream( ("cd /resources/e2e\n" + E2E_ENVVARS + "\n" @@ -205,7 +205,7 @@ public static void resetKind(Container k8s, String namespace) throws Exception { * It helper method. */ public static void createNamespace(Container k8s, String namespace) throws Exception { - LOGGER.info("Create namespace '" + namespace + "'"); + LOGGER.info("Create namespace '{}'", namespace); k8s.execute("sh", "-l", "-c", "kubectl create namespace " + namespace) .filter(EXCLUDE_TTY_WARNING) @@ -229,8 +229,7 @@ public static String createExposedHost(Container k8s, String host, int port) secondPointIndex.orElse(host.length())); String serviceName = host.substring(0, firstPointIndex.get()); String exposedServiceName = serviceName + "-exposed"; - LOGGER.info("Create service " + exposedServiceName - + " to expose service " + serviceName + " in namespace " + namespace); + LOGGER.info("Create service {} to expose service {} in namespace {}", exposedServiceName, serviceName, namespace); k8s.execute("sh", "-l", "-ce", "kubectl get service -n " + namespace + " " + exposedServiceName + " | grep -q '^" + exposedServiceName + "\\s'" @@ -385,11 +384,11 @@ public static void installStackGresConfigs(Container k8s, String namespace) */ public static void installStackGresCluster(Container k8s, String namespace, String name, int instances) throws Exception { - LOGGER.info("Deleting if exists stackgres-cluster helm chart for cluster with name " + name); + LOGGER.info("Deleting if exists stackgres-cluster helm chart for cluster with name {}", name); k8s.execute("sh", "-l", "-c", "helm delete " + name + " --namespace " + namespace + "|| true") .filter(EXCLUDE_TTY_WARNING) .forEach(LOGGER::info); - LOGGER.info("Installing stackgres-cluster helm chart for cluster with name " + name); + LOGGER.info("Installing stackgres-cluster helm chart for cluster with name {}", name); k8s.execute("sh", "-l", "-c", "helm install " + name + " --namespace " + namespace @@ -408,7 +407,7 @@ public static void installStackGresCluster(Container k8s, String namespace, Stri */ public static void upgradeStackGresCluster(Container k8s, String namespace, String name, int instances) throws Exception { - LOGGER.info("Upgrade stackgres-cluster helm chart for cluster with name " + name); + LOGGER.info("Upgrade stackgres-cluster helm chart for cluster with name {}", name); k8s.execute("sh", "-l", "-c", "helm upgrade " + name + " /resources/stackgres-cluster " @@ -428,7 +427,7 @@ public static void upgradeStackGresCluster(Container k8s, String namespace, Stri */ public static void deleteStackGresCluster(Container k8s, String namespace, String name) throws Exception { - LOGGER.info("Delete stackgres-cluster helm chart for cluster with name " + name); + LOGGER.info("Delete stackgres-cluster helm chart for cluster with name {}", name); k8s.execute("sh", "-l", "-c", "helm delete " + name + " --namespace " + namespace) .filter(EXCLUDE_TTY_WARNING) .forEach(LOGGER::info); diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/KubernetesOperatorRunner.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/KubernetesOperatorRunner.java index 873f5b1b05..24863eb47c 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/KubernetesOperatorRunner.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/KubernetesOperatorRunner.java @@ -60,7 +60,7 @@ public void run() throws Throwable { .filter(ItHelper.EXCLUDE_TTY_WARNING) .forEach(line -> LOGGER.info(line)); } catch (Exception ex) { - LOGGER.trace(ex.getMessage()); + LOGGER.trace("", ex); return; } }, executor); diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/MockKubernetesClientFactory.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/MockKubernetesClientFactory.java index 9573a38b63..0d6503c463 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/MockKubernetesClientFactory.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/app/MockKubernetesClientFactory.java @@ -87,7 +87,7 @@ private void updateTokenPeriodically() { try { updateToken(); } catch (Exception ex) { - LOGGER.warn("Error while updating the token {}", ex.getMessage()); + LOGGER.warn("Error while updating the token {}", ex.getMessage(), ex); } } if (!executor.isShutdown() && !executor.isTerminated()) { From 131b30d1cbde40d2443fda7b031d23164e4f90f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Thu, 30 Nov 2023 17:44:29 +0100 Subject: [PATCH 08/27] feat: Build with Java 21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- stackgres-k8s/src/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stackgres-k8s/src/pom.xml b/stackgres-k8s/src/pom.xml index be056fbfe8..ebca59b08b 100644 --- a/stackgres-k8s/src/pom.xml +++ b/stackgres-k8s/src/pom.xml @@ -72,7 +72,7 @@ UTF-8 - 17 + 21 ${java.version} ${java.version} ${java.version} @@ -336,7 +336,7 @@ - [3.8.1,) + [3.9.6,) ${java.version} From 2b3ca3f74f07ed471ea5aa3cbcbaddeb7867eb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Thu, 30 Nov 2023 17:52:18 +0100 Subject: [PATCH 09/27] chore: Update Quarkus to 3.6.0 and dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- stackgres-k8s/src/pom.xml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/stackgres-k8s/src/pom.xml b/stackgres-k8s/src/pom.xml index ebca59b08b..ec8b8e8f36 100644 --- a/stackgres-k8s/src/pom.xml +++ b/stackgres-k8s/src/pom.xml @@ -77,18 +77,18 @@ ${java.version} ${java.version} - 3.5.1 + 3.6.0 0.9.15 - 2.9.3 - 10.11.0 - 4.7.3 + 2.10.0 + 10.12.5 + 4.8.2 6.55.0 1.2.15 1.0.1 - 24.0.1 + 24.1.0 2.0.0 3.0.0 - 2.2.15 + 2.2.19 0.101.3 0.10.2 1.1.5 @@ -104,19 +104,19 @@ 3.11.0 3.3.0 - 3.3.1 + 3.3.2 3.1.0 - 3.1.2 - 3.1.2 - 3.3.0 - 4.7.3.6 - 3.21.0 + 3.2.2 + 3.2.2 + 3.3.1 + 4.8.1.0 + 3.21.2 3.4.1 3.1.1 0.43.0 - 3.1.5 - 3.4.0 - 2.2.15 + 3.1.6 + 3.5.0 + 2.2.19 ${maven.multiModuleProjectDirectory}/checks ${checks.location}/checkstyle.xml From 97a77c6f232c272b6316474c0321f28a9abe7d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Thu, 30 Nov 2023 17:53:09 +0100 Subject: [PATCH 10/27] chore: Adopt SequencedCollection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../apiweb/rest/ApplicationsResource.java | 2 +- .../AbstractDependencyCustomResourceTest.java | 2 +- .../apiweb/rest/RbacResourceTest.java | 6 ++--- .../apiweb/rest/StorageClassResourceTest.java | 2 +- .../io/stackgres/common/StackGresUtil.java | 2 +- .../stackgres/common/component/Component.java | 4 ++-- .../StackGresClusterPodSchedulingTest.java | 6 ++--- .../jobs/dbops/ClusterStateHandlerTest.java | 18 +++++++------- .../clusterrestart/PostgresRestartTest.java | 14 +++++------ .../reconciliation/ReconciliationResult.java | 2 +- .../resource/visitor/PairUpdaterTest.java | 6 ++--- .../app/DefaultOperatorLockHolder.java | 4 ++-- .../StackGresShardedClusterForCitusUtil.java | 2 +- .../PodTemplateFactoryDiscovererImpl.java | 2 +- .../backup/ShardedBackupCronJob.java | 2 +- .../backup/ShardedBackupCronJobV1Beta1.java | 2 +- .../cluster/ObjectStorageValidator.java | 2 +- .../dbops/DbOpsStatusManagerTest.java | 2 +- .../cluster/PostgresSslSecretTest.java | 24 +++++++++---------- .../cluster/ServiceBindingSecretTest.java | 4 ++-- .../patroni/PatroniConfigEndpointsTest.java | 2 +- .../factory/dbops/DbOpsJobTestCase.java | 4 ++-- .../ServiceBindingSecretTest.java | 4 ++-- .../shardedcluster/ShardedClustersTest.java | 2 +- .../ShardedPostgresSslSecretTest.java | 24 +++++++++---------- .../shardeddbops/ShardedDbOpsJobTestCase.java | 4 ++-- .../script/ScriptStatusManagerTest.java | 10 ++++---- .../ShardedDbOpsStatusManagerTest.java | 2 +- ...SgPoolingConfigConversionPipelineTest.java | 4 ++-- 29 files changed, 82 insertions(+), 82 deletions(-) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java index d2e13890c7..36b33ff41e 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java @@ -111,7 +111,7 @@ public Map getApplication(@MultipartForm MultipartFormDataInput String reportName = Optional.ofNullable(formDataMap.get("reportName")) .filter(m -> !m.isEmpty()) - .map(m -> m.get(0)) + .map(m -> m.getFirst()) .map(Unchecked.function(InputPart::getBodyAsString)) .orElseThrow(() -> new WebApplicationException("reportName is required", Response.Status.BAD_REQUEST)); diff --git a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/AbstractDependencyCustomResourceTest.java b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/AbstractDependencyCustomResourceTest.java index 31d4614b95..94c6b04c8e 100644 --- a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/AbstractDependencyCustomResourceTest.java +++ b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/AbstractDependencyCustomResourceTest.java @@ -81,7 +81,7 @@ void listShouldReturnAllDtos() { List resources = service.list(); assertEquals(customResources.getItems().size(), resources.size()); - checkDto(resources.get(0)); + checkDto(resources.getFirst()); } @Test diff --git a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/RbacResourceTest.java b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/RbacResourceTest.java index c1c783a6d9..99d425eba1 100644 --- a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/RbacResourceTest.java +++ b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/RbacResourceTest.java @@ -118,10 +118,10 @@ private List expectedNamespaces() { private void assertNamespacedResources(List actualNamespaced) { assertEquals(expectedNamespaces().size(), actualNamespaced.size()); - assertEquals(expectedNamespaces().iterator().next(), - actualNamespaced.iterator().next().namespace()); + assertEquals(expectedNamespaces().getFirst(), + actualNamespaced.getFirst().namespace()); - Map> resources = actualNamespaced.iterator().next().resources(); + Map> resources = actualNamespaced.getFirst().resources(); for (Map.Entry> resource : resources.entrySet()) { assertNamespacedResource(resource.getKey()); } diff --git a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/StorageClassResourceTest.java b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/StorageClassResourceTest.java index b1465c29e3..a8d8312461 100644 --- a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/StorageClassResourceTest.java +++ b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/StorageClassResourceTest.java @@ -46,7 +46,7 @@ void getShouldReturnAllStorageClassesNames() { assertEquals(1, storageClasses.size()); - assertEquals("standard", storageClasses.get(0)); + assertEquals("standard", storageClasses.getFirst()); } } diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresUtil.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresUtil.java index 32c52ba48f..e28d8015c9 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresUtil.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresUtil.java @@ -266,7 +266,7 @@ static String getServiceDnsName(@NotNull Service service) { if (status != null && "LoadBalancer".equals(service.getSpec().getType())) { List ingress = status.getLoadBalancer().getIngress(); if (ingress != null && !ingress.isEmpty()) { - LoadBalancerIngress loadBalancerIngress = ingress.get(0); + LoadBalancerIngress loadBalancerIngress = ingress.getFirst(); serviceDns = loadBalancerIngress.getHostname() != null ? loadBalancerIngress.getHostname() : loadBalancerIngress.getIp(); diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/component/Component.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/component/Component.java index f838d53674..0067bd84f2 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/component/Component.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/component/Component.java @@ -362,14 +362,14 @@ public String toString() { public Optional findLatestImageName() { return findImageName(StackGresComponent.LATEST, Seq.seq(this.subComponents) - .map(alternativeSubComponents -> alternativeSubComponents.get(0)) + .map(alternativeSubComponents -> alternativeSubComponents.getFirst()) .collect(ImmutableMap.toImmutableMap( Function.identity(), subComponent -> StackGresComponent.LATEST))); } public String getLatestImageName() { return getImageName(StackGresComponent.LATEST, Seq.seq(this.subComponents) - .map(alternativeSubComponents -> alternativeSubComponents.get(0)) + .map(alternativeSubComponents -> alternativeSubComponents.getFirst()) .collect(ImmutableMap.toImmutableMap( Function.identity(), subComponent -> StackGresComponent.LATEST))); } diff --git a/stackgres-k8s/src/common/src/test/java/io/stackgres/common/crd/sgcluster/StackGresClusterPodSchedulingTest.java b/stackgres-k8s/src/common/src/test/java/io/stackgres/common/crd/sgcluster/StackGresClusterPodSchedulingTest.java index 7cf85a3dea..8297316789 100644 --- a/stackgres-k8s/src/common/src/test/java/io/stackgres/common/crd/sgcluster/StackGresClusterPodSchedulingTest.java +++ b/stackgres-k8s/src/common/src/test/java/io/stackgres/common/crd/sgcluster/StackGresClusterPodSchedulingTest.java @@ -62,7 +62,7 @@ void shouldMathExpressionValuesSize_BeEqualsPodNodeAffinityRequiredDuringSchedul @Test void shouldMatchExpressionKey_BeEqualsForPodNodeAffinityPreferredDuringScheduling() { - nodeAffinityPreferredDuringScheduling.get(0).getPreference() + nodeAffinityPreferredDuringScheduling.getFirst().getPreference() .getMatchExpressions().forEach(matchExpression -> { assertTrue(matchExpression.getKey().equals(PREFERRED_TOPOLOGY_KEY)); }); @@ -70,7 +70,7 @@ void shouldMatchExpressionKey_BeEqualsForPodNodeAffinityPreferredDuringSchedulin @Test void shouldOperator_BeEqualsInForPodNodeAffinityPreferredDuringScheduling() { - nodeAffinityPreferredDuringScheduling.get(0) + nodeAffinityPreferredDuringScheduling.getFirst() .getPreference().getMatchExpressions().forEach(matchExpression -> { assertEquals(matchExpression.getOperator(), OPERATOR_IN); }); @@ -79,7 +79,7 @@ void shouldOperator_BeEqualsInForPodNodeAffinityPreferredDuringScheduling() { @Test void shouldMathExpressionValuesSize_BeEqualsPodNodeAffinityPreferredDuringSchedulingSize() { assertEquals(TWO_NODE_AFFFINITY_EXPRESSION_VALUES, - nodeAffinityPreferredDuringScheduling.get(0).getPreference() + nodeAffinityPreferredDuringScheduling.getFirst().getPreference() .getMatchExpressions().get(0).getValues().size()); } } diff --git a/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/ClusterStateHandlerTest.java b/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/ClusterStateHandlerTest.java index 4005342ff6..58cab81585 100644 --- a/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/ClusterStateHandlerTest.java +++ b/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/ClusterStateHandlerTest.java @@ -287,10 +287,10 @@ void givenAnInitializedClusterStatus_itShouldReuseAndNotModifyIt() { .atMost(Duration.ofMillis(500)); assertEquals(1, storedCluster.size()); - assertNull(storedCluster.get(0).getStatus().getDbOps()); + assertNull(storedCluster.getFirst().getStatus().getDbOps()); assertEquals(1, storedDbOps.size()); assertEquals(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).toList(), - getDbOpsRestartStatus(storedDbOps.get(0)).getInitialInstances()); + getDbOpsRestartStatus(storedDbOps.getFirst()).getInitialInstances()); } protected abstract void initializeClusterStatus(StackGresDbOps dbOps, StackGresCluster cluster, @@ -399,11 +399,11 @@ void givenACleanCluster_shouldUpdateTheOpStatus() { .items( ImmutableRestartEventForTest.builder() .eventType(RestartEventType.RESTARTING_POSTGRES) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.POSTGRES_RESTARTED) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.INCREASING_INSTANCES) @@ -430,19 +430,19 @@ void givenACleanCluster_shouldUpdateTheOpStatus() { .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.SWITCHOVER_INITIATED) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.SWITCHOVER_FINALIZED) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.RESTARTING_POD) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.POD_RESTARTED) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.DECREASING_INSTANCES) @@ -514,7 +514,7 @@ void givenACleanCluster_shouldRegisterEveryEvent() { .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.POD_RESTARTED) - .pod(pods.get(0)) + .pod(pods.getFirst()) .build(), ImmutableRestartEventForTest.builder() .eventType(RestartEventType.DECREASING_INSTANCES) diff --git a/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/clusterrestart/PostgresRestartTest.java b/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/clusterrestart/PostgresRestartTest.java index 04a6994052..73fd147fb7 100644 --- a/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/clusterrestart/PostgresRestartTest.java +++ b/stackgres-k8s/src/jobs/src/test/java/io/stackgres/jobs/dbops/clusterrestart/PostgresRestartTest.java @@ -86,7 +86,7 @@ void setUp() { void restartPostgres_shouldNotFail() { when(patroniApiHandler.getClusterMembers(clusterName, namespace)) .thenReturn(Uni.createFrom().item(clusterMembers)); - when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.get(0))) + when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.getFirst())) .thenReturn(Uni.createFrom().item(patroniInformation)); postgresRestart.restartPostgres(memberName, clusterName, namespace) @@ -102,7 +102,7 @@ void restartPostgres_shouldNotFail() { void restartPostgresWhenNotPendingRestart_shouldNotFail() { when(patroniApiHandler.getClusterMembers(clusterName, namespace)) .thenReturn(Uni.createFrom().item(clusterMembers)); - when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.get(0))) + when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.getFirst())) .thenReturn(Uni.createFrom().item(ImmutablePatroniInformation .copyOf(patroniInformation) .withIsPendingRestart(false))); @@ -120,7 +120,7 @@ void restartPostgresWhenNotPendingRestart_shouldNotFail() { void restartPostgresWhenStarting_shouldNotFail() { when(patroniApiHandler.getClusterMembers(clusterName, namespace)) .thenReturn(Uni.createFrom().item(clusterMembers)); - when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.get(0))) + when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.getFirst())) .thenReturn(Uni.createFrom().item(ImmutablePatroniInformation .copyOf(patroniInformation) .withState(MemberState.STARTING))) @@ -141,7 +141,7 @@ void restartPostgresWhenStarting_shouldNotFail() { void restartPostgresWhenAlreadyRestarting_shouldNotFail() { when(patroniApiHandler.getClusterMembers(clusterName, namespace)) .thenReturn(Uni.createFrom().item(clusterMembers)); - when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.get(0))) + when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.getFirst())) .thenReturn(Uni.createFrom().item(ImmutablePatroniInformation .copyOf(patroniInformation) .withState(MemberState.RESTARTING))) @@ -162,9 +162,9 @@ void restartPostgresWhenAlreadyRestarting_shouldNotFail() { void restartPostgresWhenAlreadyRestarting_shouldFail() { when(patroniApiHandler.getClusterMembers(clusterName, namespace)) .thenReturn(Uni.createFrom().item(clusterMembers)); - when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.get(0))) + when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.getFirst())) .thenReturn(Uni.createFrom().item(patroniInformation)); - when(patroniApiHandler.restartPostgres(clusterMembers.get(0))) + when(patroniApiHandler.restartPostgres(clusterMembers.getFirst())) .thenReturn(Uni.createFrom() .failure(() -> new RuntimeException("status 503: null"))); @@ -182,7 +182,7 @@ void restartPostgresWhenAlreadyRestarting_shouldFail() { void givenANonExistentMember_shouldFail() { when(patroniApiHandler.getClusterMembers(clusterName, namespace)) .thenReturn(Uni.createFrom().item(clusterMembers)); - when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.get(0))) + when(patroniApiHandler.getClusterMemberPatroniInformation(clusterMembers.getFirst())) .thenReturn(Uni.createFrom().item(patroniInformation)); assertThrows(Exception.class, () -> postgresRestart diff --git a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationResult.java b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationResult.java index a78a157174..2485c398a2 100644 --- a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationResult.java +++ b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ReconciliationResult.java @@ -65,7 +65,7 @@ public ReconciliationResult join(ReconciliationResult other) { public Exception getException() { if (!exceptions.isEmpty()) { - final Exception exception = exceptions.get(0); + final Exception exception = exceptions.getFirst(); Seq.seq(exceptions) .skip(1) .forEach(suppressedException -> exception.addSuppressed(suppressedException)); diff --git a/stackgres-k8s/src/operator-framework/src/test/java/io/stackgres/operatorframework/resource/visitor/PairUpdaterTest.java b/stackgres-k8s/src/operator-framework/src/test/java/io/stackgres/operatorframework/resource/visitor/PairUpdaterTest.java index 62f7cd03fc..8b17221e41 100644 --- a/stackgres-k8s/src/operator-framework/src/test/java/io/stackgres/operatorframework/resource/visitor/PairUpdaterTest.java +++ b/stackgres-k8s/src/operator-framework/src/test/java/io/stackgres/operatorframework/resource/visitor/PairUpdaterTest.java @@ -115,7 +115,7 @@ public void testUpdateWithSomeNodeSelectorRequirement() { List values = getPodNodeSelectorRequirement(leftMeta).getValues(); Assertions.assertNotNull(values); Assertions.assertEquals(2, values.size()); - Assertions.assertEquals("1", values.get(0)); + Assertions.assertEquals("1", values.getFirst()); Assertions.assertEquals("2", values.get(1)); } @@ -156,7 +156,7 @@ public void testUpdateSomeNodeSelectorRequirementOverwritten() { List values = getPodNodeSelectorRequirement(leftMeta).getValues(); Assertions.assertNotNull(values); Assertions.assertEquals(2, values.size()); - Assertions.assertEquals("3", values.get(0)); + Assertions.assertEquals("3", values.getFirst()); Assertions.assertEquals("4", values.get(1)); } @@ -168,7 +168,7 @@ public void testUpdateSomeNodeSelectorRequirementFullyOverwritten() { List values = getPodNodeSelectorRequirement(leftMeta).getValues(); Assertions.assertNotNull(values); Assertions.assertEquals(3, values.size()); - Assertions.assertEquals("1", values.get(0)); + Assertions.assertEquals("1", values.getFirst()); Assertions.assertEquals("2", values.get(1)); Assertions.assertEquals("3", values.get(2)); } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorLockHolder.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorLockHolder.java index a37510d548..d693962c17 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorLockHolder.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/DefaultOperatorLockHolder.java @@ -106,7 +106,7 @@ private void tryHoldLock() { throw new IllegalArgumentException("More than one SGConfig found. Please remove extra" + " SGConfig for the operator to function properly"); } - StackGresConfig config = configs.get(0); + StackGresConfig config = configs.getFirst(); final String serviceAccount = context.getString(OperatorProperty.OPERATOR_SERVICE_ACCOUNT); final String podName = context.getString(OperatorProperty.OPERATOR_POD_NAME); @@ -150,7 +150,7 @@ private void releaseLock() { throw new IllegalArgumentException("More than one SGConfig found. Please remove extra" + " SGConfig for the operator to function properly"); } - StackGresConfig config = configs.get(0); + StackGresConfig config = configs.getFirst(); final String podName = context.getString(OperatorProperty.OPERATOR_POD_NAME); scheduler.update(config, foundConfig -> { if (StackGresUtil.isLockedBy(foundConfig, podName)) { diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java index 6906f71d1a..4e89d83bf1 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/common/StackGresShardedClusterForCitusUtil.java @@ -243,7 +243,7 @@ private static void setConfigurationsBackups( .map(StackGresShardedClusterSpec::getConfigurations) .map(StackGresShardedClusterConfigurations::getBackups) .filter(Predicate.not(List::isEmpty)) - .map(backups -> backups.get(0)) + .map(backups -> backups.getFirst()) .filter(backup -> backup.getPaths() != null) .ifPresent(backup -> { if (spec.getConfigurations() == null) { diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/PodTemplateFactoryDiscovererImpl.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/PodTemplateFactoryDiscovererImpl.java index cddee15f82..3074d0db03 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/PodTemplateFactoryDiscovererImpl.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/PodTemplateFactoryDiscovererImpl.java @@ -32,6 +32,6 @@ public PodTemplateFactory discoverPodSpecFactory( throw new IllegalArgumentException( "It should be a single pod template factory per StackGres Version"); } - return podTemplateFactories.get(0); + return podTemplateFactories.getFirst(); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java index 1e9a4c67e7..feb9e9c34d 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java @@ -116,7 +116,7 @@ public Stream generateResource(StackGresShardedClusterContext conte .map(StackGresShardedClusterSpec::getConfigurations) .map(StackGresShardedClusterConfigurations::getBackups) .filter(Predicate.not(List::isEmpty)) - .map(backups -> backups.get(0)); + .map(backups -> backups.getFirst()); if (backupConfig .map(StackGresShardedClusterBackupConfiguration::getCronSchedule) .isEmpty()) { diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java index ea89c7044f..0c53f28b01 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java @@ -116,7 +116,7 @@ public Stream generateResource(StackGresShardedClusterContext conte .map(StackGresShardedClusterSpec::getConfigurations) .map(StackGresShardedClusterConfigurations::getBackups) .filter(Predicate.not(List::isEmpty)) - .map(backups -> backups.get(0)); + .map(backups -> backups.getFirst()); if (backupConfig .map(StackGresShardedClusterBackupConfiguration::getCronSchedule) .isEmpty()) { diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/ObjectStorageValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/ObjectStorageValidator.java index 472f779af2..fd9ea83c19 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/ObjectStorageValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/ObjectStorageValidator.java @@ -44,7 +44,7 @@ protected String getReference(StackGresCluster resource) { return Optional.ofNullable(resource.getSpec().getConfigurations()) .map(StackGresClusterConfigurations::getBackups) .filter(Predicate.not(List::isEmpty)) - .map(backups -> backups.get(0)) + .map(backups -> backups.getFirst()) .map(StackGresClusterBackupConfiguration::getSgObjectStorage) .orElse(null); } diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManagerTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManagerTest.java index 03901177e6..abbb81da55 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManagerTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManagerTest.java @@ -244,7 +244,7 @@ private void assertCondition(Condition expectedCondition, List data.get(PostgresSslSecret.CERTIFICATE_KEY)) .isPresent()); - Assertions.assertTrue(secretVolumePairs.get(0).getSource() + Assertions.assertTrue(secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.PRIVATE_KEY_KEY)) .isPresent()); checkCertificateAndPrivateKey( ResourceUtil.decodeSecret( - secretVolumePairs.get(0).getSource() + secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.CERTIFICATE_KEY)) .orElseThrow()), ResourceUtil.decodeSecret( - secretVolumePairs.get(0).getSource() + secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.PRIVATE_KEY_KEY)) @@ -119,31 +119,31 @@ void givenAClusterWithSslAndSecret_itShouldReuseSslSecret() { var secretVolumePairs = postgresSslSecret.buildVolumes(context).toList(); Assertions.assertEquals(PostgresSslSecret.name(cluster), - secretVolumePairs.get(0).getSource() + secretVolumePairs.getFirst().getSource() .orElseThrow() .getMetadata() .getName()); Assertions.assertEquals(1, secretVolumePairs.size()); - Assertions.assertTrue(secretVolumePairs.get(0).getSource() + Assertions.assertTrue(secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.CERTIFICATE_KEY)) .isPresent()); Assertions.assertEquals("test-certificate", ResourceUtil.decodeSecret( - secretVolumePairs.get(0).getSource() + secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.CERTIFICATE_KEY)) .orElseThrow())); - Assertions.assertTrue(secretVolumePairs.get(0).getSource() + Assertions.assertTrue(secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.PRIVATE_KEY_KEY)) .isPresent()); Assertions.assertEquals("test-private-key", ResourceUtil.decodeSecret( - secretVolumePairs.get(0).getSource() + secretVolumePairs.getFirst().getSource() .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PostgresSslSecret.PRIVATE_KEY_KEY)) diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/ServiceBindingSecretTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/ServiceBindingSecretTest.java index 6b527343f9..60e0afee00 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/ServiceBindingSecretTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/ServiceBindingSecretTest.java @@ -76,7 +76,7 @@ void generateResourseWhenServiceBindingConfigurationIsPresent() { List secrets = hasMetadataStream.toList(); assertEquals(secrets.size(), 1); - Secret serviceBindingSecret = (Secret) secrets.get(0); + Secret serviceBindingSecret = (Secret) secrets.getFirst(); assertEquals(serviceBindingSecret.getType(), "servicebinding.io/postgresql"); Map data = serviceBindingSecret.getStringData(); @@ -156,7 +156,7 @@ private void assertSecretDataWithoutConfiguration(Stream serviceBin List secrets = serviceBindingMetadata.toList(); assertEquals(secrets.size(), 1); - Secret serviceBindingSecret = (Secret) secrets.get(0); + Secret serviceBindingSecret = (Secret) secrets.getFirst(); assertEquals(serviceBindingSecret.getType(), "servicebinding.io/postgresql"); Map data = serviceBindingSecret.getStringData(); diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/patroni/PatroniConfigEndpointsTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/patroni/PatroniConfigEndpointsTest.java index 9d87b732fb..a29cfc6c3f 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/patroni/PatroniConfigEndpointsTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/patroni/PatroniConfigEndpointsTest.java @@ -421,7 +421,7 @@ private Endpoints generateEndpoint() { assertFalse(endpoints.isEmpty()); - final Endpoints endpoint = (Endpoints) endpoints.get(0); + final Endpoints endpoint = (Endpoints) endpoints.getFirst(); assertNotNull(endpoint.getMetadata()); assertNotNull(endpoint.getMetadata().getLabels()); assertNotNull(endpoint.getMetadata().getAnnotations()); diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/dbops/DbOpsJobTestCase.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/dbops/DbOpsJobTestCase.java index c2eb4a9645..0095019427 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/dbops/DbOpsJobTestCase.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/dbops/DbOpsJobTestCase.java @@ -117,7 +117,7 @@ void shouldGenerateJobWithNodeSelector_onceSgDbOpsSchedulingHasNodeSelector() { var generatedResources = dbOpsJobsGenerator.generateResource(context) .collect(Collectors.toUnmodifiableList()); - var job = (Job) generatedResources.iterator().next(); + var job = (Job) generatedResources.getFirst(); assertEquals(2, job.getSpec().getTemplate().getSpec().getNodeSelector().size()); } @@ -137,7 +137,7 @@ void shouldGenerateJobWithNodeAffinity_onceSgDbOpsSchedulingHasAffinity() { var generatedResources = dbOpsJobsGenerator.generateResource(context) .collect(Collectors.toUnmodifiableList()); - var job = (Job) generatedResources.iterator().next(); + var job = (Job) generatedResources.getFirst(); var nodeAffinity = job.getSpec().getTemplate().getSpec().getAffinity().getNodeAffinity(); assertEquals(1, nodeAffinity.getPreferredDuringSchedulingIgnoredDuringExecution().size()); assertEquals(1, nodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution() diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ServiceBindingSecretTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ServiceBindingSecretTest.java index f78905fe24..25e9bfd521 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ServiceBindingSecretTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ServiceBindingSecretTest.java @@ -81,7 +81,7 @@ void generateResourseWhenServiceBindingConfigurationIsPresent() { List secrets = hasMetadataStream.toList(); assertEquals(secrets.size(), 1); - Secret serviceBindingSecret = (Secret) secrets.get(0); + Secret serviceBindingSecret = (Secret) secrets.getFirst(); assertEquals(serviceBindingSecret.getType(), "servicebinding.io/postgresql"); Map data = serviceBindingSecret.getStringData(); @@ -161,7 +161,7 @@ private void assertSecretDataWithoutConfiguration(Stream serviceBin List secrets = serviceBindingMetadata.toList(); assertEquals(secrets.size(), 1); - Secret serviceBindingSecret = (Secret) secrets.get(0); + Secret serviceBindingSecret = (Secret) secrets.getFirst(); assertEquals(serviceBindingSecret.getType(), "servicebinding.io/postgresql"); Map data = serviceBindingSecret.getStringData(); diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClustersTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClustersTest.java index f06b2c690e..317554fc14 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClustersTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedClustersTest.java @@ -67,7 +67,7 @@ public void generateShardedClusters_shouldSetLabels() { var clusters = shardedClusters.generateResource(context).toList(); assertEquals(3, clusters.size()); assertEquals(labelFactory.coordinatorLabels(shardedCluster), - clusters.get(0).getMetadata().getLabels()); + clusters.getFirst().getMetadata().getLabels()); assertEquals(labelFactory.shardsLabels(shardedCluster), clusters.get(1).getMetadata().getLabels()); assertEquals(labelFactory.shardsLabels(shardedCluster), diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedPostgresSslSecretTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedPostgresSslSecretTest.java index efdca164b4..74cbb711fb 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedPostgresSslSecretTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardedcluster/ShardedPostgresSslSecretTest.java @@ -62,10 +62,10 @@ void givenAClusterWithoutSsl_itShouldNotGenerateSslSecret() { Assertions.assertEquals(1, generateResources.size()); Assertions.assertEquals(postgresSslSecretName(cluster), - generateResources.get(0) + generateResources.getFirst() .getMetadata() .getName()); - Assertions.assertEquals(1, Optional.of(generateResources.get(0)) + Assertions.assertEquals(1, Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .orElseThrow() .getData() @@ -81,29 +81,29 @@ void givenAClusterWithSslAndNoSecret_itShouldGenerateSslSecret() throws Exceptio var generateResources = postgresSslSecret.generateResource(context).toList(); Assertions.assertEquals(postgresSslSecretName(cluster), - generateResources.get(0) + generateResources.getFirst() .getMetadata() .getName()); Assertions.assertEquals(1, generateResources.size()); - Assertions.assertTrue(Optional.of(generateResources.get(0)) + Assertions.assertTrue(Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(CERTIFICATE_KEY)) .isPresent()); - Assertions.assertTrue(Optional.of(generateResources.get(0)) + Assertions.assertTrue(Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PRIVATE_KEY_KEY)) .isPresent()); checkCertificateAndPrivateKey( ResourceUtil.decodeSecret( - Optional.of(generateResources.get(0)) + Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(CERTIFICATE_KEY)) .orElseThrow()), ResourceUtil.decodeSecret( - Optional.of(generateResources.get(0)) + Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PRIVATE_KEY_KEY)) @@ -121,30 +121,30 @@ void givenAClusterWithSslAndSecret_itShouldReuseSslSecret() { var generateResources = postgresSslSecret.generateResource(context).toList(); Assertions.assertEquals(postgresSslSecretName(cluster), - generateResources.get(0) + generateResources.getFirst() .getMetadata() .getName()); Assertions.assertEquals(1, generateResources.size()); - Assertions.assertTrue(Optional.of(generateResources.get(0)) + Assertions.assertTrue(Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(CERTIFICATE_KEY)) .isPresent()); Assertions.assertEquals("test-certificate", ResourceUtil.decodeSecret( - Optional.of(generateResources.get(0)) + Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(CERTIFICATE_KEY)) .orElseThrow())); - Assertions.assertTrue(Optional.of(generateResources.get(0)) + Assertions.assertTrue(Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PRIVATE_KEY_KEY)) .isPresent()); Assertions.assertEquals("test-private-key", ResourceUtil.decodeSecret( - Optional.of(generateResources.get(0)) + Optional.of(generateResources.getFirst()) .map(Secret.class::cast) .map(Secret::getData) .map(data -> data.get(PRIVATE_KEY_KEY)) diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardeddbops/ShardedDbOpsJobTestCase.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardeddbops/ShardedDbOpsJobTestCase.java index 42c3e0cbb1..acf0f5ef80 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardeddbops/ShardedDbOpsJobTestCase.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/shardeddbops/ShardedDbOpsJobTestCase.java @@ -111,7 +111,7 @@ void shouldGenerateJobWithNodeSelector_onceSgDbOpsSchedulingHasNodeSelector() { var generatedResources = dbOpsJobsGenerator.generateResource(context) .collect(Collectors.toUnmodifiableList()); - var job = (Job) generatedResources.iterator().next(); + var job = (Job) generatedResources.getFirst(); assertEquals(2, job.getSpec().getTemplate().getSpec().getNodeSelector().size()); } @@ -130,7 +130,7 @@ void shouldGenerateJobWithNodeAffinity_onceSgDbOpsSchedulingHasAffinity() { var generatedResources = dbOpsJobsGenerator.generateResource(context) .collect(Collectors.toUnmodifiableList()); - var job = (Job) generatedResources.iterator().next(); + var job = (Job) generatedResources.getFirst(); var nodeAffinity = job.getSpec().getTemplate().getSpec().getAffinity().getNodeAffinity(); assertEquals(1, nodeAffinity.getPreferredDuringSchedulingIgnoredDuringExecution().size()); assertEquals(1, nodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution() diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/script/ScriptStatusManagerTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/script/ScriptStatusManagerTest.java index 69ac07bfb3..cd07f6f96e 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/script/ScriptStatusManagerTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/script/ScriptStatusManagerTest.java @@ -71,7 +71,7 @@ void scriptWithoutHashes_shouldOnlySetHashes() { when(configMapFinder.findByNameAndNamespace(any(), any())) .thenReturn(Optional.of(configMap)); expectedScript.getStatus().getScripts().get(0).setHash( - generateScriptEntryHash(expectedScripts.get(0), "CREATE DATABASE IF NOT EXISTS test;")); + generateScriptEntryHash(expectedScripts.getFirst(), "CREATE DATABASE IF NOT EXISTS test;")); expectedScript.getStatus().getScripts().get(1).setHash( generateScriptEntryHash(expectedScripts.get(1), "CREATE USER test;")); expectedScript.getStatus().getScripts().get(2).setHash( @@ -93,13 +93,13 @@ void scriptWithIdenticalHashes_shouldDoNothing() { when(configMapFinder.findByNameAndNamespace(any(), any())) .thenReturn(Optional.of(configMap)); script.getStatus().getScripts().get(0).setHash( - generateScriptEntryHash(scripts.get(0), "CREATE DATABASE IF NOT EXISTS test;")); + generateScriptEntryHash(scripts.getFirst(), "CREATE DATABASE IF NOT EXISTS test;")); script.getStatus().getScripts().get(1).setHash( generateScriptEntryHash(scripts.get(1), "CREATE USER test;")); script.getStatus().getScripts().get(2).setHash( generateScriptEntryHash(scripts.get(2), "CREATE TABLE test();")); expectedScript.getStatus().getScripts().get(0).setHash( - generateScriptEntryHash(expectedScripts.get(0), "CREATE DATABASE IF NOT EXISTS test;")); + generateScriptEntryHash(expectedScripts.getFirst(), "CREATE DATABASE IF NOT EXISTS test;")); expectedScript.getStatus().getScripts().get(1).setHash( generateScriptEntryHash(expectedScripts.get(1), "CREATE USER test;")); expectedScript.getStatus().getScripts().get(2).setHash( @@ -126,7 +126,7 @@ void scriptWithChangedHashes_shouldUpdateVersionAndSetHashes() { .build())); script.getSpec().getScripts().get(0).setScript("CREATE DATABASE test2;"); script.getStatus().getScripts().get(0).setHash( - generateScriptEntryHash(scripts.get(0), "CREATE DATABASE IF NOT EXISTS test;")); + generateScriptEntryHash(scripts.getFirst(), "CREATE DATABASE IF NOT EXISTS test;")); script.getStatus().getScripts().get(1).setHash( generateScriptEntryHash(scripts.get(1), "CREATE USER test;")); script.getStatus().getScripts().get(2).setHash( @@ -136,7 +136,7 @@ void scriptWithChangedHashes_shouldUpdateVersionAndSetHashes() { expectedScript.getSpec().getScripts().get(1).setVersion(1); expectedScript.getSpec().getScripts().get(2).setVersion(1); expectedScript.getStatus().getScripts().get(0).setHash( - generateScriptEntryHash(expectedScripts.get(0), "CREATE DATABASE test2;")); + generateScriptEntryHash(expectedScripts.getFirst(), "CREATE DATABASE test2;")); expectedScript.getStatus().getScripts().get(1).setHash( generateScriptEntryHash(expectedScripts.get(1), "CREATE USER test2;")); expectedScript.getStatus().getScripts().get(2).setHash( diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManagerTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManagerTest.java index 59a2439711..1ffd8369a6 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManagerTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManagerTest.java @@ -244,7 +244,7 @@ private void assertCondition(Condition expectedCondition, List Date: Thu, 30 Nov 2023 17:58:24 +0100 Subject: [PATCH 11/27] chore: Use pattern matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../apiweb/rest/ResourcesSerializationTest.java | 5 ++--- .../operator/ResourcesSerializationTest.java | 5 ++--- .../AbstractRequiredResourceGeneratorTest.java | 11 +++++------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/ResourcesSerializationTest.java b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/ResourcesSerializationTest.java index b8a42ca731..0a2854841f 100644 --- a/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/ResourcesSerializationTest.java +++ b/stackgres-k8s/src/api-web/src/test/java/io/stackgres/apiweb/rest/ResourcesSerializationTest.java @@ -70,9 +70,8 @@ void parametersOfGenericReturnTypesOfRestResponses_mustBeAnnotatedWithRegisterFo Arrays .stream(((ParameterizedType) t.v2.getGenericReturnType()).getActualTypeArguments()) .forEach(gt -> { - if (gt instanceof Class - && ((Class) gt).getName().startsWith("io.stackgres.")) { - Class type = (Class) gt; + if (gt instanceof Class type + && type.getName().startsWith("io.stackgres.")) { assertNotNull(type.getAnnotation(RegisterForReflection.class), "class " + type.getName() + " must be annotated with register for reflection"); } diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ResourcesSerializationTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ResourcesSerializationTest.java index b470fddfeb..161c5acb89 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ResourcesSerializationTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ResourcesSerializationTest.java @@ -69,9 +69,8 @@ void parametersOfGenericReturnTypesOfRestResponses_mustBeAnnotatedWithRegisterFo Arrays .stream(((ParameterizedType) t.v2.getGenericReturnType()).getActualTypeArguments()) .forEach(gt -> { - if (gt instanceof Class - && ((Class) gt).getName().startsWith("io.stackgres.")) { - Class type = (Class) gt; + if (gt instanceof Class type + && type.getName().startsWith("io.stackgres.")) { assertNotNull(type.getAnnotation(RegisterForReflection.class), "class " + type.getName() + " must be annotated with register for reflection"); } diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/AbstractRequiredResourceGeneratorTest.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/AbstractRequiredResourceGeneratorTest.java index 647712f44a..18f133b130 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/AbstractRequiredResourceGeneratorTest.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/AbstractRequiredResourceGeneratorTest.java @@ -152,8 +152,7 @@ public void asserThatLabelIsComplaint(Entry label) { } public void assertThatStatefulSetResourceLabelsAreComplaints(HasMetadata resource) { - if (resource instanceof StatefulSet) { - final StatefulSet statefulSet = (StatefulSet) resource; + if (resource instanceof StatefulSet statefulSet) { statefulSet.getSpec().getTemplate().getMetadata().getLabels().entrySet().stream() .forEach(label -> { asserThatLabelIsComplaint(label); @@ -180,8 +179,8 @@ private void assertThatVolumeClaimLabelsAreComplaints(StatefulSet statefulSet) { } public void assertThatCronJobResourceLabelsAreComplaints(HasMetadata resource) { - if (resource instanceof CronJob) { - ((CronJob) resource).getSpec().getJobTemplate().getMetadata().getLabels().entrySet() + if (resource instanceof CronJob job) { + job.getSpec().getJobTemplate().getMetadata().getLabels().entrySet() .stream().forEach(label -> { asserThatLabelIsComplaint(label); }); @@ -189,8 +188,8 @@ public void assertThatCronJobResourceLabelsAreComplaints(HasMetadata resource) { } public void assertThatJobResourceLabelsAreComplaints(HasMetadata resource) { - if (resource instanceof Job) { - ((Job) resource).getSpec().getTemplate().getMetadata().getLabels().entrySet().stream() + if (resource instanceof Job job) { + job.getSpec().getTemplate().getMetadata().getLabels().entrySet().stream() .forEach(label -> { asserThatLabelIsComplaint(label); }); From 231de925096467d79443c8e339d2f7767ae41d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Thu, 30 Nov 2023 18:27:01 +0100 Subject: [PATCH 12/27] chore: Refactor some code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../apiweb/rest/NamespacedClusterLogsResource.java | 5 ++--- .../transformer/AbstractClusterStatsTransformer.java | 9 +++------ .../java/io/stackgres/common/StackGresComponent.java | 3 +-- .../controller/DistributedLogsClusterReconciliator.java | 2 +- .../MinorVersionUpgradeRestartStateHandler.java | 3 +-- .../reconciliation/ResourceGeneratorReconciliator.java | 2 +- .../factory/OptionalSubResourceStreamFactory.java | 6 ++---- .../java/io/stackgres/operator/app/CrdInstaller.java | 3 +-- .../backup/BackupRequiredResourcesGenerator.java | 3 +-- .../cluster/ClusterRequiredResourcesGenerator.java | 3 +-- .../conciliation/factory/cluster/ClusterStatefulSet.java | 3 +-- .../ClusterStatefulSetContainerProfileDecorator.java | 6 ++---- .../distributedlogs/DistributedLogsStatefulSet.java | 3 +-- ...tributedLogsStatefulSetContainerProfileDecorator.java | 6 ++---- .../shardedcluster/backup/ShardedBackupCronJob.java | 3 +-- .../backup/ShardedBackupCronJobV1Beta1.java | 3 +-- .../ShardedBackupRequiredResourcesGenerator.java | 3 +-- .../ShardedClusterRequiredResourcesGenerator.java | 3 +-- .../mutation/AbstractDefaultResourceMutator.java | 2 +- .../operator/mutation/AbstractExtensionsMutator.java | 3 +-- .../PersistentVolumeSizeExpansionValidator.java | 3 +-- .../validation/cluster/RestoreConfigValidator.java | 2 +- .../operator/validation/cluster/SslValidator.java | 4 ++-- .../validation/cluster/StorageClassValidator.java | 2 +- .../operator/validation/dbops/ClusterValidator.java | 2 +- .../distributedlogs/StorageClassValidator.java | 2 +- .../validation/script/ScriptsConfigValidator.java | 4 ++-- .../shardedcluster/RestoreConfigValidator.java | 2 +- .../operator/validation/shardedcluster/SslValidator.java | 4 ++-- .../validation/shardedcluster/StorageClassValidator.java | 2 +- .../validation/shardeddbops/ShardedClusterValidator.java | 2 +- .../src/test/java/io/stackgres/operator/ItHelper.java | 2 +- 32 files changed, 41 insertions(+), 64 deletions(-) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java index 044c80a7a0..d2136de3ec 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java @@ -95,10 +95,9 @@ public List logs( final Optional> fromTuple; final Optional> toTuple; - if (!Optional.ofNullable(cluster.getSpec()) + if (Optional.ofNullable(cluster.getSpec()) .map(ClusterSpec::getDistributedLogs) - .map(ClusterDistributedLogs::getSgDistributedLogs) - .isPresent()) { + .map(ClusterDistributedLogs::getSgDistributedLogs).isEmpty()) { throw new BadRequestException( "Distributed logs are not configured for specified cluster"); } diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/transformer/AbstractClusterStatsTransformer.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/transformer/AbstractClusterStatsTransformer.java index 6035f60e66..8abee59d0a 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/transformer/AbstractClusterStatsTransformer.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/transformer/AbstractClusterStatsTransformer.java @@ -283,24 +283,21 @@ protected void setGlobalRequested(ClusterStats stats, stats.setCpuRequested(allPodStats .stream() .map(PodStatsUtil::getPodCpuRequested) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .reduce(BigInteger::add) .map(ResourceUtil::asMillicpusWithUnit) .orElse(null)); stats.setMemoryRequested(allPodStats .stream() .map(PodStatsUtil::getPodMemoryRequested) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .reduce(BigInteger::add) .map(ResourceUtil::asBytesWithUnit) .orElse(null)); stats.setDiskRequested(allPodStats .stream() .map(PodStatsUtil::getPodDiskRequested) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .reduce(BigInteger::add) .map(ResourceUtil::asBytesWithUnit) .orElse(null)); diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresComponent.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresComponent.java index 3f4483c1a8..73f37cd495 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresComponent.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/StackGresComponent.java @@ -41,8 +41,7 @@ public enum StackGresComponent { Stream.of(Components.values()) .flatMap(cs -> Stream.of(cs) .map(c -> c.getComponent(this)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .map(c -> Tuple.tuple(cs.getVersion(), c))) .forEach(component -> componentMapBuilder.put(component.v1, component.v2)); this.componentMap = componentMapBuilder.build(); diff --git a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java index 5cff58dec8..abcefb5e5c 100644 --- a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java +++ b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java @@ -166,7 +166,7 @@ private boolean updateStatus(StackGresDistributedLogs distributedLogs, String da .findAny(); final StackGresDistributedLogsStatusDatabase distributedLogsDatabase = foundDistributedLogsDatabase.orElseGet(() -> new StackGresDistributedLogsStatusDatabase()); - if (!foundDistributedLogsDatabase.isPresent()) { + if (foundDistributedLogsDatabase.isEmpty()) { distributedLogs.getStatus().getDatabases().add(distributedLogsDatabase); } diff --git a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeRestartStateHandler.java b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeRestartStateHandler.java index 17492b49c9..2a497077d8 100644 --- a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeRestartStateHandler.java +++ b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeRestartStateHandler.java @@ -66,8 +66,7 @@ private Uni getSourcePostgresVersion(StackGresCluster cluster) { return patroniApi.getClusterMembersPatroniInformation(clusterName, namespace) .onItem().transform(patronis -> patronis.stream() .map(PatroniInformation::getServerVersion) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .min(Integer::compareTo) .map(MinorVersionUpgradeRestartStateHandler::convertToPostgresVersion) .orElseThrow()); diff --git a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ResourceGeneratorReconciliator.java b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ResourceGeneratorReconciliator.java index 69cc37877f..dc68e996ec 100644 --- a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ResourceGeneratorReconciliator.java +++ b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/reconciliation/ResourceGeneratorReconciliator.java @@ -97,7 +97,7 @@ private void deleteUnwantedResources(KubernetesClient client, T context) { existingResource.v1.getMetadata().getName(), existingResource.v1.getKind(), name); handlerSelector.delete(client, context, existingResource.v1); - } else if (!existingResource.v2.isPresent() + } else if (existingResource.v2.isEmpty() && !handlerSelector.isManaged(context, existingResource.v1)) { if (handlerSelector.skipDeletion(context, existingResource.v1)) { logger.trace("Skip deletion of resource {}.{} of type {}", diff --git a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/factory/OptionalSubResourceStreamFactory.java b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/factory/OptionalSubResourceStreamFactory.java index 38618101c5..32dc219cc8 100644 --- a/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/factory/OptionalSubResourceStreamFactory.java +++ b/stackgres-k8s/src/operator-framework/src/main/java/io/stackgres/operatorframework/resource/factory/OptionalSubResourceStreamFactory.java @@ -19,16 +19,14 @@ public interface OptionalSubResourceStreamFactory listOptionalResources(C context) { return streamOptionalResources(context) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .toList(); } @Override default Stream streamResources(C context) { return streamOptionalResources(context) - .filter(Optional::isPresent) - .map(Optional::get); + .flatMap(Optional::stream); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java index be573c3262..4f5f46b587 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/app/CrdInstaller.java @@ -62,8 +62,7 @@ public CrdInstaller( public void checkUpgrade() { var resourcesRequiringUpgrade = crdLoader.scanCrds().stream() .map(crd -> crdResourceFinder.findByName(crd.getMetadata().getName())) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .flatMap(crd -> client .genericKubernetesResources(CustomResourceDefinitionContext.fromCrd(crd)) .inAnyNamespace() diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/backup/BackupRequiredResourcesGenerator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/backup/BackupRequiredResourcesGenerator.java index d2f1965c98..d940799a8d 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/backup/BackupRequiredResourcesGenerator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/backup/BackupRequiredResourcesGenerator.java @@ -153,8 +153,7 @@ private Set getClusterBackupNamespaces(final String backupNamespace) { .map(backup -> backup .map(StackGresBackup::getMetadata) .map(ObjectMeta::getNamespace)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .filter(Predicate.not(backupNamespace::equals)) .collect(Collectors.groupingBy(Function.identity())) .keySet(); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/cluster/ClusterRequiredResourcesGenerator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/cluster/ClusterRequiredResourcesGenerator.java index cd439ffd03..258309a508 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/cluster/ClusterRequiredResourcesGenerator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/cluster/ClusterRequiredResourcesGenerator.java @@ -676,8 +676,7 @@ private Set getClusterBackupNamespaces(final String clusterNamespace) { .map(backup -> backup .map(StackGresBackup::getMetadata) .map(ObjectMeta::getNamespace)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .filter(Predicate.not(clusterNamespace::equals)) .collect(Collectors.groupingBy(Function.identity())) .keySet(); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSet.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSet.java index c45d16586d..a01dd1019e 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSet.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSet.java @@ -179,8 +179,7 @@ public Stream generateResource(StackGresClusterContext context) { .map(availableVolumesPairs::get) .filter(Objects::nonNull) .map(VolumePair::getSource) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .toList(); return Stream.concat(Stream.of(clusterStatefulSet), volumeDependencies.stream()); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSetContainerProfileDecorator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSetContainerProfileDecorator.java index 3da08c1ace..584fada88e 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSetContainerProfileDecorator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/ClusterStatefulSetContainerProfileDecorator.java @@ -114,8 +114,7 @@ private void setPatroniContainerResources( .map(Container::getResources) .map(ResourceRequirements::getRequests) .map(requests -> requests.get("cpu"))) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .map(Quantity::getNumericalAmount) .reduce( amount, @@ -141,8 +140,7 @@ private void setPatroniContainerResources( .map(Container::getResources) .map(ResourceRequirements::getRequests) .map(requests -> requests.get("memory"))) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .map(Quantity::getNumericalAmount) .reduce( amount, diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSet.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSet.java index 246c4d12b5..3364caa102 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSet.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSet.java @@ -135,8 +135,7 @@ public Stream generateResource(StackGresDistributedLogsContext cont .map(availableVolumesPairs::get) .filter(Objects::nonNull) .map(VolumePair::getSource) - .filter(Optional::isPresent) - .map(Optional::get); + .flatMap(Optional::stream); return Stream.concat(Stream.of(clusterStatefulSet), volumeDependencies); } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSetContainerProfileDecorator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSetContainerProfileDecorator.java index 0017b4086a..cf8158d545 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSetContainerProfileDecorator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/distributedlogs/DistributedLogsStatefulSetContainerProfileDecorator.java @@ -112,8 +112,7 @@ private void setPatroniContainerResources( .map(Container::getResources) .map(ResourceRequirements::getRequests) .map(requests -> requests.get("cpu"))) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .map(Quantity::getNumericalAmount) .reduce( amount, @@ -139,8 +138,7 @@ private void setPatroniContainerResources( .map(Container::getResources) .map(ResourceRequirements::getRequests) .map(requests -> requests.get("memory"))) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .map(Quantity::getNumericalAmount) .reduce( amount, diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java index feb9e9c34d..432383b766 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJob.java @@ -127,8 +127,7 @@ public Stream generateResource(StackGresShardedClusterContext conte return Seq.of(backupCronJob) .append(volumes.stream() .map(VolumePair::getSource) - .filter(Optional::isPresent) - .map(Optional::get)); + .flatMap(Optional::stream)); } private CronJob createCronJob( diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java index 0c53f28b01..6d1b18d63b 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/shardedcluster/backup/ShardedBackupCronJobV1Beta1.java @@ -127,8 +127,7 @@ public Stream generateResource(StackGresShardedClusterContext conte return Seq.of(backupCronJob) .append(volumes.stream() .map(VolumePair::getSource) - .filter(Optional::isPresent) - .map(Optional::get)); + .flatMap(Optional::stream)); } private CronJob createCronJob( diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedbackup/ShardedBackupRequiredResourcesGenerator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedbackup/ShardedBackupRequiredResourcesGenerator.java index 2e62023ecb..bd993c7038 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedbackup/ShardedBackupRequiredResourcesGenerator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedbackup/ShardedBackupRequiredResourcesGenerator.java @@ -155,8 +155,7 @@ private Set getClusterBackupNamespaces(final String backupNamespace) { .map(backup -> backup .map(StackGresShardedBackup::getMetadata) .map(ObjectMeta::getNamespace)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .filter(Predicate.not(backupNamespace::equals)) .collect(Collectors.groupingBy(Function.identity())) .keySet(); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedcluster/ShardedClusterRequiredResourcesGenerator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedcluster/ShardedClusterRequiredResourcesGenerator.java index 269c5b55cd..be94f8e9c6 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedcluster/ShardedClusterRequiredResourcesGenerator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardedcluster/ShardedClusterRequiredResourcesGenerator.java @@ -543,8 +543,7 @@ private Set getClusterBackupNamespaces(final String clusterNamespace) { .map(backup -> backup .map(StackGresShardedBackup::getMetadata) .map(ObjectMeta::getNamespace)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .filter(Predicate.not(clusterNamespace::equals)) .collect(Collectors.groupingBy(Function.identity())) .keySet(); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractDefaultResourceMutator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractDefaultResourceMutator.java index 222af6f0ff..93bc14685a 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractDefaultResourceMutator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractDefaultResourceMutator.java @@ -55,7 +55,7 @@ public T mutate(R review, T resource) { setValueSection(resource); if (isTargetPropertyEmpty(resource)) { if (!Optional.ofNullable(review.getRequest().getDryRun()).orElse(false) - && !finder.findByNameAndNamespace(defaultResourceName, targetNamespace).isPresent()) { + && finder.findByNameAndNamespace(defaultResourceName, targetNamespace).isEmpty()) { defaultResource.getMetadata().setNamespace(targetNamespace); scheduler.create(defaultResource); } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractExtensionsMutator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractExtensionsMutator.java index ea8aa3569a..9951aa5ec5 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractExtensionsMutator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/mutation/AbstractExtensionsMutator.java @@ -128,8 +128,7 @@ private void mutateExtensions(R resource, StackGresCluster cluster) { .map(t -> t.extensionVersion() .map(version -> getExtension(cluster, t.extensionName(), version)) .orElseGet(() -> getExtension(cluster, t.extensionName()))) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .filter(defaultExtension -> extensions.stream() .noneMatch(extension -> extension.getName() .equals(defaultExtension.getName()))) diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/PersistentVolumeSizeExpansionValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/PersistentVolumeSizeExpansionValidator.java index d6a50a2941..f4ee707dba 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/PersistentVolumeSizeExpansionValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/PersistentVolumeSizeExpansionValidator.java @@ -140,8 +140,7 @@ protected List findClusterStorageClasses(T review) { // Since is very likely that all the storage classes are the same // we should look only for the different ones to avoid unneeded requests .map(getStorageClassFinder()::findByName) - .filter(Optional::isPresent) - .map(Optional::get); + .flatMap(Optional::stream); }) .toList(); }); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/RestoreConfigValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/RestoreConfigValidator.java index 45d7f54fe2..a48b889279 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/RestoreConfigValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/RestoreConfigValidator.java @@ -140,7 +140,7 @@ private void checkRestoreConfig( .ofNullable(review.getRequest().getOldObject().getSpec().getInitialData()) .map(StackGresClusterInitialData::getRestore); - if (!initRestoreOpt.isPresent() && oldRestoreOpt.isPresent()) { + if (initRestoreOpt.isEmpty() && oldRestoreOpt.isPresent()) { fail(errorConstraintViolationUri, "Cannot update SGCluster's restore configuration"); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/SslValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/SslValidator.java index d5dd5040ed..6a563a61d7 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/SslValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/SslValidator.java @@ -69,8 +69,8 @@ private void checkIfSecretOrKeyExists(String namespace, SecretKeySelector secret Optional secret = secretFinder .findByNameAndNamespace(secretKeySelector.getName(), namespace); - if (!secret.filter(s -> s.getData() - .containsKey(secretKeySelector.getKey())).isPresent()) { + if (secret.filter(s -> s.getData() + .containsKey(secretKeySelector.getKey())).isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/StorageClassValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/StorageClassValidator.java index 2347b96ded..667b154543 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/StorageClassValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/cluster/StorageClassValidator.java @@ -54,7 +54,7 @@ public void validate(StackGresClusterReview review) throws ValidationFailed { private void checkIfStorageClassExist(String storageClass, String onError) throws ValidationFailed { if (storageClass != null && !storageClass.isEmpty() - && !finder.findByName(storageClass).isPresent()) { + && finder.findByName(storageClass).isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/dbops/ClusterValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/dbops/ClusterValidator.java index d373b00e3a..dfe212a4f7 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/dbops/ClusterValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/dbops/ClusterValidator.java @@ -44,7 +44,7 @@ private void checkIfClusterExists(String cluster, String namespace, Optional clusterOpt = clusterFinder .findByNameAndNamespace(cluster, namespace); - if (!clusterOpt.isPresent()) { + if (clusterOpt.isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/distributedlogs/StorageClassValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/distributedlogs/StorageClassValidator.java index fc5193f818..b1672a21cb 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/distributedlogs/StorageClassValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/distributedlogs/StorageClassValidator.java @@ -55,7 +55,7 @@ public void validate(StackGresDistributedLogsReview review) throws ValidationFai private void checkIfStorageClassExist(String storageClass, String onError) throws ValidationFailed { if (storageClass != null && !storageClass.isEmpty() - && !finder.findByName(storageClass).isPresent()) { + && finder.findByName(storageClass).isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/script/ScriptsConfigValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/script/ScriptsConfigValidator.java index 21ae652801..2ad504fd2d 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/script/ScriptsConfigValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/script/ScriptsConfigValidator.java @@ -119,7 +119,7 @@ private void checkConfigMapsSelectors(StackGresScriptReview review, Optional scriptConfigMap = configMapFinder .findByNameAndNamespace(configMapRef.getName(), clusterNamespace); - if (!scriptConfigMap.isPresent()) { + if (scriptConfigMap.isEmpty()) { fail(invalidReference, "Referenced ConfigMap " + configMapRef.getName() + " does not exists in namespace " + clusterNamespace); @@ -159,7 +159,7 @@ private void checkSecretKeySelectors(StackGresScriptReview review, Optional scriptSecret = secretFinder .findByNameAndNamespace(secretRef.getName(), clusterNamespace); - if (!scriptSecret.isPresent()) { + if (scriptSecret.isEmpty()) { fail(invalidReference, "Referenced Secret " + secretRef.getName() + " does not exists in namespace " + clusterNamespace); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/RestoreConfigValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/RestoreConfigValidator.java index 91e63863c4..5eba7c99f2 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/RestoreConfigValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/RestoreConfigValidator.java @@ -158,7 +158,7 @@ private void checkRestoreConfig( .ofNullable(review.getRequest().getOldObject().getSpec().getInitialData()) .map(StackGresShardedClusterInitialData::getRestore); - if (!initRestoreOpt.isPresent() && oldRestoreOpt.isPresent()) { + if (initRestoreOpt.isEmpty() && oldRestoreOpt.isPresent()) { fail(errorConstraintViolationUri, "Cannot update SGShardedCluster's restore configuration"); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/SslValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/SslValidator.java index 555c9fc0e2..99aec22d2b 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/SslValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/SslValidator.java @@ -69,8 +69,8 @@ private void checkIfSecretOrKeyExists(String namespace, SecretKeySelector secret Optional secret = secretFinder .findByNameAndNamespace(secretKeySelector.getName(), namespace); - if (!secret.filter(s -> s.getData() - .containsKey(secretKeySelector.getKey())).isPresent()) { + if (secret.filter(s -> s.getData() + .containsKey(secretKeySelector.getKey())).isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/StorageClassValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/StorageClassValidator.java index 331fff8443..4b893543b5 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/StorageClassValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardedcluster/StorageClassValidator.java @@ -94,7 +94,7 @@ public void validate(StackGresShardedClusterReview review) throws ValidationFail private void checkIfStorageClassExist(String storageClass, String onError) throws ValidationFailed { if (storageClass != null && !storageClass.isEmpty() - && !finder.findByName(storageClass).isPresent()) { + && finder.findByName(storageClass).isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardeddbops/ShardedClusterValidator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardeddbops/ShardedClusterValidator.java index 4b91a77064..2e3f8b1ce2 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardeddbops/ShardedClusterValidator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/validation/shardeddbops/ShardedClusterValidator.java @@ -44,7 +44,7 @@ private void checkIfClusterExists(String cluster, String namespace, Optional clusterOpt = clusterFinder .findByNameAndNamespace(cluster, namespace); - if (!clusterOpt.isPresent()) { + if (clusterOpt.isEmpty()) { fail(onError); } } diff --git a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java index e0d7b9d45a..323ca0e5c7 100644 --- a/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java +++ b/stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/ItHelper.java @@ -222,7 +222,7 @@ public static String createExposedHost(Container k8s, String host, int port) Optional secondPointIndex = firstPointIndex .map(index -> host.indexOf('.', index + 1)) .filter(index -> index >= 0); - if (!firstPointIndex.isPresent()) { + if (firstPointIndex.isEmpty()) { return host; } String namespace = host.substring(firstPointIndex.get() + 1, From b2aa77d01b4e88e419ff419509719f5957685e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Fri, 1 Dec 2023 14:15:26 +0100 Subject: [PATCH 13/27] chore: Fix spotbugs issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../cluster/ClusterNonProductionOptions.java | 16 ++++++++-------- .../DistributedLogsNonProductionOptions.java | 14 +++++++------- stackgres-k8s/src/checks/checkstyle.xml | 8 ++++---- stackgres-k8s/src/checks/spotbugs-exclude.xml | 4 ++++ .../stackgres/common/crd/CustomContainer.java | 4 ++-- .../StackGresClusterNonProduction.java | 16 ++++++++-------- .../StackGresDistributedLogsNonProduction.java | 14 +++++++------- .../DistributedLogsClusterReconciliator.java | 3 ++- .../MinorVersionUpgradeJob.java | 1 - .../conciliation/AbstractConciliator.java | 18 ++++++++++++------ .../conciliation/dbops/DbOpsStatusManager.java | 6 +++++- .../ShardedDbOpsStatusManager.java | 6 +++++- stackgres-k8s/src/pom.xml | 4 ++-- .../stackgres/testutil/GeneratorTestUtil.java | 4 ++-- .../stackgres/testutil/RandomObjectUtils.java | 2 +- 15 files changed, 69 insertions(+), 51 deletions(-) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/cluster/ClusterNonProductionOptions.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/cluster/ClusterNonProductionOptions.java index 14651aca65..35b18c662c 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/cluster/ClusterNonProductionOptions.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/cluster/ClusterNonProductionOptions.java @@ -15,21 +15,21 @@ @JsonInclude(JsonInclude.Include.NON_DEFAULT) public class ClusterNonProductionOptions { - public Boolean disableClusterPodAntiAffinity; + Boolean disableClusterPodAntiAffinity; - public Boolean disablePatroniResourceRequirements; + Boolean disablePatroniResourceRequirements; - public Boolean disableClusterResourceRequirements; + Boolean disableClusterResourceRequirements; - public Boolean enableSetPatroniCpuRequests; + Boolean enableSetPatroniCpuRequests; - public Boolean enableSetClusterCpuRequests; + Boolean enableSetClusterCpuRequests; - public Boolean enableSetPatroniMemoryRequests; + Boolean enableSetPatroniMemoryRequests; - public Boolean enableSetClusterMemoryRequests; + Boolean enableSetClusterMemoryRequests; - public List enabledFeatureGates; + List enabledFeatureGates; public Boolean getDisableClusterPodAntiAffinity() { return disableClusterPodAntiAffinity; diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/distributedlogs/DistributedLogsNonProductionOptions.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/distributedlogs/DistributedLogsNonProductionOptions.java index ccd074545f..1659e5c549 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/distributedlogs/DistributedLogsNonProductionOptions.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/dto/distributedlogs/DistributedLogsNonProductionOptions.java @@ -13,19 +13,19 @@ @JsonInclude(JsonInclude.Include.NON_DEFAULT) public class DistributedLogsNonProductionOptions { - public Boolean disableClusterPodAntiAffinity; + Boolean disableClusterPodAntiAffinity; - public Boolean disablePatroniResourceRequirements; + Boolean disablePatroniResourceRequirements; - public Boolean disableClusterResourceRequirements; + Boolean disableClusterResourceRequirements; - public Boolean enableSetPatroniCpuRequests; + Boolean enableSetPatroniCpuRequests; - public Boolean enableSetClusterCpuRequests; + Boolean enableSetClusterCpuRequests; - public Boolean enableSetPatroniMemoryRequests; + Boolean enableSetPatroniMemoryRequests; - public Boolean enableSetClusterMemoryRequests; + Boolean enableSetClusterMemoryRequests; public Boolean getDisableClusterPodAntiAffinity() { return disableClusterPodAntiAffinity; diff --git a/stackgres-k8s/src/checks/checkstyle.xml b/stackgres-k8s/src/checks/checkstyle.xml index fc9cd35a4a..a1c0fd682d 100644 --- a/stackgres-k8s/src/checks/checkstyle.xml +++ b/stackgres-k8s/src/checks/checkstyle.xml @@ -45,11 +45,11 @@ - - + + @@ -57,7 +57,7 @@ - + diff --git a/stackgres-k8s/src/checks/spotbugs-exclude.xml b/stackgres-k8s/src/checks/spotbugs-exclude.xml index 03e88b60af..59fc2d9434 100644 --- a/stackgres-k8s/src/checks/spotbugs-exclude.xml +++ b/stackgres-k8s/src/checks/spotbugs-exclude.xml @@ -118,4 +118,8 @@ + + + + diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/CustomContainer.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/CustomContainer.java index 8059a84369..ddf1387189 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/CustomContainer.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/CustomContainer.java @@ -56,12 +56,12 @@ public CustomContainer(List args, List command, List env List envFrom, String image, String imagePullPolicy, Lifecycle lifecycle, Probe livenessProbe, String name, List ports, Probe readinessProbe, List resizePolicy, - ResourceRequirements resources, SecurityContext securityContext, Probe startupProbe, + ResourceRequirements resources, String restartPolicy, SecurityContext securityContext, Probe startupProbe, Boolean stdin, Boolean stdinOnce, String terminationMessagePath, String terminationMessagePolicy, Boolean tty, List volumeDevices, List volumeMounts, String workingDir) { super(args, command, env, envFrom, image, imagePullPolicy, lifecycle, livenessProbe, name, - ports, readinessProbe, resizePolicy, resources, securityContext, startupProbe, stdin, + ports, readinessProbe, resizePolicy, resources, restartPolicy, securityContext, startupProbe, stdin, stdinOnce, terminationMessagePath, terminationMessagePolicy, tty, volumeDevices, volumeMounts, workingDir); } diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgcluster/StackGresClusterNonProduction.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgcluster/StackGresClusterNonProduction.java index d6d0b2fb22..87b5c83e22 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgcluster/StackGresClusterNonProduction.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgcluster/StackGresClusterNonProduction.java @@ -23,23 +23,23 @@ builderPackage = "io.fabric8.kubernetes.api.builder") public class StackGresClusterNonProduction { - public Boolean disableClusterPodAntiAffinity; + Boolean disableClusterPodAntiAffinity; - public Boolean disablePatroniResourceRequirements; + Boolean disablePatroniResourceRequirements; - public Boolean disableClusterResourceRequirements; + Boolean disableClusterResourceRequirements; - public Boolean enableSetPatroniCpuRequests; + Boolean enableSetPatroniCpuRequests; - public Boolean enableSetClusterCpuRequests; + Boolean enableSetClusterCpuRequests; - public Boolean enableSetPatroniMemoryRequests; + Boolean enableSetPatroniMemoryRequests; - public Boolean enableSetClusterMemoryRequests; + Boolean enableSetClusterMemoryRequests; @ValidEnumList(enumClass = StackGresFeatureGates.class, allowNulls = true, message = "enabledFeatureGates must contain only babelfish-flavor") - public List enabledFeatureGates; + List enabledFeatureGates; public Boolean getDisableClusterPodAntiAffinity() { return disableClusterPodAntiAffinity; diff --git a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgdistributedlogs/StackGresDistributedLogsNonProduction.java b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgdistributedlogs/StackGresDistributedLogsNonProduction.java index abd5d4d3ba..f5a7743645 100644 --- a/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgdistributedlogs/StackGresDistributedLogsNonProduction.java +++ b/stackgres-k8s/src/common/src/main/java/io/stackgres/common/crd/sgdistributedlogs/StackGresDistributedLogsNonProduction.java @@ -21,19 +21,19 @@ builderPackage = "io.fabric8.kubernetes.api.builder") public class StackGresDistributedLogsNonProduction { - public Boolean disableClusterPodAntiAffinity; + Boolean disableClusterPodAntiAffinity; - public Boolean disablePatroniResourceRequirements; + Boolean disablePatroniResourceRequirements; - public Boolean disableClusterResourceRequirements; + Boolean disableClusterResourceRequirements; - public Boolean enableSetPatroniCpuRequests; + Boolean enableSetPatroniCpuRequests; - public Boolean enableSetClusterCpuRequests; + Boolean enableSetClusterCpuRequests; - public Boolean enableSetPatroniMemoryRequests; + Boolean enableSetPatroniMemoryRequests; - public Boolean enableSetClusterMemoryRequests; + Boolean enableSetClusterMemoryRequests; public Boolean getDisableClusterPodAntiAffinity() { return disableClusterPodAntiAffinity; diff --git a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java index abcefb5e5c..e9cfddc3fd 100644 --- a/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java +++ b/stackgres-k8s/src/distributedlogs-controller/src/main/java/io/stackgres/distributedlogs/controller/DistributedLogsClusterReconciliator.java @@ -196,7 +196,8 @@ private void handleException(KubernetesClient client, StackGresDistributedLogs d DistributedLogsControllerEventReason.DISTRIBUTEDLOGS_CONTROLLER_ERROR, message + ": " + ex.getMessage(), distributedLogs, client); } catch (RuntimeException rex) { - LOGGER.error("Failed sending event while reconciling cluster {}.{}", cluster.getNamespace(), cluster.getName(), rex); + LOGGER.error("Failed sending event while reconciling cluster {}.{}", + cluster.getNamespace(), cluster.getName(), rex); } } diff --git a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java index 98288244c0..07be1ed795 100644 --- a/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java +++ b/stackgres-k8s/src/jobs/src/main/java/io/stackgres/jobs/dbops/minorversionupgrade/MinorVersionUpgradeJob.java @@ -21,7 +21,6 @@ import io.stackgres.jobs.dbops.MutinyUtil; import io.stackgres.jobs.dbops.StateHandler; import io.stackgres.jobs.dbops.clusterrestart.ClusterRestartState; -import io.stackgres.jobs.dbops.securityupgrade.SecurityUpgradeJob; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import org.slf4j.Logger; diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java index dc386ef06e..16da0836d4 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/AbstractConciliator.java @@ -106,11 +106,15 @@ public ReconciliationResult evalReconciliationState(T config) { .anyMatch(deployedResourceKey::equals)) .toList(); if (!deployedOtherOwnerRequiredResources.isEmpty()) { - LOGGER.warn("Following resources are required but already exists in the cluster and are owned by another resource: {}", deployedOtherOwnerRequiredResources.stream() - .map(resourceKey -> resourceKey.kind() - + " " + resourceKey.namespace() - + "." + resourceKey.name()) - .collect(Collectors.joining(", "))); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn( + "Following resources are required but already exists in the cluster and are owned by another resource: {}", + deployedOtherOwnerRequiredResources.stream() + .map(resourceKey -> resourceKey.kind() + + " " + resourceKey.namespace() + + "." + resourceKey.name()) + .collect(Collectors.joining(", "))); + } // Workaround for https://github.com/kubernetes/kubernetes/issues/120960 cleanupNonGarbageCollectedResources( deployedResourcesSnapshot, deployedOtherOwnerRequiredResources); @@ -163,7 +167,9 @@ private void cleanupNonGarbageCollectedResources( try { client.resource(resource).delete(); } catch (KubernetesClientException ex) { - LOGGER.warn("Error while trying to remove ungarbaged resource {} {}.{}", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName(), ex); + LOGGER.warn("Error while trying to remove ungarbaged resource {} {}.{}", + resource.getKind(), resource.getMetadata().getNamespace(), + resource.getMetadata().getName(), ex); } } }); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java index 0453c9e65f..add9d929b7 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/dbops/DbOpsStatusManager.java @@ -83,7 +83,11 @@ public StackGresDbOps refreshCondition(StackGresDbOps source) { } if (isJobFailedAndStatusNotUpdated) { - LOGGER.debug("DbOps {} failed since the job failed but status condition is neither completed or failed", getDbOpsId(source)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "DbOps {} failed since the job failed but status condition is neither completed or failed", + getDbOpsId(source)); + } updateCondition(getFalseRunning(), source); updateCondition(getFalseCompleted(), source); updateCondition(getFailedDueToUnexpectedFailure(), source); diff --git a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java index 858a9c6d14..557b40caa0 100644 --- a/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java +++ b/stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/shardeddbops/ShardedDbOpsStatusManager.java @@ -83,7 +83,11 @@ public StackGresShardedDbOps refreshCondition(StackGresShardedDbOps source) { } if (isJobFailedAndStatusNotUpdated) { - LOGGER.debug("ShardedDbOps {} failed since the job failed but status condition is neither completed or failed", getShardedDbOpsId(source)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "ShardedDbOps {} failed since the job failed but status condition is neither completed or failed", + getShardedDbOpsId(source)); + } updateCondition(getFalseRunning(), source); updateCondition(getFalseCompleted(), source); updateCondition(getFailedDueToUnexpectedFailure(), source); diff --git a/stackgres-k8s/src/pom.xml b/stackgres-k8s/src/pom.xml index ec8b8e8f36..7eccdaea5a 100644 --- a/stackgres-k8s/src/pom.xml +++ b/stackgres-k8s/src/pom.xml @@ -85,7 +85,6 @@ 6.55.0 1.2.15 1.0.1 - 24.1.0 2.0.0 3.0.0 2.2.19 @@ -268,7 +267,6 @@ org.jetbrains annotations - ${jetbrains-annotations.version} provided true @@ -448,6 +446,8 @@ maven-pmd-plugin ${pmd-plugin.version} + + true 3 true true diff --git a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/GeneratorTestUtil.java b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/GeneratorTestUtil.java index 2e767a379b..e3489c9576 100644 --- a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/GeneratorTestUtil.java +++ b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/GeneratorTestUtil.java @@ -30,9 +30,9 @@ import io.fabric8.kubernetes.api.model.rbac.Role; import org.jooq.lambda.Seq; -public class GeneratorTestUtil { +public final class GeneratorTestUtil { - public GeneratorTestUtil() { + private GeneratorTestUtil() { throw new IllegalStateException("Should not be instantiated"); } diff --git a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/RandomObjectUtils.java b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/RandomObjectUtils.java index c9e0034528..ae52c18e8d 100644 --- a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/RandomObjectUtils.java +++ b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/RandomObjectUtils.java @@ -21,7 +21,7 @@ import io.fabric8.kubernetes.api.model.Quantity; -public class RandomObjectUtils { +public final class RandomObjectUtils { public static final Random RANDOM = new Random(7); From 34e5be4341a04d5c1927e7be6c927d05f1c45514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Fri, 1 Dec 2023 17:32:45 +0100 Subject: [PATCH 14/27] chore: Update Maven to 3.9.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- stackgres-k8s/src/.mvn/wrapper/maven-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stackgres-k8s/src/.mvn/wrapper/maven-wrapper.properties b/stackgres-k8s/src/.mvn/wrapper/maven-wrapper.properties index eacdc9ed17..346d645fd0 100644 --- a/stackgres-k8s/src/.mvn/wrapper/maven-wrapper.properties +++ b/stackgres-k8s/src/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar From f865a9a03c79bf9ec72f72dc775f8892c9fd582e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Fri, 1 Dec 2023 17:48:12 +0100 Subject: [PATCH 15/27] ci: Update builder images to jdk-21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .gitlab-ci.yml | 2 +- .gitlab-ci/image-build.yml | 2 +- .gitlab-ci/image-release.yml | 2 +- .gitlab-ci/pre-build.yml | 4 ++-- stackgres-k8s/ci/build/Dockerfile-builder | 7 +++---- stackgres-k8s/ci/build/config.yml | 12 ++++++------ stackgres-k8s/src/pom.xml | 19 ++++++++++--------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bdb5939995..40f3ea6858 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: null variables: SG_CI_IMAGE_NAME: "ci:1.23" - BUILDER_IMAGE_NAME: "builder:1.6" + BUILDER_IMAGE_NAME: "builder:1.7" SKIP_NATIVE: "false" SKIP_E2E: "false" SKIP_DEPLOY: "false" diff --git a/.gitlab-ci/image-build.yml b/.gitlab-ci/image-build.yml index 71b99e8dd4..5baaf107a6 100644 --- a/.gitlab-ci/image-build.yml +++ b/.gitlab-ci/image-build.yml @@ -19,7 +19,7 @@ retry: 2 .build image multi archs: - image: docker:20.10.12 + image: docker:24.0.7 stage: image build multi archs timeout: 1 hour script: diff --git a/.gitlab-ci/image-release.yml b/.gitlab-ci/image-release.yml index 31960965f6..43bf8c4416 100644 --- a/.gitlab-ci/image-release.yml +++ b/.gitlab-ci/image-release.yml @@ -19,7 +19,7 @@ retry: 2 .release image multi archs: - image: docker:20.10.12 + image: docker:24.0.7 stage: image build multi archs timeout: 1 hour script: diff --git a/.gitlab-ci/pre-build.yml b/.gitlab-ci/pre-build.yml index b20c169360..db21ec8283 100644 --- a/.gitlab-ci/pre-build.yml +++ b/.gitlab-ci/pre-build.yml @@ -1,5 +1,5 @@ .pre build image: - image: docker:20.10.12 + image: docker:24.0.7 stage: pre build timeout: 1 hour script: @@ -27,7 +27,7 @@ retry: 2 .pre build image multi archs: - image: docker:20.10.12 + image: docker:24.0.7 tags: - stackgres-runner-v2 stage: pre build multi archs diff --git a/stackgres-k8s/ci/build/Dockerfile-builder b/stackgres-k8s/ci/build/Dockerfile-builder index 31e75c86eb..85bcb4145a 100644 --- a/stackgres-k8s/ci/build/Dockerfile-builder +++ b/stackgres-k8s/ci/build/Dockerfile-builder @@ -3,12 +3,11 @@ # # Build the image with: # -# docker build -f stackgres-k8s/ci/build/Dockerfile-builder -t registry.gitlab.com/ongresinc/stackgres/build-amd64:1.6 stackgres-k8s/ci/build/ +# docker build -f stackgres-k8s/ci/build/Dockerfile-builder -t registry.gitlab.com/ongresinc/stackgres/build-amd64:1.7 stackgres-k8s/ci/build/ # ### -FROM quay.io/quarkus/ubi-quarkus-mandrel-builder-image:22.3-java17 +FROM quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21.0.1 USER root - RUN microdnf --nodocs install python3-pip jq util-linux findutils + RUN microdnf --nodocs install python3-pip jq util-linux findutils && microdnf clean all RUN pip3 install yamllint yq - RUN microdnf clean all diff --git a/stackgres-k8s/ci/build/config.yml b/stackgres-k8s/ci/build/config.yml index ad91a01764..553673e34b 100644 --- a/stackgres-k8s/ci/build/config.yml +++ b/stackgres-k8s/ci/build/config.yml @@ -1,11 +1,11 @@ .images: ci_image: &ci_image registry.gitlab.com/ongresinc/stackgres/ci:1.23 - jdk_build_image: &jdk_build_image registry.gitlab.com/ongresinc/stackgres/builder:1.6 - jdk_runtime_image: &jdk_runtime_image registry.access.redhat.com/ubi8/openjdk-17:1.17-4 - ubi8_micro_image: &ubi8_micro_image registry.access.redhat.com/ubi8-micro:8.8-7.1696517612 - ubi9_minimal_image: &ubi9_minimal_image registry.access.redhat.com/ubi9-minimal:9.3-1361 - admin_ui_build_image: &admin_ui_build_image registry.access.redhat.com/ubi8/nodejs-16:1-129.1698060573 - admin_ui_nginx_image: &admin_ui_nginx_image registry.access.redhat.com/ubi8/nginx-120:1-127.1698060561 + jdk_build_image: &jdk_build_image registry.gitlab.com/ongresinc/stackgres/builder:1.7 + jdk_runtime_image: &jdk_runtime_image registry.access.redhat.com/ubi8/openjdk-21-runtime:1.18-2 + ubi8_micro_image: &ubi8_micro_image registry.access.redhat.com/ubi8-micro:8.9-4 + ubi9_minimal_image: &ubi9_minimal_image registry.access.redhat.com/ubi9-minimal:9.3-1361.1699548032 + admin_ui_build_image: &admin_ui_build_image registry.access.redhat.com/ubi8/nodejs-16:1-139 + admin_ui_nginx_image: &admin_ui_nginx_image registry.access.redhat.com/ubi8/nginx-120:1-137 platforms: - linux/x86_64 - linux/aarch64 diff --git a/stackgres-k8s/src/pom.xml b/stackgres-k8s/src/pom.xml index 7eccdaea5a..d90b7a896a 100644 --- a/stackgres-k8s/src/pom.xml +++ b/stackgres-k8s/src/pom.xml @@ -87,7 +87,7 @@ 1.0.1 2.0.0 3.0.0 - 2.2.19 + 2.2.15 0.101.3 0.10.2 1.1.5 @@ -99,7 +99,6 @@ 1.13.0 0.21.0 1.70 - 19.2.1 3.11.0 3.3.0 @@ -115,7 +114,7 @@ 0.43.0 3.1.6 3.5.0 - 2.2.19 + 2.2.15 ${maven.multiModuleProjectDirectory}/checks ${checks.location}/checkstyle.xml @@ -277,12 +276,6 @@ provided true - - com.oracle.substratevm - svm - ${substratevm.version} - provided - @@ -391,6 +384,14 @@ + + + + org.codehaus.plexus + plexus-utils + 4.0.0 + + io.swagger.core.v3 From 5709236ea2ddb5b1a5b9fb61a0457e7464dbdc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Mon, 4 Dec 2023 17:05:54 +0100 Subject: [PATCH 16/27] chore: Replace swagger with quarkus-smallrye-openapi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- stackgres-k8s/src/api-web/pom.xml | 63 ++++------ .../apiweb/rest/ApplicationsResource.java | 40 +++--- .../stackgres/apiweb/rest/AuthResource.java | 30 ++--- .../stackgres/apiweb/rest/BackupResource.java | 47 +++---- .../apiweb/rest/ClusterResource.java | 94 +++++++------- .../apiweb/rest/ClusterRoleResource.java | 48 +++----- .../stackgres/apiweb/rest/ConfigResource.java | 52 +++----- .../rest/ConnectionPoolingConfigResource.java | 48 +++----- .../stackgres/apiweb/rest/DbOpsResource.java | 49 +++----- .../apiweb/rest/DistributedLogsResource.java | 48 +++----- .../apiweb/rest/ExtensionsResource.java | 19 ++- .../apiweb/rest/KubernetesInfoResource.java | 19 ++- .../apiweb/rest/NamespaceResource.java | 39 +++--- .../apiweb/rest/NamespacedBackupResource.java | 18 ++- .../rest/NamespacedClusterEventsResource.java | 20 ++- .../rest/NamespacedClusterLogsResource.java | 21 ++-- .../rest/NamespacedClusterResource.java | 18 ++- .../rest/NamespacedClusterStatsResource.java | 18 ++- .../rest/NamespacedConfigMapResource.java | 20 ++- .../apiweb/rest/NamespacedConfigResource.java | 18 ++- ...spacedConnectionPoolingConfigResource.java | 18 ++- .../rest/NamespacedDbOpsEventsResource.java | 44 +++---- .../apiweb/rest/NamespacedDbOpsResource.java | 18 ++- .../NamespacedDistributedLogsResource.java | 18 ++- .../rest/NamespacedObjectStorageResource.java | 21 ++-- .../NamespacedPostgresConfigResource.java | 22 ++-- .../rest/NamespacedProfileResource.java | 18 ++- .../apiweb/rest/NamespacedScriptResource.java | 30 ++--- .../apiweb/rest/NamespacedSecretResource.java | 20 ++- .../rest/NamespacedShardedBackupResource.java | 18 ++- .../NamespacedShardedClusterResource.java | 18 ++- ...NamespacedShardedClusterStatsResource.java | 18 ++- .../rest/NamespacedShardedDbOpsResource.java | 18 ++- .../apiweb/rest/ObjectStorageResource.java | 68 ++++------ .../apiweb/rest/PostgresConfigResource.java | 50 +++----- .../apiweb/rest/ProfileResource.java | 50 +++----- .../stackgres/apiweb/rest/RbacResource.java | 29 ++--- .../stackgres/apiweb/rest/RoleResource.java | 48 +++----- .../stackgres/apiweb/rest/ScriptResource.java | 85 ++++++------- .../apiweb/rest/ShardedBackupResource.java | 48 +++----- .../apiweb/rest/ShardedClusterResource.java | 116 ++++++++---------- .../apiweb/rest/ShardedDbOpsResource.java | 48 +++----- .../apiweb/rest/StorageClassResource.java | 20 ++- .../stackgres/apiweb/rest/UserResource.java | 64 ++++------ .../apiweb/rest/VersionsResource.java | 18 ++- .../utils/AuthenticatedSecurityScheme.java | 9 +- .../apiweb/rest/utils/CommonApiResponses.java | 14 +-- .../src/main/resources/application.properties | 7 +- 48 files changed, 665 insertions(+), 1019 deletions(-) diff --git a/stackgres-k8s/src/api-web/pom.xml b/stackgres-k8s/src/api-web/pom.xml index faff75a1d0..264e2f21d0 100644 --- a/stackgres-k8s/src/api-web/pom.xml +++ b/stackgres-k8s/src/api-web/pom.xml @@ -4,13 +4,15 @@ ~ SPDX-License-Identifier: AGPL-3.0-or-later --> - + + 4.0.0 stackgres-parent io.stackgres 1.7.0-SNAPSHOT - 4.0.0 stackgres-restapi jar @@ -68,18 +70,18 @@ jakarta.persistence-api - io.swagger.core.v3 - swagger-annotations-jakarta - - - io.swagger.core.v3 - swagger-maven-plugin-jakarta - ${swagger-maven-plugin-jakarta.version} + io.quarkus + quarkus-smallrye-openapi io.quarkus quarkus-rest-client + + io.sundr + builder-annotations + provided + io.stackgres stackgres-test-util @@ -118,6 +120,16 @@ com.ongres docker-junit-extension test + + + org.jooq + jool-java-8 + + + net.java.dev.jna + jna + + io.quarkus @@ -144,6 +156,12 @@ io.quarkus quarkus-test-keycloak-server test + + + net.java.dev.jna + jna + + @@ -179,33 +197,6 @@ io.smallrye jandex-maven-plugin - - io.swagger.core.v3 - swagger-maven-plugin-jakarta - - false - - io.stackgres.apiweb.rest - io.stackgres.apiweb.dto - io.stackgres.apiweb.security - - ${basedir}/target/ - swagger - YAML - true - true - true - true - - - - compile - - resolve - - - - diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java index 36b33ff41e..1ba3e2785e 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java @@ -20,11 +20,6 @@ import io.stackgres.apiweb.dto.ApplicationDto; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.StringUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.parameters.RequestBody; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; @@ -36,6 +31,11 @@ import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jboss.resteasy.annotations.jaxrs.PathParam; import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; import org.jboss.resteasy.plugins.providers.multipart.InputPart; @@ -50,12 +50,10 @@ public class ApplicationsResource { @Inject Instance applications; - @Operation(responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(type = "object"))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(type = SchemaType.OBJECT))}) @CommonApiResponses @GET public Map> getAllApplications() { @@ -71,12 +69,10 @@ public Map> getAllApplications() { return Map.of("applications", List.copyOf(appsDto)); } - @Operation(responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(type = "object"))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(type = SchemaType.OBJECT))}) @CommonApiResponses @GET @Path("{publisher}/{name}") @@ -92,12 +88,10 @@ public ApplicationDto getApplication(@PathParam String publisher, @PathParam Str throw new NotFoundException("Application %s/%s not found".formatted(publisher, name)); } - @Operation(responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(type = "object"))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(type = SchemaType.OBJECT))}) @RequestBody(content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA)) @CommonApiResponses @POST diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java index 76f8baadc3..d7c8db4a2d 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java @@ -16,10 +16,6 @@ import io.stackgres.apiweb.security.TokenResponse; import io.stackgres.apiweb.security.TokenUtils; import io.stackgres.apiweb.security.UserPassword; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.validation.Valid; @@ -31,6 +27,9 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,13 +48,10 @@ public class AuthResource { @Inject AuthConfig config; - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = TokenResponse.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = TokenResponse.class))}) @CommonApiResponses @POST @Path("login") @@ -81,11 +77,8 @@ public Response login(@Valid UserPassword credentials) { } } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "307", description = "Redirect") - }) + @APIResponse(responseCode = "200", description = "OK") + @APIResponse(responseCode = "307", description = "Redirect") @CommonApiResponses @GET @Path("external") @@ -96,10 +89,7 @@ public Response externalRedirect(@QueryParam("redirectTo") URI redirectTo) { .build(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK"), - }) + @APIResponse(responseCode = "200", description = "OK") @CommonApiResponses @GET @Path("type") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/BackupResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/BackupResource.java index a2344dc8e7..7d0518b68e 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/BackupResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/BackupResource.java @@ -10,60 +10,47 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.backup.BackupDto; import io.stackgres.common.crd.sgbackup.StackGresBackup; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgbackups") @RequestScoped @Authenticated public class BackupResource extends AbstractCustomResourceService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = BackupDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = BackupDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = BackupDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = BackupDto.class))}) @Override public BackupDto create(BackupDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(BackupDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = BackupDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = BackupDto.class))}) @Override public BackupDto update(BackupDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java index 327cc3814f..3a2b03e002 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java @@ -46,15 +46,14 @@ import io.stackgres.common.resource.ResourceFinder; import io.stackgres.common.resource.ResourceWriter; import io.stackgres.operatorframework.resource.ResourceUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jooq.lambda.Seq; import org.jooq.lambda.tuple.Tuple; import org.jooq.lambda.tuple.Tuple2; @@ -103,13 +102,10 @@ public ClusterResource( this.serviceFinder = serviceFinder; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = ClusterDto.class)))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY,implementation = ClusterDto.class))}) @Override public List list() { return Seq.seq(clusterScanner.getResources()) @@ -119,36 +115,27 @@ public List list() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterDto.class))}) @Override public ClusterDto create(ClusterDto resource, @Nullable Boolean dryRun) { createOrUpdateScripts(resource); return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterDto.class))}) @Override public ClusterDto update(ClusterDto resource, @Nullable Boolean dryRun) { createOrUpdateScripts(resource); return super.update(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(ClusterDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); @@ -207,9 +194,9 @@ ClusterDto setConfigMaps(ClusterDto resource) { .flatMap(List::stream)) .flatMap(managedScriptEntry -> Seq.seq( Optional.ofNullable(managedScriptEntry.getScriptSpec()) - .map(ScriptSpec::getScripts) - .stream() - .flatMap(List::stream)) + .map(ScriptSpec::getScripts) + .stream() + .flatMap(List::stream)) .zipWithIndex() .map(Tuple.tuple(managedScriptEntry)::concat)) .filter(t -> t.v2.getScriptFrom() != null @@ -344,9 +331,9 @@ private List getConfigMapsToCreate(ClusterDto resource) { .flatMap(List::stream)) .flatMap(managedScriptEntry -> Seq.seq( Optional.ofNullable(managedScriptEntry.getScriptSpec()) - .map(ScriptSpec::getScripts) - .stream() - .flatMap(List::stream)) + .map(ScriptSpec::getScripts) + .stream() + .flatMap(List::stream)) .zipWithIndex() .map(Tuple.tuple(managedScriptEntry)::concat)) .filter(t -> t.v2.getScriptFrom() != null) @@ -382,9 +369,9 @@ private List getSecretsToCreate(ClusterDto resource) { .flatMap(List::stream)) .flatMap(managedScriptEntry -> Seq.seq( Optional.ofNullable(managedScriptEntry.getScriptSpec()) - .map(ScriptSpec::getScripts) - .stream() - .flatMap(List::stream)) + .map(ScriptSpec::getScripts) + .stream() + .flatMap(List::stream)) .zipWithIndex() .map(Tuple.tuple(managedScriptEntry)::concat)) .filter(t -> t.v2.getScriptFrom() != null) @@ -412,20 +399,21 @@ private List getSecretsToCreate(ClusterDto resource) { .toList(); } - private Tuple2, ConfigMapKeySelector, - Consumer>> extractConfigMapInfo( - ClusterManagedScriptEntry managedScriptEntry, - ScriptEntry scriptEntry, - int index) { - return Tuple., ConfigMapKeySelector, - Consumer>>tuple( - scriptEntryResourceName(managedScriptEntry, index), - Tuple., ConfigMapKeySelector, - Consumer>tuple( - scriptEntry.getScriptFrom().getConfigMapScript(), - scriptEntry.getScriptFrom()::setConfigMapScript, - scriptEntry.getScriptFrom().getConfigMapKeyRef(), - scriptEntry.getScriptFrom()::setConfigMapKeyRef)); + private + Tuple2, ConfigMapKeySelector, Consumer>> + extractConfigMapInfo( + ClusterManagedScriptEntry managedScriptEntry, + ScriptEntry scriptEntry, + int index) { + return Tuple + ., ConfigMapKeySelector, Consumer>>tuple( + scriptEntryResourceName(managedScriptEntry, index), + Tuple + ., ConfigMapKeySelector, Consumer>tuple( + scriptEntry.getScriptFrom().getConfigMapScript(), + scriptEntry.getScriptFrom()::setConfigMapScript, + scriptEntry.getScriptFrom().getConfigMapKeyRef(), + scriptEntry.getScriptFrom()::setConfigMapKeyRef)); } private String scriptResourceName(ClusterDto cluster, diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterRoleResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterRoleResource.java index 29a072e400..3c463da378 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterRoleResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterRoleResource.java @@ -14,16 +14,15 @@ import io.stackgres.apiweb.dto.clusterrole.ClusterRoleDto; import io.stackgres.common.StackGresContext; import io.stackgres.common.resource.ResourceScanner; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("clusterroles") @RequestScoped @@ -38,14 +37,10 @@ public ClusterRoleResource(ResourceScanner clusterRoleScanner) { this.clusterRoleScanner = clusterRoleScanner; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = ClusterRoleDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ClusterRoleDto.class))}) @Override public List list() { return clusterRoleScanner @@ -56,34 +51,25 @@ public List list() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterRoleDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterRoleDto.class))}) @Override public ClusterRoleDto create(@Valid ClusterRoleDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(@Valid ClusterRoleDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterRoleDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterRoleDto.class))}) @Override public ClusterRoleDto update(@Valid ClusterRoleDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConfigResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConfigResource.java index 4e8d7c8371..f0f9a01e09 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConfigResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConfigResource.java @@ -10,64 +10,48 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.config.ConfigDto; import io.stackgres.common.crd.sgconfig.StackGresConfig; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jetbrains.annotations.NotNull; @Path("sgconfigs") @RequestScoped @Authenticated -public class ConfigResource extends AbstractCustomResourceService { +public class ConfigResource extends AbstractCustomResourceService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema( - implementation = ConfigDto.class - )))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ConfigDto.class))}) @Override public @NotNull List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ConfigDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ConfigDto.class))}) @Override public ConfigDto create(@NotNull ConfigDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ConfigDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ConfigDto.class))}) @Override public ConfigDto update(@NotNull ConfigDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(@NotNull ConfigDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConnectionPoolingConfigResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConnectionPoolingConfigResource.java index ceaac65280..098c154b17 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConnectionPoolingConfigResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ConnectionPoolingConfigResource.java @@ -12,14 +12,13 @@ import io.stackgres.apiweb.dto.pooling.PoolingConfigDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgpooling.StackGresPoolingConfig; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgpoolconfigs") @RequestScoped @@ -35,47 +34,34 @@ public boolean belongsToCluster(StackGresPoolingConfig resource, StackGresCluste resource.getMetadata().getName()); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = PoolingConfigDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = PoolingConfigDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = PoolingConfigDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PoolingConfigDto.class))}) @Override public PoolingConfigDto create(PoolingConfigDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(PoolingConfigDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = PoolingConfigDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PoolingConfigDto.class))}) @Override public PoolingConfigDto update(PoolingConfigDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DbOpsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DbOpsResource.java index 56e10d9cbc..25e02024c4 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DbOpsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DbOpsResource.java @@ -10,14 +10,13 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.dbops.DbOpsDto; import io.stackgres.common.crd.sgdbops.StackGresDbOps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgdbops") @RequestScoped @@ -25,47 +24,35 @@ public class DbOpsResource extends AbstractCustomResourceService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = DbOpsDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = DbOpsDto.class))}) + @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = DbOpsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DbOpsDto.class))}) @Override public DbOpsDto create(DbOpsDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(DbOpsDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = DbOpsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DbOpsDto.class))}) @Override public DbOpsDto update(DbOpsDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DistributedLogsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DistributedLogsResource.java index bab8e3a75b..72d206a4ee 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DistributedLogsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/DistributedLogsResource.java @@ -14,14 +14,13 @@ import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgcluster.StackGresClusterDistributedLogs; import io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgdistributedlogs") @RequestScoped @@ -38,47 +37,34 @@ public boolean belongsToCluster(StackGresDistributedLogs resource, StackGresClus Optional.of(resource.getMetadata().getName())); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = DistributedLogsDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = DistributedLogsDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = DistributedLogsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DistributedLogsDto.class))}) @Override public DistributedLogsDto create(DistributedLogsDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(DistributedLogsDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = DistributedLogsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DistributedLogsDto.class))}) @Override public DistributedLogsDto update(DistributedLogsDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ExtensionsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ExtensionsResource.java index 53241865e3..caa10d6974 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ExtensionsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ExtensionsResource.java @@ -13,16 +13,15 @@ import io.stackgres.common.crd.sgcluster.StackGresClusterPostgres; import io.stackgres.common.crd.sgcluster.StackGresClusterSpec; import io.stackgres.common.extension.ExtensionMetadataManager; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.QueryParam; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("extensions") @RequestScoped @@ -43,15 +42,13 @@ public ExtensionsResource( /** * Looks for all extensions that are published in configured repositories with only versions * available for the sgcluster retrieved using the namespace and name provided. + * * @return the extensions */ - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ExtensionsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ExtensionsDto.class))}) @CommonApiResponses @GET @Path("{postgresVersion}") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/KubernetesInfoResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/KubernetesInfoResource.java index 81994a0aa8..fcbb343b6a 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/KubernetesInfoResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/KubernetesInfoResource.java @@ -8,15 +8,15 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.quarkus.security.Authenticated; import io.stackgres.apiweb.rest.utils.CommonApiResponses; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.core.Response; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("kubernetes-cluster-info") @RequestScoped @@ -29,13 +29,10 @@ public class KubernetesInfoResource { /** * Return kubernetes cluster info. */ - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(type = "string"))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.STRING))}) @CommonApiResponses @GET public Response info() { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespaceResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespaceResource.java index d0970ccebd..981eaa42c7 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespaceResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespaceResource.java @@ -13,17 +13,16 @@ import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.ResourceScanner; import io.stackgres.common.resource.ResourceWriter; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces") @RequestScoped @@ -42,13 +41,10 @@ public NamespaceResource( this.namespaceWriter = namespaceWriter; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(type = "string"))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY))}) @CommonApiResponses @GET public List get() { @@ -57,23 +53,20 @@ public List get() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(type = "string"))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.STRING))}) @CommonApiResponses @Path("{name}") @POST public void create(@PathParam("name") String name) { namespaceWriter.create( new NamespaceBuilder() - .withNewMetadata() - .withName(name) - .endMetadata() - .build()); + .withNewMetadata() + .withName(name) + .endMetadata() + .build()); } } diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedBackupResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedBackupResource.java index 555d8ea04d..bebf764845 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedBackupResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedBackupResource.java @@ -8,12 +8,11 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.backup.BackupDto; import io.stackgres.common.crd.sgbackup.StackGresBackup; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgbackups") @RequestScoped @@ -21,13 +20,10 @@ public class NamespacedBackupResource extends AbstractNamespacedRestService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = BackupDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = BackupDto.class))}) @Override public BackupDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterEventsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterEventsResource.java index 554cddb048..087bf7d72d 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterEventsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterEventsResource.java @@ -24,16 +24,15 @@ import io.stackgres.common.resource.CustomResourceScanner; import io.stackgres.common.resource.ResourceScanner; import io.stackgres.operatorframework.resource.ResourceUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jetbrains.annotations.NotNull; import org.jooq.lambda.Seq; @@ -52,13 +51,10 @@ public NamespacedClusterEventsResource(ResourceScanner scanner, this.dbOpsScanner = dbOpsScanner; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = EventDto.class)))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = EventDto.class))}) @CommonApiResponses @GET @Path("{name}/events") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java index d2136de3ec..7fe02c1919 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterLogsResource.java @@ -23,11 +23,6 @@ import io.stackgres.apiweb.dto.cluster.ClusterSpec; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.CustomResourceFinder; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.BadRequestException; @@ -36,6 +31,10 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.QueryParam; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jooq.lambda.tuple.Tuple; import org.jooq.lambda.tuple.Tuple2; @@ -57,14 +56,10 @@ public NamespacedClusterLogsResource(CustomResourceFinder clusterFin /** * Query distributed logs and return a list of {@code ClusterLogEntry}. */ - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = ClusterLogEntryDto.class)))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ClusterLogEntryDto.class))}) @CommonApiResponses @GET @Path("{name}/logs") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterResource.java index c57c8ef7c4..19d8675e75 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterResource.java @@ -9,14 +9,13 @@ import io.stackgres.apiweb.dto.cluster.ClusterDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.resource.CustomResourceFinder; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgclusters") @RequestScoped @@ -35,13 +34,10 @@ public NamespacedClusterResource(CustomResourceFinder clusterFinder, this.clusterFinder = clusterFinder; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterDto.class))}) @Override public ClusterDto get(String namespace, String name) { return clusterFinder.findByNameAndNamespace(name, namespace) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterStatsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterStatsResource.java index c805362a45..bfb44dbfb1 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterStatsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedClusterStatsResource.java @@ -9,16 +9,15 @@ import io.stackgres.apiweb.dto.cluster.ClusterStatsDto; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.CustomResourceFinder; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgclusters") @RequestScoped @@ -36,13 +35,10 @@ public NamespacedClusterStatsResource( /** * Return a {@code ClusterStatus}. */ - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterStatsDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterStatsDto.class))}) @CommonApiResponses @GET @Path("{name}/stats") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigMapResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigMapResource.java index 45c043cdbf..6698506edc 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigMapResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigMapResource.java @@ -11,16 +11,15 @@ import io.stackgres.apiweb.dto.configmap.ConfigMapDto; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.ResourceScanner; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/configmaps") @RequestScoped @@ -34,13 +33,10 @@ public NamespacedConfigMapResource(ResourceScanner scanner) { this.scanner = scanner; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = ConfigMapDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ConfigMapDto.class))}) @CommonApiResponses @GET public List list(@PathParam("namespace") String namespace) { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigResource.java index a6abb47871..5e3b6b7cc1 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConfigResource.java @@ -8,12 +8,11 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.config.ConfigDto; import io.stackgres.common.crd.sgconfig.StackGresConfig; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgconfigs") @RequestScoped @@ -21,13 +20,10 @@ public class NamespacedConfigResource extends AbstractNamespacedRestService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ConfigDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ConfigDto.class))}) @Override public ConfigDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConnectionPoolingConfigResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConnectionPoolingConfigResource.java index 23652f09c3..a012c2ead4 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConnectionPoolingConfigResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedConnectionPoolingConfigResource.java @@ -11,12 +11,11 @@ import io.stackgres.apiweb.dto.pooling.PoolingConfigDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgpooling.StackGresPoolingConfig; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgpoolconfigs") @RequestScoped @@ -32,13 +31,10 @@ public boolean belongsToCluster(StackGresPoolingConfig resource, StackGresCluste resource.getMetadata().getName()); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = PoolingConfigDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PoolingConfigDto.class))}) @Override public PoolingConfigDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsEventsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsEventsResource.java index d7dcc8fa1a..99de7a6dc7 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsEventsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsEventsResource.java @@ -20,16 +20,15 @@ import io.stackgres.apiweb.dto.event.ObjectReference; import io.stackgres.common.crd.sgdbops.StackGresDbOps; import io.stackgres.common.resource.ResourceScanner; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jooq.lambda.Seq; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgdbops") @@ -50,13 +49,10 @@ public NamespacedDbOpsEventsResource(ResourceScanner scanner, this.podScanner = podScanner; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = EventDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = EventDto.class))}) @Path("/{name}/events") @GET public List list(@PathParam("namespace") String namespace, @@ -64,20 +60,20 @@ public List list(@PathParam("namespace") String namespace, Map> relatedResources = new HashMap<>(); relatedResources.put("Job", Seq.seq(jobScanner.findResourcesInNamespace(namespace)) - .filter(job -> job.getMetadata().getOwnerReferences().stream() - .anyMatch(resourceReference -> Objects - .equals(resourceReference.getKind(), StackGresDbOps.KIND) - && Objects.equals(resourceReference.getName(), name))) - .map(Job::getMetadata) - .toList()); + .filter(job -> job.getMetadata().getOwnerReferences().stream() + .anyMatch(resourceReference -> Objects + .equals(resourceReference.getKind(), StackGresDbOps.KIND) + && Objects.equals(resourceReference.getName(), name))) + .map(Job::getMetadata) + .toList()); relatedResources.put("Pod", Seq.seq(podScanner.findResourcesInNamespace(namespace)) - .filter(pod -> pod.getMetadata().getOwnerReferences().stream() - .anyMatch(resourceReference -> Objects.equals(resourceReference.getKind(), "Job") - && relatedResources.get("Job").stream().anyMatch(jobMetadata -> Objects - .equals(jobMetadata.getName(), resourceReference.getName())))) - .map(Pod::getMetadata) - .toList()); + .filter(pod -> pod.getMetadata().getOwnerReferences().stream() + .anyMatch(resourceReference -> Objects.equals(resourceReference.getKind(), "Job") + && relatedResources.get("Job").stream().anyMatch(jobMetadata -> Objects + .equals(jobMetadata.getName(), resourceReference.getName())))) + .map(Pod::getMetadata) + .toList()); return Seq.seq(scanner.findResourcesInNamespace(namespace)) .filter(event -> isDbOpsEvent(event, namespace, name, relatedResources)) .sorted(this::orderByLastTimestamp) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsResource.java index 73f4bb6520..8fa4ac529c 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDbOpsResource.java @@ -8,12 +8,11 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.dbops.DbOpsDto; import io.stackgres.common.crd.sgdbops.StackGresDbOps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgdbops") @RequestScoped @@ -21,13 +20,10 @@ public class NamespacedDbOpsResource extends AbstractNamespacedRestService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = DbOpsDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DbOpsDto.class))}) @Override public DbOpsDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDistributedLogsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDistributedLogsResource.java index 50ad7ace41..7d697b4140 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDistributedLogsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedDistributedLogsResource.java @@ -13,12 +13,11 @@ import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgcluster.StackGresClusterDistributedLogs; import io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgdistributedlogs") @RequestScoped @@ -35,13 +34,10 @@ public boolean belongsToCluster(StackGresDistributedLogs resource, StackGresClus Optional.of(resource.getMetadata().getName())); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = DistributedLogsDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DistributedLogsDto.class))}) @Override public DistributedLogsDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedObjectStorageResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedObjectStorageResource.java index 024b4925c5..d97a34c66d 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedObjectStorageResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedObjectStorageResource.java @@ -17,13 +17,12 @@ import io.stackgres.common.crd.sgcluster.StackGresClusterSpec; import io.stackgres.common.crd.sgobjectstorage.StackGresObjectStorage; import io.stackgres.common.resource.ResourceFinder; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgobjectstorages") @RequestScoped @@ -53,18 +52,14 @@ public boolean belongsToCluster(StackGresObjectStorage resource, StackGresCluste .map(StackGresClusterConfigurations::getBackups) .map(backupConfigurations -> backupConfigurations.stream() .map(StackGresClusterBackupConfiguration::getSgObjectStorage) - .anyMatch(ref -> Objects.equals(ref, objectStorageName)) - ) + .anyMatch(ref -> Objects.equals(ref, objectStorageName))) .orElse(false); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ObjectStorageDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ObjectStorageDto.class))}) @Override public ObjectStorageDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedPostgresConfigResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedPostgresConfigResource.java index 0aa8a9845b..1d58a46c75 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedPostgresConfigResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedPostgresConfigResource.java @@ -11,34 +11,30 @@ import io.stackgres.apiweb.dto.pgconfig.PostgresConfigDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgpgconfigs") @RequestScoped @Authenticated public class NamespacedPostgresConfigResource - extends AbstractNamespacedRestServiceDependency { + extends AbstractNamespacedRestServiceDependency { @Override public boolean belongsToCluster(StackGresPostgresConfig resource, StackGresCluster cluster) { return cluster.getMetadata().getNamespace().equals( resource.getMetadata().getNamespace()) && Objects.equals(cluster.getSpec().getConfigurations().getSgPostgresConfig(), - resource.getMetadata().getName()); + resource.getMetadata().getName()); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = PostgresConfigDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PostgresConfigDto.class))}) @Override public PostgresConfigDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedProfileResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedProfileResource.java index 8fcd4e3579..239c5e489e 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedProfileResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedProfileResource.java @@ -11,12 +11,11 @@ import io.stackgres.apiweb.dto.profile.ProfileDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgprofile.StackGresProfile; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sginstanceprofiles") @RequestScoped @@ -32,13 +31,10 @@ public boolean belongsToCluster(StackGresProfile resource, StackGresCluster clus resource.getMetadata().getName()); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ProfileDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ProfileDto.class))}) @Override public ProfileDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedScriptResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedScriptResource.java index 0f9e67125e..cd2c63bebc 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedScriptResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedScriptResource.java @@ -16,14 +16,13 @@ import io.stackgres.common.crd.sgcluster.StackGresClusterManagedSql; import io.stackgres.common.crd.sgcluster.StackGresClusterSpec; import io.stackgres.common.crd.sgscript.StackGresScript; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgscripts") @RequestScoped @@ -43,21 +42,18 @@ public boolean belongsToCluster(StackGresScript resource, StackGresCluster clust return cluster.getMetadata().getNamespace().equals( resource.getMetadata().getNamespace()) && Optional.of(cluster.getSpec()) - .map(StackGresClusterSpec::getManagedSql) - .map(StackGresClusterManagedSql::getScripts) - .stream() - .flatMap(List::stream) - .map(StackGresClusterManagedScriptEntry::getSgScript) - .anyMatch(sgScript -> Objects.equals(sgScript, resource.getMetadata().getName())); + .map(StackGresClusterSpec::getManagedSql) + .map(StackGresClusterManagedSql::getScripts) + .stream() + .flatMap(List::stream) + .map(StackGresClusterManagedScriptEntry::getSgScript) + .anyMatch(sgScript -> Objects.equals(sgScript, resource.getMetadata().getName())); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ScriptDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ScriptDto.class))}) @Override public ScriptDto get(String namespace, String name) { return Optional.of(super.get(namespace, name)) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedSecretResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedSecretResource.java index a7d8e60b02..50192575d3 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedSecretResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedSecretResource.java @@ -11,16 +11,15 @@ import io.stackgres.apiweb.dto.secret.SecretDto; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.ResourceScanner; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/secrets") @RequestScoped @@ -33,13 +32,10 @@ public NamespacedSecretResource(ResourceScanner scanner) { this.scanner = scanner; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = SecretDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = SecretDto.class))}) @CommonApiResponses @Authenticated @GET diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedBackupResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedBackupResource.java index 2d8a0914c1..6e8a4208ad 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedBackupResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedBackupResource.java @@ -8,12 +8,11 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.shardedbackup.ShardedBackupDto; import io.stackgres.common.crd.sgshardedbackup.StackGresShardedBackup; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgshardedbackups") @RequestScoped @@ -21,13 +20,10 @@ public class NamespacedShardedBackupResource extends AbstractNamespacedRestService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedBackupDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedBackupDto.class))}) @Override public ShardedBackupDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterResource.java index 82712c6724..1e0d21b446 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterResource.java @@ -12,14 +12,13 @@ import io.stackgres.apiweb.dto.shardedcluster.ShardedClusterDto; import io.stackgres.common.CdiUtil; import io.stackgres.common.crd.sgshardedcluster.StackGresShardedCluster; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgshardedclusters") @RequestScoped @@ -40,13 +39,10 @@ public NamespacedShardedClusterResource() { this.shardedClusterResource = null; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ClusterDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ClusterDto.class))}) @Override public ShardedClusterDto get(String namespace, String name) { return Optional.of(super.get(namespace, name)) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterStatsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterStatsResource.java index 2275020e68..c2df4e3ee6 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterStatsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedClusterStatsResource.java @@ -9,16 +9,15 @@ import io.stackgres.apiweb.dto.shardedcluster.ShardedClusterStatsDto; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.CustomResourceFinder; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgshardedclusters") @RequestScoped @@ -36,13 +35,10 @@ public NamespacedShardedClusterStatsResource( /** * Return a {@code ClusterStatus}. */ - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedClusterStatsDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedClusterStatsDto.class))}) @CommonApiResponses @GET @Path("{name}/stats") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedDbOpsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedDbOpsResource.java index 23a37417ed..bc646122f2 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedDbOpsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/NamespacedShardedDbOpsResource.java @@ -8,12 +8,11 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.shardeddbops.ShardedDbOpsDto; import io.stackgres.common.crd.sgshardeddbops.StackGresShardedDbOps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("namespaces/{namespace:[a-z0-9]([-a-z0-9]*[a-z0-9])?}/sgshardeddbops") @RequestScoped @@ -21,13 +20,10 @@ public class NamespacedShardedDbOpsResource extends AbstractNamespacedRestService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedDbOpsDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedDbOpsDto.class))}) @Override public ShardedDbOpsDto get(String namespace, String name) { return super.get(namespace, name); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ObjectStorageResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ObjectStorageResource.java index 7168c774ec..56c53ad16f 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ObjectStorageResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ObjectStorageResource.java @@ -24,22 +24,21 @@ import io.stackgres.common.resource.ResourceFinder; import io.stackgres.common.resource.ResourceWriter; import io.stackgres.operatorframework.resource.ResourceUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; +import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Path; -import org.jetbrains.annotations.NotNull; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgobjectstorages") @RequestScoped @Authenticated -public class ObjectStorageResource extends AbstractCustomResourceServiceDependency { +public class ObjectStorageResource + extends AbstractCustomResourceServiceDependency { @Inject ResourceFinder secretFinder; @@ -47,29 +46,21 @@ public class ObjectStorageResource extends AbstractCustomResourceServiceDependen @Inject ResourceWriter secretWriter; - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema( - implementation = ObjectStorageDto.class - )))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ObjectStorageDto.class))}) @Override - public @NotNull List list() { + public @Nonnull List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ObjectStorageDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ObjectStorageDto.class))}) @Override - public ObjectStorageDto create(@NotNull ObjectStorageDto resource, @Nullable Boolean dryRun) { + public ObjectStorageDto create(@Nonnull ObjectStorageDto resource, @Nullable Boolean dryRun) { setSecretKeySelectors(resource); if (!Optional.ofNullable(dryRun).orElse(false)) { createOrUpdateSecret(resource); @@ -77,15 +68,12 @@ public ObjectStorageDto create(@NotNull ObjectStorageDto resource, @Nullable Boo return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ObjectStorageDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ObjectStorageDto.class))}) @Override - public ObjectStorageDto update(@NotNull ObjectStorageDto resource, @Nullable Boolean dryRun) { + public ObjectStorageDto update(@Nonnull ObjectStorageDto resource, @Nullable Boolean dryRun) { setSecretKeySelectors(resource); if (!Optional.ofNullable(dryRun).orElse(false)) { createOrUpdateSecret(resource); @@ -93,12 +81,9 @@ public ObjectStorageDto update(@NotNull ObjectStorageDto resource, @Nullable Boo return super.update(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override - public void delete(@NotNull ObjectStorageDto resource, @Nullable Boolean dryRun) { + public void delete(@Nonnull ObjectStorageDto resource, @Nullable Boolean dryRun) { setSecretKeySelectors(resource); super.delete(resource, dryRun); } @@ -119,8 +104,7 @@ public boolean belongsToCluster(StackGresObjectStorage resource, StackGresCluste .map(StackGresClusterConfigurations::getBackups) .map(backupConfigurations -> backupConfigurations.stream() .map(StackGresClusterBackupConfiguration::getSgObjectStorage) - .anyMatch(ref -> Objects.equals(ref, storageName)) - ) + .anyMatch(ref -> Objects.equals(ref, storageName))) .orElse(false); } @@ -150,7 +134,7 @@ private void createOrUpdateSecret(ObjectStorageDto resource) { .withNamespace(namespace) .withName(name) .withOwnerReferences(finder.findByNameAndNamespace( - resource.getMetadata().getName(), resource.getMetadata().getNamespace()) + resource.getMetadata().getName(), resource.getMetadata().getNamespace()) .map(ResourceUtil::getOwnerReference) .map(ImmutableList::of) .orElse(ImmutableList.of())) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/PostgresConfigResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/PostgresConfigResource.java index 4eb31baf98..7d64682a4c 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/PostgresConfigResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/PostgresConfigResource.java @@ -12,14 +12,13 @@ import io.stackgres.apiweb.dto.pgconfig.PostgresConfigDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgpgconfigs") @RequestScoped @@ -32,50 +31,37 @@ public boolean belongsToCluster(StackGresPostgresConfig resource, StackGresClust return cluster.getMetadata().getNamespace().equals( resource.getMetadata().getNamespace()) && Objects.equals(cluster.getSpec().getConfigurations().getSgPostgresConfig(), - resource.getMetadata().getName()); + resource.getMetadata().getName()); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = PostgresConfigDto.class)))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = PostgresConfigDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = PostgresConfigDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PostgresConfigDto.class))}) @Override public PostgresConfigDto create(PostgresConfigDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(PostgresConfigDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = PostgresConfigDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PostgresConfigDto.class))}) @Override public PostgresConfigDto update(PostgresConfigDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ProfileResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ProfileResource.java index 60878c4468..57b78742ce 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ProfileResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ProfileResource.java @@ -12,14 +12,13 @@ import io.stackgres.apiweb.dto.profile.ProfileDto; import io.stackgres.common.crd.sgcluster.StackGresCluster; import io.stackgres.common.crd.sgprofile.StackGresProfile; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sginstanceprofiles") @RequestScoped @@ -32,50 +31,37 @@ public boolean belongsToCluster(StackGresProfile resource, StackGresCluster clus return cluster.getMetadata().getNamespace().equals( resource.getMetadata().getNamespace()) && Objects.equals(cluster.getSpec().getSgInstanceProfile(), - resource.getMetadata().getName()); + resource.getMetadata().getName()); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = ProfileDto.class)))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ProfileDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ProfileDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ProfileDto.class))}) @Override public ProfileDto create(ProfileDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(ProfileDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ProfileDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ProfileDto.class))}) @Override public ProfileDto update(ProfileDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java index c9faab4f26..9beb94d087 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java @@ -44,10 +44,6 @@ import io.stackgres.common.crd.sgshardedbackup.StackGresShardedBackup; import io.stackgres.common.crd.sgshardedcluster.StackGresShardedCluster; import io.stackgres.common.crd.sgshardeddbops.StackGresShardedDbOps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; @@ -57,6 +53,9 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; import org.eclipse.microprofile.jwt.Claim; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,13 +79,10 @@ public class RbacResource { @Inject KubernetesClientProvider kubernetesClientProvider; - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = SubjectAccessReviewStatus.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = SubjectAccessReviewStatus.class))}) @CommonApiResponses @GET @Path("can-i/{verb}/{resource}") @@ -123,13 +119,10 @@ public Response verb(@PathParam("verb") String verb, @PathParam("resource") Stri } } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = PermissionsListDto.class))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = PermissionsListDto.class))}) @CommonApiResponses @GET @Path("can-i") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RoleResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RoleResource.java index 27f1ced4d4..b8abf48927 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RoleResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RoleResource.java @@ -12,15 +12,14 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.role.RoleDto; import io.stackgres.common.StackGresContext; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.validation.Valid; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("roles") @RequestScoped @@ -28,14 +27,10 @@ public class RoleResource extends AbstractResourceService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = RoleDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = RoleDto.class))}) @Override public List list() { return scanner @@ -46,34 +41,25 @@ public List list() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = RoleDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = RoleDto.class))}) @Override public RoleDto create(@Valid RoleDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(@Valid RoleDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = RoleDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = RoleDto.class))}) @Override public RoleDto update(@Valid RoleDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ScriptResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ScriptResource.java index ff0975296a..cfd50131a1 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ScriptResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ScriptResource.java @@ -30,15 +30,14 @@ import io.stackgres.common.resource.ResourceFinder; import io.stackgres.common.resource.ResourceWriter; import io.stackgres.operatorframework.resource.ResourceUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jooq.lambda.Seq; import org.jooq.lambda.tuple.Tuple; import org.jooq.lambda.tuple.Tuple2; @@ -71,22 +70,18 @@ public boolean belongsToCluster(StackGresScript resource, StackGresCluster clust return cluster.getMetadata().getNamespace().equals( resource.getMetadata().getNamespace()) && Optional.of(cluster.getSpec()) - .map(StackGresClusterSpec::getManagedSql) - .map(StackGresClusterManagedSql::getScripts) - .stream() - .flatMap(List::stream) - .map(StackGresClusterManagedScriptEntry::getSgScript) - .anyMatch(sgScript -> Objects.equals(sgScript, resource.getMetadata().getName())); + .map(StackGresClusterSpec::getManagedSql) + .map(StackGresClusterManagedSql::getScripts) + .stream() + .flatMap(List::stream) + .map(StackGresClusterManagedScriptEntry::getSgScript) + .anyMatch(sgScript -> Objects.equals(sgScript, resource.getMetadata().getName())); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = ScriptDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ScriptDto.class))}) @Override public List list() { return Seq.seq(super.list()) @@ -94,13 +89,10 @@ public List list() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ScriptDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ScriptDto.class))}) @Override public ScriptDto create(ScriptDto resource, @Nullable Boolean dryRun) { List secretsToCreate = getSecretsToCreate(resource); @@ -111,22 +103,16 @@ public ScriptDto create(ScriptDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(ScriptDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ScriptDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ScriptDto.class))}) @Override public ScriptDto update(ScriptDto resource, @Nullable Boolean dryRun) { List secretsToCreate = getSecretsToCreate(resource); @@ -225,18 +211,19 @@ private List getSecretsToCreate(ScriptDto resource) { .toList(); } - private Tuple2, ConfigMapKeySelector, - Consumer>> extractConfigMapInfo( - ScriptDto resource, ScriptEntry scriptEntry, int index) { - return Tuple., ConfigMapKeySelector, - Consumer>>tuple( - scriptEntryResourceName(resource, index), - Tuple., ConfigMapKeySelector, - Consumer>tuple( - scriptEntry.getScriptFrom().getConfigMapScript(), - scriptEntry.getScriptFrom()::setConfigMapScript, - scriptEntry.getScriptFrom().getConfigMapKeyRef(), - scriptEntry.getScriptFrom()::setConfigMapKeyRef)); + private + Tuple2, ConfigMapKeySelector, Consumer>> + extractConfigMapInfo( + ScriptDto resource, ScriptEntry scriptEntry, int index) { + return Tuple + ., ConfigMapKeySelector, Consumer>>tuple( + scriptEntryResourceName(resource, index), + Tuple + ., ConfigMapKeySelector, Consumer>tuple( + scriptEntry.getScriptFrom().getConfigMapScript(), + scriptEntry.getScriptFrom()::setConfigMapScript, + scriptEntry.getScriptFrom().getConfigMapKeyRef(), + scriptEntry.getScriptFrom()::setConfigMapKeyRef)); } private String scriptEntryResourceName(ScriptDto resource, int index) { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedBackupResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedBackupResource.java index 217295f854..5246792810 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedBackupResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedBackupResource.java @@ -10,14 +10,13 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.shardedbackup.ShardedBackupDto; import io.stackgres.common.crd.sgshardedbackup.StackGresShardedBackup; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgshardedbackups") @RequestScoped @@ -25,47 +24,34 @@ public class ShardedBackupResource extends AbstractCustomResourceService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = ShardedBackupDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ShardedBackupDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedBackupDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedBackupDto.class))}) @Override public ShardedBackupDto create(ShardedBackupDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(ShardedBackupDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedBackupDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedBackupDto.class))}) @Override public ShardedBackupDto update(ShardedBackupDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedClusterResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedClusterResource.java index e5f15e52bb..d481a82f7d 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedClusterResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedClusterResource.java @@ -22,7 +22,6 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.client.KubernetesClientException; import io.quarkus.security.Authenticated; -import io.stackgres.apiweb.dto.cluster.ClusterDto; import io.stackgres.apiweb.dto.cluster.ClusterManagedScriptEntry; import io.stackgres.apiweb.dto.cluster.ClusterManagedSql; import io.stackgres.apiweb.dto.script.ScriptDto; @@ -49,15 +48,14 @@ import io.stackgres.common.resource.ResourceFinder; import io.stackgres.common.resource.ResourceWriter; import io.stackgres.operatorframework.resource.ResourceUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.jooq.lambda.Seq; import org.jooq.lambda.tuple.Tuple; import org.jooq.lambda.tuple.Tuple2; @@ -103,13 +101,10 @@ public ShardedClusterResource( this.serviceFinder = serviceFinder; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = ClusterDto.class)))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ShardedClusterDto.class))}) @Override public List list() { return Seq.seq(super.list()) @@ -119,13 +114,10 @@ public List list() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedClusterDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedClusterDto.class))}) @Override public ShardedClusterDto create(ShardedClusterDto resource, @Nullable Boolean dryRun) { if (!Optional.ofNullable(dryRun).orElse(false)) { @@ -134,13 +126,10 @@ public ShardedClusterDto create(ShardedClusterDto resource, @Nullable Boolean dr return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedClusterDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedClusterDto.class))}) @Override public ShardedClusterDto update(ShardedClusterDto resource, @Nullable Boolean dryRun) { if (!Optional.ofNullable(dryRun).orElse(false)) { @@ -149,10 +138,7 @@ public ShardedClusterDto update(ShardedClusterDto resource, @Nullable Boolean dr return super.update(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(ShardedClusterDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); @@ -210,17 +196,17 @@ ShardedClusterDto setConfigMaps(ShardedClusterDto resource) { .map(ShardedClusterCoordinator::getManagedSql) .map(ClusterManagedSql::getScripts), Optional.ofNullable(resource.getSpec()) - .map(ShardedClusterSpec::getShards) - .map(ShardedClusterShards::getManagedSql) - .map(ClusterManagedSql::getScripts)) + .map(ShardedClusterSpec::getShards) + .map(ShardedClusterShards::getManagedSql) + .map(ClusterManagedSql::getScripts)) .filter(Optional::isPresent) .map(Optional::get) .flatMap(List::stream) .flatMap(managedScriptEntry -> Seq.seq( Optional.ofNullable(managedScriptEntry.getScriptSpec()) - .map(ScriptSpec::getScripts) - .stream() - .flatMap(List::stream)) + .map(ScriptSpec::getScripts) + .stream() + .flatMap(List::stream)) .zipWithIndex() .map(Tuple.tuple(managedScriptEntry)::concat)) .filter(t -> t.v2.getScriptFrom() != null @@ -318,8 +304,7 @@ private void addFieldPrefixOnScriptValidationError(Integer sgScriptIndex, StackG } private List> getScriptsToCreate(ShardedClusterDto resource) { - return - getScriptEntries(resource) + return getScriptEntries(resource) .zipWithIndex() .filter(t -> t.v1.getScriptSpec() != null) .map(t -> { @@ -345,13 +330,12 @@ private List> getScriptsToCreate(ShardedCluster } private List getConfigMapsToCreate(ShardedClusterDto resource) { - return - getScriptEntries(resource) + return getScriptEntries(resource) .flatMap(managedScriptEntry -> Seq.seq( Optional.ofNullable(managedScriptEntry.getScriptSpec()) - .map(ScriptSpec::getScripts) - .stream() - .flatMap(List::stream)) + .map(ScriptSpec::getScripts) + .stream() + .flatMap(List::stream)) .zipWithIndex() .map(Tuple.tuple(managedScriptEntry)::concat)) .filter(t -> t.v2.getScriptFrom() != null) @@ -379,13 +363,12 @@ private List getConfigMapsToCreate(ShardedClusterDto resource) { } private List getSecretsToCreate(ShardedClusterDto resource) { - return - getScriptEntries(resource) + return getScriptEntries(resource) .flatMap(managedScriptEntry -> Seq.seq( Optional.ofNullable(managedScriptEntry.getScriptSpec()) - .map(ScriptSpec::getScripts) - .stream() - .flatMap(List::stream)) + .map(ScriptSpec::getScripts) + .stream() + .flatMap(List::stream)) .zipWithIndex() .map(Tuple.tuple(managedScriptEntry)::concat)) .filter(t -> t.v2.getScriptFrom() != null) @@ -413,20 +396,21 @@ private List getSecretsToCreate(ShardedClusterDto resource) { .toList(); } - private Tuple2, ConfigMapKeySelector, - Consumer>> extractConfigMapInfo( - ClusterManagedScriptEntry managedScriptEntry, - ScriptEntry scriptEntry, - int index) { - return Tuple., ConfigMapKeySelector, - Consumer>>tuple( - scriptEntryResourceName(managedScriptEntry, index), - Tuple., ConfigMapKeySelector, - Consumer>tuple( - scriptEntry.getScriptFrom().getConfigMapScript(), - scriptEntry.getScriptFrom()::setConfigMapScript, - scriptEntry.getScriptFrom().getConfigMapKeyRef(), - scriptEntry.getScriptFrom()::setConfigMapKeyRef)); + private + Tuple2, ConfigMapKeySelector, Consumer>> + extractConfigMapInfo( + ClusterManagedScriptEntry managedScriptEntry, + ScriptEntry scriptEntry, + int index) { + return Tuple + ., ConfigMapKeySelector, Consumer>>tuple( + scriptEntryResourceName(managedScriptEntry, index), + Tuple + ., ConfigMapKeySelector, Consumer>tuple( + scriptEntry.getScriptFrom().getConfigMapScript(), + scriptEntry.getScriptFrom()::setConfigMapScript, + scriptEntry.getScriptFrom().getConfigMapKeyRef(), + scriptEntry.getScriptFrom()::setConfigMapKeyRef)); } private String scriptResourceName(ShardedClusterDto cluster, @@ -444,9 +428,9 @@ private Seq getScriptEntries(ShardedClusterDto resour .map(ShardedClusterCoordinator::getManagedSql) .map(ClusterManagedSql::getScripts), Optional.ofNullable(resource.getSpec()) - .map(ShardedClusterSpec::getShards) - .map(ShardedClusterShards::getManagedSql) - .map(ClusterManagedSql::getScripts)) + .map(ShardedClusterSpec::getShards) + .map(ShardedClusterShards::getManagedSql) + .map(ClusterManagedSql::getScripts)) .append(Optional.ofNullable(resource.getSpec()) .map(ShardedClusterSpec::getShards) .map(ShardedClusterShards::getOverrides) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedDbOpsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedDbOpsResource.java index 2ae7b6e68b..cae2329da6 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedDbOpsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ShardedDbOpsResource.java @@ -10,14 +10,13 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.dto.shardeddbops.ShardedDbOpsDto; import io.stackgres.common.crd.sgshardeddbops.StackGresShardedDbOps; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("sgshardeddbops") @RequestScoped @@ -25,47 +24,34 @@ public class ShardedDbOpsResource extends AbstractCustomResourceService { - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = ShardedDbOpsDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = ShardedDbOpsDto.class))}) @Override public List list() { return super.list(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedDbOpsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedDbOpsDto.class))}) @Override public ShardedDbOpsDto create(ShardedDbOpsDto resource, @Nullable Boolean dryRun) { return super.create(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @Override public void delete(ShardedDbOpsDto resource, @Nullable Boolean dryRun) { super.delete(resource, dryRun); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = ShardedDbOpsDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ShardedDbOpsDto.class))}) @Override public ShardedDbOpsDto update(ShardedDbOpsDto resource, @Nullable Boolean dryRun) { return super.update(resource, dryRun); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/StorageClassResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/StorageClassResource.java index 8d4d1b77f8..5c92845eb5 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/StorageClassResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/StorageClassResource.java @@ -11,15 +11,14 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.resource.ResourceScanner; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("storageclasses") @RequestScoped @@ -33,13 +32,10 @@ public void setStorageClassScanner(ResourceScanner storageClassSca this.storageClassScanner = storageClassScanner; } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(type = "string")))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.STRING))}) @CommonApiResponses @GET public List get() { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/UserResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/UserResource.java index d805b55b1e..1a51b49791 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/UserResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/UserResource.java @@ -29,11 +29,6 @@ import io.stackgres.common.resource.ResourceFinder; import io.stackgres.common.resource.ResourceScanner; import io.stackgres.common.resource.ResourceWriter; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.annotation.Nullable; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.RequestScoped; @@ -45,6 +40,10 @@ import jakarta.ws.rs.POST; import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("users") @RequestScoped @@ -94,14 +93,10 @@ public void init() { this.namespace = WebApiProperty.RESTAPI_NAMESPACE.getString(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = "application/json", - array = @ArraySchema( - schema = @Schema(implementation = UserDto.class))) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(type = SchemaType.ARRAY, implementation = UserDto.class))}) @GET @CommonApiResponses public List list() { @@ -118,13 +113,10 @@ public List list() { .toList(); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = UserDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = UserDto.class))}) @POST @CommonApiResponses public UserDto create(@Valid UserDto resource, @Nullable Boolean dryRun) { @@ -152,10 +144,7 @@ public UserDto create(@Valid UserDto resource, @Nullable Boolean dryRun) { roleBindings, clusterRoleBindings); } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK") - }) + @APIResponse(responseCode = "200", description = "OK") @DELETE @CommonApiResponses public void delete(@Valid UserDto resource, @Nullable Boolean dryRun) { @@ -185,13 +174,10 @@ public void delete(@Valid UserDto resource, @Nullable Boolean dryRun) { } } - @Operation( - responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = { @Content( - mediaType = "application/json", - schema = @Schema(implementation = UserDto.class)) }) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = UserDto.class))}) @PUT @CommonApiResponses public UserDto update(@Valid UserDto resource, @Nullable Boolean dryRun) { @@ -314,8 +300,8 @@ private void unsetRoleBinding( } else { roleBinding.setSubjects(new ArrayList<>( roleBinding.getSubjects().stream() - .filter(userSubject::equals) - .toList())); + .filter(userSubject::equals) + .toList())); roleBindingWriter.update(roleBinding); } }); @@ -331,8 +317,8 @@ private boolean roleMatchUserRoleRef( && roleBinding.getRoleRef().getApiGroup().equals("rbac.authorization.k8s.io") && roleBinding.getRoleRef().getName().equals(userRoleRef.getName()) && Optional.ofNullable(roleBinding.getSubjects()).stream() - .flatMap(List::stream) - .anyMatch(userSubject::equals); + .flatMap(List::stream) + .anyMatch(userSubject::equals); } private RoleRef getRoleRef(UserRoleRef userRoleRef) { @@ -398,8 +384,8 @@ private void unsetClusterRoleBinding( } else { clusterRoleBinding.setSubjects(new ArrayList<>( clusterRoleBinding.getSubjects().stream() - .filter(userSubject::equals) - .toList())); + .filter(userSubject::equals) + .toList())); clusterRoleBindingWriter.update(clusterRoleBinding); } }); @@ -413,8 +399,8 @@ private boolean clusterRoleMatchUserRoleRef( && clusterRoleBinding.getRoleRef().getApiGroup().equals("rbac.authorization.k8s.io") && clusterRoleBinding.getRoleRef().getName().equals(userRoleRef.getName()) && Optional.ofNullable(clusterRoleBinding.getSubjects()).stream() - .flatMap(List::stream) - .anyMatch(userSubject::equals); + .flatMap(List::stream) + .anyMatch(userSubject::equals); } private RoleRef getClusterRoleRef(UserRoleRef userRoleRef) { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/VersionsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/VersionsResource.java index 161d857f1b..9a295fe150 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/VersionsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/VersionsResource.java @@ -12,27 +12,25 @@ import io.quarkus.security.Authenticated; import io.stackgres.apiweb.rest.utils.CommonApiResponses; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.enterprise.context.RequestScoped; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.MediaType; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; @Path("version") @RequestScoped @Authenticated public class VersionsResource { - @Operation(responses = { - @ApiResponse(responseCode = "200", description = "OK", - content = {@Content( - mediaType = MediaType.APPLICATION_JSON, - schema = @Schema(type = "object"))}) - }) + @APIResponse(responseCode = "200", description = "OK", + content = {@Content( + mediaType = MediaType.APPLICATION_JSON, + schema = @Schema(type = SchemaType.OBJECT))}) @CommonApiResponses @GET @Path("postgresql") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/AuthenticatedSecurityScheme.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/AuthenticatedSecurityScheme.java index 76de716f2e..b17995e231 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/AuthenticatedSecurityScheme.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/AuthenticatedSecurityScheme.java @@ -10,16 +10,15 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; -import io.swagger.v3.oas.annotations.security.SecurityScheme; +import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType; +import org.eclipse.microprofile.openapi.annotations.security.SecurityScheme; @SecurityScheme( - name = "JWT", + securitySchemeName = "JWT", description = "JWT authentication with bearer token", type = SecuritySchemeType.HTTP, scheme = "bearer", - bearerFormat = "Bearer [token]" -) + bearerFormat = "Bearer [token]") @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface AuthenticatedSecurityScheme { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/CommonApiResponses.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/CommonApiResponses.java index b2f2e449b1..143309fa9b 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/CommonApiResponses.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/utils/CommonApiResponses.java @@ -12,23 +12,23 @@ import java.lang.annotation.Target; import io.stackgres.apiweb.exception.ErrorResponse; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -@ApiResponse(responseCode = "400", description = "Bad Request", +@APIResponse(responseCode = "400", description = "Bad Request", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}) -@ApiResponse(responseCode = "401", description = "Unauthorized", +@APIResponse(responseCode = "401", description = "Unauthorized", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}) -@ApiResponse(responseCode = "403", description = "Forbidden", +@APIResponse(responseCode = "403", description = "Forbidden", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}) -@ApiResponse(responseCode = "500", description = "Internal Server Error", +@APIResponse(responseCode = "500", description = "Internal Server Error", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}) diff --git a/stackgres-k8s/src/api-web/src/main/resources/application.properties b/stackgres-k8s/src/api-web/src/main/resources/application.properties index 73b866a15c..e4fb5addcb 100644 --- a/stackgres-k8s/src/api-web/src/main/resources/application.properties +++ b/stackgres-k8s/src/api-web/src/main/resources/application.properties @@ -8,12 +8,17 @@ quarkus.default-locale=en-US # Quarkus Native Image quarkus.native.additional-build-args=\ + -march=compatibility,\ + -H:+UnlockExperimentalVMOptions,\ -H:IncludeResources=.*/*.yaml,\ -H:IncludeResources=.*/*.sh,\ -H:IncludeResources=.*/*.sql,\ -H:IncludeResources=.*/*.properties,\ -H:IncludeResources=.*/banner.txt,\ - -Dorg.jooq.no-logo=true + -H:-UnlockExperimentalVMOptions +# --report-unsupported-elements-at-runtime + +quarkus.smallrye-openapi.store-schema-directory=target/ # Logger Production quarkus.log.level=INFO From 35f11dea2113bfbed2b66997f305e3bdfbb9c8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Mon, 4 Dec 2023 17:06:52 +0100 Subject: [PATCH 17/27] chore: add -march=compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../apiweb/rest/ClusterResource.java | 2 +- .../src/main/resources/application.properties | 5 +++- stackgres-k8s/src/common/pom.xml | 4 ++-- .../src/main/resources/application.properties | 5 +++- .../src/main/resources/application.properties | 5 +++- stackgres-k8s/src/operator-framework/pom.xml | 2 +- stackgres-k8s/src/operator/pom.xml | 5 ++++ .../src/main/resources/application.properties | 3 +++ stackgres-k8s/src/pom.xml | 8 ++++++- .../testutil/KubernetesServerSupplier.java | 24 +++++++++++++++---- 10 files changed, 50 insertions(+), 13 deletions(-) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java index 3a2b03e002..74ce0ed190 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java @@ -105,7 +105,7 @@ public ClusterResource( @APIResponse(responseCode = "200", description = "OK", content = {@Content( mediaType = "application/json", - schema = @Schema(type = SchemaType.ARRAY,implementation = ClusterDto.class))}) + schema = @Schema(type = SchemaType.ARRAY, implementation = ClusterDto.class))}) @Override public List list() { return Seq.seq(clusterScanner.getResources()) diff --git a/stackgres-k8s/src/cluster-controller/src/main/resources/application.properties b/stackgres-k8s/src/cluster-controller/src/main/resources/application.properties index 8d2652f7f3..dd673ff171 100644 --- a/stackgres-k8s/src/cluster-controller/src/main/resources/application.properties +++ b/stackgres-k8s/src/cluster-controller/src/main/resources/application.properties @@ -8,11 +8,14 @@ quarkus.default-locale=en-US # Quarkus Native Image quarkus.native.additional-build-args=\ + -march=compatibility,\ + -H:+UnlockExperimentalVMOptions,\ -H:IncludeResources=.*/*.yaml,\ -H:IncludeResources=.*/*.sh,\ -H:IncludeResources=.*/*.sql,\ -H:IncludeResources=.*/*.properties,\ - -H:IncludeResources=templates/.* + -H:IncludeResources=templates/.*,\ + -H:-UnlockExperimentalVMOptions # Logger Production quarkus.log.level=INFO diff --git a/stackgres-k8s/src/common/pom.xml b/stackgres-k8s/src/common/pom.xml index cece53a31c..75b3635f49 100644 --- a/stackgres-k8s/src/common/pom.xml +++ b/stackgres-k8s/src/common/pom.xml @@ -34,7 +34,7 @@ io.sundr builder-annotations - compile + provided @@ -102,7 +102,7 @@ org.codehaus.mojo templating-maven-plugin - 1.0.0 + 3.0.0 diff --git a/stackgres-k8s/src/distributedlogs-controller/src/main/resources/application.properties b/stackgres-k8s/src/distributedlogs-controller/src/main/resources/application.properties index 30910ab705..29d3e40b05 100644 --- a/stackgres-k8s/src/distributedlogs-controller/src/main/resources/application.properties +++ b/stackgres-k8s/src/distributedlogs-controller/src/main/resources/application.properties @@ -8,11 +8,14 @@ quarkus.default-locale=en-US # Quarkus Native Image quarkus.native.additional-build-args=\ + -march=compatibility,\ + -H:+UnlockExperimentalVMOptions,\ -H:IncludeResources=.*/*.yaml,\ -H:IncludeResources=.*/*.sh,\ -H:IncludeResources=.*/*.sql,\ -H:IncludeResources=.*/*.properties,\ - -H:IncludeResources=templates/.* + -H:IncludeResources=templates/.*,\ + -H:-UnlockExperimentalVMOptions # Logger Production quarkus.log.level=INFO diff --git a/stackgres-k8s/src/jobs/src/main/resources/application.properties b/stackgres-k8s/src/jobs/src/main/resources/application.properties index fc16e4833e..cc8426c1cd 100644 --- a/stackgres-k8s/src/jobs/src/main/resources/application.properties +++ b/stackgres-k8s/src/jobs/src/main/resources/application.properties @@ -8,7 +8,10 @@ quarkus.default-locale=en-US # Quarkus Native Image quarkus.native.additional-build-args=\ - -H:IncludeResources=.*/*.properties + -march=compatibility,\ + -H:+UnlockExperimentalVMOptions,\ + -H:IncludeResources=.*/*.properties,\ + -H:-UnlockExperimentalVMOptions # Logger Production quarkus.log.level=INFO diff --git a/stackgres-k8s/src/operator-framework/pom.xml b/stackgres-k8s/src/operator-framework/pom.xml index 7da4b9a005..c0acf6cb49 100644 --- a/stackgres-k8s/src/operator-framework/pom.xml +++ b/stackgres-k8s/src/operator-framework/pom.xml @@ -33,7 +33,7 @@ io.sundr builder-annotations - compile + provided diff --git a/stackgres-k8s/src/operator/pom.xml b/stackgres-k8s/src/operator/pom.xml index bab8093060..a95ab03658 100644 --- a/stackgres-k8s/src/operator/pom.xml +++ b/stackgres-k8s/src/operator/pom.xml @@ -59,6 +59,11 @@ org.bouncycastle bcpkix-jdk15on + + io.sundr + builder-annotations + provided + io.stackgres diff --git a/stackgres-k8s/src/operator/src/main/resources/application.properties b/stackgres-k8s/src/operator/src/main/resources/application.properties index acafd9abef..3a9c0637bb 100644 --- a/stackgres-k8s/src/operator/src/main/resources/application.properties +++ b/stackgres-k8s/src/operator/src/main/resources/application.properties @@ -8,6 +8,8 @@ quarkus.default-locale=en-US # Quarkus Native Image quarkus.native.additional-build-args=\ + -march=compatibility,\ + -H:+UnlockExperimentalVMOptions,\ -H:IncludeResources=.*/index.txt,\ -H:IncludeResources=.*/*.yaml,\ -H:IncludeResources=.*/*.sh,\ @@ -18,6 +20,7 @@ quarkus.native.additional-build-args=\ -H:IncludeResources=prometheus-postgres-exporter/.*,\ -H:IncludeResources=babelfish/.*,\ -H:IncludeResources=webconsole/.*,\ + -H:-UnlockExperimentalVMOptions,\ --initialize-at-run-time=io.stackgres.common.ResolvConfResolverConfig,\ --initialize-at-run-time=org.bouncycastle.jcajce.provider.drbg.DRBG\\$NonceAndIV\\,org.bouncycastle.jcajce.provider.drbg.DRBG\\$Default diff --git a/stackgres-k8s/src/pom.xml b/stackgres-k8s/src/pom.xml index d90b7a896a..00b73d56ef 100644 --- a/stackgres-k8s/src/pom.xml +++ b/stackgres-k8s/src/pom.xml @@ -157,7 +157,7 @@ io.sundr builder-annotations ${sundrio.version} - compile + provided org.ow2.asm @@ -239,6 +239,12 @@ com.google.guava guava + + + com.google.j2objc + j2objc-annotations + + org.jooq diff --git a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/KubernetesServerSupplier.java b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/KubernetesServerSupplier.java index c019ca34ac..abaf718bb0 100644 --- a/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/KubernetesServerSupplier.java +++ b/stackgres-k8s/src/test-util/src/main/java/io/stackgres/testutil/KubernetesServerSupplier.java @@ -28,10 +28,10 @@ public synchronized boolean wasRetrieved() { @Override public synchronized KubernetesServer get() { if (server == null) { - KubernetesServer server = new KubernetesServer(true, true); - server.before(); - server = new WrappedKubernetesServer(server); - this.server = server; + KubernetesServer k8sServer = new KubernetesServer(true, true); + k8sServer.before(); + k8sServer = new WrappedKubernetesServer(k8sServer); + this.server = k8sServer; } return server; } @@ -45,62 +45,76 @@ static class WrappedKubernetesServer extends KubernetesServer { this.server = server; this.client = (NamespacedKubernetesClient) Proxy .newProxyInstance(NamespacedKubernetesClient.class.getClassLoader(), - new Class[] { NamespacedKubernetesClient.class }, + new Class[] { NamespacedKubernetesClient.class }, new KubernetesClientInvocationHandler(server.getClient())); } + @Override public Statement apply(Statement base, Description description) { return server.apply(base, description); } + @Override public int hashCode() { return server.hashCode(); } + @Override public void before() { server.before(); } + @Override public void after() { server.after(); } + @Override public NamespacedKubernetesClient getClient() { return client; } + @Override public MockServerExpectation expect() { return server.expect(); } + @Override public void expectAndReturnAsJson(String path, int code, T body) { server.expectAndReturnAsJson(path, code, body); } + @Override public void expectAndReturnAsJson(String method, String path, int code, T body) { server.expectAndReturnAsJson(method, path, code, body); } + @Override public void expectAndReturnAsString(String path, int code, String body) { server.expectAndReturnAsString(path, code, body); } + @Override public void expectAndReturnAsString(String method, String path, int code, String body) { server.expectAndReturnAsString(method, path, code, body); } + @Override public KubernetesMockServer getKubernetesMockServer() { return server.getKubernetesMockServer(); } + @Override public RecordedRequest getLastRequest() throws InterruptedException { return server.getLastRequest(); } + @Override public boolean equals(Object obj) { return server.equals(obj); } + @Override public String toString() { return server.toString(); } From d671da0a9b9a66b25bf427e948993575e84b821a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Mon, 4 Dec 2023 21:38:04 +0100 Subject: [PATCH 18/27] feat: Add openapi metadata directly on code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- stackgres-k8s/src/api-web/pom.xml | 2 ++ .../apiweb/rest/ApplicationsResource.java | 33 +++++++++++++++++-- .../stackgres/apiweb/rest/AuthResource.java | 26 +++++++++++++++ .../stackgres/apiweb/rest/RbacResource.java | 18 ++++++++++ .../src/main/resources/application.properties | 10 +++++- .../src/api-web/src/main/swagger/build.sh | 4 +-- stackgres-k8s/src/cluster-controller/pom.xml | 2 ++ .../src/distributedlogs-controller/pom.xml | 2 ++ stackgres-k8s/src/jobs/pom.xml | 2 ++ stackgres-k8s/src/operator/pom.xml | 2 ++ 10 files changed, 96 insertions(+), 5 deletions(-) diff --git a/stackgres-k8s/src/api-web/pom.xml b/stackgres-k8s/src/api-web/pom.xml index 264e2f21d0..fa10593559 100644 --- a/stackgres-k8s/src/api-web/pom.xml +++ b/stackgres-k8s/src/api-web/pom.xml @@ -189,6 +189,8 @@ build + generate-code + generate-code-tests diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java index 1ba3e2785e..14409838cd 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java @@ -31,11 +31,13 @@ import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.media.Content; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.jboss.resteasy.annotations.jaxrs.PathParam; import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; import org.jboss.resteasy.plugins.providers.multipart.InputPart; @@ -54,6 +56,14 @@ public class ApplicationsResource { content = {@Content( mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.OBJECT))}) + @Tag(name = "applications") + @Operation(summary = "List StackGres applications", description = """ + List of the available StackGres applications. + + ### RBAC permissions required + + None + """) @CommonApiResponses @GET public Map> getAllApplications() { @@ -73,6 +83,14 @@ public Map> getAllApplications() { content = {@Content( mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.OBJECT))}) + @Tag(name = "applications") + @Operation(summary = "Get StackGres application", description = """ + Get a StackGres application info. + + ### RBAC permissions required + + None + """) @CommonApiResponses @GET @Path("{publisher}/{name}") @@ -93,6 +111,19 @@ public ApplicationDto getApplication(@PathParam String publisher, @PathParam Str mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.OBJECT))}) @RequestBody(content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA)) + @Tag(name = "applications") + @Operation(summary = "Run Babelfish Compass application", description = """ + Run Babelfish Compass application. + + The payload must be a valid MS SQL Server script that will be checked by \ + [Babelfish Compass](https://github.com/babelfish-for-postgresql/babelfish_compass). + + ### RBAC permissions required + + * jobs create, delete + * pods list, get + * pods/exec create + """) @CommonApiResponses @POST @Path("com.ongres/babelfish-compass") @@ -130,8 +161,6 @@ public Map getApplication(@MultipartForm MultipartFormDataInput return bbfCompass.run(reportName, List.copyOf(cmFiles)); } - @SuppressFBWarnings(value = "SA_LOCAL_SELF_COMPARISON", - justification = "False positive") private BabelfishCompass getBabelfishCompassApp() { BabelfishCompass bbfCompass = null; for (SgApplication app : applications) { diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java index d7c8db4a2d..e7fd0c583b 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java @@ -27,9 +27,11 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.media.Content; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,6 +54,14 @@ public class AuthResource { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = TokenResponse.class))}) + @Tag(name = "auth") + @Operation(summary = "Login", description = """ + Log in a user and returns a JWT token. + + ### RBAC permissions required + + None + """) @CommonApiResponses @POST @Path("login") @@ -79,6 +89,14 @@ public Response login(@Valid UserPassword credentials) { @APIResponse(responseCode = "200", description = "OK") @APIResponse(responseCode = "307", description = "Redirect") + @Tag(name = "auth") + @Operation(summary = "External authentication URL", description = """ + Return the URL for external authentication. + + ### RBAC permissions required + + None + """) @CommonApiResponses @GET @Path("external") @@ -90,6 +108,14 @@ public Response externalRedirect(@QueryParam("redirectTo") URI redirectTo) { } @APIResponse(responseCode = "200", description = "OK") + @Tag(name = "auth") + @Operation(summary = "Type of authentication", description = """ + Return the configured auth mechanism type. + + ### RBAC permissions required + + None + """) @CommonApiResponses @GET @Path("type") diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java index 9beb94d087..4aba75de86 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java @@ -53,9 +53,11 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; import org.eclipse.microprofile.jwt.Claim; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.media.Content; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,6 +85,14 @@ public class RbacResource { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = SubjectAccessReviewStatus.class))}) + @Tag(name = "auth") + @Operation(summary = "Can-i over ", description = """ + Check if an user can do specified `` on specified ``. + + ### RBAC permissions required + + None + """) @CommonApiResponses @GET @Path("can-i/{verb}/{resource}") @@ -123,6 +133,14 @@ public Response verb(@PathParam("verb") String verb, @PathParam("resource") Stri content = {@Content( mediaType = "application/json", schema = @Schema(implementation = PermissionsListDto.class))}) + @Tag(name = "auth") + @Operation(summary = "Can-i list", description = """ + Return a list of namespaced and unnamespaced permissions a user has granted. + + ### RBAC permissions required + + None + """) @CommonApiResponses @GET @Path("can-i") diff --git a/stackgres-k8s/src/api-web/src/main/resources/application.properties b/stackgres-k8s/src/api-web/src/main/resources/application.properties index e4fb5addcb..2112d5f9d1 100644 --- a/stackgres-k8s/src/api-web/src/main/resources/application.properties +++ b/stackgres-k8s/src/api-web/src/main/resources/application.properties @@ -16,9 +16,17 @@ quarkus.native.additional-build-args=\ -H:IncludeResources=.*/*.properties,\ -H:IncludeResources=.*/banner.txt,\ -H:-UnlockExperimentalVMOptions -# --report-unsupported-elements-at-runtime quarkus.smallrye-openapi.store-schema-directory=target/ +quarkus.smallrye-openapi.info-title=StackGres REST API +quarkus.smallrye-openapi.info-version=1 +quarkus.smallrye-openapi.info-license-name=AGPL 3.0 +quarkus.smallrye-openapi.info-license-url=https://www.gnu.org/licenses/agpl-3.0.en.html +quarkus.smallrye-openapi.security-scheme=jwt +quarkus.smallrye-openapi.security-scheme-name=JWT +quarkus.smallrye-openapi.auto-add-tags=false +quarkus.smallrye-openapi.auto-add-server=false +quarkus.smallrye-openapi.auto-add-security=false # Logger Production quarkus.log.level=INFO diff --git a/stackgres-k8s/src/api-web/src/main/swagger/build.sh b/stackgres-k8s/src/api-web/src/main/swagger/build.sh index c5f9499dfa..ed897200f0 100644 --- a/stackgres-k8s/src/api-web/src/main/swagger/build.sh +++ b/stackgres-k8s/src/api-web/src/main/swagger/build.sh @@ -7,8 +7,8 @@ INFO_PATH="$BASE_PATH/Info.yaml" SCHEMAS_PATH="$BASE_PATH/schemas" PATHS_PATH="$BASE_PATH/paths" APIWEB_PATH="$BASE_PATH/../../.." -SWAGGER_YAML_FILE="$APIWEB_PATH/target/swagger.yaml" -SWAGGER_JSON_FILE="$APIWEB_PATH/target/swagger.json" +SWAGGER_YAML_FILE="$APIWEB_PATH/target/openapi.yaml" +SWAGGER_JSON_FILE="$APIWEB_PATH/target/openapi.json" MERGED_SWAGGER_YAML_FILE="$APIWEB_PATH/target/swagger-merged.yaml" MERGED_SWAGGER_JSON_FILE="$APIWEB_PATH/target/swagger-merged.json" STACKGRES_K8S_PATH="$APIWEB_PATH/../.." diff --git a/stackgres-k8s/src/cluster-controller/pom.xml b/stackgres-k8s/src/cluster-controller/pom.xml index faf2ee07d2..938110f045 100644 --- a/stackgres-k8s/src/cluster-controller/pom.xml +++ b/stackgres-k8s/src/cluster-controller/pom.xml @@ -118,6 +118,8 @@ build + generate-code + generate-code-tests diff --git a/stackgres-k8s/src/distributedlogs-controller/pom.xml b/stackgres-k8s/src/distributedlogs-controller/pom.xml index ed12818365..1527c03633 100644 --- a/stackgres-k8s/src/distributedlogs-controller/pom.xml +++ b/stackgres-k8s/src/distributedlogs-controller/pom.xml @@ -114,6 +114,8 @@ build + generate-code + generate-code-tests diff --git a/stackgres-k8s/src/jobs/pom.xml b/stackgres-k8s/src/jobs/pom.xml index e9b32a6dcb..2f9e243689 100644 --- a/stackgres-k8s/src/jobs/pom.xml +++ b/stackgres-k8s/src/jobs/pom.xml @@ -101,6 +101,8 @@ build + generate-code + generate-code-tests diff --git a/stackgres-k8s/src/operator/pom.xml b/stackgres-k8s/src/operator/pom.xml index a95ab03658..ee226066f4 100644 --- a/stackgres-k8s/src/operator/pom.xml +++ b/stackgres-k8s/src/operator/pom.xml @@ -145,6 +145,8 @@ build + generate-code + generate-code-tests From 24ddee832173943e6b54ca09485c0a9012d1475a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Tue, 5 Dec 2023 23:59:51 +0100 Subject: [PATCH 19/27] refactor: Add openapi annotations and move REST classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- .../rest/AbstractCustomResourceService.java | 4 +- ...stractCustomResourceServiceDependency.java | 10 ++-- .../apiweb/rest/AbstractResourceService.java | 8 +-- .../ApplicationsResource.java | 2 +- .../apiweb/rest/{ => auth}/AuthResource.java | 2 +- .../apiweb/rest/{ => auth}/RbacResource.java | 7 ++- .../rest/{ => cluster}/ClusterResource.java | 49 ++++++++++++++- .../NamespacedClusterEventsResource.java | 13 +++- .../NamespacedClusterLogsResource.java | 13 +++- .../NamespacedClusterResource.java | 17 +++++- .../NamespacedClusterStatsResource.java | 16 ++++- .../ClusterRoleResource.java | 37 +++++++++++- .../rest/{ => misc}/ExtensionsResource.java | 12 +++- .../{ => misc}/KubernetesInfoResource.java | 15 ++++- .../rest/{ => misc}/NamespaceResource.java | 20 ++++++- .../NamespacedConfigMapResource.java | 12 +++- .../{ => misc}/NamespacedSecretResource.java | 12 +++- .../rest/{ => misc}/StorageClassResource.java | 12 +++- .../rest/{ => misc}/VersionsResource.java | 14 ++++- .../apiweb/rest/{ => role}/RoleResource.java | 37 +++++++++++- .../rest/{ => sgbackup}/BackupResource.java | 37 +++++++++++- .../NamespacedBackupResource.java | 13 +++- .../rest/{ => sgconfig}/ConfigResource.java | 37 +++++++++++- .../NamespacedConfigResource.java | 13 +++- .../rest/{ => sgdbops}/DbOpsResource.java | 36 ++++++++++- .../NamespacedDbOpsEventsResource.java | 12 +++- .../NamespacedDbOpsResource.java | 13 +++- .../DistributedLogsResource.java | 37 +++++++++++- .../NamespacedDistributedLogsResource.java | 13 +++- .../NamespacedProfileResource.java | 13 +++- .../ProfileResource.java | 37 +++++++++++- .../NamespacedObjectStorageResource.java | 18 +++++- .../ObjectStorageResource.java | 55 ++++++++++++++++- .../NamespacedPostgresConfigResource.java | 13 +++- .../PostgresConfigResource.java | 37 +++++++++++- .../ConnectionPoolingConfigResource.java | 37 +++++++++++- ...spacedConnectionPoolingConfigResource.java | 13 +++- .../NamespacedScriptResource.java | 13 +++- .../rest/{ => sgscripts}/ScriptResource.java | 43 +++++++++++++- .../NamespacedShardedBackupResource.java | 13 +++- .../ShardedBackupResource.java | 37 +++++++++++- .../NamespacedShardedClusterResource.java | 15 ++++- ...NamespacedShardedClusterStatsResource.java | 14 ++++- .../ShardedClusterResource.java | 44 +++++++++++++- .../NamespacedShardedDbOpsResource.java | 13 +++- .../ShardedDbOpsResource.java | 37 +++++++++++- .../apiweb/rest/{ => user}/UserResource.java | 59 ++++++++++++++++++- .../src/api-web/src/main/swagger/build.sh | 28 ++++----- .../apiweb/rest/BackupResourceTest.java | 2 + .../rest/ClusterResourceMockedTest.java | 4 ++ .../apiweb/rest/DbOpsResourceTest.java | 2 + .../rest/DistributedLogsResourceTest.java | 2 + .../apiweb/rest/ExtensionsResourceTest.java | 1 + .../apiweb/rest/NamespaceResourceTest.java | 1 + .../rest/PgbouncerConfigResourceTest.java | 2 + .../rest/PostgresConfigResourceTest.java | 2 + .../apiweb/rest/ProfileResourceTest.java | 2 + .../apiweb/rest/RbacResourceTest.java | 2 + .../rest/ShardedBackupResourceTest.java | 2 + .../ShardedClusterResourceMockedTest.java | 3 + .../apiweb/rest/ShardedDbOpsResourceTest.java | 2 + .../apiweb/rest/StorageClassResourceTest.java | 1 + .../rest/StorageObjectResourceTest.java | 3 + 63 files changed, 1017 insertions(+), 76 deletions(-) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => applications}/ApplicationsResource.java (99%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => auth}/AuthResource.java (99%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => auth}/RbacResource.java (98%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => cluster}/ClusterResource.java (92%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => cluster}/NamespacedClusterEventsResource.java (90%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => cluster}/NamespacedClusterLogsResource.java (94%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => cluster}/NamespacedClusterResource.java (75%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => cluster}/NamespacedClusterStatsResource.java (78%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => clusterrole}/ClusterRoleResource.java (74%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/ExtensionsResource.java (87%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/KubernetesInfoResource.java (70%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/NamespaceResource.java (80%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/NamespacedConfigMapResource.java (81%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/NamespacedSecretResource.java (81%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/StorageClassResource.java (80%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => misc}/VersionsResource.java (74%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => role}/RoleResource.java (72%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgbackup}/BackupResource.java (68%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgbackup}/NamespacedBackupResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgconfig}/ConfigResource.java (67%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgconfig}/NamespacedConfigResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgdbops}/DbOpsResource.java (68%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgdbops}/NamespacedDbOpsEventsResource.java (91%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgdbops}/NamespacedDbOpsResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgdistributedlogs}/DistributedLogsResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgdistributedlogs}/NamespacedDistributedLogsResource.java (79%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sginstanceprofile}/NamespacedProfileResource.java (76%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sginstanceprofile}/ProfileResource.java (69%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgobjectstorage}/NamespacedObjectStorageResource.java (79%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgobjectstorage}/ObjectStorageResource.java (75%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgpgconfig}/NamespacedPostgresConfigResource.java (78%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgpgconfig}/PostgresConfigResource.java (72%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgpoolconfig}/ConnectionPoolingConfigResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgpoolconfig}/NamespacedConnectionPoolingConfigResource.java (77%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgscripts}/NamespacedScriptResource.java (84%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgscripts}/ScriptResource.java (89%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardedbackup}/NamespacedShardedBackupResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardedbackup}/ShardedBackupResource.java (67%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardedcluster}/NamespacedShardedClusterResource.java (79%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardedcluster}/NamespacedShardedClusterStatsResource.java (79%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardedcluster}/ShardedClusterResource.java (93%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardeddbops}/NamespacedShardedDbOpsResource.java (71%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => sgshardeddbops}/ShardedDbOpsResource.java (67%) rename stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/{ => user}/UserResource.java (91%) diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceService.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceService.java index 32d88b2595..49ae905c42 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceService.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceService.java @@ -36,13 +36,13 @@ public abstract class AbstractCustomResourceService CustomResourceScanner scanner; @Inject - CustomResourceFinder finder; + public CustomResourceFinder finder; @Inject CustomResourceScheduler scheduler; @Inject - ResourceTransformer transformer; + public ResourceTransformer transformer; /** * Looks for all resources of type {@code } that are installed in the kubernetes cluster. diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceServiceDependency.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceServiceDependency.java index 214728c8db..c5032d2ddb 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceServiceDependency.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractCustomResourceServiceDependency.java @@ -36,19 +36,19 @@ public abstract class AbstractCustomResourceServiceDependency implements ResourceRestService { @Inject - CustomResourceScanner scanner; + protected CustomResourceScanner scanner; @Inject - CustomResourceFinder finder; + protected CustomResourceFinder finder; @Inject - CustomResourceScheduler scheduler; + protected CustomResourceScheduler scheduler; @Inject - CustomResourceScanner clusterScanner; + protected CustomResourceScanner clusterScanner; @Inject - DependencyResourceTransformer transformer; + protected DependencyResourceTransformer transformer; public abstract boolean belongsToCluster(R resource, StackGresCluster cluster); diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractResourceService.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractResourceService.java index 418fe1f5c5..d787061535 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractResourceService.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AbstractResourceService.java @@ -34,16 +34,16 @@ public abstract class AbstractResourceService implements ValidatedResourceRestService { @Inject - ResourceScanner scanner; + protected ResourceScanner scanner; @Inject - ResourceFinder finder; + protected ResourceFinder finder; @Inject - ResourceWriter writer; + protected ResourceWriter writer; @Inject - ResourceTransformer transformer; + protected ResourceTransformer transformer; /** * Looks for all resources of type {@code } that are installed in the kubernetes cluster. diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/applications/ApplicationsResource.java similarity index 99% rename from stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java rename to stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/applications/ApplicationsResource.java index 14409838cd..534f5a9319 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ApplicationsResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/applications/ApplicationsResource.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -package io.stackgres.apiweb.rest; +package io.stackgres.apiweb.rest.applications; import java.io.IOException; import java.io.InputStream; diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/auth/AuthResource.java similarity index 99% rename from stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java rename to stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/auth/AuthResource.java index e7fd0c583b..86a3e6074b 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/AuthResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/auth/AuthResource.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -package io.stackgres.apiweb.rest; +package io.stackgres.apiweb.rest.auth; import java.net.URI; import java.util.Map; diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/auth/RbacResource.java similarity index 98% rename from stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java rename to stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/auth/RbacResource.java index 4aba75de86..7a404e3648 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/RbacResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/auth/RbacResource.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -package io.stackgres.apiweb.rest; +package io.stackgres.apiweb.rest.auth; import java.util.ArrayList; import java.util.HashMap; @@ -30,6 +30,7 @@ import io.quarkus.security.identity.SecurityIdentity; import io.stackgres.apiweb.app.KubernetesClientProvider; import io.stackgres.apiweb.dto.PermissionsListDto; +import io.stackgres.apiweb.rest.misc.NamespaceResource; import io.stackgres.apiweb.rest.utils.CommonApiResponses; import io.stackgres.common.crd.CommonDefinition; import io.stackgres.common.crd.sgbackup.StackGresBackup; @@ -187,7 +188,7 @@ private List buildNamespacedPermissionList( return listNamespaced; } - protected List getResourcesUnnamespaced() { + public List getResourcesUnnamespaced() { return List.of( HasMetadata.getFullResourceName(Namespace.class), HasMetadata.getFullResourceName(StorageClass.class), @@ -195,7 +196,7 @@ protected List getResourcesUnnamespaced() { HasMetadata.getFullResourceName(ClusterRoleBinding.class)); } - protected List getResourcesNamespaced() { + public List getResourcesNamespaced() { return List.of( HasMetadata.getFullResourceName(Secret.class), HasMetadata.getFullResourceName(ConfigMap.class), diff --git a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/cluster/ClusterResource.java similarity index 92% rename from stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java rename to stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/cluster/ClusterResource.java index 74ce0ed190..a95717d28d 100644 --- a/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/ClusterResource.java +++ b/stackgres-k8s/src/api-web/src/main/java/io/stackgres/apiweb/rest/cluster/ClusterResource.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -package io.stackgres.apiweb.rest; +package io.stackgres.apiweb.rest.cluster; import static io.stackgres.common.patroni.StackGresPasswordKeys.SUPERUSER_PASSWORD_KEY; import static io.stackgres.common.patroni.StackGresPasswordKeys.SUPERUSER_USERNAME; @@ -31,6 +31,8 @@ import io.stackgres.apiweb.dto.script.ScriptEntry; import io.stackgres.apiweb.dto.script.ScriptFrom; import io.stackgres.apiweb.dto.script.ScriptSpec; +import io.stackgres.apiweb.rest.AbstractCustomResourceService; +import io.stackgres.apiweb.rest.sgscripts.ScriptResource; import io.stackgres.apiweb.transformer.ScriptTransformer; import io.stackgres.common.ManagedSqlUtil; import io.stackgres.common.PatroniUtil; @@ -50,10 +52,12 @@ import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Path; +import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.media.Content; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.jooq.lambda.Seq; import org.jooq.lambda.tuple.Tuple; import org.jooq.lambda.tuple.Tuple2; @@ -106,6 +110,18 @@ public ClusterResource( content = {@Content( mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ClusterDto.class))}) + @Tag(name = "sgcluster") + @Operation(summary = "List sgclusters", description = """ + List sgclusters and read values from the referenced secrets and configmaps. + + ### RBAC permissions required + + * sgclusters list + * pod list + * services list + * secrets get + * configmaps get + """) @Override public List list() { return Seq.seq(clusterScanner.getResources()) @@ -119,6 +135,19 @@ public List list() { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ClusterDto.class))}) + @Tag(name = "sgcluster") + @Operation(summary = "Create a sgcluster", description = """ + Create a sgcluster. + If values for some script configmap or secret is provided respectively a secret or + configmap named as the script if name is provided or as the sgcluster with + `-init-script-