Skip to content

Commit c21fbb3

Browse files
committed
ROSAControlPlane to use net info from RosaNetwork CR
1 parent 7456f86 commit c21fbb3

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,22 @@ spec:
775775
x-kubernetes-validations:
776776
- message: rosaClusterName is immutable
777777
rule: self == oldSelf
778+
rosaNetworkRef:
779+
description: |-
780+
RosaNetworkRef references RosaNetwork custom resource that contains the networking infrastructure
781+
for Rosa HCP cluster
782+
properties:
783+
name:
784+
default: ""
785+
description: |-
786+
Name of the referent.
787+
This field is effectively required, but due to backwards compatibility is
788+
allowed to be empty. Instances of this type with an empty value here are
789+
almost certainly wrong.
790+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
791+
type: string
792+
type: object
793+
x-kubernetes-map-type: atomic
778794
subnets:
779795
description: |-
780796
The Subnet IDs to use when installing the cluster.
@@ -808,14 +824,12 @@ spec:
808824
to worker instances.
809825
type: string
810826
required:
811-
- availabilityZones
812827
- channelGroup
813828
- installerRoleARN
814829
- oidcID
815830
- region
816831
- rolesRef
817832
- rosaClusterName
818-
- subnets
819833
- supportRoleARN
820834
- version
821835
- versionGate

controlplane/rosa/api/v1beta2/rosacontrolplane_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ type RosaControlPlaneSpec struct { //nolint: maligned
9292

9393
// The Subnet IDs to use when installing the cluster.
9494
// SubnetIDs should come in pairs; two per availability zone, one private and one public.
95+
// +optional
9596
Subnets []string `json:"subnets"`
9697

9798
// AvailabilityZones describe AWS AvailabilityZones of the worker nodes.
9899
// should match the AvailabilityZones of the provided Subnets.
99100
// a machinepool will be created for each availabilityZone.
101+
// +optional
100102
AvailabilityZones []string `json:"availabilityZones"`
101103

102104
// The AWS Region the cluster lives in.
@@ -228,6 +230,11 @@ type RosaControlPlaneSpec struct { //nolint: maligned
228230
// ClusterRegistryConfig represents registry config used with the cluster.
229231
// +optional
230232
ClusterRegistryConfig *RegistryConfig `json:"clusterRegistryConfig,omitempty"`
233+
234+
// RosaNetworkRef references RosaNetwork custom resource that contains the networking infrastructure
235+
// for Rosa HCP cluster
236+
// +optional
237+
RosaNetworkRef *corev1.LocalObjectReference `json:"rosaNetworkRef,omitempty"`
231238
}
232239

233240
// RegistryConfig for ROSA-HCP cluster

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

Lines changed: 5 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: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,27 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
313313
return ctrl.Result{RequeueAfter: time.Second * 60}, nil
314314
}
315315

316-
ocmClusterSpec, err := buildOCMClusterSpec(rosaScope.ControlPlane.Spec, creator)
316+
rosaNet := &expinfrav1.RosaNetwork{}
317+
// Does the control plane reference RosaNetwork?
318+
if rosaScope.ControlPlane.Spec.RosaNetworkRef != nil {
319+
objKey := client.ObjectKey{
320+
Name: rosaScope.ControlPlane.Spec.RosaNetworkRef.Name,
321+
Namespace: rosaScope.ControlPlane.Namespace,
322+
}
323+
324+
err := rosaScope.Client.Get(ctx, objKey, rosaNet)
325+
if err != nil {
326+
return ctrl.Result{}, fmt.Errorf("failed to fetch RosaNetwork: %w", err)
327+
}
328+
329+
// Is the referenced RosaNetwork ready yet?
330+
if !conditions.IsTrue(rosaNet, expinfrav1.RosaNetworkReadyCondition) {
331+
rosaScope.Info(fmt.Sprintf("referenced RosaNetwork %s is not ready", rosaNet.Name))
332+
return ctrl.Result{RequeueAfter: time.Minute}, nil
333+
}
334+
}
335+
336+
ocmClusterSpec, err := buildOCMClusterSpec(rosaScope.ControlPlane.Spec, rosaNet, creator)
317337
if err != nil {
318338
return ctrl.Result{}, err
319339
}
@@ -907,12 +927,25 @@ func validateControlPlaneSpec(ocmClient rosa.OCMClient, rosaScope *scope.ROSACon
907927
return "", nil
908928
}
909929

910-
func buildOCMClusterSpec(controlPlaneSpec rosacontrolplanev1.RosaControlPlaneSpec, creator *rosaaws.Creator) (ocm.Spec, error) {
930+
func buildOCMClusterSpec(controlPlaneSpec rosacontrolplanev1.RosaControlPlaneSpec, rosaNet *expinfrav1.RosaNetwork, creator *rosaaws.Creator) (ocm.Spec, error) {
911931
billingAccount := controlPlaneSpec.BillingAccount
912932
if billingAccount == "" {
913933
billingAccount = creator.AccountID
914934
}
915935

936+
var subnetIDs []string
937+
var availabilityZones []string
938+
939+
if controlPlaneSpec.RosaNetworkRef == nil {
940+
subnetIDs = controlPlaneSpec.Subnets
941+
availabilityZones = controlPlaneSpec.AvailabilityZones
942+
} else {
943+
for _, v := range rosaNet.Status.Subnets {
944+
subnetIDs = append(subnetIDs, v.PublicSubnet, v.PrivateSubnet)
945+
availabilityZones = append(availabilityZones, v.AvailabilityZone)
946+
}
947+
}
948+
916949
ocmClusterSpec := ocm.Spec{
917950
DryRun: ptr.To(false),
918951
Name: controlPlaneSpec.RosaClusterName,
@@ -924,12 +957,12 @@ func buildOCMClusterSpec(controlPlaneSpec rosacontrolplanev1.RosaControlPlaneSpe
924957
DisableWorkloadMonitoring: ptr.To(true),
925958
DefaultIngress: ocm.NewDefaultIngressSpec(), // n.b. this is a no-op when it's set to the default value
926959
ComputeMachineType: controlPlaneSpec.DefaultMachinePoolSpec.InstanceType,
927-
AvailabilityZones: controlPlaneSpec.AvailabilityZones,
960+
AvailabilityZones: availabilityZones,
928961
Tags: controlPlaneSpec.AdditionalTags,
929962
EtcdEncryption: controlPlaneSpec.EtcdEncryptionKMSARN != "",
930963
EtcdEncryptionKMSArn: controlPlaneSpec.EtcdEncryptionKMSARN,
931964

932-
SubnetIds: controlPlaneSpec.Subnets,
965+
SubnetIds: subnetIDs,
933966
IsSTS: true,
934967
RoleARN: controlPlaneSpec.InstallerRoleARN,
935968
SupportRoleARN: controlPlaneSpec.SupportRoleARN,
@@ -990,8 +1023,8 @@ func buildOCMClusterSpec(controlPlaneSpec rosacontrolplanev1.RosaControlPlaneSpe
9901023
ocmClusterSpec.Autoscaling = true
9911024
ocmClusterSpec.MaxReplicas = computeAutoscaling.MaxReplicas
9921025
ocmClusterSpec.MinReplicas = computeAutoscaling.MinReplicas
993-
} else if len(controlPlaneSpec.AvailabilityZones) > 1 {
994-
ocmClusterSpec.ComputeNodes = len(controlPlaneSpec.AvailabilityZones)
1026+
} else if len(ocmClusterSpec.AvailabilityZones) > 1 {
1027+
ocmClusterSpec.ComputeNodes = len(ocmClusterSpec.AvailabilityZones)
9951028
}
9961029

9971030
if controlPlaneSpec.ProvisionShardID != "" {

0 commit comments

Comments
 (0)