From bed29b8d30d50b4c0ff2aeaf8df07d0b414c7a53 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Sat, 6 Jan 2024 02:52:52 +0100 Subject: [PATCH] DocDB: Add reference configuration of Cluster to dbClusterParameterGroupName * config and generated files * associated uptest example extension Signed-off-by: Yury Tsarev (cherry picked from commit 6993dfd0a2f2440be9d2ef91f4c9cb247037db1f) --- apis/docdb/v1beta1/zz_cluster_types.go | 18 +++ apis/docdb/v1beta1/zz_generated.deepcopy.go | 20 +++ apis/docdb/v1beta1/zz_generated.resolvers.go | 32 ++++ config/docdb/config.go | 3 + examples/docdb/cluster.yaml | 22 +++ .../crds/docdb.aws.upbound.io_clusters.yaml | 150 ++++++++++++++++++ 6 files changed, 245 insertions(+) diff --git a/apis/docdb/v1beta1/zz_cluster_types.go b/apis/docdb/v1beta1/zz_cluster_types.go index ee956aae79..edc0cf58ff 100755 --- a/apis/docdb/v1beta1/zz_cluster_types.go +++ b/apis/docdb/v1beta1/zz_cluster_types.go @@ -33,8 +33,17 @@ type ClusterInitParameters struct { BackupRetentionPeriod *float64 `json:"backupRetentionPeriod,omitempty" tf:"backup_retention_period,omitempty"` // A cluster parameter group to associate with the cluster. + // +crossplane:generate:reference:type=github.com/upbound/provider-aws/apis/docdb/v1beta1.ClusterParameterGroup DBClusterParameterGroupName *string `json:"dbClusterParameterGroupName,omitempty" tf:"db_cluster_parameter_group_name,omitempty"` + // Reference to a ClusterParameterGroup in docdb to populate dbClusterParameterGroupName. + // +kubebuilder:validation:Optional + DBClusterParameterGroupNameRef *v1.Reference `json:"dbClusterParameterGroupNameRef,omitempty" tf:"-"` + + // Selector for a ClusterParameterGroup in docdb to populate dbClusterParameterGroupName. + // +kubebuilder:validation:Optional + DBClusterParameterGroupNameSelector *v1.Selector `json:"dbClusterParameterGroupNameSelector,omitempty" tf:"-"` + // A DB subnet group to associate with this DB instance. DBSubnetGroupName *string `json:"dbSubnetGroupName,omitempty" tf:"db_subnet_group_name,omitempty"` @@ -236,9 +245,18 @@ type ClusterParameters struct { BackupRetentionPeriod *float64 `json:"backupRetentionPeriod,omitempty" tf:"backup_retention_period,omitempty"` // A cluster parameter group to associate with the cluster. + // +crossplane:generate:reference:type=github.com/upbound/provider-aws/apis/docdb/v1beta1.ClusterParameterGroup // +kubebuilder:validation:Optional DBClusterParameterGroupName *string `json:"dbClusterParameterGroupName,omitempty" tf:"db_cluster_parameter_group_name,omitempty"` + // Reference to a ClusterParameterGroup in docdb to populate dbClusterParameterGroupName. + // +kubebuilder:validation:Optional + DBClusterParameterGroupNameRef *v1.Reference `json:"dbClusterParameterGroupNameRef,omitempty" tf:"-"` + + // Selector for a ClusterParameterGroup in docdb to populate dbClusterParameterGroupName. + // +kubebuilder:validation:Optional + DBClusterParameterGroupNameSelector *v1.Selector `json:"dbClusterParameterGroupNameSelector,omitempty" tf:"-"` + // A DB subnet group to associate with this DB instance. // +kubebuilder:validation:Optional DBSubnetGroupName *string `json:"dbSubnetGroupName,omitempty" tf:"db_subnet_group_name,omitempty"` diff --git a/apis/docdb/v1beta1/zz_generated.deepcopy.go b/apis/docdb/v1beta1/zz_generated.deepcopy.go index 6d2b67a5e7..5d43c3b73a 100644 --- a/apis/docdb/v1beta1/zz_generated.deepcopy.go +++ b/apis/docdb/v1beta1/zz_generated.deepcopy.go @@ -69,6 +69,16 @@ func (in *ClusterInitParameters) DeepCopyInto(out *ClusterInitParameters) { *out = new(string) **out = **in } + if in.DBClusterParameterGroupNameRef != nil { + in, out := &in.DBClusterParameterGroupNameRef, &out.DBClusterParameterGroupNameRef + *out = new(v1.Reference) + (*in).DeepCopyInto(*out) + } + if in.DBClusterParameterGroupNameSelector != nil { + in, out := &in.DBClusterParameterGroupNameSelector, &out.DBClusterParameterGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } if in.DBSubnetGroupName != nil { in, out := &in.DBSubnetGroupName, &out.DBSubnetGroupName *out = new(string) @@ -1200,6 +1210,16 @@ func (in *ClusterParameters) DeepCopyInto(out *ClusterParameters) { *out = new(string) **out = **in } + if in.DBClusterParameterGroupNameRef != nil { + in, out := &in.DBClusterParameterGroupNameRef, &out.DBClusterParameterGroupNameRef + *out = new(v1.Reference) + (*in).DeepCopyInto(*out) + } + if in.DBClusterParameterGroupNameSelector != nil { + in, out := &in.DBClusterParameterGroupNameSelector, &out.DBClusterParameterGroupNameSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } if in.DBSubnetGroupName != nil { in, out := &in.DBSubnetGroupName, &out.DBSubnetGroupName *out = new(string) diff --git a/apis/docdb/v1beta1/zz_generated.resolvers.go b/apis/docdb/v1beta1/zz_generated.resolvers.go index 7255200970..1bc7735565 100644 --- a/apis/docdb/v1beta1/zz_generated.resolvers.go +++ b/apis/docdb/v1beta1/zz_generated.resolvers.go @@ -24,6 +24,22 @@ func (mg *Cluster) ResolveReferences(ctx context.Context, c client.Reader) error var mrsp reference.MultiResolutionResponse var err error + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.DBClusterParameterGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.DBClusterParameterGroupNameRef, + Selector: mg.Spec.ForProvider.DBClusterParameterGroupNameSelector, + To: reference.To{ + List: &ClusterParameterGroupList{}, + Managed: &ClusterParameterGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.DBClusterParameterGroupName") + } + mg.Spec.ForProvider.DBClusterParameterGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.DBClusterParameterGroupNameRef = rsp.ResolvedReference + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.KMSKeyID), Extract: reference.ExternalName(), @@ -56,6 +72,22 @@ func (mg *Cluster) ResolveReferences(ctx context.Context, c client.Reader) error mg.Spec.ForProvider.VPCSecurityGroupIds = reference.ToPtrValues(mrsp.ResolvedValues) mg.Spec.ForProvider.VPCSecurityGroupIDRefs = mrsp.ResolvedReferences + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.DBClusterParameterGroupName), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.DBClusterParameterGroupNameRef, + Selector: mg.Spec.InitProvider.DBClusterParameterGroupNameSelector, + To: reference.To{ + List: &ClusterParameterGroupList{}, + Managed: &ClusterParameterGroup{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.DBClusterParameterGroupName") + } + mg.Spec.InitProvider.DBClusterParameterGroupName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.DBClusterParameterGroupNameRef = rsp.ResolvedReference + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.KMSKeyID), Extract: reference.ExternalName(), diff --git a/config/docdb/config.go b/config/docdb/config.go index 60970f92c4..69e3e71c18 100644 --- a/config/docdb/config.go +++ b/config/docdb/config.go @@ -17,6 +17,9 @@ func Configure(p *config.Provider) { } return conn, nil } + r.References["db_cluster_parameter_group_name"] = config.Reference{ + TerraformName: "aws_docdb_cluster_parameter_group", + } }) p.AddResourceConfigurator("aws_docdb_cluster_instance", func(r *config.Resource) { diff --git a/examples/docdb/cluster.yaml b/examples/docdb/cluster.yaml index 04e06b2a89..c4e04f24cc 100644 --- a/examples/docdb/cluster.yaml +++ b/examples/docdb/cluster.yaml @@ -18,6 +18,9 @@ spec: masterUsername: foo preferredBackupWindow: 07:00-09:00 skipFinalSnapshot: true + dbClusterParameterGroupNameSelector: + matchLabels: + testing.upbound.io/example-name: docdb-cluster-test --- @@ -33,3 +36,22 @@ metadata: type: Opaque stringData: password: "Upboundtest!" + +--- + +apiVersion: docdb.aws.upbound.io/v1beta1 +kind: ClusterParameterGroup +metadata: + annotations: + meta.upbound.io/example-id: docdb/v1beta1/cluster + labels: + testing.upbound.io/example-name: docdb-cluster-test + name: example +spec: + forProvider: + description: docdb cluster parameter group + family: docdb5.0 + parameter: + - name: tls + value: enabled + region: us-west-2 diff --git a/package/crds/docdb.aws.upbound.io_clusters.yaml b/package/crds/docdb.aws.upbound.io_clusters.yaml index 6c2c02c4ca..0dcf010556 100644 --- a/package/crds/docdb.aws.upbound.io_clusters.yaml +++ b/package/crds/docdb.aws.upbound.io_clusters.yaml @@ -85,6 +85,81 @@ spec: dbClusterParameterGroupName: description: A cluster parameter group to associate with the cluster. type: string + dbClusterParameterGroupNameRef: + description: Reference to a ClusterParameterGroup in docdb to + populate dbClusterParameterGroupName. + properties: + name: + description: Name of the referenced object. + type: string + policy: + description: Policies for referencing. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + required: + - name + type: object + dbClusterParameterGroupNameSelector: + description: Selector for a ClusterParameterGroup in docdb to + populate dbClusterParameterGroupName. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + policy: + description: Policies for selection. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + type: object dbSubnetGroupName: description: A DB subnet group to associate with this DB instance. type: string @@ -371,6 +446,81 @@ spec: dbClusterParameterGroupName: description: A cluster parameter group to associate with the cluster. type: string + dbClusterParameterGroupNameRef: + description: Reference to a ClusterParameterGroup in docdb to + populate dbClusterParameterGroupName. + properties: + name: + description: Name of the referenced object. + type: string + policy: + description: Policies for referencing. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + required: + - name + type: object + dbClusterParameterGroupNameSelector: + description: Selector for a ClusterParameterGroup in docdb to + populate dbClusterParameterGroupName. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + policy: + description: Policies for selection. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + type: object dbSubnetGroupName: description: A DB subnet group to associate with this DB instance. type: string