-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱Add initial Rosa machine pool integration tests #5214
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:main
from
PanSpagetka:rosa-initial-integration-test
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/aws/aws-sdk-go/service/sts/stsiface" | ||
"github.com/blang/semver" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
|
@@ -16,6 +17,7 @@ import ( | |
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"k8s.io/client-go/tools/record" | ||
|
@@ -31,6 +33,7 @@ import ( | |
|
||
rosacontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/rosa/api/v1beta2" | ||
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2" | ||
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud" | ||
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope" | ||
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger" | ||
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/rosa" | ||
|
@@ -48,11 +51,15 @@ type ROSAMachinePoolReconciler struct { | |
Recorder record.EventRecorder | ||
WatchFilterValue string | ||
Endpoints []scope.ServiceEndpoint | ||
NewStsClient func(cloud.ScopeUsage, cloud.Session, logger.Wrapper, runtime.Object) stsiface.STSAPI | ||
NewOCMClient func(ctx context.Context, rosaScope *scope.ROSAControlPlaneScope) (rosa.OCMClient, error) | ||
} | ||
|
||
// SetupWithManager is used to setup the controller. | ||
func (r *ROSAMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { | ||
log := logger.FromContext(ctx) | ||
r.NewOCMClient = rosa.NewWrappedOCMClient | ||
r.NewStsClient = scope.NewSTSClient | ||
|
||
gvk, err := apiutil.GVKForObject(new(expinfrav1.ROSAMachinePool), mgr.GetScheme()) | ||
if err != nil { | ||
|
@@ -148,6 +155,7 @@ func (r *ROSAMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Requ | |
ControlPlane: controlPlane, | ||
ControllerName: "rosaControlPlane", | ||
Endpoints: r.Endpoints, | ||
NewStsClient: r.NewStsClient, | ||
}) | ||
if err != nil { | ||
return ctrl.Result{}, errors.Wrap(err, "failed to create rosaControlPlane scope") | ||
|
@@ -185,9 +193,12 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context, | |
return ctrl.Result{}, err | ||
} | ||
} | ||
if r.NewOCMClient == nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: NewOCMClient is nil") | ||
} | ||
|
||
ocmClient, err := rosa.NewOCMClient(ctx, rosaControlPlaneScope) | ||
if err != nil { | ||
ocmClient, err := r.NewOCMClient(ctx, rosaControlPlaneScope) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, check for nil |
||
if err != nil || ocmClient == nil { | ||
// TODO: need to expose in status, as likely the credentials are invalid | ||
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: %w", err) | ||
} | ||
|
@@ -197,7 +208,6 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context, | |
return ctrl.Result{}, fmt.Errorf("failed to validate ROSAMachinePool.spec: %w", err) | ||
} | ||
if failureMessage != nil { | ||
machinePoolScope.RosaMachinePool.Status.FailureMessage = failureMessage | ||
// dont' requeue because input is invalid and manual intervention is needed. | ||
return ctrl.Result{}, nil | ||
} | ||
|
@@ -220,7 +230,6 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context, | |
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
if found { | ||
if rosaMachinePool.Spec.AvailabilityZone == "" { | ||
// reflect the current AvailabilityZone in the spec if not set. | ||
|
@@ -298,8 +307,8 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete( | |
) error { | ||
machinePoolScope.Info("Reconciling deletion of RosaMachinePool") | ||
|
||
ocmClient, err := rosa.NewOCMClient(ctx, rosaControlPlaneScope) | ||
if err != nil { | ||
ocmClient, err := r.NewOCMClient(ctx, rosaControlPlaneScope) | ||
if err != nil || ocmClient == nil { | ||
// TODO: need to expose in status, as likely the credentials are invalid | ||
return fmt.Errorf("failed to create OCM client: %w", err) | ||
} | ||
|
@@ -320,7 +329,7 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete( | |
return nil | ||
} | ||
|
||
func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) error { | ||
func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope *scope.RosaMachinePoolScope, ocmClient rosa.OCMClient, nodePool *cmv1.NodePool) error { | ||
version := machinePoolScope.RosaMachinePool.Spec.Version | ||
if version == "" || version == rosa.RawVersionID(nodePool.Version()) { | ||
machinePoolScope.RosaMachinePool.Status.AvailableUpgrades = nodePool.Version().AvailableUpgrades() | ||
|
@@ -335,7 +344,8 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope | |
} | ||
|
||
if scheduledUpgrade == nil { | ||
scheduledUpgrade, err = rosa.ScheduleNodePoolUpgrade(ocmClient, clusterID, nodePool, version, time.Now()) | ||
rosaOCMClient := ocmClient.(*ocm.Client) | ||
scheduledUpgrade, err = rosa.ScheduleNodePoolUpgrade(rosaOCMClient, clusterID, nodePool, version, time.Now()) | ||
if err != nil { | ||
return fmt.Errorf("failed to schedule nodePool upgrade to version %s: %w", version, err) | ||
} | ||
|
@@ -357,7 +367,7 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope | |
return nil | ||
} | ||
|
||
func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) (*cmv1.NodePool, error) { | ||
func (r *ROSAMachinePoolReconciler) updateNodePool(machinePoolScope *scope.RosaMachinePoolScope, ocmClient rosa.OCMClient, nodePool *cmv1.NodePool) (*cmv1.NodePool, error) { | ||
machinePool := machinePoolScope.RosaMachinePool.DeepCopy() | ||
// default all fields before comparing, so that nil/unset fields don't cause an unnecessary update call. | ||
machinePool.Default() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for nil, r.NewOCMClient could be nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forget this,
if r.NewOCMClient != nil