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

PCP-2735: EKS cluster deletion stuck with error failed to delete OIDC provider #897

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pkg/cloud/services/eks/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ import (
"sigs.k8s.io/cluster-api/controllers/remote"
)

const (
// OIDCProviderARNAnnotation set/unset this annotation to managed control plane.
// This is required in case of force pivot control plane status do not have ARN in status.
// In that cases annotation will be used to delete oidc resource.
OIDCProviderARNAnnotation = "aws.spectrocloud.com/oidcProviderArn"
)

func (s *Service) reconcileOIDCProvider(cluster *eks.Cluster) error {
if !s.scope.ControlPlane.Spec.AssociateOIDCProvider {
return nil
Expand All @@ -56,7 +63,7 @@ func (s *Service) reconcileOIDCProvider(cluster *eks.Cluster) error {
if anno == nil {
anno = make(map[string]string)
}
anno["aws.spectrocloud.com/oidcProviderArn"] = oidcProvider
anno[OIDCProviderARNAnnotation] = oidcProvider
s.scope.ControlPlane.SetAnnotations(anno)
if err := s.scope.PatchObject(); err != nil {
return errors.Wrap(err, "failed to update control plane with OIDC provider ARN")
Expand Down Expand Up @@ -140,10 +147,15 @@ func (s *Service) reconcileTrustPolicy() error {
}

func (s *Service) deleteOIDCProvider() error {
anno := s.scope.ControlPlane.GetAnnotations()
arn := anno["aws.spectrocloud.com/oidcProviderArn"]

// In case of force pivot managed control plane do not have ARN in status, that lead to oidcProvider not getting cleaned up during delete.
// OIDCProviderARNAnnotation will be used to avoid it.

annotations := s.scope.ControlPlane.GetAnnotations()
arn := annotations[OIDCProviderARNAnnotation]

if arn == "" {
// Upgrade support for cluster without OIDCProviderARNAnnotation set
arn = s.scope.ControlPlane.Status.OIDCProvider.ARN
}

Expand All @@ -161,6 +173,10 @@ func (s *Service) deleteOIDCProvider() error {
return errors.Wrap(err, "failed to update control plane with OIDC provider ARN")
}

// Remove OIDCProviderARNAnnotation after successfully deleting oidc provider
annotations[OIDCProviderARNAnnotation] = ""
s.scope.ControlPlane.SetAnnotations(annotations)

return nil
}

Expand Down