@@ -31,6 +31,7 @@ import (
31
31
32
32
stsv2 "github.com/aws/aws-sdk-go-v2/service/sts"
33
33
sts "github.com/aws/aws-sdk-go/service/sts"
34
+ "github.com/aws/aws-sdk-go/service/sts/stsiface"
34
35
"github.com/google/go-cmp/cmp"
35
36
idputils "github.com/openshift-online/ocm-common/pkg/idp/utils"
36
37
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
@@ -40,6 +41,7 @@ import (
40
41
corev1 "k8s.io/api/core/v1"
41
42
apierrors "k8s.io/apimachinery/pkg/api/errors"
42
43
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
44
+ "k8s.io/apimachinery/pkg/runtime"
43
45
"k8s.io/apimachinery/pkg/types"
44
46
kerrors "k8s.io/apimachinery/pkg/util/errors"
45
47
"k8s.io/apiserver/pkg/storage/names"
@@ -58,6 +60,7 @@ import (
58
60
rosacontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/rosa/api/v1beta2"
59
61
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
60
62
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/annotations"
63
+ "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud"
61
64
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
62
65
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
63
66
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/rosa"
@@ -89,11 +92,15 @@ type ROSAControlPlaneReconciler struct {
89
92
WatchFilterValue string
90
93
WaitInfraPeriod time.Duration
91
94
Endpoints []scope.ServiceEndpoint
95
+ NewStsClient func (cloud.ScopeUsage , cloud.Session , logger.Wrapper , runtime.Object ) stsiface.STSAPI
96
+ NewOCMClient func (ctx context.Context , rosaScope * scope.ROSAControlPlaneScope ) (rosa.OCMClient , error )
92
97
}
93
98
94
99
// SetupWithManager is used to setup the controller.
95
100
func (r * ROSAControlPlaneReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
96
101
log := logger .FromContext (ctx )
102
+ r .NewOCMClient = rosa .NewWrappedOCMClient
103
+ r .NewStsClient = scope .NewSTSClient
97
104
98
105
rosaControlPlane := & rosacontrolplanev1.ROSAControlPlane {}
99
106
c , err := ctrl .NewControllerManagedBy (mgr ).
@@ -173,6 +180,7 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
173
180
ControllerName : strings .ToLower (rosaControlPlaneKind ),
174
181
Endpoints : r .Endpoints ,
175
182
Logger : log ,
183
+ NewStsClient : r .NewStsClient ,
176
184
})
177
185
if err != nil {
178
186
return ctrl.Result {}, fmt .Errorf ("failed to create scope: %w" , err )
@@ -202,9 +210,12 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
202
210
return ctrl.Result {}, err
203
211
}
204
212
}
213
+ if r .NewOCMClient == nil {
214
+ return ctrl.Result {}, fmt .Errorf ("failed to create OCM client: NewOCMClient is nil" )
215
+ }
205
216
206
- ocmClient , err := rosa .NewOCMClient (ctx , rosaScope )
207
- if err != nil {
217
+ ocmClient , err := r .NewOCMClient (ctx , rosaScope )
218
+ if err != nil || ocmClient == nil {
208
219
// TODO: need to expose in status, as likely the credentials are invalid
209
220
return ctrl.Result {}, fmt .Errorf ("failed to create OCM client: %w" , err )
210
221
}
@@ -336,7 +347,7 @@ func (r *ROSAControlPlaneReconciler) reconcileDelete(ctx context.Context, rosaSc
336
347
}
337
348
338
349
ocmClient , err := rosa .NewOCMClient (ctx , rosaScope )
339
- if err != nil {
350
+ if err != nil || ocmClient == nil {
340
351
// TODO: need to expose in status, as likely the credentials are invalid
341
352
return ctrl.Result {}, fmt .Errorf ("failed to create OCM client: %w" , err )
342
353
}
@@ -410,7 +421,7 @@ func (r *ROSAControlPlaneReconciler) deleteMachinePools(ctx context.Context, ros
410
421
return len (machinePools ) == 0 , nil
411
422
}
412
423
413
- func (r * ROSAControlPlaneReconciler ) reconcileClusterVersion (rosaScope * scope.ROSAControlPlaneScope , ocmClient * ocm. Client , cluster * cmv1.Cluster ) error {
424
+ func (r * ROSAControlPlaneReconciler ) reconcileClusterVersion (rosaScope * scope.ROSAControlPlaneScope , ocmClient rosa. OCMClient , cluster * cmv1.Cluster ) error {
414
425
version := rosaScope .ControlPlane .Spec .Version
415
426
if version == rosa .RawVersionID (cluster .Version ()) {
416
427
conditions .MarkFalse (rosaScope .ControlPlane , rosacontrolplanev1 .ROSAControlPlaneUpgradingCondition , "upgraded" , clusterv1 .ConditionSeverityInfo , "" )
@@ -428,14 +439,15 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.RO
428
439
return nil
429
440
}
430
441
431
- scheduledUpgrade , err := rosa .CheckExistingScheduledUpgrade (ocmClient , cluster )
442
+ rosaOCMClient := ocmClient .(* ocm.Client )
443
+ scheduledUpgrade , err := rosa .CheckExistingScheduledUpgrade (rosaOCMClient , cluster )
432
444
if err != nil {
433
445
return fmt .Errorf ("failed to get existing scheduled upgrades: %w" , err )
434
446
}
435
447
436
448
if scheduledUpgrade == nil {
437
449
ack := (rosaScope .ControlPlane .Spec .VersionGate == rosacontrolplanev1 .Acknowledge || rosaScope .ControlPlane .Spec .VersionGate == rosacontrolplanev1 .AlwaysAcknowledge )
438
- scheduledUpgrade , err = rosa .ScheduleControlPlaneUpgrade (ocmClient , cluster , version , time .Now (), ack )
450
+ scheduledUpgrade , err = rosa .ScheduleControlPlaneUpgrade (rosaOCMClient , cluster , version , time .Now (), ack )
439
451
if err != nil {
440
452
condition := & clusterv1.Condition {
441
453
Type : rosacontrolplanev1 .ROSAControlPlaneUpgradingCondition ,
@@ -465,7 +477,7 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.RO
465
477
return nil
466
478
}
467
479
468
- func (r * ROSAControlPlaneReconciler ) updateOCMCluster (rosaScope * scope.ROSAControlPlaneScope , ocmClient * ocm. Client , cluster * cmv1.Cluster , creator * rosaaws.Creator ) error {
480
+ func (r * ROSAControlPlaneReconciler ) updateOCMCluster (rosaScope * scope.ROSAControlPlaneScope , ocmClient rosa. OCMClient , cluster * cmv1.Cluster , creator * rosaaws.Creator ) error {
469
481
ocmClusterSpec , updated := r .updateOCMClusterSpec (rosaScope .ControlPlane , cluster )
470
482
471
483
if updated {
@@ -764,7 +776,7 @@ func (r *ROSAControlPlaneReconciler) reconcileExternalAuthBootstrapKubeconfig(ct
764
776
return nil
765
777
}
766
778
767
- func (r * ROSAControlPlaneReconciler ) reconcileKubeconfig (ctx context.Context , rosaScope * scope.ROSAControlPlaneScope , ocmClient * ocm. Client , cluster * cmv1.Cluster ) error {
779
+ func (r * ROSAControlPlaneReconciler ) reconcileKubeconfig (ctx context.Context , rosaScope * scope.ROSAControlPlaneScope , ocmClient rosa. OCMClient , cluster * cmv1.Cluster ) error {
768
780
rosaScope .Debug ("Reconciling ROSA kubeconfig for cluster" , "cluster-name" , rosaScope .RosaClusterName ())
769
781
770
782
clusterRef := client .ObjectKeyFromObject (rosaScope .Cluster )
@@ -785,8 +797,9 @@ func (r *ROSAControlPlaneReconciler) reconcileKubeconfig(ctx context.Context, ro
785
797
userName := fmt .Sprintf ("%s-capi-admin" , clusterName )
786
798
apiServerURL := cluster .API ().URL ()
787
799
800
+ c := ocmClient .(* ocm.Client )
788
801
// create new user with admin privileges in the ROSA cluster if 'userName' doesn't already exist.
789
- err = rosa .CreateAdminUserIfNotExist (ocmClient , cluster .ID (), userName , password )
802
+ err = rosa .CreateAdminUserIfNotExist (c , cluster .ID (), userName , password )
790
803
if err != nil {
791
804
return err
792
805
}
@@ -876,7 +889,7 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterAdminPassword(ctx context.C
876
889
return password , nil
877
890
}
878
891
879
- func validateControlPlaneSpec (ocmClient * ocm. Client , rosaScope * scope.ROSAControlPlaneScope ) (string , error ) {
892
+ func validateControlPlaneSpec (ocmClient rosa. OCMClient , rosaScope * scope.ROSAControlPlaneScope ) (string , error ) {
880
893
version := rosaScope .ControlPlane .Spec .Version
881
894
channelGroup := rosaScope .ControlPlane .Spec .ChannelGroup
882
895
valid , err := ocmClient .ValidateHypershiftVersion (version , channelGroup )
0 commit comments