/
externalsecret_types.go
262 lines (206 loc) · 8.78 KB
/
externalsecret_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// SecretStoreRef defines which SecretStore to fetch the ExternalSecret data.
type SecretStoreRef struct {
// Name of the SecretStore resource
Name string `json:"name"`
// Kind of the SecretStore resource (SecretStore or ClusterSecretStore)
// Defaults to `SecretStore`
// +optional
Kind string `json:"kind,omitempty"`
}
// ExternalSecretCreationPolicy defines rules on how to create the resulting Secret.
// +kubebuilder:validation:Enum=Owner;Merge;None
type ExternalSecretCreationPolicy string
const (
// Owner creates the Secret and sets .metadata.ownerReferences to the ExternalSecret resource.
Owner ExternalSecretCreationPolicy = "Owner"
// Merge does not create the Secret, but merges the data fields to the Secret.
Merge ExternalSecretCreationPolicy = "Merge"
// None does not create a Secret (future use with injector).
None ExternalSecretCreationPolicy = "None"
)
// ExternalSecretTemplateMetadata defines metadata fields for the Secret blueprint.
type ExternalSecretTemplateMetadata struct {
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// +optional
Labels map[string]string `json:"labels,omitempty"`
}
// ExternalSecretTemplate defines a blueprint for the created Secret resource.
// we can not use native corev1.Secret, it will have empty ObjectMeta values: https://github.com/kubernetes-sigs/controller-tools/issues/448
type ExternalSecretTemplate struct {
// +optional
Type corev1.SecretType `json:"type,omitempty"`
// EngineVersion specifies the template engine version
// that should be used to compile/execute the
// template specified in .data and .templateFrom[].
// +kubebuilder:default="v1"
EngineVersion TemplateEngineVersion `json:"engineVersion,omitempty"`
// +optional
Metadata ExternalSecretTemplateMetadata `json:"metadata,omitempty"`
// +optional
Data map[string]string `json:"data,omitempty"`
// +optional
TemplateFrom []TemplateFrom `json:"templateFrom,omitempty"`
}
// +kubebuilder:validation:Enum=v1;v2
type TemplateEngineVersion string
const (
TemplateEngineV1 TemplateEngineVersion = "v1"
TemplateEngineV2 TemplateEngineVersion = "v2"
)
// +kubebuilder:validation:MinProperties=1
// +kubebuilder:validation:MaxProperties=1
type TemplateFrom struct {
ConfigMap *TemplateRef `json:"configMap,omitempty"`
Secret *TemplateRef `json:"secret,omitempty"`
}
type TemplateRef struct {
Name string `json:"name"`
Items []TemplateRefItem `json:"items"`
}
type TemplateRefItem struct {
Key string `json:"key"`
}
// ExternalSecretTarget defines the Kubernetes Secret to be created
// There can be only one target per ExternalSecret.
type ExternalSecretTarget struct {
// Name defines the name of the Secret resource to be managed
// This field is immutable
// Defaults to the .metadata.name of the ExternalSecret resource
// +optional
Name string `json:"name,omitempty"`
// CreationPolicy defines rules on how to create the resulting Secret
// Defaults to 'Owner'
// +optional
// +kubebuilder:default="Owner"
CreationPolicy ExternalSecretCreationPolicy `json:"creationPolicy,omitempty"`
// Template defines a blueprint for the created Secret resource.
// +optional
Template *ExternalSecretTemplate `json:"template,omitempty"`
// Immutable defines if the final secret will be immutable
// +optional
Immutable bool `json:"immutable,omitempty"`
}
// ExternalSecretData defines the connection between the Kubernetes Secret key (spec.data.<key>) and the Provider data.
type ExternalSecretData struct {
SecretKey string `json:"secretKey"`
RemoteRef ExternalSecretDataRemoteRef `json:"remoteRef"`
}
// ExternalSecretDataRemoteRef defines Provider data location.
type ExternalSecretDataRemoteRef struct {
// Key is the key used in the Provider, mandatory
Key string `json:"key"`
// Used to select a specific version of the Provider value, if supported
// +optional
Version string `json:"version,omitempty"`
// +optional
// Used to select a specific property of the Provider value (if a map), if supported
Property string `json:"property,omitempty"`
// +optional
// Used to define a conversion Strategy
// +kubebuilder:default="Default"
ConversionStrategy ExternalSecretConversionStrategy `json:"conversionStrategy,omitempty"`
}
// +kubebuilder:validation:Enum=Default;Unicode
type ExternalSecretConversionStrategy string
const (
ExternalSecretConversionDefault ExternalSecretConversionStrategy = "Default"
ExternalSecretConversionUnicode ExternalSecretConversionStrategy = "Unicode"
)
// ExternalSecretSpec defines the desired state of ExternalSecret.
type ExternalSecretSpec struct {
SecretStoreRef SecretStoreRef `json:"secretStoreRef"`
Target ExternalSecretTarget `json:"target"`
// RefreshInterval is the amount of time before the values are read again from the SecretStore provider
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h"
// May be set to zero to fetch and create it once. Defaults to 1h.
// +kubebuilder:default="1h"
RefreshInterval *metav1.Duration `json:"refreshInterval,omitempty"`
// Data defines the connection between the Kubernetes Secret keys and the Provider data
// +optional
Data []ExternalSecretData `json:"data,omitempty"`
// DataFrom is used to fetch all properties from a specific Provider data
// If multiple entries are specified, the Secret keys are merged in the specified order
// +optional
DataFrom []ExternalSecretDataRemoteRef `json:"dataFrom,omitempty"`
}
type ExternalSecretConditionType string
const (
ExternalSecretReady ExternalSecretConditionType = "Ready"
ExternalSecretDeleted ExternalSecretConditionType = "Deleted"
)
type ExternalSecretStatusCondition struct {
Type ExternalSecretConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
// +optional
Reason string `json:"reason,omitempty"`
// +optional
Message string `json:"message,omitempty"`
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}
const (
// ConditionReasonSecretSynced indicates that the secrets was synced.
ConditionReasonSecretSynced = "SecretSynced"
// ConditionReasonSecretSyncedError indicates that there was an error syncing the secret.
ConditionReasonSecretSyncedError = "SecretSyncedError"
// ConditionReasonSecretDeleted indicates that the secret has been deleted.
ConditionReasonSecretDeleted = "SecretDeleted"
ReasonInvalidStoreRef = "InvalidStoreRef"
ReasonProviderClientConfig = "InvalidProviderClientConfig"
ReasonUpdateFailed = "UpdateFailed"
ReasonUpdated = "Updated"
)
type ExternalSecretStatus struct {
// +nullable
// refreshTime is the time and date the external secret was fetched and
// the target secret updated
RefreshTime metav1.Time `json:"refreshTime,omitempty"`
// SyncedResourceVersion keeps track of the last synced version
SyncedResourceVersion string `json:"syncedResourceVersion,omitempty"`
// +optional
Conditions []ExternalSecretStatusCondition `json:"conditions,omitempty"`
// Binding represents a servicebinding.io Provisioned Service reference to the secret
Binding corev1.LocalObjectReference `json:"binding,omitempty"`
}
// +kubebuilder:object:root=true
// ExternalSecret is the Schema for the external-secrets API.
// +kubebuilder:subresource:status
// +kubebuilder:deprecatedversion
// +kubebuilder:resource:scope=Namespaced,categories={externalsecrets},shortName=es
// +kubebuilder:printcolumn:name="Store",type=string,JSONPath=`.spec.secretStoreRef.name`
// +kubebuilder:printcolumn:name="Refresh Interval",type=string,JSONPath=`.spec.refreshInterval`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`
type ExternalSecret struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ExternalSecretSpec `json:"spec,omitempty"`
Status ExternalSecretStatus `json:"status,omitempty"`
}
const (
// AnnotationDataHash is used to ensure consistency.
AnnotationDataHash = "reconcile.external-secrets.io/data-hash"
)
// +kubebuilder:object:root=true
// ExternalSecretList contains a list of ExternalSecret resources.
type ExternalSecretList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ExternalSecret `json:"items"`
}