diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index 2585237f84..5f3940e652 100644 --- a/pkg/cloud/services/eks/oidc.go +++ b/pkg/cloud/services/eks/oidc.go @@ -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 @@ -140,8 +147,8 @@ func (s *Service) reconcileTrustPolicy() error { } func (s *Service) deleteOIDCProvider() error { - anno := s.scope.ControlPlane.GetAnnotations() - arn := anno["aws.spectrocloud.com/oidcProviderArn"] + annotations := s.scope.ControlPlane.GetAnnotations() + arn := annotations[OidcProviderArnAnnotation] if arn == "" { arn = s.scope.ControlPlane.Status.OIDCProvider.ARN @@ -161,6 +168,9 @@ func (s *Service) deleteOIDCProvider() error { return errors.Wrap(err, "failed to update control plane with OIDC provider ARN") } + annotations[OidcProviderArnAnnotation] = "" + s.scope.ControlPlane.SetAnnotations(annotations) + return nil }