Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3b899b1
WIP
xocasdashdash Oct 26, 2024
1626ba5
formatted
xocasdashdash Oct 26, 2024
040de4b
added default grant type, implemented an initial version of the contr…
xocasdashdash Oct 26, 2024
b39d843
updated generated files
xocasdashdash Oct 26, 2024
56cc0d2
fixed tests
xocasdashdash Oct 26, 2024
8f94522
added an example
xocasdashdash Oct 26, 2024
958db2f
lint issues
xocasdashdash Oct 26, 2024
51cfe0d
added DefaultGrant to the crossplane package definition
xocasdashdash Oct 27, 2024
dccf1f8
renamed from DefaultGrants to DefaultPrivileges
xocasdashdash Oct 27, 2024
55cbe73
added resolver back and added one more object type to the list of res…
xocasdashdash Oct 27, 2024
6074590
added missing target role to CRD
xocasdashdash Oct 27, 2024
62241e3
renamed example to match expected value
xocasdashdash Oct 27, 2024
0e978db
fixed syntax issue related to https://github.com/crossplane/crossplan…
xocasdashdash Oct 27, 2024
2272420
added default privileges to the schema and fixed a typo
xocasdashdash Oct 27, 2024
7be0aa2
more fixes and added some debugging
xocasdashdash Oct 27, 2024
fd1c4c7
made revoke more simple by just revoking all, fixed bug on grant query
xocasdashdash Oct 27, 2024
c645665
fixed an issue when searching for default privileges
xocasdashdash Oct 27, 2024
1f9b69b
fix some linting issues
xocasdashdash Oct 7, 2025
8c69144
fix: adapt for v2, fix default privileges and add examples and tests
fernandezcuesta Feb 11, 2026
97e9014
Merge pull request #1 from fernandezcuesta/follow-up
xocasdashdash Feb 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Check the example:
2. Create managed resources for your SQL server flavor:

- **MySQL**: `Database`, `Grant`, `User` (See [the examples](examples/mysql))
- **PostgreSQL**: `Database`, `Grant`, `Extension`, `Role` (See [the examples](examples/postgresql))
- **PostgreSQL**: `Database`, `Grant`, `DefaultPrivileges`, `Extension`, `Role` (See [the examples](examples/postgresql))
- **MSSQL**: `Database`, `Grant`, `User` (See [the examples](examples/mssql))

[crossplane]: https://crossplane.io
Expand Down
109 changes: 109 additions & 0 deletions apis/cluster/postgresql/v1alpha1/default_privileges_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package v1alpha1

import (
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:object:root=true

// A DefaultPrivileges represents the declarative state of a PostgreSQL DefaultPrivileges.
// +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="TARGET_ROLE",type="string",JSONPath=".spec.forProvider.targetRole"
// +kubebuilder:printcolumn:name="SCHEMA",type="string",JSONPath=".spec.forProvider.schema"
// +kubebuilder:printcolumn:name="DATABASE",type="string",JSONPath=".spec.forProvider.database"
// +kubebuilder:printcolumn:name="PRIVILEGES",type="string",JSONPath=".spec.forProvider.privileges"
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,sql}
type DefaultPrivileges struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DefaultPrivilegesSpec `json:"spec"`
Status DefaultPrivilegesStatus `json:"status,omitempty"`
}

// A DefaultPrivilegesSpec defines the desired state of a Default Grant.
type DefaultPrivilegesSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider DefaultPrivilegesParameters `json:"forProvider"`
}

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

// DefaultPrivilegesParameters defines the desired state of a Default Grant.
type DefaultPrivilegesParameters struct {
// Privileges to be granted.
// See https://www.postgresql.org/docs/current/sql-grant.html for available privileges.
// +optional
Privileges GrantPrivileges `json:"privileges,omitempty"`

// TargetRole is the role whose future objects will have default privileges applied.
// When this role creates new objects, the specified privileges are automatically
// granted. Maps to FOR ROLE in ALTER DEFAULT PRIVILEGES.
// See https://www.postgresql.org/docs/current/sql-alterdefaultprivileges.html
// +required
TargetRole *string `json:"targetRole"`

// ObjectType to which the privileges are granted.
// +kubebuilder:validation:Enum=table;sequence;function;schema;type
// +required
ObjectType *string `json:"objectType,omitempty"`

// WithOption allows an option to be set on the grant.
// See https://www.postgresql.org/docs/current/sql-grant.html for available
// options for each grant type, and the effects of applying the option.
// +kubebuilder:validation:Enum=ADMIN;GRANT
// +optional
WithOption *GrantOption `json:"withOption,omitempty"`

// Role is the role that will receive the default privileges (the grantee).
// Maps to TO in ALTER DEFAULT PRIVILEGES ... GRANT ... TO role.
// +optional
// +crossplane:generate:reference:type=Role
Role *string `json:"role,omitempty"`

// RoleRef to which default privileges are granted.
// +immutable
// +optional
RoleRef *xpv1.Reference `json:"roleRef,omitempty"`

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

// Database in which the default privileges are applied
// +optional
// +crossplane:generate:reference:type=Database
Database *string `json:"database,omitempty"`

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

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

// Schema in which the default privileges are applied
// +required
Schema *string `json:"schema,omitempty"`
}

// +kubebuilder:object:root=true

// DefaultPrivilegesList contains a list of DefaultPrivileges.
type DefaultPrivilegesList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DefaultPrivileges `json:"items"`
}
9 changes: 9 additions & 0 deletions apis/cluster/postgresql/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ var (
GrantGroupVersionKind = SchemeGroupVersion.WithKind(GrantKind)
)

// DefaultPrivileges type metadata.
var (
DefaultPrivilegesKind = reflect.TypeOf(DefaultPrivileges{}).Name()
DefaultPrivilegesGroupKind = schema.GroupKind{Group: Group, Kind: DefaultPrivilegesKind}.String()
DefaultPrivilegesKindAPIVersion = DefaultPrivilegesKind + "." + SchemeGroupVersion.String()
DefaultPrivilegesGroupVersionKind = SchemeGroupVersion.WithKind(DefaultPrivilegesKind)
)

// Schema type metadata.
var (
SchemaKind = reflect.TypeOf(Schema{}).Name()
Expand All @@ -106,4 +114,5 @@ func init() {
SchemeBuilder.Register(&Grant{}, &GrantList{})
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
SchemeBuilder.Register(&Schema{}, &SchemaList{})
SchemeBuilder.Register(&DefaultPrivileges{}, &DefaultPrivilegesList{})
}
162 changes: 162 additions & 0 deletions apis/cluster/postgresql/v1alpha1/zz_generated.deepcopy.go

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

50 changes: 50 additions & 0 deletions apis/cluster/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/cluster/postgresql/v1alpha1/zz_generated.managedlist.go

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

Loading