Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DBSubnetGroup to v1beta1 #162

Merged
merged 8 commits into from
Apr 8, 2020

Conversation

gauravgahlot
Copy link

@gauravgahlot gauravgahlot commented Mar 23, 2020

Description of your changes

  • Moved DBSubnetGroup implementation from v1alpha3 to v1beta1.
  • Added implementation for DBSubnetGroup update

Tested with the following:

apiVersion: database.aws.crossplane.io/v1beta1
kind: DBSubnetGroup
metadata:
  name: sample-dbsubnetgroup
  annotations:
    crossplane.io/external-name: managed-resource-dbsubnetgroup
spec:
  forProvider:
    description: EKS vpc to rds
    subnetIdRefs:
      - name: sample-subnet1
      - name: sample-subnet2
      - name: sample-subnet3
    tags:
      - key: name
        value: my-cool-dbsubnetgroup
  reclaimPolicy: Delete
  providerRef:
    name: aws-provider

Checklist

I have:

  • Run make reviewable to ensure this PR is ready for review.
  • Ensured this PR contains a neat, self-documenting set of commits.
  • Updated any relevant documentation, examples, or release notes.
  • Updated the dependencies in app.yaml to include any new role permissions.

@infinitecompute infinitecompute linked an issue Mar 25, 2020 that may be closed by this pull request
apis/database/v1beta1/dbsubnetgroup_referencers.go Outdated Show resolved Hide resolved
pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
if !ok {
return errors.New(errUnexpectedObject)
}

cr.Status.SetConditions(runtimev1alpha1.Deleting())

req := e.client.DeleteDBSubnetGroupRequest(&awsrds.DeleteDBSubnetGroupInput{
DBSubnetGroupName: aws.String(cr.Spec.DBSubnetGroupName),
DBSubnetGroupName: aws.String(cr.Spec.ForProvider.DBSubnetGroupName),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DBSubnetGroupName: aws.String(cr.Spec.ForProvider.DBSubnetGroupName),
DBSubnetGroupName: meta.GetExternalName(cr),

if !ok {
return errors.New(errUnexpectedObject)
}

cr.Status.SetConditions(runtimev1alpha1.Deleting())

req := e.client.DeleteDBSubnetGroupRequest(&awsrds.DeleteDBSubnetGroupInput{
DBSubnetGroupName: aws.String(cr.Spec.DBSubnetGroupName),
DBSubnetGroupName: aws.String(cr.Spec.ForProvider.DBSubnetGroupName),
})

_, err := req.Send(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, err := req.Send(ctx)
_, err := req.Send(ctx)
return errors.Wrap(resource.Ignore(rds.IsDBSubnetGroupNotFoundErr, err), errDelete)

resource.Ignore will skip that specific error by running the func you provide, which is rds.IsDBSubnetGroupNotFoundErr in this case.

apis/database/v1beta1/dbsubnetgroup_types.go Outdated Show resolved Hide resolved
Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good. I think we can merge it after the comments are addressed. I'd also suggest going over the commit list and consolidate some of them. For commit messages, I'm not sure whether we have a convention but I usually go with dbsubnetgroup: this commit does that.

apis/database/v1beta1/dbsubnetgroup_types.go Outdated Show resolved Hide resolved
pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
}

// IsDBSubnetGroupUpToDate checks whether there is a change in any of the modifiable fields.
func IsDBSubnetGroupUpToDate(p v1beta1.DBSubnetGroupParameters, sg rds.DBSubnetGroup) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only 2 fields that might need update since Modify call takes only those. So, it might be easier just to check DBSubnetGroupDescription and SubnetIDs fields and see whether they changed and return.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment assumed that we were not able to update the tags but that's actually possible later I realized. So, you need to check tags as well.

apis/database/v1beta1/dbsubnetgroup_types.go Outdated Show resolved Hide resolved
SubnetIds: cr.Spec.SubnetIDs,
DBSubnetGroupDescription: aws.String(cr.Spec.ForProvider.DBSubnetGroupDescription),
DBSubnetGroupName: aws.String(cr.Spec.ForProvider.DBSubnetGroupName),
SubnetIds: cr.Spec.ForProvider.SubnetIDs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, in my comment, I was saying that DBSubnetGroupParameters should have a Tags field and it seems to be the case now.

pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
Comment on lines 165 to 168
SubnetGroupStatus string `json:"subnetGroupStatus,omitempty"`

// DBSubnetGroupArn is the Amazon Resource Name (ARN) for this DB subnet group.
DBSubnetGroupArn string `json:"dbSubnetGroupArn,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think state and arn would be sufficient for names as it's already implied with these fields being under DBSubnetGroup CRD. I see that they are indeed named as DBSubnetGroupArn and SubnetGroupStatus in cloud API but IMO we should go with state and arn as it's really unnecessary.

// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.groupStatus"
// +kubebuilder:printcolumn:name="GROUPNAME",type="string",JSONPath=".spec.forProvider.groupName"
// +kubebuilder:printcolumn:name="DESCRIPTION",type="string",JSONPath=".spec.forProvider.description"
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.atProvider.groupStatus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.atProvider.groupStatus"
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.atProvider.subnetGroupStatus"

// +kubebuilder:printcolumn:name="GROUPNAME",type="string",JSONPath=".spec.groupName"
// +kubebuilder:printcolumn:name="DESCRIPTION",type="string",JSONPath=".spec.description"
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.groupStatus"
// +kubebuilder:printcolumn:name="GROUPNAME",type="string",JSONPath=".spec.forProvider.groupName"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// +kubebuilder:printcolumn:name="GROUPNAME",type="string",JSONPath=".spec.forProvider.groupName"


// CreatePatch creates a *v1beta1.DBSubnetGroupParameters that has only the changed
// values between the target *v1beta1.DBSubnetGroupParameters and the current *rds.DBSubnetGroup
func CreatePatch(in *rds.DBSubnetGroup, target *v1beta1.DBSubnetGroupParameters) (*v1beta1.DBSubnetGroupParameters, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any usage of func CreatePatch other than is-up-to-date check, so, it'd be better if you can remove it after making the is-up-to-date simpler.

pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
}

// IsDBSubnetGroupUpToDate checks whether there is a change in any of the modifiable fields.
func IsDBSubnetGroupUpToDate(p v1beta1.DBSubnetGroupParameters, sg rds.DBSubnetGroup) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment assumed that we were not able to update the tags but that's actually possible later I realized. So, you need to check tags as well.

Tags []Tag `json:"tags,omitempty"`
}

// A DBSubnetGroupSpec defines the desired state of a DBSubnetGroup.
type DBSubnetGroupSpec struct {
runtimev1alpha1.ResourceSpec `json:",inline"`
DBSubnetGroupParameters `json:",inline"`
ForProvider DBSubnetGroupParameters `json:"forProvider,omitempty"`
}

// DBSubnetGroupExternalStatus keeps the state for the external resource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBSubnetGroupExternalStatus doesn't seem to be used anywhere, so you might as well remove it.

apis/database/v1beta1/dbsubnetgroup_types.go Outdated Show resolved Hide resolved
apis/database/v1beta1/dbsubnetgroup_types.go Outdated Show resolved Hide resolved
if id == value {
return nil
}
}

sg.Spec.SubnetIDs = append(sg.Spec.SubnetIDs, value)
sg.Spec.ForProvider.SubnetIDs = append(sg.Spec.ForProvider.SubnetIDs, value)
return nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the line var _ resource.AttributeReferencer = (*SubnetIDReferencerForDBSubnetGroup)(nil) as that struct already has its own test file to test this interface conformance.

pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
@muvaf
Copy link
Member

muvaf commented Apr 6, 2020

Please make sure the functionality works as expected by testing manually.

@gauravgahlot gauravgahlot requested a review from muvaf April 7, 2020 11:32
Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few nitpicks unaddressed but the PR should be ready to go. @gauravgahlot thank you!

pkg/controller/database/dbsubnetgroup/controller.go Outdated Show resolved Hide resolved
@muvaf muvaf requested a review from hasheddan April 7, 2020 22:31
Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nitpicks, but I think we can move forward and circle back around for any clean-up. Thanks for your great work @gauravgahlot! Could you post any manual testing you have done as a comment? (or point me to where you already have if I missed it scrolling through the comments)

@@ -167,7 +166,8 @@ func TestDBSubnetGroupNameReferencerBuild(t *testing.T) {
input: input{
readerFn: func(ctx context.Context, key client.ObjectKey, obj runtime.Object) error {
p := obj.(*DBSubnetGroup)
p.Spec.DBSubnetGroupName = mockDBSubnetGroupName
// p.Spec.ForProvider.DBSubnetGroupName = mockDBSubnetGroupName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed here

SubnetStatus: aws.StringValue(sn.SubnetStatus),
}
}
// DBSubnetGroupObservation is the representation of the current state that is observed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: would you mind moving this up above DBSubnetGroupStatus where DBSubnetGroupExternalStatus is currently?

)

// Client is the external client used for DBSubnetGroup Custom Resource
type Client interface { // nolint:gocyclo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: is // nolint:gocyclo needed here?

@@ -19,17 +19,20 @@ package fake
import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: might make sense to move this file fake/dbsubnetgroup.go from clients/rds to clients/dbsubnetgroup

Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! You can consider squash some commits and/or clean up commit messages before the merge but that shouldn't block merging. cc @negz for merge.

Gaurav Gahlot and others added 2 commits April 8, 2020 17:19
Signed-off-by: Gaurav Gahlot <ggahlot@infracloud.io>
Signed-off-by: Gaurav Gahlot <gaurav.gahlot19@gmail.com>
gauravgahlot and others added 6 commits April 8, 2020 17:19
Signed-off-by: Gaurav Gahlot <gaurav.gahlot19@gmail.com>
Signed-off-by: Gaurav Gahlot <ggahlot@infracloud.io>
Signed-off-by: Gaurav Gahlot <ggahlot@infracloud.io>
Signed-off-by: Gaurav Gahlot <ggahlot@infracloud.io>
Signed-off-by: Gaurav Gahlot <gaurav.gahlot19@gmail.com>
Signed-off-by: Gaurav Gahlot <gaurav.gahlot19@gmail.com>
@negz negz merged commit 7864298 into crossplane-contrib:master Apr 8, 2020
@gauravgahlot gauravgahlot deleted the v1beta1-dbsubnetgroup branch April 9, 2020 16:13
ajaykangare pushed a commit to ajaykangare/provider-aws that referenced this pull request Jun 5, 2020
Move DBSubnetGroup to v1beta1

Signed-off-by: Gaurav Gahlot <ggahlot@infracloud.io>
Signed-off-by: ajaykangare <ajaykangare1993@gmail.com>
wolffbe pushed a commit to wolffbe/provider-aws that referenced this pull request Feb 12, 2021
Move DBSubnetGroup to v1beta1

Signed-off-by: Gaurav Gahlot <ggahlot@infracloud.io>
namku pushed a commit to namku/provider-aws that referenced this pull request Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DBSubnet Group from Alpha to Beta
6 participants