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

Handling external deletion of the resources in the clusterresources group #584

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

worryg0d
Copy link
Collaborator

@worryg0d worryg0d commented Oct 3, 2023

Issue 572

Added:

  • handling of the external deletion of the resources on Instaclustr
  • fixed external changes for VPC peering resources when Instaclustr API returns a list of subnets in a different order

closes #572

@worryg0d worryg0d self-assigned this Oct 3, 2023
@worryg0d worryg0d added the enhancement New feature or request label Oct 3, 2023
@worryg0d worryg0d marked this pull request as draft October 3, 2023 11:42
@worryg0d worryg0d force-pushed the issue-572-clusterresources branch 4 times, most recently from c118958 to 659e937 Compare October 3, 2023 12:24
@worryg0d worryg0d marked this pull request as ready for review October 3, 2023 12:26
@@ -375,3 +375,7 @@ func (c *mockClient) GetResizeOperationsByClusterDataCentreID(cdcID string) ([]*
func (c *mockClient) GetAWSVPCPeering(peerID string) (*models.AWSVPCPeering, error) {
panic("GetAWSVPCPeering: is not implemented")
}

func (c *mockClient) CheckIfAWSEndpointServicePrincipalExists(id string) (bool, error) {
panic("CheckIfAWSEndpointServicePrincipalExists: is not implemented")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Everything is great, but I think we should cover it with tests in future

@OleksiienkoMykyta
Copy link
Collaborator

I agree with your statment, we should rename "state" to "instaclustrResourceState"

@@ -2215,6 +2215,31 @@ func (c *Client) UpdateClusterSettings(clusterID string, settings *models.Cluste
return nil
}

func (c *Client) CheckIfAWSEndpointServicePrincipalExists(id string) (bool, error) {
url := c.serverHostname + AWSEndpointServicePrincipalEndpoint + "/" + id
Copy link
Collaborator

Choose a reason for hiding this comment

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

AWSEndpointServicePrincipalEndpoint already has a backslash at the end, why did you add an additional one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@@ -2215,6 +2215,31 @@ func (c *Client) UpdateClusterSettings(clusterID string, settings *models.Cluste
return nil
}

func (c *Client) CheckIfAWSEndpointServicePrincipalExists(id string) (bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this method to GetAWSEndpointServicePrincipal and will return the service principal entity itself and an error. We can check the existence of the principal by using errors.Is(err, instaclustr.NotFound) func also

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@@ -49,6 +48,8 @@ type AWSVPCPeeringReconciler struct {
EventRecorder record.EventRecorder
}

const awsVPCPeeringStatusCodeDeleted = "deleted"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use const from package models instead of this variable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to the models pkg

@worryg0d worryg0d force-pushed the issue-572-clusterresources branch from 659e937 to 3fb5ed9 Compare October 5, 2023 08:00
@worryg0d worryg0d requested a review from testisnullus October 5, 2023 08:01
@ribaraka
Copy link
Contributor

I want to hear your opinion about the added state field which indicates the state of the resource on Instaclustr. Maybe changing it to something like instaclustrResourceState will be better.

The source of truth is the Instaclustr Console. So whatever the state/status of the Instaclustr resource is, it should be directly reflected on the k8s state field without any deviation. For now, I don't see a good reason to create a new field or give a new name to the existing state field of the resource.

Because some resources also have their status codes like AWS VPC peering. So it looks a bit weird when there is the following status:

status:
  state: CREATED
  statusCode: deleted

The field state indicates that the resource is created on Instaclustr, but statusCode: deleted indicates that the VPC peering is deleted on AWS.

In this example, I suggest you maintain consistency between the state and statusCode fields, or, even better, you can consider using only the state field to represent the statusCode.

@@ -129,6 +129,7 @@ func (r *AWSEncryptionKeyReconciler) handleCreate(
)

encryptionKey.Status = *encryptionKeyStatus
encryptionKey.Status.State = models.CreatedStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

try the thing I suggested by replacing statusCode with state or vice versa, as you prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Started using existing Status field

l := log.FromContext(ctx)

patch := key.NewPatch()
key.Status.State = models.DeletedStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

again, the thing with displaying the statuscode in the state

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 196 to 227
func (r *AWSEndpointServicePrincipalReconciler) newWatchStatusJob(ctx context.Context, principal *clusterresourcesv1beta1.AWSEndpointServicePrincipal) scheduler.Job {
return func() error {
_, err := r.API.GetAWSEndpointServicePrincipal(principal.Status.ID)
if err != nil {
if errors.Is(err, instaclustr.NotFound) {
return r.handleExternalDelete(ctx, principal)
}

return err
}

return nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

add a checker here for the existence of k8s resource

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added here and for other resources

@worryg0d worryg0d force-pushed the issue-572-clusterresources branch from 3fb5ed9 to 2f9b933 Compare October 11, 2023 07:45
@worryg0d worryg0d requested a review from ribaraka October 11, 2023 07:46
@worryg0d worryg0d force-pushed the issue-572-clusterresources branch from 2f9b933 to 8d99391 Compare October 12, 2023 12:27
@testisnullus testisnullus merged commit 4d5d744 into main Oct 17, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

External Deletion
5 participants