/
redisuser_types.go
95 lines (75 loc) · 2.63 KB
/
redisuser_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Copyright 2022.
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 v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/instaclustr/operator/pkg/models"
)
// RedisUserSpec defines the desired state of RedisUser
type RedisUserSpec struct {
// SecretRef references to the secret which stores user's credentials
SecretRef *SecretReference `json:"secretRef"`
InitialPermissions string `json:"initialPermissions"`
}
// RedisUserStatus defines the observed state of RedisUser
type RedisUserStatus struct {
ID string `json:"ID,omitempty"`
ClustersEvents map[string]string `json:"clustersEvents,omitempty"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// RedisUser is the Schema for the redisusers API
type RedisUser struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RedisUserSpec `json:"spec,omitempty"`
Status RedisUserStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// RedisUserList contains a list of RedisUser
type RedisUserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RedisUser `json:"items"`
}
func (rs *RedisUserSpec) ToInstAPI(password, clusterID, username string) *models.RedisUser {
return &models.RedisUser{
ClusterID: clusterID,
Username: username,
Password: password,
InitialPermissions: rs.InitialPermissions,
}
}
func (r *RedisUser) GetDeletionFinalizer() string {
return models.DeletionFinalizer + "_" + r.Namespace + "_" + r.Name
}
func (r *RedisUser) ToInstAPIUpdate(password, id string) *models.RedisUserUpdate {
return &models.RedisUserUpdate{
ID: id,
Password: password,
}
}
func (r *RedisUser) NewPatch() client.Patch {
old := r.DeepCopy()
return client.MergeFrom(old)
}
func (r *RedisUser) GetClusterEvents() map[string]string {
return r.Status.ClustersEvents
}
func (r *RedisUser) SetClusterEvents(events map[string]string) {
r.Status.ClustersEvents = events
}
func init() {
SchemeBuilder.Register(&RedisUser{}, &RedisUserList{})
}