Skip to content

Commit 4cd7b3f

Browse files
Merge pull request #166 from zzzeek/add_mdb_account
add controller to create and delete individual usernames in mariadb / galera
2 parents c971bdd + 484a1f6 commit 4cd7b3f

37 files changed

+1619
-39
lines changed

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: openstack.org
26
layout:
37
- go.kubebuilder.io/v3
@@ -42,4 +46,13 @@ resources:
4246
defaulting: true
4347
validation: true
4448
webhookVersion: v1
49+
- api:
50+
crdVersion: v1
51+
namespaced: true
52+
controller: true
53+
domain: openstack.org
54+
group: mariadb
55+
kind: MariaDBAccount
56+
path: github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1
57+
version: v1beta1
4558
version: "3"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.11.1
7+
creationTimestamp: null
8+
name: mariadbaccounts.mariadb.openstack.org
9+
spec:
10+
group: mariadb.openstack.org
11+
names:
12+
kind: MariaDBAccount
13+
listKind: MariaDBAccountList
14+
plural: mariadbaccounts
15+
singular: mariadbaccount
16+
scope: Namespaced
17+
versions:
18+
- name: v1beta1
19+
schema:
20+
openAPIV3Schema:
21+
description: MariaDBAccount is the Schema for the mariadbaccounts API
22+
properties:
23+
apiVersion:
24+
description: 'APIVersion defines the versioned schema of this representation
25+
of an object. Servers should convert recognized schemas to the latest
26+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
type: string
28+
kind:
29+
description: 'Kind is a string value representing the REST resource this
30+
object represents. Servers may infer this from the endpoint the client
31+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
32+
type: string
33+
metadata:
34+
type: object
35+
spec:
36+
description: MariaDBAccountSpec defines the desired state of MariaDBAccount
37+
properties:
38+
secret:
39+
description: Name of secret which contains DatabasePassword
40+
type: string
41+
userName:
42+
description: UserName for new account
43+
type: string
44+
required:
45+
- secret
46+
- userName
47+
type: object
48+
status:
49+
description: MariaDBAccountStatus defines the observed state of MariaDBAccount
50+
properties:
51+
conditions:
52+
description: Deployment Conditions
53+
items:
54+
description: Condition defines an observation of a API resource
55+
operational state.
56+
properties:
57+
lastTransitionTime:
58+
description: Last time the condition transitioned from one status
59+
to another. This should be when the underlying condition changed.
60+
If that is not known, then using the time when the API field
61+
changed is acceptable.
62+
format: date-time
63+
type: string
64+
message:
65+
description: A human readable message indicating details about
66+
the transition.
67+
type: string
68+
reason:
69+
description: The reason for the condition's last transition
70+
in CamelCase.
71+
type: string
72+
severity:
73+
description: Severity provides a classification of Reason code,
74+
so the current situation is immediately understandable and
75+
could act accordingly. It is meant for situations where Status=False
76+
and it should be indicated if it is just informational, warning
77+
(next reconciliation might fix it) or an error (e.g. DB create
78+
issue and no actions to automatically resolve the issue can/should
79+
be done). For conditions where Status=Unknown or Status=True
80+
the Severity should be SeverityNone.
81+
type: string
82+
status:
83+
description: Status of the condition, one of True, False, Unknown.
84+
type: string
85+
type:
86+
description: Type of condition in CamelCase.
87+
type: string
88+
required:
89+
- lastTransitionTime
90+
- status
91+
- type
92+
type: object
93+
type: array
94+
hash:
95+
additionalProperties:
96+
type: string
97+
description: Map of hashes to track e.g. job status
98+
type: object
99+
type: object
100+
type: object
101+
served: true
102+
storage: true
103+
subresources:
104+
status: {}

api/v1beta1/conditions.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import (
2323
const (
2424
// MariaDBInitializedCondition Status=True condition which indicates if the MariaDB dbinit has completed
2525
MariaDBInitializedCondition condition.Type = "MariaDBInitialized"
26+
27+
MariaDBDatabaseReadyCondition condition.Type = "MariaDBDatabaseReady"
28+
29+
MariaDBAccountReadyCondition condition.Type = "MariaDBAccountReady"
30+
31+
// MariaDBServerReadyCondition Status=True condition which indicates that the MariaDB and/or
32+
// Galera server is ready for database / account create/drop operations to proceed
33+
MariaDBServerReadyCondition condition.Type = "MariaDBServerReady"
2634
)
2735

2836
// MariaDB Reasons used by API objects.
@@ -60,4 +68,22 @@ const (
6068

6169
// MariaDBInitializedErrorMessage
6270
MariaDBInitializedErrorMessage = "MariaDB dbinit error occured %s"
71+
72+
MariaDBDatabaseReadyInitMessage = "MariaDBDatabase not yet available"
73+
74+
MariaDBDatabaseReadyMessage = "MariaDBDatabase ready"
75+
76+
MariaDBServerReadyInitMessage = "MariaDB / Galera server not yet available"
77+
78+
MariaDBServerReadyMessage = "MariaDB / Galera server ready"
79+
80+
MariaDBAccountReadyInitMessage = "MariaDBAccount create / drop not started"
81+
82+
MariaDBAccountReadyMessage = "MariaDBAccount creation complete"
83+
84+
MariaDBAccountSecretNotReadyMessage = "MariaDBAccount secret is missing or incomplete: %s"
85+
86+
MariaDBErrorRetrievingMariaDBDatabaseMessage = "Error retrieving MariaDBDatabase instance %s"
87+
88+
MariaDBErrorRetrievingMariaDBGaleraMessage = "Error retrieving MariaDB/Galera instance %s"
6389
)

api/v1beta1/mariadbaccount_types.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
const (
25+
// AccountCreateHash hash
26+
AccountCreateHash = "accountcreate"
27+
28+
// AccountDeleteHash hash
29+
AccountDeleteHash = "accountdelete"
30+
)
31+
32+
// MariaDBAccountSpec defines the desired state of MariaDBAccount
33+
type MariaDBAccountSpec struct {
34+
// UserName for new account
35+
// +kubebuilder:validation:Required
36+
UserName string `json:"userName"`
37+
38+
// Name of secret which contains DatabasePassword
39+
// +kubebuilder:validation:Required
40+
Secret string `json:"secret"`
41+
}
42+
43+
// MariaDBAccountStatus defines the observed state of MariaDBAccount
44+
type MariaDBAccountStatus struct {
45+
// Deployment Conditions
46+
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`
47+
48+
// Map of hashes to track e.g. job status
49+
Hash map[string]string `json:"hash,omitempty"`
50+
}
51+
52+
//+kubebuilder:object:root=true
53+
//+kubebuilder:subresource:status
54+
55+
// MariaDBAccount is the Schema for the mariadbaccounts API
56+
type MariaDBAccount struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ObjectMeta `json:"metadata,omitempty"`
59+
60+
Spec MariaDBAccountSpec `json:"spec,omitempty"`
61+
Status MariaDBAccountStatus `json:"status,omitempty"`
62+
}
63+
64+
//+kubebuilder:object:root=true
65+
66+
// MariaDBAccountList contains a list of MariaDBAccount
67+
type MariaDBAccountList struct {
68+
metav1.TypeMeta `json:",inline"`
69+
metav1.ListMeta `json:"metadata,omitempty"`
70+
Items []MariaDBAccount `json:"items"`
71+
}
72+
73+
func init() {
74+
SchemeBuilder.Register(&MariaDBAccount{}, &MariaDBAccountList{})
75+
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)