Skip to content

Commit

Permalink
Merge pull request #285 from ulucinar/postgresql-config
Browse files Browse the repository at this point in the history
Add PostgreSQLServerConfiguration managed resource
  • Loading branch information
ulucinar authored Aug 27, 2021
2 parents faab5b5 + 84959ca commit 33f728d
Show file tree
Hide file tree
Showing 29 changed files with 1,523 additions and 17 deletions.
142 changes: 142 additions & 0 deletions apis/database/v1beta1/configuration_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
Copyright 2021 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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

apisv1alpha3 "github.com/crossplane/provider-azure/apis/v1alpha3"
)

// +kubebuilder:object:root=true

// A PostgreSQLServerConfiguration is a managed resource that represents an Azure
// PostgreSQL Server Configuration.
// +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="VERSION",type="string",JSONPath=".spec.forProvider.version"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
type PostgreSQLServerConfiguration struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SQLServerConfigurationSpec `json:"spec"`
Status SQLServerConfigurationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

// SQLServerConfigurationParameters define the desired state of an Azure SQL
// Database Server Configuration, either PostgreSQL or MySQL Configuration.
type SQLServerConfigurationParameters struct {
// ResourceGroupName specifies the name of the resource group that should
// contain this SQLServer.
// +immutable
ResourceGroupName string `json:"resourceGroupName,omitempty"`

// ResourceGroupNameRef - A reference to a ResourceGroup object to retrieve
// its name
// +immutable
ResourceGroupNameRef *xpv1.Reference `json:"resourceGroupNameRef,omitempty"`

// ResourceGroupNameSelector - A selector for a ResourceGroup object to
// retrieve its name
// +immutable
ResourceGroupNameSelector *xpv1.Selector `json:"resourceGroupNameSelector,omitempty"`

// ServerName specifies the name of the server that this
// configuration applies to.
// +immutable
ServerName string `json:"serverName,omitempty"`

// ServerNameRef - A reference to a PostgreSQLServer object to retrieve
// its name
// +immutable
ServerNameRef *xpv1.Reference `json:"serverNameRef,omitempty"`

// ServerNameSelector - A selector for a PostgreSQLServer object to
// retrieve its name
// +immutable
ServerNameSelector *xpv1.Selector `json:"serverNameSelector,omitempty"`

// Name - Configuration name to be applied
// +kubebuilder:validation:Required
// +immutable
Name string `json:"name"`

// Value - Configuration value to be applied
// Can be left unset to read the current value
// as a result of late-initialization.
// +kubebuilder:validation:Optional
Value *string `json:"value,omitempty"`
}

// A SQLServerConfigurationSpec defines the desired state of a SQLServer
// Configuration.
type SQLServerConfigurationSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider SQLServerConfigurationParameters `json:"forProvider"`
}

// SQLServerConfigurationObservation represents the current state of Azure SQL resource.
type SQLServerConfigurationObservation struct {
// ID - Resource ID
ID string `json:"id,omitempty"`

// Name - Resource name.
Name string `json:"name,omitempty"`

// Type - Resource type.
Type string `json:"type,omitempty"`

// DataType - Data type for the configuration
DataType string `json:"dataType,omitempty"`

// Value - Applied configuration value
Value string `json:"value,omitempty"`

// DefaultValue - Default value for this configuration
DefaultValue string `json:"defaultValue,omitempty"`

// Source - Applied configuration source
Source string `json:"source,omitempty"`

// Description - Description for the configuration
Description string `json:"description,omitempty"`

// LastOperation represents the state of the last operation started by the
// controller.
LastOperation apisv1alpha3.AsyncOperation `json:"lastOperation,omitempty"`
}

// A SQLServerConfigurationStatus represents the observed state of a
// SQLServerConfiguration.
type SQLServerConfigurationStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider SQLServerConfigurationObservation `json:"atProvider,omitempty"`
}
35 changes: 35 additions & 0 deletions apis/database/v1beta1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,38 @@ func (mg *PostgreSQLServer) ResolveReferences(ctx context.Context, c client.Read

return nil
}

// ResolveReferences of this PostgreSQLServerConfiguration.
func (mg *PostgreSQLServerConfiguration) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// Resolve spec.forProvider.resourceGroupName
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ForProvider.ResourceGroupName,
Reference: mg.Spec.ForProvider.ResourceGroupNameRef,
Selector: mg.Spec.ForProvider.ResourceGroupNameSelector,
To: reference.To{Managed: &v1alpha3.ResourceGroup{}, List: &v1alpha3.ResourceGroupList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.resourceGroupName")
}
mg.Spec.ForProvider.ResourceGroupName = rsp.ResolvedValue
mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference

// Resolve spec.forProvider.resourceGroupName
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ForProvider.ServerName,
Reference: mg.Spec.ForProvider.ServerNameRef,
Selector: mg.Spec.ForProvider.ServerNameSelector,
To: reference.To{Managed: &PostgreSQLServer{}, List: &PostgreSQLServerList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.serverName")
}
mg.Spec.ForProvider.ServerName = rsp.ResolvedValue
mg.Spec.ForProvider.ServerNameRef = rsp.ResolvedReference

return nil
}
9 changes: 9 additions & 0 deletions apis/database/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ var (
PostgreSQLServerGroupVersionKind = SchemeGroupVersion.WithKind(PostgreSQLServerKind)
)

// PostgreSQLServerConfiguration type metadata.
var (
PostgreSQLServerConfigurationKind = reflect.TypeOf(PostgreSQLServerConfiguration{}).Name()
PostgreSQLServerConfigurationGroupKind = schema.GroupKind{Group: Group, Kind: PostgreSQLServerConfigurationKind}.String()
PostgreSQLServerConfigurationKindAPIVersion = PostgreSQLServerConfigurationKind + "." + SchemeGroupVersion.String()
PostgreSQLServerConfigurationGroupVersionKind = SchemeGroupVersion.WithKind(PostgreSQLServerConfigurationKind)
)

func init() {
SchemeBuilder.Register(&MySQLServer{}, &MySQLServerList{})
SchemeBuilder.Register(&PostgreSQLServer{}, &PostgreSQLServerList{})
SchemeBuilder.Register(&PostgreSQLServerConfiguration{}, &PostgreSQLServerConfigurationList{})
}
149 changes: 149 additions & 0 deletions apis/database/v1beta1/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 33f728d

Please sign in to comment.