Skip to content

Commit

Permalink
PostgreSQL CREATE SCHEMA support (#181)
Browse files Browse the repository at this point in the history
* 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 <456305+larhauga@users.noreply.github.com>
Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>

* Generate files for PostgreSQL Schema

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>

* Expand PostgreSQL config example to include secret and ssl mode, docker info

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>

* Avoid new(string) and use nicer ptr.To values in test

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>

---------

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>
Co-authored-by: Lars Haugan <456305+larhauga@users.noreply.github.com>
  • Loading branch information
chlunde and larhauga authored Jun 10, 2024
1 parent 6162fb8 commit 15b7298
Show file tree
Hide file tree
Showing 12 changed files with 1,653 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apis/postgresql/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ var (
GrantGroupVersionKind = SchemeGroupVersion.WithKind(GrantKind)
)

// Schema type metadata.
var (
SchemaKind = reflect.TypeOf(Schema{}).Name()
SchemaGroupKind = schema.GroupKind{Group: Group, Kind: SchemaKind}.String()
SchemaKindAPIVersion = SchemaKind + "." + SchemeGroupVersion.String()
SchemaGroupVersionKind = SchemeGroupVersion.WithKind(SchemaKind)
)

func init() {
SchemeBuilder.Register(&ProviderConfig{}, &ProviderConfigList{})
SchemeBuilder.Register(&ProviderConfigUsage{}, &ProviderConfigUsageList{})
SchemeBuilder.Register(&Database{}, &DatabaseList{})
SchemeBuilder.Register(&Role{}, &RoleList{})
SchemeBuilder.Register(&Grant{}, &GrantList{})
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
SchemeBuilder.Register(&Schema{}, &SchemaList{})
}
94 changes: 94 additions & 0 deletions apis/postgresql/v1alpha1/schema_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copyright 2024 The Crossplane Authors.
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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// A SchemaSpec defines the desired state of a Schema.
type SchemaSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider SchemaParameters `json:"forProvider"`
}

// SchemaParameters define the desired state of a PostgreSQL schema.
type SchemaParameters struct {
// Role for ownership of this schema.
// +optional
// +crossplane:generate:reference:type=Role
Role *string `json:"role,omitempty"`

// RoleRef references the role object this schema is for.
// +immutable
// +optional
RoleRef *xpv1.Reference `json:"roleRef,omitempty"`

// RoleSelector selects a reference to a Role this schema is for.
// +immutable
// +optional
RoleSelector *xpv1.Selector `json:"roleSelector,omitempty"`

// Database this schema is for.
// +optional
// +crossplane:generate:reference:type=Database
Database *string `json:"database,omitempty"`

// DatabaseRef references the database object this schema is for.
// +immutable
// +optional
DatabaseRef *xpv1.Reference `json:"databaseRef,omitempty"`

// DatabaseSelector selects a reference to a Database this schema is for.
// +immutable
// +optional
DatabaseSelector *xpv1.Selector `json:"databaseSelector,omitempty"`
}

// A SchemaStatus represents the observed state of a Schema.
type SchemaStatus struct {
xpv1.ResourceStatus `json:",inline"`
}

// +kubebuilder:object:root=true

// A Schema represents the declarative state of a PostgreSQL schema.
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="ROLE",type="string",JSONPath=".spec.forProvider.role"
// +kubebuilder:printcolumn:name="DATABASE",type="string",JSONPath=".spec.forProvider.database"
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,sql}
type Schema struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SchemaSpec `json:"spec"`
Status SchemaStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// SchemaList contains a list of Schema
type SchemaList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Schema `json:"items"`
}
137 changes: 137 additions & 0 deletions apis/postgresql/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions apis/postgresql/v1alpha1/zz_generated.managed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions apis/postgresql/v1alpha1/zz_generated.managedlist.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15b7298

Please sign in to comment.