@@ -38,6 +38,20 @@ const (
3838 DatabaseReclaimRetain DatabaseReclaimPolicy = "retain"
3939)
4040
41+ // UsageSpecType describes the type of usage specified in the `usage` field of the
42+ // `Database` object.
43+ // +enum
44+ type UsageSpecType string
45+
46+ const (
47+ // GrantUsageSpecType indicates a grant usage permission.
48+ // The default usage permission is grant.
49+ GrantUsageSpecType UsageSpecType = "grant"
50+
51+ // RevokeUsageSpecType indicates a revoke usage permission.
52+ RevokeUsageSpecType UsageSpecType = "revoke"
53+ )
54+
4155// DatabaseSpec is the specification of a Postgresql Database, built around the
4256// `CREATE DATABASE`, `ALTER DATABASE`, and `DROP DATABASE` SQL commands of
4357// PostgreSQL.
@@ -177,18 +191,22 @@ type DatabaseSpec struct {
177191 // The list of foreign data wrappers to be managed in the database
178192 // +optional
179193 FDWs []FDWSpec `json:"fdws,omitempty"`
194+
195+ // The list of foreign servers to be managed in the database
196+ // +optional
197+ Servers []ServerSpec `json:"servers,omitempty"`
180198}
181199
182200// DatabaseObjectSpec contains the fields which are common to every
183201// database object
184202type DatabaseObjectSpec struct {
185- // Name of the extension/ schema
203+ // Name of the object ( extension, schema, FDW, server)
186204 Name string `json:"name"`
187205
188- // Specifies whether an extension/ schema should be present or absent in
189- // the database. If set to `present`, the extension/schema will be
190- // created if it does not exist. If set to `absent`, the
191- // extension/schema will be removed if it exists.
206+ // Specifies whether an object (e.g schema) should be present or absent
207+ // in the database. If set to `present`, the object will be created if
208+ // it does not exist. If set to `absent`, the extension/schema will be
209+ // removed if it exists.
192210 // +kubebuilder:default:="present"
193211 // +kubebuilder:validation:Enum=present;absent
194212 // +optional
@@ -246,8 +264,7 @@ type FDWSpec struct {
246264 // +optional
247265 Owner string `json:"owner,omitempty"`
248266
249- // Options specifies the configuration options for the FDW
250- // (key is the option name, value is the option value).
267+ // Options specifies the configuration options for the FDW.
251268 // +optional
252269 Options []OptionSpec `json:"options,omitempty"`
253270
@@ -256,17 +273,30 @@ type FDWSpec struct {
256273 Usages []UsageSpec `json:"usage,omitempty"`
257274}
258275
276+ // ServerSpec configures a server of a foreign data wrapper
277+ type ServerSpec struct {
278+ // Common fields
279+ DatabaseObjectSpec `json:",inline"`
280+
281+ // The name of the Foreign Data Wrapper (FDW)
282+ // +kubebuilder:validation:XValidation:rule="self != ''",message="fdw is required"
283+ FdwName string `json:"fdw"`
284+
285+ // Options specifies the configuration options for the server
286+ // (key is the option name, value is the option value).
287+ // +optional
288+ Options []OptionSpec `json:"options,omitempty"`
289+
290+ // List of roles for which `USAGE` privileges on the server are granted or revoked.
291+ // +optional
292+ Usages []UsageSpec `json:"usage,omitempty"`
293+ }
294+
259295// OptionSpec holds the name, value and the ensure field for an option
260296type OptionSpec struct {
261297 // Name of the option
262298 Name string `json:"name"`
263299
264- // Value and ensure field of the option
265- OptionSpecValue `json:",inline"`
266- }
267-
268- // OptionSpecValue holds the value and the ensure field for an option
269- type OptionSpecValue struct {
270300 // Value of the option
271301 Value string `json:"value"`
272302
@@ -283,13 +313,14 @@ type OptionSpecValue struct {
283313// UsageSpec configures a usage for a foreign data wrapper
284314type UsageSpec struct {
285315 // Name of the usage
316+ // +kubebuilder:validation:XValidation:rule="self != ''",message="name is required"
286317 Name string `json:"name"`
287318
288319 // The type of usage
289320 // +kubebuilder:default:="grant"
290321 // +kubebuilder:validation:Enum=grant;revoke
291322 // +optional
292- Type string `json:"type,omitempty"`
323+ Type UsageSpecType `json:"type,omitempty"`
293324}
294325
295326// DatabaseStatus defines the observed state of Database
@@ -318,6 +349,10 @@ type DatabaseStatus struct {
318349 // FDWs is the status of the managed FDWs
319350 // +optional
320351 FDWs []DatabaseObjectStatus `json:"fdws,omitempty"`
352+
353+ // Servers is the status of the managed servers
354+ // +optional
355+ Servers []DatabaseObjectStatus `json:"servers,omitempty"`
321356}
322357
323358// DatabaseObjectStatus is the status of the managed database objects
0 commit comments