Skip to content

Commit

Permalink
Merge pull request #9 from uselagoon/feat-mongodb-implementation
Browse files Browse the repository at this point in the history
feat: mongodb implementation
  • Loading branch information
Marco Cadetg authored May 29, 2024
2 parents 34ad84a + af95b34 commit 27ac329
Show file tree
Hide file tree
Showing 26 changed files with 1,978 additions and 51 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ resources:
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: MongoDBProvider
path: github.com/uselagoon/dbaas-controller/api/v1alpha1
version: v1alpha1
version: "3"
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"`
}
138 changes: 138 additions & 0 deletions api/v1alpha1/mongodbprovider_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
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

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// MongoDBAuth defines the authorisation mechanisms that mongo can use
type MongoDBAuth struct {
//+kubebuilder:required
//+kubebuilder:validation:Required
//+kubebuilder:validation:Enum=SCRAM-SHA-1;SCRAM-SHA-256;MONGODB-CR;MongoDB-AWS;X509
// Mechanism is the authentication mechanism for the MongoDB connection
// https://www.mongodb.com/docs/drivers/go/current/fundamentals/auth/#std-label-golang-authentication-mechanisms
Mechanism string `json:"mechanism"`

//+kubebuilder:optional
//+kubebuilder:default:admin
// Source is the source of the authentication mechanism for the MongoDB connection
Source string `json:"source,omitempty"`

//+kubebuilder:optional
//+kubebuilder:default:true
// TLS is the flag to enable or disable TLS for the MongoDB connection
TLS bool `json:"tls,omitempty"`
}

type MongoDBConnection struct {
//+kubebuilder:required
// Name is the name of the MongoDB connection
// it is used to identify the connection. Please use a unique name
// for each connection. This field will be used in the MongoDBProvider
// to reference the connection. The MongoDBProvider controller will
// error if the name is not unique.
Name string `json:"name"`

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

//+kubebuilder:optional
// ReplicaHostnames is the list of hostnames of the relational database replicas
ReplicaHostnames []string `json:"replicaHostnames,omitempty"`

//+kubebuilder:required
// PasswordSecretRef is the reference to the secret containing the password
PasswordSecretRef v1.SecretReference `json:"passwordSecretRef"`

//+kubebuilder:optional
//+kubebuilder:default:=27017
//+kubebuilder:validation:Required
//+kubebuilder:validation:Minimum=1
//+kubebuilder:validation:Maximum=65535
// Port is the port of the relational database
Port int `json:"port,omitempty"`

//+kubebuilder:optional
//+kubebuilder:default:=root
// Username is the username of the relational database
Username string `json:"username,omitempty"`

//+kubebuilder:required
// Auth is the authentication mechanism for the MongoDB connection
Auth MongoDBAuth `json:"auth"`

//+kubebuilder:optional
//+kubebuilder:default:=true
// Enabled is a flag to enable or disable the relational database
Enabled bool `json:"enabled,omitempty"`
}

// MongoDBProviderSpec defines the desired state of MongoDBProvider
type MongoDBProviderSpec struct {
//+kubebuilder:required
//+kubebuilder:validation:Required
//+kubebuilder:validation:Enum=production;development;custom
//+kubebuilder:default:=development
// Scope is the scope of the database request
// it can be either "production" or "development" or "custom"
Scope string `json:"scope"`

//+kubebuilder:validation:MinItems=1
// Connections defines the connection to a relational database
Connections []MongoDBConnection `json:"connections"`
}

// MongoDBProviderStatus defines the observed state of MongoDBProvider
type MongoDBProviderStatus struct {
// Conditions defines the status conditions
Conditions []metav1.Condition `json:"conditions,omitempty"`

// ConnectionStatus provides the status of the relational database
ConnectionStatus []ConnectionStatus `json:"connectionStatus,omitempty"` // nolint:lll

// ObservedGeneration is the last observed generation
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// MongoDBDProvider is the Schema for the mongodbproviders API
type MongoDBDProvider struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MongoDBProviderSpec `json:"spec,omitempty"`
Status MongoDBProviderStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// MongoDBProviderList contains a list of MongoDBProvider
type MongoDBProviderList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MongoDBDProvider `json:"items"`
}

func init() {
SchemeBuilder.Register(&MongoDBDProvider{}, &MongoDBProviderList{})
}
35 changes: 3 additions & 32 deletions api/v1alpha1/relationaldatabaseprovider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

// Connection defines the connection to a relational database like MySQL or PostgreSQL
type Connection struct {
//+kubebuilder:required
// Name is the name of the relational database like MySQL or PostgreSQL connection
// it is used to identify the connection. Please use a unique name
// for each connection. This field will be used in the DatabaseRequest
Expand Down Expand Up @@ -53,10 +54,10 @@ type Connection struct {
// Username is the username of the relational database
Username string `json:"username"`

//+kubebuilder:required
//+kubebuilder:optional
//+kubebuilder:default:=true
// Enabled is a flag to enable or disable the relational database
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled,omitempty"`
}

// RelationalDatabaseProviderSpec defines the desired state of RelationalDatabaseProvider
Expand All @@ -81,36 +82,6 @@ type RelationalDatabaseProviderSpec struct {
Connections []Connection `json:"connections"`
}

// ConnectionStatus defines the status of a relational database connection
type ConnectionStatus struct {
//+kubebuilder:required
// Name is the name of the relational 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 controller will
// error if the name is not unique.
Name string `json:"name"`

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

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

//+kubebuilder:required
//+kubebuilder:validation:Required
// Enabled is a flag to indicate whether a MySQL 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 relational database
Status string `json:"status"`
}

// RelationalDatabaseProviderStatus defines the observed state of RelationalDatabaseProvider
type RelationalDatabaseProviderStatus struct {
// Conditions defines the status conditions
Expand Down
Loading

0 comments on commit 27ac329

Please sign in to comment.