Skip to content

Commit c1975bb

Browse files
rosa: use the openshift/rosa libraries where we can
Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 66bb485 commit c1975bb

File tree

13 files changed

+624
-745
lines changed

13 files changed

+624
-745
lines changed

controlplane/rosa/controllers/rosacontrolplane_controller.go

Lines changed: 118 additions & 147 deletions
Large diffs are not rendered by default.

exp/controllers/rosamachinepool_controller.go

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

88
"github.com/blang/semver"
99
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
10+
"github.com/openshift/rosa/pkg/ocm"
1011
"github.com/pkg/errors"
1112
corev1 "k8s.io/api/core/v1"
1213
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -175,11 +176,11 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
175176
}
176177
}
177178

178-
rosaClient, err := rosa.NewRosaClient(ctx, rosaControlPlaneScope)
179+
ocmClient, err := rosa.NewOCMClient(ctx, rosaControlPlaneScope)
179180
if err != nil {
180-
return ctrl.Result{}, fmt.Errorf("failed to create a rosa client: %w", err)
181+
// TODO: need to expose in status, as likely the credentials are invalid
182+
return ctrl.Result{}, fmt.Errorf("failed to create OCM client: %w", err)
181183
}
182-
defer rosaClient.Close()
183184

184185
failureMessage, err := validateMachinePoolSpec(machinePoolScope)
185186
if err != nil {
@@ -197,7 +198,7 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
197198
machinePool := machinePoolScope.MachinePool
198199
controlPlane := machinePoolScope.ControlPlane
199200

200-
createdNodePool, found, err := rosaClient.GetNodePool(*controlPlane.Status.ID, rosaMachinePool.Spec.NodePoolName)
201+
createdNodePool, found, err := ocmClient.GetNodePool(*controlPlane.Status.ID, rosaMachinePool.Spec.NodePoolName)
201202
if err != nil {
202203
return ctrl.Result{}, err
203204
}
@@ -208,7 +209,7 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
208209
conditions.MarkTrue(rosaMachinePool, expinfrav1.RosaMachinePoolReadyCondition)
209210
rosaMachinePool.Status.Ready = true
210211

211-
if err := r.reconcileMachinePoolVersion(machinePoolScope, rosaClient, createdNodePool); err != nil {
212+
if err := r.reconcileMachinePoolVersion(machinePoolScope, ocmClient, createdNodePool); err != nil {
212213
return ctrl.Result{}, err
213214
}
214215

@@ -250,15 +251,15 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
250251

251252
npBuilder.AWSNodePool(cmv1.NewAWSNodePool().InstanceType(rosaMachinePool.Spec.InstanceType))
252253
if rosaMachinePool.Spec.Version != "" {
253-
npBuilder.Version(cmv1.NewVersion().ID(rosa.VersionID(rosaMachinePool.Spec.Version)))
254+
npBuilder.Version(cmv1.NewVersion().ID(ocm.CreateVersionID(rosaMachinePool.Spec.Version, ocm.DefaultChannelGroup)))
254255
}
255256

256257
nodePoolSpec, err := npBuilder.Build()
257258
if err != nil {
258259
return ctrl.Result{}, fmt.Errorf("failed to build rosa nodepool: %w", err)
259260
}
260261

261-
createdNodePool, err = rosaClient.CreateNodePool(*controlPlane.Status.ID, nodePoolSpec)
262+
createdNodePool, err = ocmClient.CreateNodePool(*controlPlane.Status.ID, nodePoolSpec)
262263
if err != nil {
263264
return ctrl.Result{}, fmt.Errorf("failed to create nodepool: %w", err)
264265
}
@@ -274,18 +275,18 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete(
274275
) error {
275276
machinePoolScope.Info("Reconciling deletion of RosaMachinePool")
276277

277-
rosaClient, err := rosa.NewRosaClient(ctx, rosaControlPlaneScope)
278+
ocmClient, err := rosa.NewOCMClient(ctx, rosaControlPlaneScope)
278279
if err != nil {
279-
return fmt.Errorf("failed to create a rosa client: %w", err)
280+
// TODO: need to expose in status, as likely the credentials are invalid
281+
return fmt.Errorf("failed to create OCM client: %w", err)
280282
}
281-
defer rosaClient.Close()
282283

283-
nodePool, found, err := rosaClient.GetNodePool(*machinePoolScope.ControlPlane.Status.ID, machinePoolScope.NodePoolName())
284+
nodePool, found, err := ocmClient.GetNodePool(*machinePoolScope.ControlPlane.Status.ID, machinePoolScope.NodePoolName())
284285
if err != nil {
285286
return err
286287
}
287288
if found {
288-
if err := rosaClient.DeleteNodePool(*machinePoolScope.ControlPlane.Status.ID, nodePool.ID()); err != nil {
289+
if err := ocmClient.DeleteNodePool(*machinePoolScope.ControlPlane.Status.ID, nodePool.ID()); err != nil {
289290
return err
290291
}
291292
}
@@ -295,7 +296,7 @@ func (r *ROSAMachinePoolReconciler) reconcileDelete(
295296
return nil
296297
}
297298

298-
func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope *scope.RosaMachinePoolScope, rosaClient *rosa.RosaClient, nodePool *cmv1.NodePool) error {
299+
func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope *scope.RosaMachinePoolScope, ocmClient *ocm.Client, nodePool *cmv1.NodePool) error {
299300
version := machinePoolScope.RosaMachinePool.Spec.Version
300301
if version == "" {
301302
version = machinePoolScope.ControlPlane.Spec.Version
@@ -307,13 +308,26 @@ func (r *ROSAMachinePoolReconciler) reconcileMachinePoolVersion(machinePoolScope
307308
}
308309

309310
clusterID := *machinePoolScope.ControlPlane.Status.ID
310-
scheduledUpgrade, err := rosaClient.CheckNodePoolExistingScheduledUpgrade(clusterID, nodePool)
311+
_, scheduledUpgrade, err := ocmClient.GetHypershiftNodePoolUpgrade(clusterID, machinePoolScope.ControlPlane.Spec.RosaClusterName, nodePool.ID())
311312
if err != nil {
312313
return fmt.Errorf("failed to get existing scheduled upgrades: %w", err)
313314
}
314315

315316
if scheduledUpgrade == nil {
316-
scheduledUpgrade, err = rosaClient.ScheduleNodePoolUpgrade(clusterID, nodePool, version, time.Now())
317+
policy, err := ocmClient.BuildNodeUpgradePolicy(version, nodePool.ID(), ocm.UpgradeScheduling{
318+
AutomaticUpgrades: false,
319+
// The OCM API places guardrails around the minimum and maximum delay that a user can request,
320+
// for the next run of the upgrade, which is [5min,6mo]. Set our next run request to something
321+
// slightly longer than 5min to make sure we account for the latency between when we send this
322+
// request and when the server processes it.
323+
// https://gitlab.cee.redhat.com/service/uhc-clusters-service/-/blob/master/cmd/clusters-service/servecmd/apiserver/upgrade_policy_handlers.go
324+
NextRun: time.Now().Add(6 * time.Minute),
325+
})
326+
if err != nil {
327+
return fmt.Errorf("failed to create nodePool upgrade schedule to version %s: %w", version, err)
328+
}
329+
330+
scheduledUpgrade, err = ocmClient.ScheduleNodePoolUpgrade(clusterID, nodePool.ID(), policy)
317331
if err != nil {
318332
return fmt.Errorf("failed to schedule nodePool upgrade to version %s: %w", version, err)
319333
}

go.mod

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/apparentlymart/go-cidr v1.1.0
1414
github.com/aws/amazon-vpc-cni-k8s v1.15.4
1515
github.com/aws/aws-lambda-go v1.41.0
16-
github.com/aws/aws-sdk-go v1.44.332
16+
github.com/aws/aws-sdk-go v1.45.26
1717
github.com/awslabs/goformation/v4 v4.19.5
1818
github.com/blang/semver v3.5.1+incompatible
1919
github.com/coreos/ignition v0.35.0
@@ -26,12 +26,16 @@ require (
2626
github.com/google/gofuzz v1.2.0
2727
github.com/onsi/ginkgo/v2 v2.13.1
2828
github.com/onsi/gomega v1.30.0
29-
github.com/openshift-online/ocm-sdk-go v0.1.388
29+
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909
30+
github.com/openshift-online/ocm-sdk-go v0.1.403
31+
github.com/openshift/rosa v1.2.35-rc1.0.20240221134836-0beb882e5836
3032
github.com/pkg/errors v0.9.1
31-
github.com/prometheus/client_golang v1.17.0
33+
github.com/prometheus/client_golang v1.18.0
3234
github.com/sergi/go-diff v1.3.1
35+
github.com/sirupsen/logrus v1.9.3
3336
github.com/spf13/cobra v1.8.0
3437
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace
38+
github.com/zgalor/weberr v0.6.0
3539
golang.org/x/crypto v0.18.0
3640
golang.org/x/text v0.14.0
3741
gopkg.in/yaml.v2 v2.4.0
@@ -64,9 +68,13 @@ require (
6468
github.com/adrg/xdg v0.4.0 // indirect
6569
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
6670
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
71+
github.com/aws/aws-sdk-go-v2 v1.24.1 // indirect
72+
github.com/aws/aws-sdk-go-v2/service/iam v1.27.1 // indirect
73+
github.com/aws/smithy-go v1.19.0 // indirect
6774
github.com/aymerick/douceur v0.2.0 // indirect
6875
github.com/beorn7/perks v1.0.1 // indirect
6976
github.com/blang/semver/v4 v4.0.0 // indirect
77+
github.com/briandowns/spinner v1.11.1 // indirect
7078
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
7179
github.com/cespare/xxhash/v2 v2.2.0 // indirect
7280
github.com/chai2010/gettext-go v1.0.2 // indirect
@@ -93,6 +101,7 @@ require (
93101
github.com/felixge/httpsnoop v1.0.4 // indirect
94102
github.com/fsnotify/fsnotify v1.6.0 // indirect
95103
github.com/fvbommel/sortorder v1.1.0 // indirect
104+
github.com/ghodss/yaml v1.0.0 // indirect
96105
github.com/go-errors/errors v1.4.2 // indirect
97106
github.com/go-logr/stdr v1.2.2 // indirect
98107
github.com/go-logr/zapr v1.2.4 // indirect
@@ -103,7 +112,7 @@ require (
103112
github.com/gobuffalo/flect v1.0.2 // indirect
104113
github.com/gogo/protobuf v1.3.2 // indirect
105114
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
106-
github.com/golang/glog v1.1.2 // indirect
115+
github.com/golang/glog v1.2.0 // indirect
107116
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
108117
github.com/golang/protobuf v1.5.3 // indirect
109118
github.com/google/btree v1.0.1 // indirect
@@ -115,11 +124,12 @@ require (
115124
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
116125
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
117126
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
118-
github.com/google/uuid v1.3.1 // indirect
119-
github.com/gorilla/css v1.0.0 // indirect
127+
github.com/google/uuid v1.6.0 // indirect
128+
github.com/gorilla/css v1.0.1 // indirect
120129
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
121130
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
122131
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
132+
github.com/hashicorp/go-version v1.6.0 // indirect
123133
github.com/hashicorp/hcl v1.0.0 // indirect
124134
github.com/huandu/xstrings v1.4.0 // indirect
125135
github.com/imdario/mergo v0.3.13 // indirect
@@ -135,8 +145,7 @@ require (
135145
github.com/mattn/go-colorable v0.1.13 // indirect
136146
github.com/mattn/go-isatty v0.0.20 // indirect
137147
github.com/mattn/go-runewidth v0.0.14 // indirect
138-
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
139-
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
148+
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
140149
github.com/mitchellh/copystructure v1.2.0 // indirect
141150
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
142151
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -155,16 +164,17 @@ require (
155164
github.com/pelletier/go-toml v1.9.5 // indirect
156165
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
157166
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
158-
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
159-
github.com/prometheus/common v0.44.0 // indirect
160-
github.com/prometheus/procfs v0.11.1 // indirect
167+
github.com/prometheus/client_model v0.5.0 // indirect
168+
github.com/prometheus/common v0.46.0 // indirect
169+
github.com/prometheus/procfs v0.12.0 // indirect
161170
github.com/rivo/uniseg v0.4.2 // indirect
162171
github.com/russross/blackfriday/v2 v2.1.0 // indirect
163172
github.com/sagikazarmark/locafero v0.3.0 // indirect
164173
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
165174
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b // indirect
166175
github.com/sanathkr/yaml v0.0.0-20170819201035-0056894fa522 // indirect
167176
github.com/shopspring/decimal v1.3.1 // indirect
177+
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
168178
github.com/sourcegraph/conc v0.3.0 // indirect
169179
github.com/spf13/afero v1.10.0 // indirect
170180
github.com/spf13/cast v1.5.1 // indirect
@@ -174,6 +184,7 @@ require (
174184
github.com/valyala/fastjson v1.6.4 // indirect
175185
github.com/vincent-petithory/dataurl v1.0.0 // indirect
176186
github.com/xlab/treeprint v1.2.0 // indirect
187+
gitlab.com/c0b/go-ordered-json v0.0.0-20171130231205-49bbdab258c2 // indirect
177188
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
178189
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
179190
go.etcd.io/etcd/client/v3 v3.5.10 // indirect
@@ -190,20 +201,20 @@ require (
190201
go.uber.org/multierr v1.11.0 // indirect
191202
go.uber.org/zap v1.25.0 // indirect
192203
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
193-
golang.org/x/net v0.18.0 // indirect
194-
golang.org/x/oauth2 v0.14.0 // indirect
204+
golang.org/x/net v0.20.0 // indirect
205+
golang.org/x/oauth2 v0.16.0 // indirect
195206
golang.org/x/sync v0.4.0 // indirect
196207
golang.org/x/sys v0.16.0 // indirect
197208
golang.org/x/term v0.16.0 // indirect
198209
golang.org/x/time v0.3.0 // indirect
199210
golang.org/x/tools v0.14.0 // indirect
200211
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
201-
google.golang.org/appengine v1.6.7 // indirect
212+
google.golang.org/appengine v1.6.8 // indirect
202213
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
203214
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
204215
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
205216
google.golang.org/grpc v1.59.0 // indirect
206-
google.golang.org/protobuf v1.31.0 // indirect
217+
google.golang.org/protobuf v1.32.0 // indirect
207218
gopkg.in/inf.v0 v0.9.1 // indirect
208219
gopkg.in/ini.v1 v1.67.0 // indirect
209220
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect

0 commit comments

Comments
 (0)