Skip to content

Commit 0cee061

Browse files
authored
Merge pull request #228 from runkecheng/user_manager
*: Support user management through crd. #175
2 parents d6ffd93 + 582192a commit 0cee061

File tree

23 files changed

+1392
-5
lines changed

23 files changed

+1392
-5
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ COPY controllers/ controllers/
1818
COPY backup/ backup/
1919
COPY internal/ internal/
2020
COPY utils/ utils/
21+
COPY mysqluser/ mysqluser/
2122

2223
# Build
2324
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager cmd/manager/main.go

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ resources:
2727
kind: Backup
2828
path: github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1
2929
version: v1alpha1
30+
- api:
31+
crdVersion: v1
32+
namespaced: true
33+
controller: true
34+
domain: radondb.com
35+
group: mysql
36+
kind: MysqlUser
37+
path: github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1
38+
version: v1alpha1
3039
version: "3"

api/v1alpha1/mysqluser_types.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
Copyright 2021 RadonDB.
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 v1alpha1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// UserSpec defines the desired state of User.
28+
type UserSpec struct {
29+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
30+
// Important: Run "make" to regenerate code after modifying this file
31+
32+
// Username is the name of user to be operated.
33+
// This field should be immutable.
34+
// +kubebuilder:validation:Required
35+
// +kubebuilder:validation:Pattern="^[A-Za-z0-9_]{2,26}$"
36+
User string `json:"user,omitempty"`
37+
38+
// Hosts is the grants hosts.
39+
// +kubebuilder:validation:Required
40+
// +kubebuilder:validation:MinItems=1
41+
Hosts []string `json:"hosts,omitempty"`
42+
43+
// UserOwner Contains parameters about the cluster bound by user.
44+
// +kubebuilder:validation:Required
45+
UserOwner UserOwner `json:"userOwner,omitempty"`
46+
47+
// SecretSelector Contains parameters about the secret object bound by user.
48+
// +kubebuilder:validation:Required
49+
SecretSelector SecretSelector `json:"secretSelector,omitempty"`
50+
51+
// Permissions is the list of roles that user has in the specified database.
52+
// +optional
53+
Permissions []UserPermission `json:"permissions,omitempty"`
54+
}
55+
56+
type UserOwner struct {
57+
// ClusterName is the name of cluster.
58+
ClusterName string `json:"clusterName,omitempty"`
59+
60+
// NameSpace is the nameSpace of cluster.
61+
NameSpace string `json:"nameSpace,omitempty"`
62+
}
63+
64+
type SecretSelector struct {
65+
// SecretName is the name of secret object.
66+
SecretName string `json:"secretName,omitempty"`
67+
68+
// SecretKey is the key of secret object.
69+
SecretKey string `json:"secretKey,omitempty"`
70+
}
71+
72+
// UserPermission defines a UserPermission permission.
73+
type UserPermission struct {
74+
// Database is the grants database.
75+
// +kubebuilder:validation:Pattern="^([*]|[A-Za-z0-9_]{2,26})$"
76+
Database string `json:"database,omitempty"`
77+
78+
// Tables is the grants tables inside the database.
79+
// +kubebuilder:validation:MinItems=1
80+
Tables []string `json:"tables,omitempty"`
81+
82+
// Privileges is the normal privileges(comma delimited, such as "SELECT,CREATE").
83+
// Optional parameters can refer to: https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html.
84+
// +kubebuilder:validation:MinItems=1
85+
Privileges []string `json:"privileges,omitempty"`
86+
}
87+
88+
// UserStatus defines the observed state of MysqlUser.
89+
type UserStatus struct {
90+
// Conditions represents the MysqlUser resource conditions list.
91+
// +optional
92+
Conditions []MySQLUserCondition `json:"conditions,omitempty"`
93+
94+
// AllowedHosts contains the list of hosts that the user is allowed to connect from.
95+
AllowedHosts []string `json:"allowedHosts,omitempty"`
96+
}
97+
98+
// MysqlUserConditionType defines the condition types of a MysqlUser resource.
99+
type MysqlUserConditionType string
100+
101+
const (
102+
// MySQLUserReady means the MySQL user is ready when database exists.
103+
MySQLUserReady MysqlUserConditionType = "Ready"
104+
)
105+
106+
// MySQLUserCondition defines the condition struct for a MysqlUser resource.
107+
type MySQLUserCondition struct {
108+
// Type of MysqlUser condition.
109+
Type MysqlUserConditionType `json:"type"`
110+
// Status of the condition, one of True, False, Unknown.
111+
Status corev1.ConditionStatus `json:"status"`
112+
// The last time this condition was updated.
113+
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
114+
// Last time the condition transitioned from one status to another.
115+
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
116+
// The reason for the condition's last transition.
117+
Reason string `json:"reason"`
118+
// A human readable message indicating details about the transition.
119+
Message string `json:"message"`
120+
}
121+
122+
//+kubebuilder:object:root=true
123+
//+kubebuilder:subresource:status
124+
//+kubebuilder:subresource:finalizers
125+
// MysqlUser is the Schema for the users API.
126+
type MysqlUser struct {
127+
metav1.TypeMeta `json:",inline"`
128+
metav1.ObjectMeta `json:"metadata,omitempty"`
129+
130+
Spec UserSpec `json:"spec,omitempty"`
131+
Status UserStatus `json:"status,omitempty"`
132+
}
133+
134+
//+kubebuilder:object:root=true
135+
// MysqlUserList contains a list of MysqlUser.
136+
type MysqlUserList struct {
137+
metav1.TypeMeta `json:",inline"`
138+
metav1.ListMeta `json:"metadata,omitempty"`
139+
Items []MysqlUser `json:"items"`
140+
}
141+
142+
func init() {
143+
SchemeBuilder.Register(&MysqlUser{}, &MysqlUserList{})
144+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 187 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)