-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
c118958
to
659e937
Compare
pkg/instaclustr/mock/client.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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
I agree with your statment, we should rename "state" to "instaclustrResourceState" |
pkg/instaclustr/client.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
pkg/instaclustr/client.go
Outdated
@@ -2215,6 +2215,31 @@ func (c *Client) UpdateClusterSettings(clusterID string, settings *models.Cluste | |||
return nil | |||
} | |||
|
|||
func (c *Client) CheckIfAWSEndpointServicePrincipalExists(id string) (bool, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
659e937
to
3fb5ed9
Compare
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
In this example, I suggest you maintain consistency between the |
@@ -129,6 +129,7 @@ func (r *AWSEncryptionKeyReconciler) handleCreate( | |||
) | |||
|
|||
encryptionKey.Status = *encryptionKeyStatus | |||
encryptionKey.Status.State = models.CreatedStatus |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
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 | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
3fb5ed9
to
2f9b933
Compare
2f9b933
to
8d99391
Compare
Issue 572
Added:
closes #572