From 5bb327db6c72ae037c94c7f776da830914bf06c1 Mon Sep 17 00:00:00 2001 From: Amit Sahastrabuddhe Date: Wed, 27 Mar 2024 10:34:40 +0530 Subject: [PATCH 1/6] eks oidc arn deletion error --- pkg/cloud/services/eks/oidc.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index 2585237f84..03320ac3e2 100644 --- a/pkg/cloud/services/eks/oidc.go +++ b/pkg/cloud/services/eks/oidc.go @@ -161,6 +161,9 @@ func (s *Service) deleteOIDCProvider() error { return errors.Wrap(err, "failed to update control plane with OIDC provider ARN") } + anno["aws.spectrocloud.com/oidcProviderArn"] = "" + s.scope.ControlPlane.SetAnnotations(anno) + return nil } From d4b897c06c50e1d1db97d08fd203ab9c570042f4 Mon Sep 17 00:00:00 2001 From: Amit Sahastrabuddhe Date: Wed, 27 Mar 2024 10:39:18 +0530 Subject: [PATCH 2/6] eks oidc arn deletion error --- pkg/cloud/services/eks/oidc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index 03320ac3e2..74037b1239 100644 --- a/pkg/cloud/services/eks/oidc.go +++ b/pkg/cloud/services/eks/oidc.go @@ -140,8 +140,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["aws.spectrocloud.com/oidcProviderArn"] if arn == "" { arn = s.scope.ControlPlane.Status.OIDCProvider.ARN @@ -161,8 +161,8 @@ func (s *Service) deleteOIDCProvider() error { return errors.Wrap(err, "failed to update control plane with OIDC provider ARN") } - anno["aws.spectrocloud.com/oidcProviderArn"] = "" - s.scope.ControlPlane.SetAnnotations(anno) + annotations["aws.spectrocloud.com/oidcProviderArn"] = "" + s.scope.ControlPlane.SetAnnotations(annotations) return nil } From ee24eb7ace7e61bf40490905e4cb9c33ccda3b49 Mon Sep 17 00:00:00 2001 From: Amit Sahastrabuddhe Date: Wed, 27 Mar 2024 11:48:14 +0530 Subject: [PATCH 3/6] code refactor --- pkg/cloud/services/eks/oidc.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index 74037b1239..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 @@ -141,7 +148,7 @@ func (s *Service) reconcileTrustPolicy() error { func (s *Service) deleteOIDCProvider() error { annotations := s.scope.ControlPlane.GetAnnotations() - arn := annotations["aws.spectrocloud.com/oidcProviderArn"] + arn := annotations[OidcProviderArnAnnotation] if arn == "" { arn = s.scope.ControlPlane.Status.OIDCProvider.ARN @@ -161,7 +168,7 @@ func (s *Service) deleteOIDCProvider() error { return errors.Wrap(err, "failed to update control plane with OIDC provider ARN") } - annotations["aws.spectrocloud.com/oidcProviderArn"] = "" + annotations[OidcProviderArnAnnotation] = "" s.scope.ControlPlane.SetAnnotations(annotations) return nil From 151b01ec5833f66bac7cbb098a5d47f69e685f3c Mon Sep 17 00:00:00 2001 From: Amit Sahastrabuddhe Date: Wed, 27 Mar 2024 16:53:07 +0530 Subject: [PATCH 4/6] code refactor --- pkg/cloud/services/eks/oidc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index 5f3940e652..86145597a8 100644 --- a/pkg/cloud/services/eks/oidc.go +++ b/pkg/cloud/services/eks/oidc.go @@ -63,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") From 054522498063ec11b9812193a9c7d6d5a20a9160 Mon Sep 17 00:00:00 2001 From: Amit Sahastrabuddhe Date: Wed, 27 Mar 2024 17:00:20 +0530 Subject: [PATCH 5/6] code refactor --- pkg/cloud/services/eks/oidc.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index 86145597a8..efbdcd6c0c 100644 --- a/pkg/cloud/services/eks/oidc.go +++ b/pkg/cloud/services/eks/oidc.go @@ -147,10 +147,15 @@ func (s *Service) reconcileTrustPolicy() error { } func (s *Service) deleteOIDCProvider() error { + + // 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 } @@ -168,6 +173,7 @@ 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) From 7047c04e0c956c3a9770d1b8a984e0f5efe6ed39 Mon Sep 17 00:00:00 2001 From: Amit Sahastrabuddhe Date: Wed, 27 Mar 2024 19:52:59 +0530 Subject: [PATCH 6/6] code refactor --- pkg/cloud/services/eks/oidc.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/cloud/services/eks/oidc.go b/pkg/cloud/services/eks/oidc.go index efbdcd6c0c..784c9ce67a 100644 --- a/pkg/cloud/services/eks/oidc.go +++ b/pkg/cloud/services/eks/oidc.go @@ -37,10 +37,10 @@ import ( ) const ( - // OidcProviderArnAnnotation set/unset this annotation to managed control plane. + // 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" + OIDCProviderARNAnnotation = "aws.spectrocloud.com/oidcProviderArn" ) func (s *Service) reconcileOIDCProvider(cluster *eks.Cluster) error { @@ -63,7 +63,7 @@ func (s *Service) reconcileOIDCProvider(cluster *eks.Cluster) error { if anno == nil { anno = make(map[string]string) } - anno[OidcProviderArnAnnotation] = 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") @@ -149,13 +149,13 @@ func (s *Service) reconcileTrustPolicy() error { func (s *Service) deleteOIDCProvider() error { // 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. + // OIDCProviderARNAnnotation will be used to avoid it. annotations := s.scope.ControlPlane.GetAnnotations() - arn := annotations[OidcProviderArnAnnotation] + arn := annotations[OIDCProviderARNAnnotation] if arn == "" { - // Upgrade support for cluster without OidcProviderArnAnnotation set + // Upgrade support for cluster without OIDCProviderARNAnnotation set arn = s.scope.ControlPlane.Status.OIDCProvider.ARN } @@ -173,8 +173,8 @@ 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] = "" + // Remove OIDCProviderARNAnnotation after successfully deleting oidc provider + annotations[OIDCProviderARNAnnotation] = "" s.scope.ControlPlane.SetAnnotations(annotations) return nil