From 34bdcc877c95604fbf876a15703ca0c854c20c57 Mon Sep 17 00:00:00 2001 From: rknaur Date: Thu, 6 Feb 2025 14:03:43 +0100 Subject: [PATCH] Fix OCM client wrapper --- .../rosa/controllers/rosacontrolplane_controller.go | 8 +++----- exp/controllers/rosamachinepool_controller.go | 3 +-- pkg/rosa/idps.go | 5 ++--- pkg/rosa/versions.go | 6 +++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/controlplane/rosa/controllers/rosacontrolplane_controller.go b/controlplane/rosa/controllers/rosacontrolplane_controller.go index 1c62e3abe6..a97b5753ec 100644 --- a/controlplane/rosa/controllers/rosacontrolplane_controller.go +++ b/controlplane/rosa/controllers/rosacontrolplane_controller.go @@ -439,15 +439,14 @@ func (r *ROSAControlPlaneReconciler) reconcileClusterVersion(rosaScope *scope.RO return nil } - rosaOCMClient := ocmClient.(*ocm.Client) - scheduledUpgrade, err := rosa.CheckExistingScheduledUpgrade(rosaOCMClient, cluster) + scheduledUpgrade, err := rosa.CheckExistingScheduledUpgrade(ocmClient, cluster) if err != nil { return fmt.Errorf("failed to get existing scheduled upgrades: %w", err) } if scheduledUpgrade == nil { ack := (rosaScope.ControlPlane.Spec.VersionGate == rosacontrolplanev1.Acknowledge || rosaScope.ControlPlane.Spec.VersionGate == rosacontrolplanev1.AlwaysAcknowledge) - scheduledUpgrade, err = rosa.ScheduleControlPlaneUpgrade(rosaOCMClient, cluster, version, time.Now(), ack) + scheduledUpgrade, err = rosa.ScheduleControlPlaneUpgrade(ocmClient, cluster, version, time.Now(), ack) if err != nil { condition := &clusterv1.Condition{ Type: rosacontrolplanev1.ROSAControlPlaneUpgradingCondition, @@ -797,9 +796,8 @@ func (r *ROSAControlPlaneReconciler) reconcileKubeconfig(ctx context.Context, ro userName := fmt.Sprintf("%s-capi-admin", clusterName) apiServerURL := cluster.API().URL() - c := ocmClient.(*ocm.Client) // create new user with admin privileges in the ROSA cluster if 'userName' doesn't already exist. - err = rosa.CreateAdminUserIfNotExist(c, cluster.ID(), userName, password) + err = rosa.CreateAdminUserIfNotExist(ocmClient, cluster.ID(), userName, password) if err != nil { return err } diff --git a/exp/controllers/rosamachinepool_controller.go b/exp/controllers/rosamachinepool_controller.go index 9c0f2d207a..1b77decfc5 100644 --- a/exp/controllers/rosamachinepool_controller.go +++ b/exp/controllers/rosamachinepool_controller.go @@ -344,8 +344,7 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope } if scheduledUpgrade == nil { - rosaOCMClient := ocmClient.(*ocm.Client) - scheduledUpgrade, err = rosa.ScheduleNodePoolUpgrade(rosaOCMClient, clusterID, nodePool, version, time.Now()) + scheduledUpgrade, err = rosa.ScheduleNodePoolUpgrade(ocmClient, clusterID, nodePool, version, time.Now()) if err != nil { return fmt.Errorf("failed to schedule nodePool upgrade to version %s: %w", version, err) } diff --git a/pkg/rosa/idps.go b/pkg/rosa/idps.go index 61cb21254d..0d80bd7d56 100644 --- a/pkg/rosa/idps.go +++ b/pkg/rosa/idps.go @@ -4,7 +4,6 @@ import ( "fmt" cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" - "github.com/openshift/rosa/pkg/ocm" ) const ( @@ -14,7 +13,7 @@ const ( // CreateAdminUserIfNotExist creates a new admin user withe username/password in the cluster if username doesn't already exist. // the user is granted admin privileges by being added to a special IDP called `cluster-admin` which will be created if it doesn't already exist. -func CreateAdminUserIfNotExist(client *ocm.Client, clusterID, username, password string) error { +func CreateAdminUserIfNotExist(client OCMClient, clusterID, username, password string) error { existingClusterAdminIDP, userList, err := findExistingClusterAdminIDP(client, clusterID) if err != nil { return fmt.Errorf("failed to find existing cluster admin IDP: %w", err) @@ -75,7 +74,7 @@ func CreateAdminUserIfNotExist(client *ocm.Client, clusterID, username, password } // CreateUserIfNotExist creates a new user with `username` and adds it to the group if it doesn't already exist. -func CreateUserIfNotExist(client *ocm.Client, clusterID string, group, username string) (*cmv1.User, error) { +func CreateUserIfNotExist(client OCMClient, clusterID string, group, username string) (*cmv1.User, error) { user, err := client.GetUser(clusterID, group, username) if user != nil || err != nil { return user, err diff --git a/pkg/rosa/versions.go b/pkg/rosa/versions.go index 80fafd226a..6205368a6b 100644 --- a/pkg/rosa/versions.go +++ b/pkg/rosa/versions.go @@ -13,7 +13,7 @@ import ( var MinSupportedVersion = semver.MustParse("4.14.0") // CheckExistingScheduledUpgrade checks and returns the current upgrade schedule if any. -func CheckExistingScheduledUpgrade(client *ocm.Client, cluster *cmv1.Cluster) (*cmv1.ControlPlaneUpgradePolicy, error) { +func CheckExistingScheduledUpgrade(client OCMClient, cluster *cmv1.Cluster) (*cmv1.ControlPlaneUpgradePolicy, error) { upgradePolicies, err := client.GetControlPlaneUpgradePolicies(cluster.ID()) if err != nil { return nil, err @@ -27,7 +27,7 @@ func CheckExistingScheduledUpgrade(client *ocm.Client, cluster *cmv1.Cluster) (* } // ScheduleControlPlaneUpgrade schedules a new control plane upgrade to the specified version at the specified time. -func ScheduleControlPlaneUpgrade(client *ocm.Client, cluster *cmv1.Cluster, version string, nextRun time.Time, ack bool) (*cmv1.ControlPlaneUpgradePolicy, error) { +func ScheduleControlPlaneUpgrade(client OCMClient, cluster *cmv1.Cluster, version string, nextRun time.Time, ack bool) (*cmv1.ControlPlaneUpgradePolicy, error) { // earliestNextRun is set to at least 5 min from now by the OCM API. // Set our next run request to something slightly longer than 5min to make sure we account for the latency between when we send this // request and when the server processes it. @@ -71,7 +71,7 @@ func ScheduleControlPlaneUpgrade(client *ocm.Client, cluster *cmv1.Cluster, vers } // ScheduleNodePoolUpgrade schedules a new nodePool upgrade to the specified version at the specified time. -func ScheduleNodePoolUpgrade(client *ocm.Client, clusterID string, nodePool *cmv1.NodePool, version string, nextRun time.Time) (*cmv1.NodePoolUpgradePolicy, error) { +func ScheduleNodePoolUpgrade(client OCMClient, clusterID string, nodePool *cmv1.NodePool, version string, nextRun time.Time) (*cmv1.NodePoolUpgradePolicy, error) { // earliestNextRun is set to at least 5 min from now by the OCM API. // Set our next run request to something slightly longer than 5min to make sure we account for the latency between when we send this // request and when the server processes it.