@@ -27,34 +27,34 @@ const (
27
27
DEFAULT_MONGODB_ROOT_AUTHENTICATION_DATABASE = "admin"
28
28
)
29
29
30
- type MongoDBRootSecretLookup struct {
30
+ type MongoDBDatabaseRootSecretLookup struct {
31
31
Name string `json:"name"`
32
32
Namespace string `json:"namespace"`
33
33
Field string `json:"field"`
34
34
}
35
35
36
- type MongoDBCredentials []MongoDBCredential
37
- type MongoDBCredential struct {
36
+ type MongoDBDatabaseCredentials []MongoDBDatabaseCredential
37
+ type MongoDBDatabaseCredential struct {
38
38
UserName string `json:"username"`
39
39
Vault Vault `json:"vault"`
40
40
}
41
41
42
- // MongoDBSpec defines the desired state of MongoDB
42
+ // MongoDBDatabaseSpec defines the desired state of MongoDBDatabase
43
43
// IMPORTANT: Run "make" to regenerate code after modifying this file
44
- type MongoDBSpec struct {
44
+ type MongoDBDatabaseSpec struct {
45
45
DatabaseName string `json:"databaseName"`
46
46
HostName string `json:"hostName"`
47
47
// +optional
48
48
RootUsername string `json:"rootUsername"`
49
49
// +optional
50
- RootAuthenticationDatabase string `json:"rootAuthDatabase"`
51
- RootSecretLookup MongoDBRootSecretLookup `json:"rootSecretLookup"`
52
- Credentials MongoDBCredentials `json:"credentials"`
50
+ RootAuthenticationDatabase string `json:"rootAuthDatabase"`
51
+ RootSecretLookup MongoDBDatabaseRootSecretLookup `json:"rootSecretLookup"`
52
+ Credentials MongoDBDatabaseCredentials `json:"credentials"`
53
53
}
54
54
55
- // MongoDBStatus defines the observed state of MongoDB
55
+ // MongoDBDatabaseStatus defines the observed state of MongoDBDatabase
56
56
// IMPORTANT: Run "make" to regenerate code after modifying this file
57
- type MongoDBStatus struct {
57
+ type MongoDBDatabaseStatus struct {
58
58
DatabaseStatus DatabaseStatus `json:"database"`
59
59
CredentialsStatus CredentialsStatus `json:"credentials"`
60
60
LastUpdateTime metav1.Time `json:"lastUpdateTime"`
@@ -63,36 +63,36 @@ type MongoDBStatus struct {
63
63
// +kubebuilder:object:root=true
64
64
// +kubebuilder:subresource:status
65
65
66
- // MongoDB is the Schema for the mongodbs API
67
- type MongoDB struct {
66
+ // MongoDBDatabase is the Schema for the mongodbs API
67
+ type MongoDBDatabase struct {
68
68
metav1.TypeMeta `json:",inline"`
69
69
metav1.ObjectMeta `json:"metadata,omitempty"`
70
70
71
- Spec MongoDBSpec `json:"spec,omitempty"`
72
- Status MongoDBStatus `json:"status,omitempty"`
71
+ Spec MongoDBDatabaseSpec `json:"spec,omitempty"`
72
+ Status MongoDBDatabaseStatus `json:"status,omitempty"`
73
73
}
74
74
75
75
// +kubebuilder:object:root=true
76
76
77
- // MongoDBList contains a list of MongoDB
78
- type MongoDBList struct {
77
+ // MongoDBDatabaseList contains a list of MongoDBDatabase
78
+ type MongoDBDatabaseList struct {
79
79
metav1.TypeMeta `json:",inline"`
80
80
metav1.ListMeta `json:"metadata,omitempty"`
81
- Items []MongoDB `json:"items"`
81
+ Items []MongoDBDatabase `json:"items"`
82
82
}
83
83
84
84
/*
85
85
Alignes credentials status with spec by removing unneeded statuses. Mutates the original.
86
86
Returns removed statuses.
87
87
*/
88
- func (mongodb * MongoDB ) RemoveUnneededCredentialsStatus () * CredentialsStatus {
88
+ func (d * MongoDBDatabase ) RemoveUnneededCredentialsStatus () * CredentialsStatus {
89
89
removedStatuses := make (CredentialsStatus , 0 )
90
- statuses := & mongodb .Status .CredentialsStatus
90
+ statuses := & d .Status .CredentialsStatus
91
91
for i := 0 ; i < len (* statuses ); i ++ {
92
92
status := (* statuses )[i ]
93
93
found := false
94
94
if status != nil {
95
- for _ , credential := range mongodb .Spec .Credentials {
95
+ for _ , credential := range d .Spec .Credentials {
96
96
if credential .UserName == status .Username {
97
97
found = true
98
98
}
@@ -105,32 +105,32 @@ func (mongodb *MongoDB) RemoveUnneededCredentialsStatus() *CredentialsStatus {
105
105
i --
106
106
}
107
107
}
108
- mongodb .Status .CredentialsStatus = * statuses
108
+ d .Status .CredentialsStatus = * statuses
109
109
return & removedStatuses
110
110
}
111
111
112
- func (this * MongoDB ) SetDefaults () error {
113
- if this .Spec .RootUsername == "" {
114
- this .Spec .RootUsername = DEFAULT_MONGODB_ROOT_USER
112
+ func (d * MongoDBDatabase ) SetDefaults () error {
113
+ if d .Spec .RootUsername == "" {
114
+ d .Spec .RootUsername = DEFAULT_MONGODB_ROOT_USER
115
115
}
116
- if this .Spec .RootAuthenticationDatabase == "" {
117
- this .Spec .RootAuthenticationDatabase = DEFAULT_MONGODB_ROOT_AUTHENTICATION_DATABASE
116
+ if d .Spec .RootAuthenticationDatabase == "" {
117
+ d .Spec .RootAuthenticationDatabase = DEFAULT_MONGODB_ROOT_AUTHENTICATION_DATABASE
118
118
}
119
- if this .Spec .RootSecretLookup .Name == "" {
119
+ if d .Spec .RootSecretLookup .Name == "" {
120
120
return errors .New ("must specify root secret" )
121
121
}
122
- if this .Spec .RootSecretLookup .Field == "" {
122
+ if d .Spec .RootSecretLookup .Field == "" {
123
123
return errors .New ("must specify root secret field" )
124
124
}
125
- if this .Spec .RootSecretLookup .Namespace == "" {
126
- this .Spec .RootSecretLookup .Namespace = this .ObjectMeta .Namespace
125
+ if d .Spec .RootSecretLookup .Namespace == "" {
126
+ d .Spec .RootSecretLookup .Namespace = d .ObjectMeta .Namespace
127
127
}
128
- if this .Status .CredentialsStatus == nil || len (this .Status .CredentialsStatus ) == 0 {
129
- this .Status .CredentialsStatus = make ([]* CredentialStatus , 0 )
128
+ if d .Status .CredentialsStatus == nil || len (d .Status .CredentialsStatus ) == 0 {
129
+ d .Status .CredentialsStatus = make ([]* CredentialStatus , 0 )
130
130
}
131
131
return nil
132
132
}
133
133
134
134
func init () {
135
- SchemeBuilder .Register (& MongoDB {}, & MongoDBList {})
135
+ SchemeBuilder .Register (& MongoDBDatabase {}, & MongoDBDatabaseList {})
136
136
}
0 commit comments