Database Integrations
Overview
KubeArchive requires a database to store resources. This document list the databases supported, how to set up the database schema and how to add new database integrations.
PostgreSQL
Currently, PostgreSQL is the only fully supported database engine. The KubeArchive integration test suite runs with the PostgreSQL version detailed in the kubearchive.sql file.
The PostgreSQL implementation is available here.
Configuration and Customization
Schema
KubeArchive offers a kubearchive.sql
file with the instructions to set up
the schema as part of the installation process.
The provided schema includes indexes. KubeArchive users should review and customize the indexes if needed based on the expected queries and the amount and distribution of the expected archived data. |
The schema includes the creation of the database kubearchive
owned by the kubearchive
user.
The schema expects the existence of a kubearchive
database user fow owning this database.
An account with admin privileges should run
|
Database Credentials
The kubearchive-database-credentials
Secret stores the information to connect KubeArchive with the Database.
The default content of this Secret when KubeArchive is installed is:
kind: Secret
type: Opaque
metadata:
name: kubearchive-database-credentials
namespace: kubearchive
stringData:
DATABASE_KIND: postgresql
DATABASE_PORT: "5432"
DATABASE_URL: "kubearchive-rw.postgresql.svc.cluster.local"
DATABASE_DB: "kubearchive"
DATABASE_USER: "kubearchive"
DATABASE_PASSWORD: "Databas3Passw0rd" # notsecret
Update the secret with the specific values of your database and restart the pods accordingly to pick the new values. The command for changing the most common values, URL and password, is:
kubectl patch secret -n kubearchive kubearchive-database-credentials \
--patch='{"stringData": {
"DATABASE_URL": "database.example.com", (1)
"DATABASE_PASSWORD": "password" (2)
}}'
1 | The database URL |
2 | The database password |
If you change the |
Don’t forget to restart kubearchive sink and api as both access the database:
|
Adding a New Database
To add a new database integration follow the instructions:
-
Create a new file under
pkg/database
named after the new database engine. -
Include an init function that:
-
Inserts in the
RegisteredDBCreators
map an entry keyed with the name of the DB type with anewDBCreatorFunc
implementation as value. -
Inserts in the
RegisteredDatabases
map an entry keyed with the name of the DB type with anewDatabaseFunc
as value.
-
The newDBCreatorFunc
This function receives the set of environment variables with the database configuration and returns a
DBCreator
implementation.
The DBCreator
should include env
as a parameter so the GetConnectionString
can access them.
The DBInterface
implementation returned by the newDatabaseFunc
This section includes the development guidelines expected by the KubeArchive maintainers. |
The DBInterface
should be a struct with
Database
embedded.
Make sure to implement the interfaces that are part of it:
All the interfaces work with objects from the sqlbuilder Go library. Check out the docs to see how to work with them. |
Some interfaces, like Other interfaces, like Those implementations may have the functionality that you need. Check them before implementing your own. |
If the database interaction logic changes from the implementation in the Database
struct,
override the implementation of the affected functions.
For example, a database that does not support upsert queries
needs to implement ResourceInserter
as a series of SELECT
and an INSERT
statements.
Take a look at the current database integrations and feel free to contribute to our code adding new database integrations!