mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-08-23 22:26:49 +00:00
🐛 Switch the order of deletion of access entry and iamrole when managedcluster gets deleted. (#1022)
* Delete access entry before iam role Signed-off-by: Jeffrey Wong <jeffreywong0417@gmail.com> * Fix error handling to fix unit test Signed-off-by: Jeffrey Wong <jeffreywong0417@gmail.com> * Fix go fmt error Signed-off-by: Jeffrey Wong <jeffreywong0417@gmail.com> --------- Signed-off-by: Jeffrey Wong <jeffreywong0417@gmail.com> Co-authored-by: Jeffrey Wong <jeffreywong0417@gmail.com>
This commit is contained in:
co-authored by
Jeffrey Wong
parent
8c494744fa
commit
5bcfeca203
@@ -28,6 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
resourceNotFound = "ResourceNotFoundException"
|
||||||
errNoSuchEntity = "NoSuchEntity"
|
errNoSuchEntity = "NoSuchEntity"
|
||||||
errEntityAlreadyExists = "EntityAlreadyExists"
|
errEntityAlreadyExists = "EntityAlreadyExists"
|
||||||
trustPolicyTemplatePath = "managed-cluster-policy/TrustPolicy.tmpl"
|
trustPolicyTemplatePath = "managed-cluster-policy/TrustPolicy.tmpl"
|
||||||
@@ -77,14 +78,14 @@ func (c *AWSIRSAHubDriver) Cleanup(ctx context.Context, managedCluster *clusterv
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = deleteIAMRole(ctx, c.cfg, roleName)
|
eksClient := eks.NewFromConfig(c.cfg)
|
||||||
|
_, hubClusterName := commonhelpers.GetAwsAccountIdAndClusterName(c.hubClusterArn)
|
||||||
|
err = deleteAccessEntry(ctx, eksClient, roleArn, hubClusterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
eksClient := eks.NewFromConfig(c.cfg)
|
err = deleteIAMRole(ctx, c.cfg, roleName)
|
||||||
_, hubClusterName := commonhelpers.GetAwsAccountIdAndClusterName(c.hubClusterArn)
|
|
||||||
err = deleteAccessEntry(ctx, eksClient, roleArn, hubClusterName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -313,6 +314,10 @@ func deleteAccessEntry(ctx context.Context, eksClient *eks.Client, roleArn strin
|
|||||||
|
|
||||||
_, err := eksClient.DeleteAccessEntry(ctx, params)
|
_, err := eksClient.DeleteAccessEntry(ctx, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), resourceNotFound) {
|
||||||
|
logger.V(4).Error(err, "Access Entry already deleted for HubClusterName", "HubClusterName", hubClusterName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
logger.V(4).Error(err, "Failed to delete Access Entry for HubClusterName", "HubClusterName", hubClusterName)
|
logger.V(4).Error(err, "Failed to delete Access Entry for HubClusterName", "HubClusterName", hubClusterName)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user