Skip to content

Commit e7f18ec

Browse files
committed
ROSAControlPlane to use net info from RosaNetwork CR
1 parent 3b0895f commit e7f18ec

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
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
@@ -776,6 +776,22 @@ spec:
776776
x-kubernetes-validations:
777777
- message: rosaClusterName is immutable
778778
rule: self == oldSelf
779+
rosaNetworkRef:
780+
description: |-
781+
RosaNetworkRef references RosaNetwork custom resource that contains the networking infrastructure
782+
for Rosa HCP cluster
783+
properties:
784+
name:
785+
default: ""
786+
description: |-
787+
Name of the referent.
788+
This field is effectively required, but due to backwards compatibility is
789+
allowed to be empty. Instances of this type with an empty value here are
790+
almost certainly wrong.
791+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
792+
type: string
793+
type: object
794+
x-kubernetes-map-type: atomic
779795
subnets:
780796
description: |-
781797
The Subnet IDs to use when installing the cluster.
@@ -809,14 +825,12 @@ spec:
809825
to worker instances.
810826
type: string
811827
required:
812-
- availabilityZones
813828
- channelGroup
814829
- installerRoleARN
815830
- oidcID
816831
- region
817832
- rolesRef
818833
- rosaClusterName
819-
- subnets
820834
- supportRoleARN
821835
- version
822836
- versionGate

controlplane/rosa/api/v1beta2/rosacontrolplane_types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ type RosaControlPlaneSpec struct { //nolint: maligned
9595

9696
// The Subnet IDs to use when installing the cluster.
9797
// SubnetIDs should come in pairs; two per availability zone, one private and one public.
98-
Subnets []string `json:"subnets"`
98+
// +optional
99+
Subnets []string `json:"subnets,omitempty"`
99100

100101
// AvailabilityZones describe AWS AvailabilityZones of the worker nodes.
101102
// should match the AvailabilityZones of the provided Subnets.
102103
// a machinepool will be created for each availabilityZone.
103-
AvailabilityZones []string `json:"availabilityZones"`
104+
// +optional
105+
AvailabilityZones []string `json:"availabilityZones,omitempty"`
104106

105107
// The AWS Region the cluster lives in.
106108
Region string `json:"region"`
@@ -231,6 +233,11 @@ type RosaControlPlaneSpec struct { //nolint: maligned
231233
// ClusterRegistryConfig represents registry config used with the cluster.
232234
// +optional
233235
ClusterRegistryConfig *RegistryConfig `json:"clusterRegistryConfig,omitempty"`
236+
237+
// RosaNetworkRef references RosaNetwork custom resource that contains the networking infrastructure
238+
// for Rosa HCP cluster
239+
// +optional
240+
RosaNetworkRef *corev1.LocalObjectReference `json:"rosaNetworkRef,omitempty"`
234241
}
235242

236243
// 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)