Skip to content

Commit 4e748e2

Browse files
authored
Merge pull request #4780 from serngawy/fields
🌱 Add missing Fields to RosaControlPlane
2 parents 2d8b068 + 3b6ea0f commit 4e748e2

File tree

6 files changed

+202
-67
lines changed

6 files changed

+202
-67
lines changed

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ spec:
4545
type: object
4646
spec:
4747
properties:
48+
autoscaling:
49+
description: Autoscaling specifies auto scaling behaviour for the
50+
MachinePools.
51+
properties:
52+
maxReplicas:
53+
minimum: 1
54+
type: integer
55+
minReplicas:
56+
minimum: 1
57+
type: integer
58+
type: object
4859
availabilityZones:
4960
description: AWS AvailabilityZones of the worker nodes should match
5061
the AvailabilityZones of the Subnets.
@@ -113,10 +124,41 @@ spec:
113124
description: 'TODO: these are to satisfy ocm sdk. Explore how to drop
114125
them.'
115126
type: string
116-
machineCIDR:
117-
description: Block of IP addresses used by OpenShift while installing
118-
the cluster, for example "10.0.0.0/16".
127+
instanceType:
128+
description: The instance type to use, for example `r5.xlarge`. Instance
129+
type ref; https://aws.amazon.com/ec2/instance-types/
119130
type: string
131+
network:
132+
description: Network config for the ROSA HCP cluster.
133+
properties:
134+
hostPrefix:
135+
default: 23
136+
description: Network host prefix which is defaulted to `23` if
137+
not specified.
138+
type: integer
139+
machineCIDR:
140+
description: IP addresses block used by OpenShift while installing
141+
the cluster, for example "10.0.0.0/16".
142+
format: cidr
143+
type: string
144+
networkType:
145+
default: OVNKubernetes
146+
description: The CNI network type default is OVNKubernetes.
147+
enum:
148+
- OVNKubernetes
149+
- Other
150+
type: string
151+
podCIDR:
152+
description: IP address block from which to assign pod IP addresses,
153+
for example `10.128.0.0/14`.
154+
format: cidr
155+
type: string
156+
serviceCIDR:
157+
description: IP address block from which to assign service IP
158+
addresses, for example `172.30.0.0/16`.
159+
format: cidr
160+
type: string
161+
type: object
120162
oidcID:
121163
description: The ID of the OpenID Connect Provider.
122164
type: string
@@ -307,7 +349,6 @@ spec:
307349
required:
308350
- availabilityZones
309351
- installerRoleARN
310-
- machineCIDR
311352
- oidcID
312353
- region
313354
- rolesRef

controlplane/rosa/api/v1beta2/rosacontrolplane_types.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

2323
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
24+
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
2425
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2526
)
2627

@@ -43,9 +44,6 @@ type RosaControlPlaneSpec struct { //nolint: maligned
4344
// should match the AvailabilityZones of the Subnets.
4445
AvailabilityZones []string `json:"availabilityZones"`
4546

46-
// Block of IP addresses used by OpenShift while installing the cluster, for example "10.0.0.0/16".
47-
MachineCIDR *string `json:"machineCIDR"`
48-
4947
// The AWS Region the cluster lives in.
5048
Region *string `json:"region"`
5149

@@ -90,6 +88,44 @@ type RosaControlPlaneSpec struct { //nolint: maligned
9088
// IdentityRef is a reference to an identity to be used when reconciling the managed control plane.
9189
// If no identity is specified, the default identity for this controller will be used.
9290
IdentityRef *infrav1.AWSIdentityReference `json:"identityRef,omitempty"`
91+
92+
// Network config for the ROSA HCP cluster.
93+
Network *NetworkSpec `json:"network,omitempty"`
94+
95+
// The instance type to use, for example `r5.xlarge`. Instance type ref; https://aws.amazon.com/ec2/instance-types/
96+
// +optional
97+
InstanceType string `json:"instanceType,omitempty"`
98+
99+
// Autoscaling specifies auto scaling behaviour for the MachinePools.
100+
// +optional
101+
Autoscaling *expinfrav1.RosaMachinePoolAutoScaling `json:"autoscaling,omitempty"`
102+
}
103+
104+
// NetworkSpec for ROSA-HCP.
105+
type NetworkSpec struct {
106+
// IP addresses block used by OpenShift while installing the cluster, for example "10.0.0.0/16".
107+
// +kubebuilder:validation:Format=cidr
108+
MachineCIDR string `json:"machineCIDR,omitempty"`
109+
110+
// IP address block from which to assign pod IP addresses, for example `10.128.0.0/14`.
111+
// +kubebuilder:validation:Format=cidr
112+
// +optional
113+
PodCIDR string `json:"podCIDR,omitempty"`
114+
115+
// IP address block from which to assign service IP addresses, for example `172.30.0.0/16`.
116+
// +kubebuilder:validation:Format=cidr
117+
// +optional
118+
ServiceCIDR string `json:"serviceCIDR,omitempty"`
119+
120+
// Network host prefix which is defaulted to `23` if not specified.
121+
// +kubebuilder:default=23
122+
// +optional
123+
HostPrefix int `json:"hostPrefix,omitempty"`
124+
125+
// The CNI network type default is OVNKubernetes.
126+
// +kubebuilder:validation:Enum=OVNKubernetes;Other
127+
// +kubebuilder:default=OVNKubernetes
128+
NetworkType string `json:"networkType,omitempty"`
93129
}
94130

95131
// AWSRolesRef contains references to various AWS IAM roles required for operators to make calls against the AWS API.

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

Lines changed: 26 additions & 5 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: 88 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,6 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
262262
return ctrl.Result{RequeueAfter: time.Second * 60}, nil
263263
}
264264

265-
_, machineCIDR, err := net.ParseCIDR(*rosaScope.ControlPlane.Spec.MachineCIDR)
266-
if err != nil {
267-
// TODO: expose in status, exit reconciliation
268-
rosaScope.Error(err, "rosacontrolplane.spec.machineCIDR invalid")
269-
}
270-
271265
billingAccount := *rosaScope.Identity.Account
272266
if rosaScope.ControlPlane.Spec.BillingAccount != "" {
273267
billingAccount = rosaScope.ControlPlane.Spec.BillingAccount
@@ -283,66 +277,62 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
283277
Expiration: time.Now().Add(1 * time.Hour),
284278
DisableWorkloadMonitoring: ptr.To(true),
285279
DefaultIngress: ocm.NewDefaultIngressSpec(), // n.b. this is a no-op when it's set to the default value
280+
ComputeMachineType: rosaScope.ControlPlane.Spec.InstanceType,
286281

287282
SubnetIds: rosaScope.ControlPlane.Spec.Subnets,
288283
AvailabilityZones: rosaScope.ControlPlane.Spec.AvailabilityZones,
289-
NetworkType: "OVNKubernetes",
290-
MachineCIDR: *machineCIDR,
284+
NetworkType: rosaScope.ControlPlane.Spec.Network.NetworkType,
291285
IsSTS: true,
292286
RoleARN: *rosaScope.ControlPlane.Spec.InstallerRoleARN,
293287
SupportRoleARN: *rosaScope.ControlPlane.Spec.SupportRoleARN,
294-
OperatorIAMRoles: []ocm.OperatorIAMRole{
295-
{
296-
Name: "cloud-credentials",
297-
Namespace: "openshift-ingress-operator",
298-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.IngressARN,
299-
},
300-
{
301-
Name: "installer-cloud-credentials",
302-
Namespace: "openshift-image-registry",
303-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.ImageRegistryARN,
304-
},
305-
{
306-
Name: "ebs-cloud-credentials",
307-
Namespace: "openshift-cluster-csi-drivers",
308-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.StorageARN,
309-
},
310-
{
311-
Name: "cloud-credentials",
312-
Namespace: "openshift-cloud-network-config-controller",
313-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.NetworkARN,
314-
},
315-
{
316-
Name: "kube-controller-manager",
317-
Namespace: "kube-system",
318-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.KubeCloudControllerARN,
319-
},
320-
{
321-
Name: "kms-provider",
322-
Namespace: "kube-system",
323-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.KMSProviderARN,
324-
},
325-
{
326-
Name: "control-plane-operator",
327-
Namespace: "kube-system",
328-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.ControlPlaneOperatorARN,
329-
},
330-
{
331-
Name: "capa-controller-manager",
332-
Namespace: "kube-system",
333-
RoleARN: rosaScope.ControlPlane.Spec.RolesRef.NodePoolManagementARN,
334-
},
335-
},
336-
WorkerRoleARN: *rosaScope.ControlPlane.Spec.WorkerRoleARN,
337-
OidcConfigId: *rosaScope.ControlPlane.Spec.OIDCID,
338-
Mode: "auto",
288+
OperatorIAMRoles: getOperatorIAMRole(*rosaScope.ControlPlane),
289+
WorkerRoleARN: *rosaScope.ControlPlane.Spec.WorkerRoleARN,
290+
OidcConfigId: *rosaScope.ControlPlane.Spec.OIDCID,
291+
Mode: "auto",
339292
Hypershift: ocm.Hypershift{
340293
Enabled: true,
341294
},
342295
BillingAccount: billingAccount,
343296
AWSCreator: creator,
344297
}
345298

299+
_, machineCIDR, err := net.ParseCIDR(rosaScope.ControlPlane.Spec.Network.MachineCIDR)
300+
if err == nil {
301+
spec.MachineCIDR = *machineCIDR
302+
} else {
303+
// TODO: expose in status
304+
rosaScope.Error(err, "rosacontrolplane.spec.network.machineCIDR invalid", rosaScope.ControlPlane.Spec.Network.MachineCIDR)
305+
return ctrl.Result{}, nil
306+
}
307+
308+
if rosaScope.ControlPlane.Spec.Network.PodCIDR != "" {
309+
_, podCIDR, err := net.ParseCIDR(rosaScope.ControlPlane.Spec.Network.PodCIDR)
310+
if err == nil {
311+
spec.PodCIDR = *podCIDR
312+
} else {
313+
// TODO: expose in status.
314+
rosaScope.Error(err, "rosacontrolplane.spec.network.podCIDR invalid", rosaScope.ControlPlane.Spec.Network.PodCIDR)
315+
return ctrl.Result{}, nil
316+
}
317+
}
318+
319+
if rosaScope.ControlPlane.Spec.Network.ServiceCIDR != "" {
320+
_, serviceCIDR, err := net.ParseCIDR(rosaScope.ControlPlane.Spec.Network.ServiceCIDR)
321+
if err == nil {
322+
spec.ServiceCIDR = *serviceCIDR
323+
} else {
324+
// TODO: expose in status.
325+
rosaScope.Error(err, "rosacontrolplane.spec.network.serviceCIDR invalid", rosaScope.ControlPlane.Spec.Network.ServiceCIDR)
326+
return ctrl.Result{}, nil
327+
}
328+
}
329+
330+
// Set autoscale replica
331+
if rosaScope.ControlPlane.Spec.Autoscaling != nil {
332+
spec.MaxReplicas = rosaScope.ControlPlane.Spec.Autoscaling.MaxReplicas
333+
spec.MinReplicas = rosaScope.ControlPlane.Spec.Autoscaling.MinReplicas
334+
}
335+
346336
cluster, err = ocmClient.CreateCluster(spec)
347337
if err != nil {
348338
// TODO: need to expose in status, as likely the spec is invalid
@@ -356,6 +346,51 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
356346
return ctrl.Result{}, nil
357347
}
358348

349+
func getOperatorIAMRole(rosaControlPlane rosacontrolplanev1.ROSAControlPlane) []ocm.OperatorIAMRole {
350+
return []ocm.OperatorIAMRole{
351+
{
352+
Name: "cloud-credentials",
353+
Namespace: "openshift-ingress-operator",
354+
RoleARN: rosaControlPlane.Spec.RolesRef.IngressARN,
355+
},
356+
{
357+
Name: "installer-cloud-credentials",
358+
Namespace: "openshift-image-registry",
359+
RoleARN: rosaControlPlane.Spec.RolesRef.ImageRegistryARN,
360+
},
361+
{
362+
Name: "ebs-cloud-credentials",
363+
Namespace: "openshift-cluster-csi-drivers",
364+
RoleARN: rosaControlPlane.Spec.RolesRef.StorageARN,
365+
},
366+
{
367+
Name: "cloud-credentials",
368+
Namespace: "openshift-cloud-network-config-controller",
369+
RoleARN: rosaControlPlane.Spec.RolesRef.NetworkARN,
370+
},
371+
{
372+
Name: "kube-controller-manager",
373+
Namespace: "kube-system",
374+
RoleARN: rosaControlPlane.Spec.RolesRef.KubeCloudControllerARN,
375+
},
376+
{
377+
Name: "kms-provider",
378+
Namespace: "kube-system",
379+
RoleARN: rosaControlPlane.Spec.RolesRef.KMSProviderARN,
380+
},
381+
{
382+
Name: "control-plane-operator",
383+
Namespace: "kube-system",
384+
RoleARN: rosaControlPlane.Spec.RolesRef.ControlPlaneOperatorARN,
385+
},
386+
{
387+
Name: "capa-controller-manager",
388+
Namespace: "kube-system",
389+
RoleARN: rosaControlPlane.Spec.RolesRef.NodePoolManagementARN,
390+
},
391+
}
392+
}
393+
359394
func (r *ROSAControlPlaneReconciler) reconcileDelete(ctx context.Context, rosaScope *scope.ROSAControlPlaneScope) (res ctrl.Result, reterr error) {
360395
rosaScope.Info("Reconciling ROSAControlPlane delete")
361396

templates/cluster-template-rosa-machinepool.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ spec:
3232
region: "${AWS_REGION}"
3333
accountID: "${AWS_ACCOUNT_ID}"
3434
creatorARN: "${AWS_CREATOR_ARN}"
35-
machineCIDR: "10.0.0.0/16"
35+
network:
36+
machineCIDR: "10.0.0.0/16"
3637
rolesRef:
3738
ingressARN: "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${OPERATOR_ROLES_PREFIX}-openshift-ingress-operator-cloud-credentials"
3839
imageRegistryARN: "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${OPERATOR_ROLES_PREFIX}-openshift-image-registry-installer-cloud-credentials"

templates/cluster-template-rosa.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ spec:
3232
region: "${AWS_REGION}"
3333
accountID: "${AWS_ACCOUNT_ID}"
3434
creatorARN: "${AWS_CREATOR_ARN}"
35-
machineCIDR: "10.0.0.0/16"
35+
network:
36+
machineCIDR: "10.0.0.0/16"
3637
rolesRef:
3738
ingressARN: "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${OPERATOR_ROLES_PREFIX}-openshift-ingress-operator-cloud-credentials"
3839
imageRegistryARN: "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${OPERATOR_ROLES_PREFIX}-openshift-image-registry-installer-cloud-credentials"

0 commit comments

Comments
 (0)