From 8e580ea98090052beb47d13e704e03531b3405b0 Mon Sep 17 00:00:00 2001 From: Dkaykay Date: Wed, 14 Apr 2021 13:00:12 +0200 Subject: [PATCH] feat: implement AWS RDS DB ParameterGroups Signed-off-by: Dkaykay --- apis/rds/v1alpha1/custom_types.go | 7 + apis/rds/v1alpha1/generator-config.yaml | 5 +- apis/rds/v1alpha1/zz_db_parameter_group.go | 107 ++++++++ apis/rds/v1alpha1/zz_generated.deepcopy.go | 246 +++++++++++++++++- apis/rds/v1alpha1/zz_generated.managed.go | 56 ++++ apis/rds/v1alpha1/zz_generated.managedlist.go | 9 + apis/rds/v1alpha1/zz_types.go | 24 +- examples/rds/dbparametergroup.yaml | 15 ++ ...s.aws.crossplane.io_dbparametergroups.yaml | 198 ++++++++++++++ pkg/controller/aws.go | 2 + pkg/controller/rds/dbparametergroup/setup.go | 148 +++++++++++ .../rds/dbparametergroup/zz_controller.go | 239 +++++++++++++++++ .../rds/dbparametergroup/zz_conversions.go | 113 ++++++++ 13 files changed, 1151 insertions(+), 18 deletions(-) create mode 100644 apis/rds/v1alpha1/zz_db_parameter_group.go create mode 100644 examples/rds/dbparametergroup.yaml create mode 100644 package/crds/rds.aws.crossplane.io_dbparametergroups.yaml create mode 100644 pkg/controller/rds/dbparametergroup/setup.go create mode 100644 pkg/controller/rds/dbparametergroup/zz_controller.go create mode 100644 pkg/controller/rds/dbparametergroup/zz_conversions.go diff --git a/apis/rds/v1alpha1/custom_types.go b/apis/rds/v1alpha1/custom_types.go index 99b331c2ee..f9dc2e73a8 100644 --- a/apis/rds/v1alpha1/custom_types.go +++ b/apis/rds/v1alpha1/custom_types.go @@ -18,6 +18,13 @@ package v1alpha1 import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" +// CustomDBParameterGroupParameters are custom parameters for DBParameterGroup +type CustomDBParameterGroupParameters struct { + // A list of parameters to associate with this DB parameter group + // +optional + Parameters []Parameter `json:"parameters,omitempty"` +} + // CustomDBClusterParameters are custom parameters for DBCluster type CustomDBClusterParameters struct { diff --git a/apis/rds/v1alpha1/generator-config.yaml b/apis/rds/v1alpha1/generator-config.yaml index a4e3856277..28c333bb0a 100644 --- a/apis/rds/v1alpha1/generator-config.yaml +++ b/apis/rds/v1alpha1/generator-config.yaml @@ -9,6 +9,10 @@ ignore: - CreateDBClusterInput.VpcSecurityGroupIds - ModifyDBClusterInput.VpcSecurityGroupIds - DBCluster.PendingModifiedValues + - CreateDBParameterGroupInput.DBParameterGroupName + - DeleteDBParameterGroupInput.DBParameterGroupName + - ModifyDBParameterGroupInput.DBParameterGroupName + - DescribeDBParameterGroupsInput.DBParameterGroupName resource_names: - DBClusterEndpoint - CustomAvailabilityZone @@ -16,7 +20,6 @@ ignore: - DBClusterSnapshot - DBInstance - DBInstanceReadReplica - - DBParameterGroup - DBProxy - DBSecurityGroup - DBSnapshot diff --git a/apis/rds/v1alpha1/zz_db_parameter_group.go b/apis/rds/v1alpha1/zz_db_parameter_group.go new file mode 100644 index 0000000000..4d57deab72 --- /dev/null +++ b/apis/rds/v1alpha1/zz_db_parameter_group.go @@ -0,0 +1,107 @@ +/* +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. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package v1alpha1 + +import ( + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// DBParameterGroupParameters defines the desired state of DBParameterGroup +type DBParameterGroupParameters struct { + // Region is which region the DBParameterGroup will be created. + // +kubebuilder:validation:Required + Region string `json:"region"` + // The DB parameter group family name. A DB parameter group can be associated + // with one and only one DB parameter group family, and can be applied only + // to a DB instance running a database engine and engine version compatible + // with that DB parameter group family. + // + // To list all of the available parameter group families, use the following + // command: + // + // aws rds describe-db-engine-versions --query "DBEngineVersions[].DBParameterGroupFamily" + // + // The output contains duplicates. + // +kubebuilder:validation:Required + DBParameterGroupFamily *string `json:"dbParameterGroupFamily"` + // The description for the DB parameter group. + // +kubebuilder:validation:Required + Description *string `json:"description"` + // Tags to assign to the DB parameter group. + Tags []*Tag `json:"tags,omitempty"` + CustomDBParameterGroupParameters `json:",inline"` +} + +// DBParameterGroupSpec defines the desired state of DBParameterGroup +type DBParameterGroupSpec struct { + xpv1.ResourceSpec `json:",inline"` + ForProvider DBParameterGroupParameters `json:"forProvider"` +} + +// DBParameterGroupObservation defines the observed state of DBParameterGroup +type DBParameterGroupObservation struct { + // The Amazon Resource Name (ARN) for the DB parameter group. + DBParameterGroupARN *string `json:"dbParameterGroupARN,omitempty"` + // The name of the DB parameter group. + DBParameterGroupName *string `json:"dbParameterGroupName,omitempty"` +} + +// DBParameterGroupStatus defines the observed state of DBParameterGroup. +type DBParameterGroupStatus struct { + xpv1.ResourceStatus `json:",inline"` + AtProvider DBParameterGroupObservation `json:"atProvider"` +} + +// +kubebuilder:object:root=true + +// DBParameterGroup is the Schema for the DBParameterGroups API +// +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="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,aws} +type DBParameterGroup struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec DBParameterGroupSpec `json:"spec,omitempty"` + Status DBParameterGroupStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// DBParameterGroupList contains a list of DBParameterGroups +type DBParameterGroupList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []DBParameterGroup `json:"items"` +} + +// Repository type metadata. +var ( + DBParameterGroupKind = "DBParameterGroup" + DBParameterGroupGroupKind = schema.GroupKind{Group: Group, Kind: DBParameterGroupKind}.String() + DBParameterGroupKindAPIVersion = DBParameterGroupKind + "." + GroupVersion.String() + DBParameterGroupGroupVersionKind = GroupVersion.WithKind(DBParameterGroupKind) +) + +func init() { + SchemeBuilder.Register(&DBParameterGroup{}, &DBParameterGroupList{}) +} diff --git a/apis/rds/v1alpha1/zz_generated.deepcopy.go b/apis/rds/v1alpha1/zz_generated.deepcopy.go index f8ad0b2418..f88a32ce70 100644 --- a/apis/rds/v1alpha1/zz_generated.deepcopy.go +++ b/apis/rds/v1alpha1/zz_generated.deepcopy.go @@ -412,6 +412,28 @@ func (in *CustomDBClusterParameters) DeepCopy() *CustomDBClusterParameters { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomDBParameterGroupParameters) DeepCopyInto(out *CustomDBParameterGroupParameters) { + *out = *in + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + *out = make([]Parameter, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomDBParameterGroupParameters. +func (in *CustomDBParameterGroupParameters) DeepCopy() *CustomDBParameterGroupParameters { + if in == nil { + return nil + } + out := new(CustomDBParameterGroupParameters) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DBCluster) DeepCopyInto(out *DBCluster) { *out = *in @@ -1701,6 +1723,17 @@ func (in *DBEngineVersion) DeepCopyInto(out *DBEngineVersion) { *out = new(string) **out = **in } + if in.SupportedEngineModes != nil { + in, out := &in.SupportedEngineModes, &out.SupportedEngineModes + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } if in.SupportsGlobalDatabases != nil { in, out := &in.SupportsGlobalDatabases, &out.SupportsGlobalDatabases *out = new(bool) @@ -2211,19 +2244,93 @@ func (in *DBInstanceStatusInfo) DeepCopy() *DBInstanceStatusInfo { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DBParameterGroup) DeepCopyInto(out *DBParameterGroup) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroup. +func (in *DBParameterGroup) DeepCopy() *DBParameterGroup { + if in == nil { + return nil + } + out := new(DBParameterGroup) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DBParameterGroup) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBParameterGroupList) DeepCopyInto(out *DBParameterGroupList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]DBParameterGroup, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupList. +func (in *DBParameterGroupList) DeepCopy() *DBParameterGroupList { + if in == nil { + return nil + } + out := new(DBParameterGroupList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DBParameterGroupList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBParameterGroupObservation) DeepCopyInto(out *DBParameterGroupObservation) { *out = *in if in.DBParameterGroupARN != nil { in, out := &in.DBParameterGroupARN, &out.DBParameterGroupARN *out = new(string) **out = **in } - if in.DBParameterGroupFamily != nil { - in, out := &in.DBParameterGroupFamily, &out.DBParameterGroupFamily + if in.DBParameterGroupName != nil { + in, out := &in.DBParameterGroupName, &out.DBParameterGroupName *out = new(string) **out = **in } - if in.DBParameterGroupName != nil { - in, out := &in.DBParameterGroupName, &out.DBParameterGroupName +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupObservation. +func (in *DBParameterGroupObservation) DeepCopy() *DBParameterGroupObservation { + if in == nil { + return nil + } + out := new(DBParameterGroupObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBParameterGroupParameters) DeepCopyInto(out *DBParameterGroupParameters) { + *out = *in + if in.DBParameterGroupFamily != nil { + in, out := &in.DBParameterGroupFamily, &out.DBParameterGroupFamily *out = new(string) **out = **in } @@ -2232,20 +2339,66 @@ func (in *DBParameterGroup) DeepCopyInto(out *DBParameterGroup) { *out = new(string) **out = **in } + if in.Tags != nil { + in, out := &in.Tags, &out.Tags + *out = make([]*Tag, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(Tag) + (*in).DeepCopyInto(*out) + } + } + } + in.CustomDBParameterGroupParameters.DeepCopyInto(&out.CustomDBParameterGroupParameters) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroup. -func (in *DBParameterGroup) DeepCopy() *DBParameterGroup { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupParameters. +func (in *DBParameterGroupParameters) DeepCopy() *DBParameterGroupParameters { if in == nil { return nil } - out := new(DBParameterGroup) + out := new(DBParameterGroupParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBParameterGroupSpec) DeepCopyInto(out *DBParameterGroupSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + in.ForProvider.DeepCopyInto(&out.ForProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupSpec. +func (in *DBParameterGroupSpec) DeepCopy() *DBParameterGroupSpec { + if in == nil { + return nil + } + out := new(DBParameterGroupSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DBParameterGroupStatus) DeepCopyInto(out *DBParameterGroupStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupStatus. +func (in *DBParameterGroupStatus) DeepCopy() *DBParameterGroupStatus { + if in == nil { + return nil + } + out := new(DBParameterGroupStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBParameterGroupStatus_SDK) DeepCopyInto(out *DBParameterGroupStatus_SDK) { *out = *in if in.DBParameterGroupName != nil { in, out := &in.DBParameterGroupName, &out.DBParameterGroupName @@ -2259,12 +2412,47 @@ func (in *DBParameterGroupStatus) DeepCopyInto(out *DBParameterGroupStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupStatus. -func (in *DBParameterGroupStatus) DeepCopy() *DBParameterGroupStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroupStatus_SDK. +func (in *DBParameterGroupStatus_SDK) DeepCopy() *DBParameterGroupStatus_SDK { if in == nil { return nil } - out := new(DBParameterGroupStatus) + out := new(DBParameterGroupStatus_SDK) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DBParameterGroup_SDK) DeepCopyInto(out *DBParameterGroup_SDK) { + *out = *in + if in.DBParameterGroupARN != nil { + in, out := &in.DBParameterGroupARN, &out.DBParameterGroupARN + *out = new(string) + **out = **in + } + if in.DBParameterGroupFamily != nil { + in, out := &in.DBParameterGroupFamily, &out.DBParameterGroupFamily + *out = new(string) + **out = **in + } + if in.DBParameterGroupName != nil { + in, out := &in.DBParameterGroupName, &out.DBParameterGroupName + *out = new(string) + **out = **in + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DBParameterGroup_SDK. +func (in *DBParameterGroup_SDK) DeepCopy() *DBParameterGroup_SDK { + if in == nil { + return nil + } + out := new(DBParameterGroup_SDK) in.DeepCopyInto(out) return out } @@ -2849,6 +3037,17 @@ func (in *EngineDefaults) DeepCopyInto(out *EngineDefaults) { *out = new(string) **out = **in } + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + *out = make([]*Parameter, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(Parameter) + (*in).DeepCopyInto(*out) + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EngineDefaults. @@ -3733,6 +3932,17 @@ func (in *OrderableDBInstanceOption) DeepCopyInto(out *OrderableDBInstanceOption *out = new(string) **out = **in } + if in.SupportedEngineModes != nil { + in, out := &in.SupportedEngineModes, &out.SupportedEngineModes + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } if in.SupportsEnhancedMonitoring != nil { in, out := &in.SupportsEnhancedMonitoring, &out.SupportsEnhancedMonitoring *out = new(bool) @@ -3818,6 +4028,11 @@ func (in *Parameter) DeepCopyInto(out *Parameter) { *out = new(string) **out = **in } + if in.ApplyMethod != nil { + in, out := &in.ApplyMethod, &out.ApplyMethod + *out = new(string) + **out = **in + } if in.ApplyType != nil { in, out := &in.ApplyType, &out.ApplyType *out = new(string) @@ -3858,6 +4073,17 @@ func (in *Parameter) DeepCopyInto(out *Parameter) { *out = new(string) **out = **in } + if in.SupportedEngineModes != nil { + in, out := &in.SupportedEngineModes, &out.SupportedEngineModes + *out = make([]*string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(string) + **out = **in + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Parameter. diff --git a/apis/rds/v1alpha1/zz_generated.managed.go b/apis/rds/v1alpha1/zz_generated.managed.go index ab812e28ee..fb81451aaa 100644 --- a/apis/rds/v1alpha1/zz_generated.managed.go +++ b/apis/rds/v1alpha1/zz_generated.managed.go @@ -75,3 +75,59 @@ func (mg *DBCluster) SetProviderReference(r *xpv1.Reference) { func (mg *DBCluster) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { mg.Spec.WriteConnectionSecretToReference = r } + +// GetCondition of this DBParameterGroup. +func (mg *DBParameterGroup) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this DBParameterGroup. +func (mg *DBParameterGroup) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetProviderConfigReference of this DBParameterGroup. +func (mg *DBParameterGroup) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +/* +GetProviderReference of this DBParameterGroup. +Deprecated: Use GetProviderConfigReference. +*/ +func (mg *DBParameterGroup) GetProviderReference() *xpv1.Reference { + return mg.Spec.ProviderReference +} + +// GetWriteConnectionSecretToReference of this DBParameterGroup. +func (mg *DBParameterGroup) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this DBParameterGroup. +func (mg *DBParameterGroup) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this DBParameterGroup. +func (mg *DBParameterGroup) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetProviderConfigReference of this DBParameterGroup. +func (mg *DBParameterGroup) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +/* +SetProviderReference of this DBParameterGroup. +Deprecated: Use SetProviderConfigReference. +*/ +func (mg *DBParameterGroup) SetProviderReference(r *xpv1.Reference) { + mg.Spec.ProviderReference = r +} + +// SetWriteConnectionSecretToReference of this DBParameterGroup. +func (mg *DBParameterGroup) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} diff --git a/apis/rds/v1alpha1/zz_generated.managedlist.go b/apis/rds/v1alpha1/zz_generated.managedlist.go index 960b136af5..7872cdf3c0 100644 --- a/apis/rds/v1alpha1/zz_generated.managedlist.go +++ b/apis/rds/v1alpha1/zz_generated.managedlist.go @@ -28,3 +28,12 @@ func (l *DBClusterList) GetItems() []resource.Managed { } return items } + +// GetItems of this DBParameterGroupList. +func (l *DBParameterGroupList) GetItems() []resource.Managed { + items := make([]resource.Managed, len(l.Items)) + for i := range l.Items { + items[i] = &l.Items[i] + } + return items +} diff --git a/apis/rds/v1alpha1/zz_types.go b/apis/rds/v1alpha1/zz_types.go index b304620ddd..31a0f6d416 100644 --- a/apis/rds/v1alpha1/zz_types.go +++ b/apis/rds/v1alpha1/zz_types.go @@ -340,6 +340,8 @@ type DBEngineVersion struct { Status *string `json:"status,omitempty"` + SupportedEngineModes []*string `json:"supportedEngineModes,omitempty"` + SupportsGlobalDatabases *bool `json:"supportsGlobalDatabases,omitempty"` SupportsLogExportsToCloudwatchLogs *bool `json:"supportsLogExportsToCloudwatchLogs,omitempty"` @@ -513,7 +515,13 @@ type DBInstanceStatusInfo struct { StatusType *string `json:"statusType,omitempty"` } -type DBParameterGroup struct { +type DBParameterGroupStatus_SDK struct { + DBParameterGroupName *string `json:"dbParameterGroupName,omitempty"` + + ParameterApplyStatus *string `json:"parameterApplyStatus,omitempty"` +} + +type DBParameterGroup_SDK struct { DBParameterGroupARN *string `json:"dbParameterGroupARN,omitempty"` DBParameterGroupFamily *string `json:"dbParameterGroupFamily,omitempty"` @@ -523,12 +531,6 @@ type DBParameterGroup struct { Description *string `json:"description,omitempty"` } -type DBParameterGroupStatus struct { - DBParameterGroupName *string `json:"dbParameterGroupName,omitempty"` - - ParameterApplyStatus *string `json:"parameterApplyStatus,omitempty"` -} - type DBProxy struct { CreatedDate *metav1.Time `json:"createdDate,omitempty"` @@ -704,6 +706,8 @@ type EngineDefaults struct { DBParameterGroupFamily *string `json:"dbParameterGroupFamily,omitempty"` Marker *string `json:"marker,omitempty"` + + Parameters []*Parameter `json:"parameters,omitempty"` } type Event struct { @@ -973,6 +977,8 @@ type OrderableDBInstanceOption struct { StorageType *string `json:"storageType,omitempty"` + SupportedEngineModes []*string `json:"supportedEngineModes,omitempty"` + SupportsEnhancedMonitoring *bool `json:"supportsEnhancedMonitoring,omitempty"` SupportsGlobalDatabases *bool `json:"supportsGlobalDatabases,omitempty"` @@ -999,6 +1005,8 @@ type Outpost struct { type Parameter struct { AllowedValues *string `json:"allowedValues,omitempty"` + ApplyMethod *string `json:"applyMethod,omitempty"` + ApplyType *string `json:"applyType,omitempty"` DataType *string `json:"dataType,omitempty"` @@ -1014,6 +1022,8 @@ type Parameter struct { ParameterValue *string `json:"parameterValue,omitempty"` Source *string `json:"source,omitempty"` + + SupportedEngineModes []*string `json:"supportedEngineModes,omitempty"` } type PendingCloudwatchLogsExports struct { diff --git a/examples/rds/dbparametergroup.yaml b/examples/rds/dbparametergroup.yaml new file mode 100644 index 0000000000..f3d7e28959 --- /dev/null +++ b/examples/rds/dbparametergroup.yaml @@ -0,0 +1,15 @@ +apiVersion: rds.aws.crossplane.io/v1alpha1 +kind: DBParameterGroup +metadata: + name: example-dbparametergroup +spec: + forProvider: + region: eu-central-1 + dbParameterGroupFamily: postgres9.6 + description: example + parameters: + - parameterName: application_name + parameterValue: "example" + applyMethod: immediate + providerConfigRef: + name: example diff --git a/package/crds/rds.aws.crossplane.io_dbparametergroups.yaml b/package/crds/rds.aws.crossplane.io_dbparametergroups.yaml new file mode 100644 index 0000000000..4da77051bf --- /dev/null +++ b/package/crds/rds.aws.crossplane.io_dbparametergroups.yaml @@ -0,0 +1,198 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.4.0 + creationTimestamp: null + name: dbparametergroups.rds.aws.crossplane.io +spec: + group: rds.aws.crossplane.io + names: + categories: + - crossplane + - managed + - aws + kind: DBParameterGroup + listKind: DBParameterGroupList + plural: dbparametergroups + singular: dbparametergroup + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .metadata.annotations.crossplane\.io/external-name + name: EXTERNAL-NAME + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: DBParameterGroup is the Schema for the DBParameterGroups API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: DBParameterGroupSpec defines the desired state of DBParameterGroup + properties: + deletionPolicy: + description: DeletionPolicy specifies what will happen to the underlying external when this managed resource is deleted - either "Delete" or "Orphan" the external resource. The "Delete" policy is the default when no policy is specified. + enum: + - Orphan + - Delete + type: string + forProvider: + description: DBParameterGroupParameters defines the desired state of DBParameterGroup + properties: + dbParameterGroupFamily: + description: "The DB parameter group family name. A DB parameter group can be associated with one and only one DB parameter group family, and can be applied only to a DB instance running a database engine and engine version compatible with that DB parameter group family. \n To list all of the available parameter group families, use the following command: \n aws rds describe-db-engine-versions --query \"DBEngineVersions[].DBParameterGroupFamily\" \n The output contains duplicates." + type: string + description: + description: The description for the DB parameter group. + type: string + parameters: + description: A list of parameters to associate with this DB parameter group + items: + properties: + allowedValues: + type: string + applyMethod: + type: string + applyType: + type: string + dataType: + type: string + description: + type: string + isModifiable: + type: boolean + minimumEngineVersion: + type: string + parameterName: + type: string + parameterValue: + type: string + source: + type: string + supportedEngineModes: + items: + type: string + type: array + type: object + type: array + region: + description: Region is which region the DBParameterGroup will be created. + type: string + tags: + description: Tags to assign to the DB parameter group. + items: + properties: + key: + type: string + value: + type: string + type: object + type: array + required: + - dbParameterGroupFamily + - description + - region + type: object + providerConfigRef: + description: ProviderConfigReference specifies how the provider that will be used to create, observe, update, and delete this managed resource should be configured. + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + providerRef: + description: 'ProviderReference specifies the provider that will be used to create, observe, update, and delete this managed resource. Deprecated: Please use ProviderConfigReference, i.e. `providerConfigRef`' + properties: + name: + description: Name of the referenced object. + type: string + required: + - name + type: object + writeConnectionSecretToRef: + description: WriteConnectionSecretToReference specifies the namespace and name of a Secret to which any connection details for this managed resource should be written. Connection details frequently include the endpoint, username, and password required to connect to the managed resource. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + required: + - forProvider + type: object + status: + description: DBParameterGroupStatus defines the observed state of DBParameterGroup. + properties: + atProvider: + description: DBParameterGroupObservation defines the observed state of DBParameterGroup + properties: + dbParameterGroupARN: + description: The Amazon Resource Name (ARN) for the DB parameter group. + type: string + dbParameterGroupName: + description: The name of the DB parameter group. + type: string + type: object + conditions: + description: Conditions of the resource. + items: + description: A Condition that may apply to a resource. + properties: + lastTransitionTime: + description: LastTransitionTime is the last time this condition transitioned from one status to another. + format: date-time + type: string + message: + description: A Message containing details about this condition's last transition from one status to another, if any. + type: string + reason: + description: A Reason for this condition's last transition from one status to another. + type: string + status: + description: Status of this condition; is it currently True, False, or Unknown? + type: string + type: + description: Type of this condition. At most one of each condition type may apply to a resource at any point in time. + type: string + required: + - lastTransitionTime + - reason + - status + - type + type: object + type: array + required: + - atProvider + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/pkg/controller/aws.go b/pkg/controller/aws.go index 5f1bc0e0f7..d067b26bb4 100644 --- a/pkg/controller/aws.go +++ b/pkg/controller/aws.go @@ -73,6 +73,7 @@ import ( "github.com/crossplane/provider-aws/pkg/controller/notification/snssubscription" "github.com/crossplane/provider-aws/pkg/controller/notification/snstopic" "github.com/crossplane/provider-aws/pkg/controller/rds/dbcluster" + "github.com/crossplane/provider-aws/pkg/controller/rds/dbparametergroup" "github.com/crossplane/provider-aws/pkg/controller/redshift" "github.com/crossplane/provider-aws/pkg/controller/route53/hostedzone" "github.com/crossplane/provider-aws/pkg/controller/route53/resourcerecordset" @@ -148,6 +149,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error { key.SetupKey, filesystem.SetupFileSystem, dbcluster.SetupDBCluster, + dbparametergroup.SetupDBParameterGroup, } { if err := setup(mgr, l, rl); err != nil { return err diff --git a/pkg/controller/rds/dbparametergroup/setup.go b/pkg/controller/rds/dbparametergroup/setup.go new file mode 100644 index 0000000000..f64d553f1e --- /dev/null +++ b/pkg/controller/rds/dbparametergroup/setup.go @@ -0,0 +1,148 @@ +package dbparametergroup + +import ( + "context" + + svcsdk "github.com/aws/aws-sdk-go/service/rds" + svcsdkapi "github.com/aws/aws-sdk-go/service/rds/rdsiface" + "github.com/pkg/errors" + "k8s.io/client-go/util/workqueue" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/event" + "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/rds/v1alpha1" + awsclients "github.com/crossplane/provider-aws/pkg/clients" +) + +// SetupDBParameterGroup adds a controller that reconciles DBParametergroup. +func SetupDBParameterGroup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error { + name := managed.ControllerName(svcapitypes.DBParameterGroupGroupKind) + opts := []option{ + func(e *external) { + e.preCreate = preCreate + e.preObserve = preObserve + e.preUpdate = preUpdate + e.preDelete = preDelete + e.postObserve = postObserve + c := &custom{client: e.client, kube: e.kube} + e.isUpToDate = c.isUpToDate + }, + } + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(controller.Options{ + RateLimiter: ratelimiter.NewDefaultManagedRateLimiter(rl), + }). + For(&svcapitypes.DBParameterGroup{}). + Complete(managed.NewReconciler(mgr, + resource.ManagedKind(svcapitypes.DBParameterGroupGroupVersionKind), + managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), + managed.WithLogger(l.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) +} + +type custom struct { + kube client.Client + client svcsdkapi.RDSAPI +} + +func preObserve(_ context.Context, cr *svcapitypes.DBParameterGroup, obj *svcsdk.DescribeDBParameterGroupsInput) error { + obj.DBParameterGroupName = awsclients.String(meta.GetExternalName(cr)) + return nil +} + +func postObserve(_ context.Context, cr *svcapitypes.DBParameterGroup, obj *svcsdk.DescribeDBParameterGroupsOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + if err != nil { + return managed.ExternalObservation{}, err + } + cr.SetConditions(xpv1.Available()) + return obs, err +} + +func preCreate(_ context.Context, cr *svcapitypes.DBParameterGroup, obj *svcsdk.CreateDBParameterGroupInput) error { + obj.DBParameterGroupName = awsclients.String(meta.GetExternalName(cr)) + return nil +} + +func preUpdate(_ context.Context, cr *svcapitypes.DBParameterGroup, obj *svcsdk.ModifyDBParameterGroupInput) error { + obj.DBParameterGroupName = awsclients.String(meta.GetExternalName(cr)) + obj.Parameters = make([]*svcsdk.Parameter, len(cr.Spec.ForProvider.Parameters)) + + for i, v := range cr.Spec.ForProvider.Parameters { + // check if mandatory parameters are set (ApplyMethod, ParameterName, ParameterValue) + if (v.ApplyMethod == nil) || (v.ParameterName == nil) || (v.ParameterValue == nil) { + return errors.New("ApplyMethod, ParameterName and ParameterValue are mandatory fields and can not be nil") + } + obj.Parameters[i] = &svcsdk.Parameter{ + AllowedValues: v.AllowedValues, + ApplyMethod: v.ApplyMethod, + ApplyType: v.ApplyType, + DataType: v.DataType, + Description: v.Description, + IsModifiable: v.IsModifiable, + MinimumEngineVersion: v.MinimumEngineVersion, + ParameterName: v.ParameterName, + ParameterValue: v.ParameterValue, + Source: v.Source, + SupportedEngineModes: v.SupportedEngineModes, + } + } + return nil +} + +func preDelete(_ context.Context, cr *svcapitypes.DBParameterGroup, obj *svcsdk.DeleteDBParameterGroupInput) (bool, error) { + obj.DBParameterGroupName = awsclients.String(meta.GetExternalName(cr)) + return false, nil +} + +func (e *custom) isUpToDate(cr *svcapitypes.DBParameterGroup, obj *svcsdk.DescribeDBParameterGroupsOutput) (bool, error) { + // TODO(Dkaykay): We need isUpToDate to have context. + ctx := context.TODO() + results, err := e.getCurrentDBParameters(ctx, cr) + if err != nil { + return false, err + } + observed := make(map[string]svcsdk.Parameter, len(results)) + for _, p := range results { + observed[awsclients.StringValue(p.ParameterName)] = *p + } + // compare CR with currently set Parameters + for _, v := range cr.Spec.ForProvider.Parameters { + existing, ok := observed[awsclients.StringValue(v.ParameterName)] + if !ok { + return false, nil + } + switch { + case awsclients.StringValue(existing.ParameterValue) != awsclients.StringValue(v.ParameterValue): + return false, nil + case awsclients.StringValue(existing.ApplyMethod) != awsclients.StringValue(v.ApplyMethod): + return false, nil + } + } + return true, err +} + +func (e *custom) getCurrentDBParameters(ctx context.Context, cr *svcapitypes.DBParameterGroup) ([]*svcsdk.Parameter, error) { + input := &svcsdk.DescribeDBParametersInput{ + DBParameterGroupName: awsclients.String(meta.GetExternalName(cr)), + MaxRecords: awsclients.Int64(20), + } + var results []*svcsdk.Parameter + err := e.client.DescribeDBParametersPagesWithContext(ctx, input, func(page *svcsdk.DescribeDBParametersOutput, lastPage bool) bool { + results = append(results, page.Parameters...) + return !lastPage + }) + if err != nil { + return results, err + } + return results, nil +} diff --git a/pkg/controller/rds/dbparametergroup/zz_controller.go b/pkg/controller/rds/dbparametergroup/zz_controller.go new file mode 100644 index 0000000000..2da6950a88 --- /dev/null +++ b/pkg/controller/rds/dbparametergroup/zz_controller.go @@ -0,0 +1,239 @@ +/* +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. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package dbparametergroup + +import ( + "context" + + svcapi "github.com/aws/aws-sdk-go/service/rds" + svcsdk "github.com/aws/aws-sdk-go/service/rds" + svcsdkapi "github.com/aws/aws-sdk-go/service/rds/rdsiface" + "github.com/google/go-cmp/cmp" + "github.com/pkg/errors" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/meta" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + cpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + + svcapitypes "github.com/crossplane/provider-aws/apis/rds/v1alpha1" + awsclient "github.com/crossplane/provider-aws/pkg/clients" +) + +const ( + errUnexpectedObject = "managed resource is not an DBParameterGroup resource" + + errCreateSession = "cannot create a new session" + errCreate = "cannot create DBParameterGroup in AWS" + errUpdate = "cannot update DBParameterGroup in AWS" + errDescribe = "failed to describe DBParameterGroup" + errDelete = "failed to delete DBParameterGroup" +) + +type connector struct { + kube client.Client + opts []option +} + +func (c *connector) Connect(ctx context.Context, mg cpresource.Managed) (managed.ExternalClient, error) { + cr, ok := mg.(*svcapitypes.DBParameterGroup) + if !ok { + return nil, errors.New(errUnexpectedObject) + } + sess, err := awsclient.GetConfigV1(ctx, c.kube, mg, cr.Spec.ForProvider.Region) + if err != nil { + return nil, errors.Wrap(err, errCreateSession) + } + return newExternal(c.kube, svcapi.New(sess), c.opts), nil +} + +func (e *external) Observe(ctx context.Context, mg cpresource.Managed) (managed.ExternalObservation, error) { + cr, ok := mg.(*svcapitypes.DBParameterGroup) + if !ok { + return managed.ExternalObservation{}, errors.New(errUnexpectedObject) + } + if meta.GetExternalName(cr) == "" { + return managed.ExternalObservation{ + ResourceExists: false, + }, nil + } + input := GenerateDescribeDBParameterGroupsInput(cr) + if err := e.preObserve(ctx, cr, input); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "pre-observe failed") + } + resp, err := e.client.DescribeDBParameterGroupsWithContext(ctx, input) + if err != nil { + return managed.ExternalObservation{ResourceExists: false}, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDescribe) + } + resp = e.filterList(cr, resp) + if len(resp.DBParameterGroups) == 0 { + return managed.ExternalObservation{ResourceExists: false}, nil + } + currentSpec := cr.Spec.ForProvider.DeepCopy() + if err := e.lateInitialize(&cr.Spec.ForProvider, resp); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "late-init failed") + } + GenerateDBParameterGroup(resp).Status.AtProvider.DeepCopyInto(&cr.Status.AtProvider) + + upToDate, err := e.isUpToDate(cr, resp) + if err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, "isUpToDate check failed") + } + return e.postObserve(ctx, cr, resp, managed.ExternalObservation{ + ResourceExists: true, + ResourceUpToDate: upToDate, + ResourceLateInitialized: !cmp.Equal(&cr.Spec.ForProvider, currentSpec), + }, nil) +} + +func (e *external) Create(ctx context.Context, mg cpresource.Managed) (managed.ExternalCreation, error) { + cr, ok := mg.(*svcapitypes.DBParameterGroup) + if !ok { + return managed.ExternalCreation{}, errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Creating()) + input := GenerateCreateDBParameterGroupInput(cr) + if err := e.preCreate(ctx, cr, input); err != nil { + return managed.ExternalCreation{}, errors.Wrap(err, "pre-create failed") + } + resp, err := e.client.CreateDBParameterGroupWithContext(ctx, input) + if err != nil { + return managed.ExternalCreation{}, awsclient.Wrap(err, errCreate) + } + + if resp.DBParameterGroup.DBParameterGroupArn != nil { + cr.Status.AtProvider.DBParameterGroupARN = resp.DBParameterGroup.DBParameterGroupArn + } + if resp.DBParameterGroup.DBParameterGroupName != nil { + cr.Status.AtProvider.DBParameterGroupName = resp.DBParameterGroup.DBParameterGroupName + } + + return e.postCreate(ctx, cr, resp, managed.ExternalCreation{}, err) +} + +func (e *external) Update(ctx context.Context, mg cpresource.Managed) (managed.ExternalUpdate, error) { + cr, ok := mg.(*svcapitypes.DBParameterGroup) + if !ok { + return managed.ExternalUpdate{}, errors.New(errUnexpectedObject) + } + input := GenerateModifyDBParameterGroupInput(cr) + if err := e.preUpdate(ctx, cr, input); err != nil { + return managed.ExternalUpdate{}, errors.Wrap(err, "pre-update failed") + } + resp, err := e.client.ModifyDBParameterGroupWithContext(ctx, input) + if err != nil { + return managed.ExternalUpdate{}, awsclient.Wrap(err, errUpdate) + } + return e.postUpdate(ctx, cr, resp, managed.ExternalUpdate{}, err) +} + +func (e *external) Delete(ctx context.Context, mg cpresource.Managed) error { + cr, ok := mg.(*svcapitypes.DBParameterGroup) + if !ok { + return errors.New(errUnexpectedObject) + } + cr.Status.SetConditions(xpv1.Deleting()) + input := GenerateDeleteDBParameterGroupInput(cr) + ignore, err := e.preDelete(ctx, cr, input) + if err != nil { + return errors.Wrap(err, "pre-delete failed") + } + if ignore { + return nil + } + resp, err := e.client.DeleteDBParameterGroupWithContext(ctx, input) + return e.postDelete(ctx, cr, resp, awsclient.Wrap(cpresource.Ignore(IsNotFound, err), errDelete)) +} + +type option func(*external) + +func newExternal(kube client.Client, client svcsdkapi.RDSAPI, opts []option) *external { + e := &external{ + kube: kube, + client: client, + preObserve: nopPreObserve, + postObserve: nopPostObserve, + lateInitialize: nopLateInitialize, + isUpToDate: alwaysUpToDate, + filterList: nopFilterList, + preCreate: nopPreCreate, + postCreate: nopPostCreate, + preDelete: nopPreDelete, + postDelete: nopPostDelete, + preUpdate: nopPreUpdate, + postUpdate: nopPostUpdate, + } + for _, f := range opts { + f(e) + } + return e +} + +type external struct { + kube client.Client + client svcsdkapi.RDSAPI + preObserve func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DescribeDBParameterGroupsInput) error + postObserve func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DescribeDBParameterGroupsOutput, managed.ExternalObservation, error) (managed.ExternalObservation, error) + filterList func(*svcapitypes.DBParameterGroup, *svcsdk.DescribeDBParameterGroupsOutput) *svcsdk.DescribeDBParameterGroupsOutput + lateInitialize func(*svcapitypes.DBParameterGroupParameters, *svcsdk.DescribeDBParameterGroupsOutput) error + isUpToDate func(*svcapitypes.DBParameterGroup, *svcsdk.DescribeDBParameterGroupsOutput) (bool, error) + preCreate func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.CreateDBParameterGroupInput) error + postCreate func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.CreateDBParameterGroupOutput, managed.ExternalCreation, error) (managed.ExternalCreation, error) + preDelete func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DeleteDBParameterGroupInput) (bool, error) + postDelete func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DeleteDBParameterGroupOutput, error) error + preUpdate func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.ModifyDBParameterGroupInput) error + postUpdate func(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DBParameterGroupNameMessage, managed.ExternalUpdate, error) (managed.ExternalUpdate, error) +} + +func nopPreObserve(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DescribeDBParameterGroupsInput) error { + return nil +} +func nopPostObserve(_ context.Context, _ *svcapitypes.DBParameterGroup, _ *svcsdk.DescribeDBParameterGroupsOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { + return obs, err +} +func nopFilterList(_ *svcapitypes.DBParameterGroup, list *svcsdk.DescribeDBParameterGroupsOutput) *svcsdk.DescribeDBParameterGroupsOutput { + return list +} + +func nopLateInitialize(*svcapitypes.DBParameterGroupParameters, *svcsdk.DescribeDBParameterGroupsOutput) error { + return nil +} +func alwaysUpToDate(*svcapitypes.DBParameterGroup, *svcsdk.DescribeDBParameterGroupsOutput) (bool, error) { + return true, nil +} + +func nopPreCreate(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.CreateDBParameterGroupInput) error { + return nil +} +func nopPostCreate(_ context.Context, _ *svcapitypes.DBParameterGroup, _ *svcsdk.CreateDBParameterGroupOutput, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { + return cre, err +} +func nopPreDelete(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.DeleteDBParameterGroupInput) (bool, error) { + return false, nil +} +func nopPostDelete(_ context.Context, _ *svcapitypes.DBParameterGroup, _ *svcsdk.DeleteDBParameterGroupOutput, err error) error { + return err +} +func nopPreUpdate(context.Context, *svcapitypes.DBParameterGroup, *svcsdk.ModifyDBParameterGroupInput) error { + return nil +} +func nopPostUpdate(_ context.Context, _ *svcapitypes.DBParameterGroup, _ *svcsdk.DBParameterGroupNameMessage, upd managed.ExternalUpdate, err error) (managed.ExternalUpdate, error) { + return upd, err +} diff --git a/pkg/controller/rds/dbparametergroup/zz_conversions.go b/pkg/controller/rds/dbparametergroup/zz_conversions.go new file mode 100644 index 0000000000..a77adb1cce --- /dev/null +++ b/pkg/controller/rds/dbparametergroup/zz_conversions.go @@ -0,0 +1,113 @@ +/* +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. +*/ + +// Code generated by ack-generate. DO NOT EDIT. + +package dbparametergroup + +import ( + "github.com/aws/aws-sdk-go/aws/awserr" + svcsdk "github.com/aws/aws-sdk-go/service/rds" + + svcapitypes "github.com/crossplane/provider-aws/apis/rds/v1alpha1" +) + +// NOTE(muvaf): We return pointers in case the function needs to start with an +// empty object, hence need to return a new pointer. + +// GenerateDescribeDBParameterGroupsInput returns input for read +// operation. +func GenerateDescribeDBParameterGroupsInput(cr *svcapitypes.DBParameterGroup) *svcsdk.DescribeDBParameterGroupsInput { + res := &svcsdk.DescribeDBParameterGroupsInput{} + + return res +} + +// GenerateDBParameterGroup returns the current state in the form of *svcapitypes.DBParameterGroup. +func GenerateDBParameterGroup(resp *svcsdk.DescribeDBParameterGroupsOutput) *svcapitypes.DBParameterGroup { + cr := &svcapitypes.DBParameterGroup{} + + found := false + for _, elem := range resp.DBParameterGroups { + if elem.DBParameterGroupArn != nil { + cr.Status.AtProvider.DBParameterGroupARN = elem.DBParameterGroupArn + } + if elem.DBParameterGroupFamily != nil { + cr.Spec.ForProvider.DBParameterGroupFamily = elem.DBParameterGroupFamily + } + if elem.DBParameterGroupName != nil { + cr.Status.AtProvider.DBParameterGroupName = elem.DBParameterGroupName + } + if elem.Description != nil { + cr.Spec.ForProvider.Description = elem.Description + } + found = true + break + } + if !found { + return cr + } + + return cr +} + +// GenerateCreateDBParameterGroupInput returns a create input. +func GenerateCreateDBParameterGroupInput(cr *svcapitypes.DBParameterGroup) *svcsdk.CreateDBParameterGroupInput { + res := &svcsdk.CreateDBParameterGroupInput{} + + if cr.Spec.ForProvider.DBParameterGroupFamily != nil { + res.SetDBParameterGroupFamily(*cr.Spec.ForProvider.DBParameterGroupFamily) + } + if cr.Spec.ForProvider.Description != nil { + res.SetDescription(*cr.Spec.ForProvider.Description) + } + if cr.Spec.ForProvider.Tags != nil { + f2 := []*svcsdk.Tag{} + for _, f2iter := range cr.Spec.ForProvider.Tags { + f2elem := &svcsdk.Tag{} + if f2iter.Key != nil { + f2elem.SetKey(*f2iter.Key) + } + if f2iter.Value != nil { + f2elem.SetValue(*f2iter.Value) + } + f2 = append(f2, f2elem) + } + res.SetTags(f2) + } + + return res +} + +// GenerateModifyDBParameterGroupInput returns an update input. +func GenerateModifyDBParameterGroupInput(cr *svcapitypes.DBParameterGroup) *svcsdk.ModifyDBParameterGroupInput { + res := &svcsdk.ModifyDBParameterGroupInput{} + + return res +} + +// GenerateDeleteDBParameterGroupInput returns a deletion input. +func GenerateDeleteDBParameterGroupInput(cr *svcapitypes.DBParameterGroup) *svcsdk.DeleteDBParameterGroupInput { + res := &svcsdk.DeleteDBParameterGroupInput{} + + return res +} + +// IsNotFound returns whether the given error is of type NotFound or not. +func IsNotFound(err error) bool { + awsErr, ok := err.(awserr.Error) + return ok && awsErr.Code() == "DBParameterGroupNotFound" +}