externalsecret_types.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package v1alpha1
  13. import (
  14. corev1 "k8s.io/api/core/v1"
  15. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  16. )
  17. // SecretStoreRef defines which SecretStore to fetch the ExternalSecret data.
  18. type SecretStoreRef struct {
  19. // Name of the SecretStore resource
  20. Name string `json:"name"`
  21. // Kind of the SecretStore resource (SecretStore or ClusterSecretStore)
  22. // Defaults to `SecretStore`
  23. // +optional
  24. Kind string `json:"kind,omitempty"`
  25. }
  26. // ExternalSecretCreationPolicy defines rules on how to create the resulting Secret.
  27. type ExternalSecretCreationPolicy string
  28. const (
  29. // Owner creates the Secret and sets .metadata.ownerReferences to the ExternalSecret resource.
  30. Owner ExternalSecretCreationPolicy = "Owner"
  31. // Merge does not create the Secret, but merges the data fields to the Secret.
  32. Merge ExternalSecretCreationPolicy = "Merge"
  33. // None does not create a Secret (future use with injector).
  34. None ExternalSecretCreationPolicy = "None"
  35. )
  36. // ExternalSecretTemplateMetadata defines metadata fields for the Secret blueprint.
  37. type ExternalSecretTemplateMetadata struct {
  38. // +optional
  39. Annotations map[string]string `json:"annotations,omitempty"`
  40. // +optional
  41. Labels map[string]string `json:"labels,omitempty"`
  42. }
  43. // ExternalSecretTemplate defines a blueprint for the created Secret resource.
  44. type ExternalSecretTemplate struct {
  45. // +optional
  46. Type corev1.SecretType `json:"type,omitempty"`
  47. // +optional
  48. Metadata ExternalSecretTemplateMetadata `json:"metadata,omitempty"`
  49. }
  50. // ExternalSecretTarget defines the Kubernetes Secret to be created
  51. // There can be only one target per ExternalSecret.
  52. type ExternalSecretTarget struct {
  53. // Name defines the name of the Secret resource to be managed
  54. // This field is immutable
  55. // Defaults to the .metadata.name of the ExternalSecret resource
  56. // +optional
  57. Name string `json:"name,omitempty"`
  58. // CreationPolicy defines rules on how to create the resulting Secret
  59. // Defaults to 'Owner'
  60. // +optional
  61. CreationPolicy ExternalSecretCreationPolicy `json:"creationPolicy,omitempty"`
  62. }
  63. // ExternalSecretData defines the connection between the Kubernetes Secret key (spec.data.<key>) and the Provider data.
  64. type ExternalSecretData struct {
  65. SecretKey string `json:"secretKey"`
  66. RemoteRef ExternalSecretDataRemoteRef `json:"remoteRef"`
  67. }
  68. // ExternalSecretDataRemoteRef defines Provider data location.
  69. type ExternalSecretDataRemoteRef struct {
  70. // Key is the key used in the Provider, mandatory
  71. Key string `json:"key"`
  72. // Used to select a specific version of the Provider value, if supported
  73. // +optional
  74. Version string `json:"version,omitempty"`
  75. // +optional
  76. // Used to select a specific property of the Provider value (if a map), if supported
  77. Property string `json:"property,omitempty"`
  78. }
  79. // ExternalSecretSpec defines the desired state of ExternalSecret.
  80. type ExternalSecretSpec struct {
  81. SecretStoreRef SecretStoreRef `json:"secretStoreRef"`
  82. Target ExternalSecretTarget `json:"target"`
  83. // RefreshInterval is the amount of time before the values reading again from the SecretStore provider
  84. // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h" (from time.ParseDuration)
  85. // May be set to zero to fetch and create it once
  86. // TODO: Default to some value?
  87. // +optional
  88. RefreshInterval string `json:"refreshInterval,omitempty"`
  89. // Data defines the connection between the Kubernetes Secret keys and the Provider data
  90. // +optional
  91. Data []ExternalSecretData `json:"data,omitempty"`
  92. // DataFrom is used to fetch all properties from a specific Provider data
  93. // If multiple entries are specified, the Secret keys are merged in the specified order
  94. // +optional
  95. DataFrom []ExternalSecretDataRemoteRef `json:"dataFrom,omitempty"`
  96. }
  97. // ExternalSecretStatusPhase represents the current phase of the Secret sync.
  98. type ExternalSecretStatusPhase string
  99. const (
  100. // ExternalSecret created, controller did not yet sync the ExternalSecret or other dependencies are missing (e.g. secret store or configmap template).
  101. ExternalSecretPending ExternalSecretStatusPhase = "Pending"
  102. // ExternalSecret is being actively synced according to spec.
  103. ExternalSecretSyncing ExternalSecretStatusPhase = "Syncing"
  104. // ExternalSecret can not be synced, this might require user intervention.
  105. ExternalSecretFailing ExternalSecretStatusPhase = "Failing"
  106. // ExternalSecret can not be synced right now and will not able to.
  107. ExternalSecretFailed ExternalSecretStatusPhase = "Failed"
  108. // ExternalSecret was synced successfully (one-time use only).
  109. ExternalSecretCompleted ExternalSecretStatusPhase = "Completed"
  110. )
  111. type ExternalSecretConditionType string
  112. const (
  113. InSync ExternalSecretConditionType = "InSync"
  114. )
  115. type ExternalSecretStatusCondition struct {
  116. Type SecretStoreConditionType `json:"type"`
  117. Status corev1.ConditionStatus `json:"status"`
  118. // +optional
  119. Reason string `json:"reason,omitempty"`
  120. // +optional
  121. Message string `json:"message,omitempty"`
  122. // +optional
  123. LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
  124. // +optional
  125. LastSyncTime metav1.Time `json:"lastSyncTime,omitempty"`
  126. }
  127. type ExternalSecretStatus struct {
  128. // +optional
  129. Phase ExternalSecretStatusPhase `json:"phase"`
  130. // +optional
  131. Conditions []ExternalSecretStatusCondition `json:"conditions"`
  132. }
  133. // +kubebuilder:object:root=true
  134. // ExternalSecret is the Schema for the externalsecrets API.
  135. type ExternalSecret struct {
  136. metav1.TypeMeta `json:",inline"`
  137. metav1.ObjectMeta `json:"metadata,omitempty"`
  138. Spec ExternalSecretSpec `json:"spec,omitempty"`
  139. Status ExternalSecretStatus `json:"status,omitempty"`
  140. }
  141. // +kubebuilder:object:root=true
  142. // ExternalSecretList contains a list of ExternalSecret.
  143. type ExternalSecretList struct {
  144. metav1.TypeMeta `json:",inline"`
  145. metav1.ListMeta `json:"metadata,omitempty"`
  146. Items []ExternalSecret `json:"items"`
  147. }
  148. func init() {
  149. SchemeBuilder.Register(&ExternalSecret{}, &ExternalSecretList{})
  150. }