@@ -24,10 +24,13 @@ import (
2424	"fmt" 
2525	"net" 
2626	"net/url" 
27+ 	"reflect" 
2728	"strconv" 
2829	"strings" 
2930	"time" 
3031
32+ 	stsv2 "github.com/aws/aws-sdk-go-v2/service/sts" 
33+ 	sts "github.com/aws/aws-sdk-go/service/sts" 
3134	"github.com/google/go-cmp/cmp" 
3235	idputils "github.com/openshift-online/ocm-common/pkg/idp/utils" 
3336	cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" 
@@ -206,7 +209,7 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
206209		return  ctrl.Result {}, fmt .Errorf ("failed to create OCM client: %w" , err )
207210	}
208211
209- 	creator , err  :=  rosaaws .CreatorForCallerIdentity (rosaScope .Identity )
212+ 	creator , err  :=  rosaaws .CreatorForCallerIdentity (convertStsV2 ( rosaScope .Identity ) )
210213	if  err  !=  nil  {
211214		return  ctrl.Result {}, fmt .Errorf ("failed to transform caller identity to creator: %w" , err )
212215	}
@@ -334,7 +337,7 @@ func (r *ROSAControlPlaneReconciler) reconcileDelete(ctx context.Context, rosaSc
334337		return  ctrl.Result {}, fmt .Errorf ("failed to create OCM client: %w" , err )
335338	}
336339
337- 	creator , err  :=  rosaaws .CreatorForCallerIdentity (rosaScope .Identity )
340+ 	creator , err  :=  rosaaws .CreatorForCallerIdentity (convertStsV2 ( rosaScope .Identity ) )
338341	if  err  !=  nil  {
339342		return  ctrl.Result {}, fmt .Errorf ("failed to transform caller identity to creator: %w" , err )
340343	}
@@ -439,23 +442,75 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.RO
439442}
440443
441444func  (r  * ROSAControlPlaneReconciler ) updateOCMCluster (rosaScope  * scope.ROSAControlPlaneScope , ocmClient  * ocm.Client , cluster  * cmv1.Cluster , creator  * rosaaws.Creator ) error  {
445+ 	ocmClusterSpec  :=  ocm.Spec {}
446+ 	updated  :=  false 
442447	currentAuditLogRole  :=  cluster .AWS ().AuditLog ().RoleArn ()
443- 	if  currentAuditLogRole  ==  rosaScope .ControlPlane .Spec .AuditLogRoleARN  {
444- 		return  nil 
448+ 
449+ 	if  currentAuditLogRole  !=  rosaScope .ControlPlane .Spec .AuditLogRoleARN  {
450+ 		ocmClusterSpec .AuditLogRoleARN  =  ptr .To (rosaScope .ControlPlane .Spec .AuditLogRoleARN )
451+ 		updated  =  true 
445452	}
446453
447- 	ocmClusterSpec  :=  ocm.Spec {
448- 		AuditLogRoleARN : ptr .To (rosaScope .ControlPlane .Spec .AuditLogRoleARN ),
454+ 	// Check for registry config changes 
455+ 	regConfig  :=  & rosacontrolplanev1.RegistryConfig {
456+ 		RegistrySources : & rosacontrolplanev1.RegistrySources {},
449457	}
458+ 	if  rosaScope .ControlPlane .Spec .ClusterRegistryConfig  !=  nil  {
459+ 		regConfig .AdditionalTrustedCa  =  rosaScope .ControlPlane .Spec .ClusterRegistryConfig .AdditionalTrustedCa 
460+ 		regConfig .AllowedRegistriesForImport  =  rosaScope .ControlPlane .Spec .ClusterRegistryConfig .AllowedRegistriesForImport 
450461
451- 	// if this fails, the provided role is likely invalid or it doesn't have the required permissions. 
452- 	if  err  :=  ocmClient .UpdateCluster (cluster .ID (), creator , ocmClusterSpec ); err  !=  nil  {
453- 		conditions .MarkFalse (rosaScope .ControlPlane ,
454- 			rosacontrolplanev1 .ROSAControlPlaneValidCondition ,
455- 			rosacontrolplanev1 .ROSAControlPlaneInvalidConfigurationReason ,
456- 			clusterv1 .ConditionSeverityError ,
457- 			err .Error ())
458- 		return  err 
462+ 		if  rosaScope .ControlPlane .Spec .ClusterRegistryConfig .RegistrySources  !=  nil  {
463+ 			regConfig .RegistrySources .AllowedRegistries  =  rosaScope .ControlPlane .Spec .ClusterRegistryConfig .RegistrySources .AllowedRegistries 
464+ 			regConfig .RegistrySources .BlockedRegistries  =  rosaScope .ControlPlane .Spec .ClusterRegistryConfig .RegistrySources .BlockedRegistries 
465+ 			regConfig .RegistrySources .InsecureRegistries  =  rosaScope .ControlPlane .Spec .ClusterRegistryConfig .RegistrySources .InsecureRegistries 
466+ 		}
467+ 	}
468+ 	if  ! reflect .DeepEqual (regConfig .AdditionalTrustedCa , cluster .RegistryConfig ().AdditionalTrustedCa ()) {
469+ 		ocmClusterSpec .AdditionalTrustedCa  =  regConfig .AdditionalTrustedCa 
470+ 		updated  =  true 
471+ 	}
472+ 	if  ! reflect .DeepEqual (regConfig .RegistrySources .AllowedRegistries , cluster .RegistryConfig ().RegistrySources ().AllowedRegistries ()) {
473+ 		ocmClusterSpec .AllowedRegistries  =  regConfig .RegistrySources .AllowedRegistries 
474+ 		updated  =  true 
475+ 	}
476+ 	if  ! reflect .DeepEqual (regConfig .RegistrySources .BlockedRegistries , cluster .RegistryConfig ().RegistrySources ().BlockedRegistries ()) {
477+ 		ocmClusterSpec .BlockedRegistries  =  regConfig .RegistrySources .BlockedRegistries 
478+ 		updated  =  true 
479+ 	}
480+ 	if  ! reflect .DeepEqual (regConfig .RegistrySources .InsecureRegistries , cluster .RegistryConfig ().RegistrySources ().InsecureRegistries ()) {
481+ 		ocmClusterSpec .InsecureRegistries  =  regConfig .RegistrySources .InsecureRegistries 
482+ 		updated  =  true 
483+ 	}
484+ 
485+ 	var  newAllowedRegisters , oldAllowedRegisters  []string 
486+ 	if  len (regConfig .AllowedRegistriesForImport ) >  0  {
487+ 		for  id  :=  range  regConfig .AllowedRegistriesForImport  {
488+ 			newAllowedRegisters  =  append (newAllowedRegisters , regConfig .AllowedRegistriesForImport [id ].DomainName + ":" + 
489+ 				strconv .FormatBool (regConfig .AllowedRegistriesForImport [id ].Insecure ))
490+ 		}
491+ 	}
492+ 	if  len (cluster .RegistryConfig ().AllowedRegistriesForImport ()) >  0  {
493+ 		for  id  :=  range  cluster .RegistryConfig ().AllowedRegistriesForImport () {
494+ 			oldAllowedRegisters  =  append (oldAllowedRegisters , cluster .RegistryConfig ().AllowedRegistriesForImport ()[id ].DomainName ()+ ":" + 
495+ 				strconv .FormatBool (cluster .RegistryConfig ().AllowedRegistriesForImport ()[id ].Insecure ()))
496+ 		}
497+ 	}
498+ 	if  ! reflect .DeepEqual (newAllowedRegisters , oldAllowedRegisters ) {
499+ 		ocmClusterSpec .AllowedRegistriesForImport  =  strings .Join (newAllowedRegisters , "," )
500+ 		updated  =  true 
501+ 	}
502+ 
503+ 	if  updated  {
504+ 		// Update the cluster. 
505+ 		rosaScope .Info ("Updating cluster" )
506+ 		if  err  :=  ocmClient .UpdateCluster (cluster .ID (), creator , ocmClusterSpec ); err  !=  nil  {
507+ 			conditions .MarkFalse (rosaScope .ControlPlane ,
508+ 				rosacontrolplanev1 .ROSAControlPlaneValidCondition ,
509+ 				rosacontrolplanev1 .ROSAControlPlaneInvalidConfigurationReason ,
510+ 				clusterv1 .ConditionSeverityError ,
511+ 				err .Error ())
512+ 			return  err 
513+ 		}
459514	}
460515
461516	return  nil 
@@ -888,6 +943,28 @@ func buildOCMClusterSpec(controlPlaneSpec rosacontrolplanev1.RosaControlPlaneSpe
888943		}
889944	}
890945
946+ 	// Set the cluster registry config. 
947+ 	if  controlPlaneSpec .ClusterRegistryConfig  !=  nil  {
948+ 		if  len (controlPlaneSpec .ClusterRegistryConfig .AdditionalTrustedCa ) >  0  {
949+ 			ocmClusterSpec .AdditionalTrustedCa  =  controlPlaneSpec .ClusterRegistryConfig .AdditionalTrustedCa 
950+ 		}
951+ 
952+ 		if  len (controlPlaneSpec .ClusterRegistryConfig .AllowedRegistriesForImport ) >  0  {
953+ 			registers  :=  make ([]string , 0 )
954+ 			for  id  :=  range  controlPlaneSpec .ClusterRegistryConfig .AllowedRegistriesForImport  {
955+ 				registers  =  append (registers , controlPlaneSpec .ClusterRegistryConfig .AllowedRegistriesForImport [id ].DomainName + ":" + 
956+ 					strconv .FormatBool (controlPlaneSpec .ClusterRegistryConfig .AllowedRegistriesForImport [id ].Insecure ))
957+ 			}
958+ 			ocmClusterSpec .AllowedRegistriesForImport  =  strings .Join (registers , "," )
959+ 		}
960+ 
961+ 		if  controlPlaneSpec .ClusterRegistryConfig .RegistrySources  !=  nil  {
962+ 			ocmClusterSpec .BlockedRegistries  =  controlPlaneSpec .ClusterRegistryConfig .RegistrySources .BlockedRegistries 
963+ 			ocmClusterSpec .AllowedRegistries  =  controlPlaneSpec .ClusterRegistryConfig .RegistrySources .AllowedRegistries 
964+ 			ocmClusterSpec .InsecureRegistries  =  controlPlaneSpec .ClusterRegistryConfig .RegistrySources .InsecureRegistries 
965+ 		}
966+ 	}
967+ 
891968	return  ocmClusterSpec , nil 
892969}
893970
@@ -996,3 +1073,12 @@ func buildAPIEndpoint(cluster *cmv1.Cluster) (*clusterv1.APIEndpoint, error) {
9961073		Port : int32 (port ), // #nosec G109 
9971074	}, nil 
9981075}
1076+ 
1077+ // TODO: Remove this and update the aws-sdk lib to v2. 
1078+ func  convertStsV2 (identity  * sts.GetCallerIdentityOutput ) * stsv2.GetCallerIdentityOutput  {
1079+ 	return  & stsv2.GetCallerIdentityOutput {
1080+ 		Account : identity .Account ,
1081+ 		Arn :     identity .Arn ,
1082+ 		UserId :  identity .UserId ,
1083+ 	}
1084+ }
0 commit comments