-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic Sql Datasource for operator (#5363)
- Loading branch information
Showing
6 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
operator/controller/src/test/java/io/apicurio/registry/operator/it/SqlDatasourceITTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.apicurio.registry.operator.it; | ||
|
||
import io.apicurio.registry.operator.api.v1.ApicurioRegistry3; | ||
import io.apicurio.registry.operator.api.v1.spec.Sql; | ||
import io.apicurio.registry.operator.api.v1.spec.sql.Datasource; | ||
import io.apicurio.registry.operator.resource.ResourceFactory; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
@QuarkusTest | ||
public class SqlDatasourceITTest extends ITBase { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SqlDatasourceITTest.class); | ||
|
||
@Test | ||
void testSqlDatasource() { | ||
client.load(SqlDatasourceITTest.class.getResourceAsStream("/k8s/example-postgres.yaml")).create(); | ||
// await for postgres to be available | ||
await().ignoreExceptions().until(() -> (1 == client.apps().statefulSets().inNamespace(namespace) | ||
.withName("postgresql-db").get().getStatus().getReadyReplicas())); | ||
|
||
var registry = ResourceFactory.deserialize("/k8s/examples/simple.apicurioregistry3.yaml", | ||
ApicurioRegistry3.class); | ||
registry.getMetadata().setNamespace(namespace); | ||
var sql = new Sql(); | ||
registry.getSpec().getApp().setSql(sql); | ||
var datasource = new Datasource(); | ||
sql.setDatasource(datasource); | ||
datasource.setUrl("jdbc:postgresql://postgres-db:5432/apicurio"); | ||
datasource.setUsername("postgres-username"); | ||
datasource.setPassword("postgres-password"); | ||
|
||
client.resource(registry).create(); | ||
|
||
await().ignoreExceptions().until(() -> { | ||
assertThat(client.apps().deployments().inNamespace(namespace) | ||
.withName(registry.getMetadata().getName() + "-app-deployment").get().getStatus() | ||
.getReadyReplicas().intValue()).isEqualTo(1); | ||
var podName = client.pods().inNamespace(namespace).list().getItems().stream() | ||
.map(pod -> pod.getMetadata().getName()) | ||
.filter(podN -> podN.startsWith("simple-app-deployment")).findFirst().get(); | ||
assertThat(client.pods().inNamespace(namespace).withName(podName).getLog()) | ||
.contains("Database type: postgresql"); | ||
|
||
return true; | ||
}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
operator/controller/src/test/resources/k8s/example-postgres.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# PostgreSQL StatefulSet | ||
apiVersion: apps/v1 | ||
kind: StatefulSet | ||
metadata: | ||
name: postgresql-db | ||
spec: | ||
serviceName: postgresql-db-service | ||
selector: | ||
matchLabels: | ||
app: postgresql-db | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: postgresql-db | ||
spec: | ||
containers: | ||
- name: postgresql-db | ||
image: quay.io/sclorg/postgresql-15-c9s:latest | ||
volumeMounts: | ||
- mountPath: /var/lib/pgsql/data | ||
name: cache-volume | ||
env: | ||
- name: POSTGRESQL_USER | ||
value: postgres-username | ||
- name: POSTGRESQL_PASSWORD | ||
value: postgres-password | ||
- name: POSTGRESQL_DATABASE | ||
value: apicurio | ||
volumes: | ||
- name: cache-volume | ||
emptyDir: {} | ||
--- | ||
# PostgreSQL StatefulSet Service | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: postgres-db | ||
spec: | ||
selector: | ||
app: postgresql-db | ||
ports: | ||
- port: 5432 | ||
targetPort: 5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
operator/model/src/main/java/io/apicurio/registry/operator/api/v1/spec/Sql.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.apicurio.registry.operator.api.v1.spec; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.fasterxml.jackson.annotation.Nulls; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import io.apicurio.registry.operator.api.v1.spec.sql.Datasource; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonPropertyOrder({ "datasource" }) | ||
@JsonDeserialize(using = JsonDeserializer.None.class) | ||
@Getter | ||
@Setter | ||
@ToString | ||
public class Sql { | ||
|
||
@JsonProperty("datasource") | ||
@JsonPropertyDescription(""" | ||
SQL data source.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private Datasource datasource; | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
operator/model/src/main/java/io/apicurio/registry/operator/api/v1/spec/sql/Datasource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.apicurio.registry.operator.api.v1.spec.sql; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.fasterxml.jackson.annotation.Nulls; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonPropertyOrder({ "url", "username", "password" }) | ||
@JsonDeserialize(using = JsonDeserializer.None.class) | ||
@Getter | ||
@Setter | ||
@ToString | ||
public class Datasource { | ||
|
||
@JsonProperty("url") | ||
@JsonPropertyDescription(""" | ||
Data source URL: \\n URL of the PostgreSQL | ||
database, for example: `jdbc:postgresql://<service name>.<namespace>.svc:5432/<database name>`.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private String url; | ||
|
||
@JsonProperty("username") | ||
@JsonPropertyDescription(""" | ||
Data source username.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private String username; | ||
|
||
@JsonProperty("password") | ||
@JsonPropertyDescription(""" | ||
Data source password.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private String password; | ||
|
||
// TODO: support values from Secrets: | ||
// | ||
// Proposal to support secrets, add alternative fields like: | ||
// @JsonProperty("passwordFrom") | ||
// @JsonPropertyDescription(""" | ||
// Data source password from Secret/ConfigMap/...""") | ||
// @JsonSetter(nulls = Nulls.SKIP) | ||
// private EnvVarSource passwordFrom; | ||
|
||
} |