Skip to content

Commit 15b7298

Browse files
chlundelarhauga
andauthored
PostgreSQL CREATE SCHEMA support (#181)
* Schema controller for PostgreSQL This adds support for CREATE SCHEMA (not any DDL like Schema hero). This is needed to run third party solutions that require the schema to exist, like grafana operator and temporal operator. Co-authored-by: Lars Haugan <[email protected]> Signed-off-by: Carl Henrik Lunde <[email protected]> * Generate files for PostgreSQL Schema Signed-off-by: Carl Henrik Lunde <[email protected]> * Expand PostgreSQL config example to include secret and ssl mode, docker info Signed-off-by: Carl Henrik Lunde <[email protected]> * Avoid new(string) and use nicer ptr.To values in test Signed-off-by: Carl Henrik Lunde <[email protected]> --------- Signed-off-by: Carl Henrik Lunde <[email protected]> Co-authored-by: Lars Haugan <[email protected]>
1 parent 6162fb8 commit 15b7298

File tree

12 files changed

+1653
-0
lines changed

12 files changed

+1653
-0
lines changed

apis/postgresql/v1alpha1/register.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,20 @@ var (
9090
GrantGroupVersionKind = SchemeGroupVersion.WithKind(GrantKind)
9191
)
9292

93+
// Schema type metadata.
94+
var (
95+
SchemaKind = reflect.TypeOf(Schema{}).Name()
96+
SchemaGroupKind = schema.GroupKind{Group: Group, Kind: SchemaKind}.String()
97+
SchemaKindAPIVersion = SchemaKind + "." + SchemeGroupVersion.String()
98+
SchemaGroupVersionKind = SchemeGroupVersion.WithKind(SchemaKind)
99+
)
100+
93101
func init() {
94102
SchemeBuilder.Register(&ProviderConfig{}, &ProviderConfigList{})
95103
SchemeBuilder.Register(&ProviderConfigUsage{}, &ProviderConfigUsageList{})
96104
SchemeBuilder.Register(&Database{}, &DatabaseList{})
97105
SchemeBuilder.Register(&Role{}, &RoleList{})
98106
SchemeBuilder.Register(&Grant{}, &GrantList{})
99107
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
108+
SchemeBuilder.Register(&Schema{}, &SchemaList{})
100109
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2024 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
23+
)
24+
25+
// A SchemaSpec defines the desired state of a Schema.
26+
type SchemaSpec struct {
27+
xpv1.ResourceSpec `json:",inline"`
28+
ForProvider SchemaParameters `json:"forProvider"`
29+
}
30+
31+
// SchemaParameters define the desired state of a PostgreSQL schema.
32+
type SchemaParameters struct {
33+
// Role for ownership of this schema.
34+
// +optional
35+
// +crossplane:generate:reference:type=Role
36+
Role *string `json:"role,omitempty"`
37+
38+
// RoleRef references the role object this schema is for.
39+
// +immutable
40+
// +optional
41+
RoleRef *xpv1.Reference `json:"roleRef,omitempty"`
42+
43+
// RoleSelector selects a reference to a Role this schema is for.
44+
// +immutable
45+
// +optional
46+
RoleSelector *xpv1.Selector `json:"roleSelector,omitempty"`
47+
48+
// Database this schema is for.
49+
// +optional
50+
// +crossplane:generate:reference:type=Database
51+
Database *string `json:"database,omitempty"`
52+
53+
// DatabaseRef references the database object this schema is for.
54+
// +immutable
55+
// +optional
56+
DatabaseRef *xpv1.Reference `json:"databaseRef,omitempty"`
57+
58+
// DatabaseSelector selects a reference to a Database this schema is for.
59+
// +immutable
60+
// +optional
61+
DatabaseSelector *xpv1.Selector `json:"databaseSelector,omitempty"`
62+
}
63+
64+
// A SchemaStatus represents the observed state of a Schema.
65+
type SchemaStatus struct {
66+
xpv1.ResourceStatus `json:",inline"`
67+
}
68+
69+
// +kubebuilder:object:root=true
70+
71+
// A Schema represents the declarative state of a PostgreSQL schema.
72+
// +kubebuilder:subresource:status
73+
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
74+
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
75+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
76+
// +kubebuilder:printcolumn:name="ROLE",type="string",JSONPath=".spec.forProvider.role"
77+
// +kubebuilder:printcolumn:name="DATABASE",type="string",JSONPath=".spec.forProvider.database"
78+
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,sql}
79+
type Schema struct {
80+
metav1.TypeMeta `json:",inline"`
81+
metav1.ObjectMeta `json:"metadata,omitempty"`
82+
83+
Spec SchemaSpec `json:"spec"`
84+
Status SchemaStatus `json:"status,omitempty"`
85+
}
86+
87+
// +kubebuilder:object:root=true
88+
89+
// SchemaList contains a list of Schema
90+
type SchemaList struct {
91+
metav1.TypeMeta `json:",inline"`
92+
metav1.ListMeta `json:"metadata,omitempty"`
93+
Items []Schema `json:"items"`
94+
}

apis/postgresql/v1alpha1/zz_generated.deepcopy.go

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/postgresql/v1alpha1/zz_generated.managed.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/postgresql/v1alpha1/zz_generated.managedlist.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)