Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mongodb implementation #9

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: create-kind-cluster
create-kind-cluster:
docker network inspect $(KIND_CLUSTER) >/dev/null || docker network create $(KIND_CLUSTER)
kind create cluster --wait=60s --name=$(KIND_CLUSTER) --config=kind-config.yaml
@if ! kind get clusters | grep -q $(KIND_CLUSTER); then \
docker network inspect $(KIND_CLUSTER) >/dev/null 2>&1 || docker network create $(KIND_CLUSTER); \
kind create cluster --wait=60s --name=$(KIND_CLUSTER) --config=kind-config.yaml; \
else \
echo "Cluster $(KIND_CLUSTER) already exists"; \
fi

.PHONY: delete-kind-cluster
delete-kind-cluster:
Expand Down
12 changes: 11 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ resources:
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: lagoon.sh
group: crd
kind: RelationalDatabaseProvider
path: github.com/uselagoon/dbaas-controller/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: lagoon.sh
group: crd
kind: DatabaseMySQLProvider
kind: MongoDBProvider
path: github.com/uselagoon/dbaas-controller/api/v1alpha1
version: v1alpha1
version: "3"
54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ It allows for provisiong and deprovisioning of shared MySQL/MariaDB, PostgreSQL,
## Current Status of the Project

WIP - Work in Progress
There is still a lot of work to be done on this project. The current status is that the controller is able to provision and deprovision MySQL databases. But there is still a lot of work to be done to make it production ready.
There is still a some work to be done on this project. The current status is that the controller is able to provision and deprovision MySQL databases. But there is still a lot of work to be done to make it production ready.

- [x] Setup e2e tests
- [x] Provision MySQL databases (basic) - no support for additional users, seeding, etc.
- [x] Deprovision MySQL databases
- [ ] Provision PostgreSQL databases
- [ ] Deprovision PostgreSQL databases
- [x] Provision PostgreSQL databases
- [x] Deprovision PostgreSQL databases
- [ ] Provision MongoDB databases
- [ ] Deprovision MongoDB databases
- [ ] Plan to migrate from old `dbaaas-operator` to `dbaas-controller`
Expand Down Expand Up @@ -58,57 +58,59 @@ Key Features:

To interact with the dbaas-controller, the following CRDs are introduced:

- DatabaseXProvider
- This CRD is used to define a database provider, such as MySQL, PostgreSQL, or MongoDB.
- RelationalDatabaseProvider
- This CRD is used to define a database provider, such as MySQL and PostgreSQL.
- DatabaseRequest
- DatabaseMigration

Basic usage of the CRs in combination with the dbaas-controller is outlined below.

- DatabaseRequest: Lagoon creates a DatabaseRequest CR to request a database instance
- The dbaas-controller processes the request and provisions the database instance based on the request
- The controller uses the relevant DatabaseXProvider CR to determine how it should provision the database
- The controller uses the relevant RelationalDatabaseProvider CR to determine how it should provision the database

## DatabaseMySQLProvider CRD Documentation
## RelationalDatabaseProvider CRD Documentation

The `DatabaseMySQLProvider` CRD defines a Kubernetes-native way to manage MySQL database connections and configurations. This custom resource allows to define MySQL databases.
The `RelationalDatabaseProvider` CRD defines a Kubernetes-native way to manage relational database connections and configurations. This custom resource allows to define MySQL and PostgreSQL databases.

Use the status mysqlConnectionStatus field to check the status of the MySQL connections defined in the spec.
Use the status connectionStatus field to check the status of the MySQL connections defined in the spec.

### DatabaseMySQLProvider Spec Fields
### RelationalDatabaseProvider Spec Fields

- kind (required): The type of database provider, which can be either mysql or postgresql.
- scope (required): Defines the scope of the database request, which influences the environment setup. Valid values are production, development, and custom. Defaults to development if not specified.
- mysqlConnections (required): A list of `MySQLConnection` objects that detail the connection parameters to MySQL databases. At least one connection must be defined.
- connections (required): A list of `connection` objects that detail the connection parameters to MySQL or PostgreSQL databases. At least one connection must be defined.

- MySQLConnection Fields
- name (required): A unique name for the MySQL database connection, used to identify and reference the connection in database requests.
- hostname (required): The hostname of the MySQL database server.
- replicaHostnames (optional): A list of hostnames for the MySQL replica databases.
- connection Fields
- name (required): A unique name for the MySQL or PostgreSQL database connection, used to identify and reference the connection in database requests.
- hostname (required): The hostname of the MySQL or PostgreSQL database server.
- replicaHostnames (optional): A list of hostnames for the MySQLi or PostgreSQL replica databases.
- passwordSecretRef (required): A reference to a Kubernetes Secret containing the password for the database connection.
- port (required): The port on which the MySQL database server is listening. Must be between 1 and 65535.
- username (required): The username for logging into the MySQL database.
- port (required): The port on which the MySQLi or PostgreSQL database server is listening. Must be between 1 and 65535.
- username (required): The username for logging into the MySQLi or PostgreSQL database.
- enabled (required): A flag indicating whether this database connection is enabled. Defaults to true.

### DatabaseMySQLProvider Status Fields
### RelationalDatabaseProvider Status Fields

- conditions: Provides detailed conditions of the MySQLProvider like readiness, errors, etc.
- mysqlConnectionStatus: A list of statuses for the MySQL connections defined in the spec.
- conditions: Provides detailed conditions of the `RelationalDatabaseProvider` like readiness, errors, etc.
- connectionStatus: A list of statuses for the MySQL or PostgreSQL connections defined in the spec.

- MySQLConnectionStatus Fields
- hostname (required): The hostname of the MySQL database server.
- mysqlVersion (required): The version of the MySQL server.
- connectionStatus Fields
- hostname (required): The hostname of the MySQL or PostgreSQL database server.
- mysqlVersion (required): The version of the MySQL or PostgreSQL server.
- enabled (required): Indicates if the database connection is enabled.
- status (required): The current status of the database connection, with valid values being available and unavailable.
- observedGeneration: Reflects the generation of the most recently observed DatabaseMySQLProvider object.
- observedGeneration: Reflects the generation of the most recently observed RelationalDatabaseProvider object.

### DatabaseMySQLProvider Example
### RelationalDatabaseProvider Example

```yaml
apiVersion: v1alpha1
kind: DatabaseMySQLProvider
kind: RelationalDatabaseProvider
metadata:
name: example-mysql-provider
spec:
kind: mysql
scope: development
mysqlConnections:
- name: primary-db
Expand Down
47 changes: 47 additions & 0 deletions api/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

// ConnectionStatus defines the status of a database connection, it can be either relational database or mongodb
type ConnectionStatus struct {
//+kubebuilder:required
// Name is the name of the database connection
// it is used to identify the connection. Please use a unique name
// for each connection. This field will be used in the DatabaseRequest
// to reference the connection. The relationaldatabaseprovider and mongodbprovider
// controllers will error if the name is not unique.
Name string `json:"name"`

//+kubebuilder:required
// Hostname is the hostname of the database
Hostname string `json:"hostname"`

//+kubebuilder:required
// DatabaseVersion is the version of the database
DatabaseVersion string `json:"databaseVersion"`

//+kubebuilder:required
//+kubebuilder:validation:Required
// Enabled is a flag to indicate whether a database is enabled or not
Enabled bool `json:"enabled"`

//+kubebuilder:required
//+kubebuilder:validation:Required
//+kubebuilder:validation:Enum=available;unavailable
// Status is the status of the database
Status string `json:"status"`
}
143 changes: 0 additions & 143 deletions api/v1alpha1/databasemysqlprovider_types.go

This file was deleted.

Loading