Skip to content

Commit 6ea0a20

Browse files
committed
Add ROSA-HCP AutoNode for karpenter auto scale
Signed-off-by: serngawy <[email protected]>
1 parent bd8766a commit 6ea0a20

File tree

8 files changed

+178
-54
lines changed

8 files changed

+178
-54
lines changed

config/crd/bases/controlplane.cluster.x-k8s.io_rosacontrolplanes.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ spec:
6363
AuditLogRoleARN defines the role that is used to forward audit logs to AWS CloudWatch.
6464
If not set, audit log forwarding is disabled.
6565
type: string
66+
autoNode:
67+
description: AutoNode set the autoNode mode and autoNode role ARN.
68+
properties:
69+
mode:
70+
default: disabled
71+
description: AutoNode mode allowed values are enabled & disabled
72+
enum:
73+
- enabled
74+
- disabled
75+
type: string
76+
roleARN:
77+
description: |-
78+
AutoNode role ARN that has the IAM Policy and cluster-specific Role that gives permissions to the Karpenter controller.
79+
The role must be attached with the same OIDC-ID that is used with the ROSA-HCP cluster.
80+
type: string
81+
type: object
6682
availabilityZones:
6783
description: |-
6884
AvailabilityZones describe AWS AvailabilityZones of the worker nodes.

controlplane/rosa/api/v1beta2/rosacontrolplane_types.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ const (
7272
Nightly ChannelGroupType = "nightly"
7373
)
7474

75+
// AutoNodeMode specifies the auto node mode
76+
type AutoNodeMode string
77+
78+
const (
79+
// Enable auto node mode
80+
Enabled AutoNodeMode = "enabled"
81+
82+
// Disable auto node mode
83+
Disabled AutoNodeMode = "disabled"
84+
)
85+
7586
// RosaControlPlaneSpec defines the desired state of ROSAControlPlane.
7687
type RosaControlPlaneSpec struct { //nolint: maligned
7788
// Cluster name must be valid DNS-1035 label, so it must consist of lower case alphanumeric
@@ -234,6 +245,24 @@ type RosaControlPlaneSpec struct { //nolint: maligned
234245
// ClusterRegistryConfig represents registry config used with the cluster.
235246
// +optional
236247
ClusterRegistryConfig *RegistryConfig `json:"clusterRegistryConfig,omitempty"`
248+
249+
// AutoNode set the autoNode mode and autoNode role ARN.
250+
// +optional
251+
AutoNode *AutoNode `json:"autoNode,omitempty"`
252+
}
253+
254+
// AutoNode set the autoNode mode and autoNode role ARN.
255+
type AutoNode struct {
256+
// AutoNode mode allowed values are enabled & disabled
257+
// +kubebuilder:validation:Enum=enabled;disabled
258+
// +kubebuilder:default=disabled
259+
// +optional
260+
Mode AutoNodeMode `json:"mode,omitempty"`
261+
262+
// AutoNode role ARN that has the IAM Policy and cluster-specific Role that gives permissions to the Karpenter controller.
263+
// The role must be attached with the same OIDC-ID that is used with the ROSA-HCP cluster.
264+
// +optional
265+
RoleARN string `json:"roleARN,omitempty"`
237266
}
238267

239268
// RegistryConfig for ROSA-HCP cluster

controlplane/rosa/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/rosa/controllers/rosacontrolplane_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,18 @@ func (r *ROSAControlPlaneReconciler) updateOCMClusterSpec(rosaControlPlane *rosa
578578
updated = true
579579
}
580580

581+
if rosaControlPlane.Spec.AutoNode != nil {
582+
if ocmClusterSpec.AutoNodeMode != string(rosaControlPlane.Spec.AutoNode.Mode) {
583+
ocmClusterSpec.AutoNodeMode = string(rosaControlPlane.Spec.AutoNode.Mode)
584+
updated = true
585+
}
586+
587+
if ocmClusterSpec.AutoNodeRoleARN != rosaControlPlane.Spec.AutoNode.RoleARN {
588+
ocmClusterSpec.AutoNodeRoleARN = rosaControlPlane.Spec.AutoNode.RoleARN
589+
updated = true
590+
}
591+
}
592+
581593
return ocmClusterSpec, updated
582594
}
583595

@@ -1039,6 +1051,12 @@ func buildOCMClusterSpec(controlPlaneSpec rosacontrolplanev1.RosaControlPlaneSpe
10391051
}
10401052
}
10411053

1054+
// Set auto node karpenter config
1055+
if controlPlaneSpec.AutoNode != nil {
1056+
ocmClusterSpec.AutoNodeMode = string(controlPlaneSpec.AutoNode.Mode)
1057+
ocmClusterSpec.AutoNodeRoleARN = controlPlaneSpec.AutoNode.RoleARN
1058+
}
1059+
10421060
return ocmClusterSpec, nil
10431061
}
10441062

controlplane/rosa/controllers/rosacontrolplane_controller_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestUpdateOCMClusterSpec(t *testing.T) {
181181
})
182182

183183
// Test case 6: channel group update
184-
t.Run("Update AllowedRegistriesForImport", func(t *testing.T) {
184+
t.Run("Update channel group", func(t *testing.T) {
185185
rosaControlPlane := &rosacontrolplanev1.ROSAControlPlane{
186186
Spec: rosacontrolplanev1.RosaControlPlaneSpec{
187187
ChannelGroup: rosacontrolplanev1.Candidate,
@@ -203,6 +203,34 @@ func TestUpdateOCMClusterSpec(t *testing.T) {
203203
g.Expect(updated).To(BeTrue())
204204
g.Expect(ocmSpec).To(Equal(expectedOCMSpec))
205205
})
206+
207+
// Test case 7: AutoNode update
208+
t.Run("Update Auto Node", func(t *testing.T) {
209+
rosaControlPlane := &rosacontrolplanev1.ROSAControlPlane{
210+
Spec: rosacontrolplanev1.RosaControlPlaneSpec{
211+
AutoNode: &rosacontrolplanev1.AutoNode{
212+
Mode: rosacontrolplanev1.Enabled,
213+
RoleARN: "autoNodeARN",
214+
},
215+
},
216+
}
217+
218+
mockCluster, _ := v1.NewCluster().
219+
AutoNode(v1.NewClusterAutoNode().Mode("disabled")).
220+
AWS(v1.NewAWS().AutoNode(v1.NewAwsAutoNode().RoleArn("anyARN"))).
221+
Build()
222+
223+
expectedOCMSpec := ocm.Spec{
224+
AutoNodeMode: "enabled",
225+
AutoNodeRoleARN: "autoNodeARN",
226+
}
227+
228+
reconciler := &ROSAControlPlaneReconciler{}
229+
ocmSpec, updated := reconciler.updateOCMClusterSpec(rosaControlPlane, mockCluster)
230+
231+
g.Expect(updated).To(BeTrue())
232+
g.Expect(ocmSpec).To(Equal(expectedOCMSpec))
233+
})
206234
}
207235

208236
func TestRosaControlPlaneReconcileStatusVersion(t *testing.T) {

go.mod

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ require (
3939
github.com/google/gofuzz v1.2.0
4040
github.com/onsi/ginkgo/v2 v2.23.3
4141
github.com/onsi/gomega v1.36.3
42-
github.com/openshift-online/ocm-common v0.0.29
43-
github.com/openshift-online/ocm-sdk-go v0.1.465
44-
github.com/openshift/rosa v1.2.55
42+
github.com/openshift-online/ocm-api-model/clientapi v0.0.431
43+
github.com/openshift-online/ocm-common v0.0.31
44+
github.com/openshift-online/ocm-sdk-go v0.1.476
45+
github.com/openshift/rosa v1.99.9-testing.0.20250926125556-7903b7e2b476
4546
github.com/pkg/errors v0.9.1
46-
github.com/prometheus/client_golang v1.19.1
47+
github.com/prometheus/client_golang v1.23.0
4748
github.com/sergi/go-diff v1.3.1
4849
github.com/sirupsen/logrus v1.9.3
4950
github.com/spf13/cobra v1.9.1
5051
github.com/spf13/pflag v1.0.6
5152
github.com/zgalor/weberr v0.8.2
52-
golang.org/x/crypto v0.36.0
53-
golang.org/x/net v0.38.0
54-
golang.org/x/text v0.23.0
53+
golang.org/x/crypto v0.41.0
54+
golang.org/x/net v0.43.0
55+
golang.org/x/text v0.28.0
5556
gopkg.in/yaml.v2 v2.4.0
5657
k8s.io/api v0.32.3
5758
k8s.io/apiextensions-apiserver v0.32.3
@@ -70,7 +71,11 @@ require (
7071
sigs.k8s.io/yaml v1.4.0
7172
)
7273

73-
require github.com/aws/aws-sdk-go v1.55.7 // indirect
74+
require (
75+
github.com/aws/aws-sdk-go v1.55.7 // indirect
76+
github.com/kylelemons/godebug v1.1.0 // indirect
77+
github.com/openshift-online/ocm-api-model/model v0.0.431 // indirect
78+
)
7479

7580
require (
7681
al.essio.dev/pkg/shellescape v1.5.1 // indirect
@@ -172,7 +177,7 @@ require (
172177
github.com/mattn/go-colorable v0.1.13 // indirect
173178
github.com/mattn/go-isatty v0.0.20 // indirect
174179
github.com/mattn/go-runewidth v0.0.14 // indirect
175-
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
180+
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
176181
github.com/mitchellh/copystructure v1.2.0 // indirect
177182
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
178183
github.com/mitchellh/reflectwalk v1.0.2 // indirect
@@ -190,9 +195,9 @@ require (
190195
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
191196
github.com/pelletier/go-toml v1.9.5 // indirect
192197
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
193-
github.com/prometheus/client_model v0.6.1 // indirect
194-
github.com/prometheus/common v0.55.0 // indirect
195-
github.com/prometheus/procfs v0.15.1 // indirect
198+
github.com/prometheus/client_model v0.6.2 // indirect
199+
github.com/prometheus/common v0.65.0 // indirect
200+
github.com/prometheus/procfs v0.17.0 // indirect
196201
github.com/rivo/uniseg v0.4.2 // indirect
197202
github.com/russross/blackfriday/v2 v2.1.0 // indirect
198203
github.com/sagikazarmark/locafero v0.7.0 // indirect
@@ -223,17 +228,17 @@ require (
223228
go.uber.org/multierr v1.11.0 // indirect
224229
go.uber.org/zap v1.27.0 // indirect
225230
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
226-
golang.org/x/oauth2 v0.28.0 // indirect
227-
golang.org/x/sync v0.12.0 // indirect
228-
golang.org/x/sys v0.31.0 // indirect
229-
golang.org/x/term v0.30.0 // indirect
231+
golang.org/x/oauth2 v0.30.0 // indirect
232+
golang.org/x/sync v0.16.0 // indirect
233+
golang.org/x/sys v0.35.0 // indirect
234+
golang.org/x/term v0.34.0 // indirect
230235
golang.org/x/time v0.8.0 // indirect
231-
golang.org/x/tools v0.30.0 // indirect
236+
golang.org/x/tools v0.35.0 // indirect
232237
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
233238
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
234239
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
235240
google.golang.org/grpc v1.67.3 // indirect
236-
google.golang.org/protobuf v1.36.5 // indirect
241+
google.golang.org/protobuf v1.36.8 // indirect
237242
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
238243
gopkg.in/inf.v0 v0.9.1 // indirect
239244
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)