Skip to content

Commit

Permalink
feat: add psql database, update crossplane-runtime, add shortnames (#250
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cristiGuranIonos authored Jul 9, 2024
1 parent 2a8aa1d commit 1452c35
Show file tree
Hide file tree
Showing 56 changed files with 1,812 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apis/alb/v1alpha1/applicationloadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type ApplicationLoadBalancerStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=alb;applicationlb
type ApplicationLoadBalancer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion apis/backup/v1alpha1/backupunit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type BackupUnitStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=bu;bkpunit
type BackupUnit struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion apis/compute/v1alpha1/firewallrule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type FirewallRuleStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=fwr;firewall
type FirewallRule struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion apis/dataplatform/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type DataplatformClusterStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=dpc;datapc
type DataplatformCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion apis/dataplatform/v1alpha1/nodepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type DataplatformNodepoolStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=dpn;datanp
type DataplatformNodepool struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion apis/dbaas/mongo/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ type ClusterStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=mc;mongoc;mongocluster
type MongoCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion apis/dbaas/postgres/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type ClusterStatus struct {
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.atProvider.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=psqlc;pgc
type PostgresCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
120 changes: 120 additions & 0 deletions apis/dbaas/postgres/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Copyright 2020 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 (
"reflect"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

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

// PostgresDatabaseParameters are the observable fields of a Database.
// Required fields in order to create a DBaaS Database:
// ClusterConfig,
// Name,
// Owner,
type PostgresDatabaseParameters struct {
// +kubebuilder:validation:Required
//
ClusterCfg ClusterConfig `json:"clusterConfig"`
// The database name.
//
// +kubebuilder:validation:Required
Name string `json:"name"`
// The name of the role owning a given database.
//
// +kubebuilder:validation:Required
Owner UserConfig `json:"owner"`
}

// +kubebuilder:object:root=true

// A PostgresDatabase is an example API type.
// +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="Database ID",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=pgdb;psqldb;pgdb
type PostgresDatabase struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PostgresDatabaseSpec `json:"spec"`
Status DatabaseStatus `json:"status,omitempty"`
}

// A DatabaseStatus represents the observed state of a Database.
type DatabaseStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider DatabaseObservation `json:"atProvider,omitempty"`
}

// DatabaseObservation are the observable fields of a Database.
type DatabaseObservation struct {
DatabaseID string `json:"DatabaseId,omitempty"`
}

// A PostgresDatabaseSpec defines the desired state of a Database.
type PostgresDatabaseSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider PostgresDatabaseParameters `json:"forProvider"`
}

// +kubebuilder:object:root=true

// PostgresDatabaseList contains a list of Database
type PostgresDatabaseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PostgresDatabase `json:"items"`
}

// UserConfig is used by resources that need to link postgres users via id or via reference.
type UserConfig struct {
// UserName is the Name of the User on which the resource will be created.
// It needs to be provided directly or via reference.
//
// +immutable
// +crossplane:generate:reference:type=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/dbaas/postgres/v1alpha1.PostgresUser
// +crossplane:generate:reference:extractor=github.com/ionos-cloud/crossplane-provider-ionoscloud/apis/dbaas/postgres/v1alpha1.ExtractPostgresUserID()
UserName string `json:"userName,omitempty"`
// UserIDRef references to a User to retrieve its Name.
//
// +optional
// +immutable
UserNameRef *xpv1.Reference `json:"UserNameRef,omitempty"`
// UserNameSelector selects reference to a User to retrieve its UserName.
//
// +optional
UserNameSelector *xpv1.Selector `json:"UserNameSelector,omitempty"`
}

// Cluster type metadata.
var (
PostgresDatabaseKind = reflect.TypeOf(PostgresDatabase{}).Name()
PostgresDatabaseGroupKind = schema.GroupKind{Group: Group, Kind: PostgresDatabaseKind}.String()
PostgresDatabaseKindAPIVersion = PostgresDatabaseKind + "." + SchemeGroupVersion.String()
PostgresDatabaseGroupVersionKind = SchemeGroupVersion.WithKind(PostgresDatabaseKind)
)

func init() {
SchemeBuilder.Register(&PostgresDatabase{}, &PostgresDatabaseList{})
}
14 changes: 14 additions & 0 deletions apis/dbaas/postgres/v1alpha1/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ func ExtractPostgresClusterID() reference.ExtractValueFn {
return meta.GetExternalName(res)
}
}

// ExtractPostgresUserID returns the externalName of a referenced User.
func ExtractPostgresUserID() reference.ExtractValueFn {
return func(mg resource.Managed) string {
res, ok := mg.(*PostgresUser)
if !ok {
return ""
}
if meta.GetExternalName(res) == res.Name {
return ""
}
return meta.GetExternalName(res)
}
}
2 changes: 1 addition & 1 deletion apis/dbaas/postgres/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type ClusterConfig struct {
// +kubebuilder:printcolumn:name="USERNAME",priority=1,type="string",JSONPath=".spec.forProvider.credentials.username"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud}
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,ionoscloud},shortName=pgu;pguser;psqlu
type PostgresUser struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
150 changes: 150 additions & 0 deletions apis/dbaas/postgres/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 1452c35

Please sign in to comment.