Skip to content

Commit abd21bc

Browse files
committed
Add initial Rosa machine pool integration tests
1 parent 85759ce commit abd21bc

File tree

10 files changed

+814
-21
lines changed

10 files changed

+814
-21
lines changed

controlplane/rosa/controllers/rosacontrolplane_controller.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
stsv2 "github.com/aws/aws-sdk-go-v2/service/sts"
3333
sts "github.com/aws/aws-sdk-go/service/sts"
34+
"github.com/aws/aws-sdk-go/service/sts/stsiface"
3435
"github.com/google/go-cmp/cmp"
3536
idputils "github.com/openshift-online/ocm-common/pkg/idp/utils"
3637
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
@@ -40,6 +41,7 @@ import (
4041
corev1 "k8s.io/api/core/v1"
4142
apierrors "k8s.io/apimachinery/pkg/api/errors"
4243
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
44+
"k8s.io/apimachinery/pkg/runtime"
4345
"k8s.io/apimachinery/pkg/types"
4446
kerrors "k8s.io/apimachinery/pkg/util/errors"
4547
"k8s.io/apiserver/pkg/storage/names"
@@ -58,6 +60,7 @@ import (
5860
rosacontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/rosa/api/v1beta2"
5961
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
6062
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/annotations"
63+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud"
6164
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
6265
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
6366
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/rosa"
@@ -89,6 +92,8 @@ type ROSAControlPlaneReconciler struct {
8992
WatchFilterValue string
9093
WaitInfraPeriod time.Duration
9194
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)
9297
}
9398

9499
// SetupWithManager is used to setup the controller.
@@ -173,6 +178,7 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
173178
ControllerName: strings.ToLower(rosaControlPlaneKind),
174179
Endpoints: r.Endpoints,
175180
Logger: log,
181+
NewStsClient: r.NewStsClient,
176182
})
177183
if err != nil {
178184
return ctrl.Result{}, fmt.Errorf("failed to create scope: %w", err)
@@ -203,7 +209,7 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
203209
}
204210
}
205211

206-
ocmClient, err := rosa.NewOCMClient(ctx, rosaScope)
212+
ocmClient, err := r.NewOCMClient(ctx, rosaScope)
207213
if err != nil {
208214
// TODO: need to expose in status, as likely the credentials are invalid
209215
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: %w", err)
@@ -406,7 +412,7 @@ func (r *ROSAControlPlaneReconciler) deleteMachinePools(ctx context.Context, ros
406412
return len(machinePools) == 0, nil
407413
}
408414

409-
func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.ROSAControlPlaneScope, ocmClient *ocm.Client, cluster *cmv1.Cluster) error {
415+
func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.ROSAControlPlaneScope, ocmClient rosa.OCMClient, cluster *cmv1.Cluster) error {
410416
version := rosaScope.ControlPlane.Spec.Version
411417
if version == rosa.RawVersionID(cluster.Version()) {
412418
conditions.MarkFalse(rosaScope.ControlPlane, rosacontrolplanev1.ROSAControlPlaneUpgradingCondition, "upgraded", clusterv1.ConditionSeverityInfo, "")
@@ -461,7 +467,7 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.RO
461467
return nil
462468
}
463469

464-
func (r *ROSAControlPlaneReconciler) updateOCMCluster(rosaScope *scope.ROSAControlPlaneScope, ocmClient *ocm.Client, cluster *cmv1.Cluster, creator *rosaaws.Creator) error {
470+
func (r *ROSAControlPlaneReconciler) updateOCMCluster(rosaScope *scope.ROSAControlPlaneScope, ocmClient rosa.OCMClient, cluster *cmv1.Cluster, creator *rosaaws.Creator) error {
465471
ocmClusterSpec, updated := r.updateOCMClusterSpec(rosaScope.ControlPlane, cluster)
466472

467473
if updated {
@@ -758,7 +764,7 @@ func (r *ROSAControlPlaneReconciler) reconcileExternalAuthBootstrapKubeconfig(ct
758764
return nil
759765
}
760766

761-
func (r *ROSAControlPlaneReconciler) reconcileKubeconfig(ctx context.Context, rosaScope *scope.ROSAControlPlaneScope, ocmClient *ocm.Client, cluster *cmv1.Cluster) error {
767+
func (r *ROSAControlPlaneReconciler) reconcileKubeconfig(ctx context.Context, rosaScope *scope.ROSAControlPlaneScope, ocmClient rosa.OCMClient, cluster *cmv1.Cluster) error {
762768
rosaScope.Debug("Reconciling ROSA kubeconfig for cluster", "cluster-name", rosaScope.RosaClusterName())
763769

764770
clusterRef := client.ObjectKeyFromObject(rosaScope.Cluster)
@@ -870,7 +876,7 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterAdminPassword(ctx context.C
870876
return password, nil
871877
}
872878

873-
func validateControlPlaneSpec(ocmClient *ocm.Client, rosaScope *scope.ROSAControlPlaneScope) (string, error) {
879+
func validateControlPlaneSpec(ocmClient rosa.OCMClient, rosaScope *scope.ROSAControlPlaneScope) (string, error) {
874880
version := rosaScope.ControlPlane.Spec.Version
875881
valid, err := ocmClient.ValidateHypershiftVersion(version, ocm.DefaultChannelGroup)
876882
if err != nil {

exp/controllers/rosamachinepool_controller.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/aws/aws-sdk-go/aws"
99
"github.com/aws/aws-sdk-go/service/ec2"
10+
"github.com/aws/aws-sdk-go/service/sts/stsiface"
1011
"github.com/blang/semver"
1112
"github.com/google/go-cmp/cmp"
1213
"github.com/google/go-cmp/cmp/cmpopts"
@@ -16,6 +17,7 @@ import (
1617
corev1 "k8s.io/api/core/v1"
1718
apierrors "k8s.io/apimachinery/pkg/api/errors"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
"k8s.io/apimachinery/pkg/runtime"
1921
"k8s.io/apimachinery/pkg/runtime/schema"
2022
"k8s.io/apimachinery/pkg/util/intstr"
2123
"k8s.io/client-go/tools/record"
@@ -31,6 +33,7 @@ import (
3133

3234
rosacontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/rosa/api/v1beta2"
3335
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
36+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud"
3437
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
3538
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
3639
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/rosa"
@@ -48,6 +51,8 @@ type ROSAMachinePoolReconciler struct {
4851
Recorder record.EventRecorder
4952
WatchFilterValue string
5053
Endpoints []scope.ServiceEndpoint
54+
NewStsClient func(cloud.ScopeUsage, cloud.Session, logger.Wrapper, runtime.Object) stsiface.STSAPI
55+
NewOCMClient func(ctx context.Context, rosaScope *scope.ROSAControlPlaneScope) (rosa.OCMClient, error)
5156
}
5257

5358
// SetupWithManager is used to setup the controller.
@@ -148,6 +153,7 @@ func (r *ROSAMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Requ
148153
ControlPlane: controlPlane,
149154
ControllerName: "rosaControlPlane",
150155
Endpoints: r.Endpoints,
156+
NewStsClient: r.NewStsClient,
151157
})
152158
if err != nil {
153159
return ctrl.Result{}, errors.Wrap(err, "failed to create rosaControlPlane scope")
@@ -186,7 +192,7 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
186192
}
187193
}
188194

189-
ocmClient, err := rosa.NewOCMClient(ctx, rosaControlPlaneScope)
195+
ocmClient, err := r.NewOCMClient(ctx, rosaControlPlaneScope)
190196
if err != nil {
191197
// TODO: need to expose in status, as likely the credentials are invalid
192198
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: %w", err)
@@ -298,7 +304,7 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete(
298304
) error {
299305
machinePoolScope.Info("Reconciling deletion of RosaMachinePool")
300306

301-
ocmClient, err := rosa.NewOCMClient(ctx, rosaControlPlaneScope)
307+
ocmClient, err := r.NewOCMClient(ctx, rosaControlPlaneScope)
302308
if err != nil {
303309
// TODO: need to expose in status, as likely the credentials are invalid
304310
return fmt.Errorf("failed to create OCM client: %w", err)
@@ -320,7 +326,7 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete(
320326
return nil
321327
}
322328

323-
func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) error {
329+
func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope *scope.RosaMachinePoolScope, ocmClient rosa.OCMClient, nodePool *cmv1.NodePool) error {
324330
version := machinePoolScope.RosaMachinePool.Spec.Version
325331
if version == "" || version == rosa.RawVersionID(nodePool.Version()) {
326332
conditions.MarkFalse(machinePoolScope.RosaMachinePool, expinfrav1.RosaMachinePoolUpgradingCondition, "upgraded", clusterv1.ConditionSeverityInfo, "")
@@ -356,7 +362,7 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope
356362
return nil
357363
}
358364

359-
func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) (*cmv1.NodePool, error) {
365+
func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaMachinePoolScope, ocmClient rosa.OCMClient, nodePool *cmv1.NodePool) (*cmv1.NodePool, error) {
360366
machinePool := machinePoolScope.RosaMachinePool.DeepCopy()
361367
// default all fields before comparing, so that nil/unset fields don't cause an unnecessary update call.
362368
machinePool.Default()

0 commit comments

Comments
 (0)