Skip to content

Commit 49b3824

Browse files
committed
RosaNetwork: new CRD & reconciler to provision net infra for ROSA-HCP
1 parent a0968d3 commit 49b3824

22 files changed

+1140
-13
lines changed

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ resources:
5858
- group: infrastructure
5959
version: v1beta2
6060
kind: AWSManagedCluster
61+
- group: infrastructure
62+
kind: ROSANetwork
63+
version: v1beta2

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
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.17.3
7+
name: rosanetworks.infrastructure.cluster.x-k8s.io
8+
spec:
9+
group: infrastructure.cluster.x-k8s.io
10+
names:
11+
categories:
12+
- cluster-api
13+
kind: ROSANetwork
14+
listKind: ROSANetworkList
15+
plural: rosanetworks
16+
shortNames:
17+
- rosanet
18+
singular: rosanetwork
19+
scope: Namespaced
20+
versions:
21+
- name: v1beta2
22+
schema:
23+
openAPIV3Schema:
24+
description: ROSANetwork is the schema for the rosanetworks API
25+
properties:
26+
apiVersion:
27+
description: |-
28+
APIVersion defines the versioned schema of this representation of an object.
29+
Servers should convert recognized schemas to the latest internal value, and
30+
may reject unrecognized values.
31+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
32+
type: string
33+
kind:
34+
description: |-
35+
Kind is a string value representing the REST resource this object represents.
36+
Servers may infer this from the endpoint the client submits requests to.
37+
Cannot be updated.
38+
In CamelCase.
39+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
40+
type: string
41+
metadata:
42+
type: object
43+
spec:
44+
description: ROSANetworkSpec defines the desired state of ROSANetwork
45+
properties:
46+
availabilityZoneCount:
47+
default: 1
48+
description: |-
49+
The number of availability zones to be used for creation of the network infrastructure.
50+
You can specify anything between one and four, depending on the chosen AWS region.
51+
type: integer
52+
availabilityZones:
53+
description: |-
54+
The list of availability zones to be used for creation of the network infrastructure.
55+
You can specify anything between one and four valid availability zones from a given region.
56+
Should you specify both the availabilityZoneCount and availabilityZones, the list of availability zones takes preference.
57+
items:
58+
type: string
59+
type: array
60+
cidrBlock:
61+
description: CIDR block to be used for the VPC
62+
format: cidr
63+
type: string
64+
identityRef:
65+
description: |-
66+
IdentityRef is a reference to an identity to be used when reconciling rosa network.
67+
If no identity is specified, the default identity for this controller will be used.
68+
properties:
69+
kind:
70+
description: Kind of the identity.
71+
enum:
72+
- AWSClusterControllerIdentity
73+
- AWSClusterRoleIdentity
74+
- AWSClusterStaticIdentity
75+
type: string
76+
name:
77+
description: Name of the identity.
78+
minLength: 1
79+
type: string
80+
required:
81+
- kind
82+
- name
83+
type: object
84+
region:
85+
description: The AWS region in which the components of ROSA network
86+
infrastruture are to be crated
87+
type: string
88+
stackName:
89+
description: The name of the cloudformation stack under which the
90+
network infrastructure would be created
91+
type: string
92+
required:
93+
- cidrBlock
94+
- region
95+
- stackName
96+
type: object
97+
status:
98+
description: ROSANetworkStatus defines the observed state of ROSANetwork
99+
properties:
100+
conditions:
101+
description: Conditions specifies the conditions for ROSANetwork
102+
items:
103+
description: Condition defines an observation of a Cluster API resource
104+
operational state.
105+
properties:
106+
lastTransitionTime:
107+
description: |-
108+
lastTransitionTime is the last time the condition transitioned from one status to another.
109+
This should be when the underlying condition changed. If that is not known, then using the time when
110+
the API field changed is acceptable.
111+
format: date-time
112+
type: string
113+
message:
114+
description: |-
115+
message is a human readable message indicating details about the transition.
116+
This field may be empty.
117+
maxLength: 10240
118+
minLength: 1
119+
type: string
120+
reason:
121+
description: |-
122+
reason is the reason for the condition's last transition in CamelCase.
123+
The specific API may choose whether or not this field is considered a guaranteed API.
124+
This field may be empty.
125+
maxLength: 256
126+
minLength: 1
127+
type: string
128+
severity:
129+
description: |-
130+
severity provides an explicit classification of Reason code, so the users or machines can immediately
131+
understand the current situation and act accordingly.
132+
The Severity field MUST be set only when Status=False.
133+
maxLength: 32
134+
type: string
135+
status:
136+
description: status of the condition, one of True, False, Unknown.
137+
type: string
138+
type:
139+
description: |-
140+
type of condition in CamelCase or in foo.example.com/CamelCase.
141+
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
142+
can be useful (see .node.status.conditions), the ability to deconflict is important.
143+
maxLength: 256
144+
minLength: 1
145+
type: string
146+
required:
147+
- lastTransitionTime
148+
- status
149+
- type
150+
type: object
151+
type: array
152+
resources:
153+
description: Resources created in the cloudformation stack
154+
items:
155+
description: CFResource groups information pertaining to a resource
156+
created as a part of a cloudformation stack
157+
properties:
158+
logicalId:
159+
description: LogicalResourceID of the created resource.
160+
type: string
161+
physicalId:
162+
description: PhysicalResourceID of the created resource.
163+
type: string
164+
reason:
165+
description: Message pertaining to the status of the resource
166+
type: string
167+
resource:
168+
description: 'Type of the created resource: AWS::EC2::VPC, AWS::EC2::Subnet,
169+
...'
170+
type: string
171+
status:
172+
description: 'Status of the resource: CREATE_IN_PROGRESS, CREATE_COMPLETE,
173+
...'
174+
type: string
175+
required:
176+
- logicalId
177+
- physicalId
178+
- reason
179+
- resource
180+
- status
181+
type: object
182+
type: array
183+
subnets:
184+
description: Array of created private, public subnets and availability
185+
zones, grouped by availability zones
186+
items:
187+
description: ROSANetworkSubnet groups public and private subnet
188+
and the availability zone in which the two subnets got created
189+
properties:
190+
availabilityZone:
191+
description: Availability zone of the subnet pair, for example
192+
us-west-2a
193+
type: string
194+
privateSubnet:
195+
description: ID of the private subnet, for example subnet-07a20d6c41af2b725
196+
type: string
197+
publicSubnet:
198+
description: ID of the public subnet, for example subnet-0f7e49a3ce68ff338
199+
type: string
200+
required:
201+
- availabilityZone
202+
- privateSubnet
203+
- publicSubnet
204+
type: object
205+
type: array
206+
type: object
207+
type: object
208+
served: true
209+
storage: true
210+
subresources:
211+
status: {}

config/crd/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ resources:
2626
- bases/controlplane.cluster.x-k8s.io_rosacontrolplanes.yaml
2727
- bases/infrastructure.cluster.x-k8s.io_rosaclusters.yaml
2828
- bases/infrastructure.cluster.x-k8s.io_rosamachinepools.yaml
29+
- bases/infrastructure.cluster.x-k8s.io_rosanetworks.yaml
2930
# +kubebuilder:scaffold:crdkustomizeresource
3031

3132
patchesStrategicMerge:
@@ -41,6 +42,7 @@ patchesStrategicMerge:
4142
- patches/webhook_in_awsmanagedcontrolplanetemplates.yaml
4243
- patches/webhook_in_eksconfigs.yaml
4344
- patches/webhook_in_eksconfigtemplates.yaml
45+
#- patches/webhook_in_rosanetworks.yaml
4446
# +kubebuilder:scaffold:crdkustomizewebhookpatch
4547

4648
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
@@ -57,6 +59,7 @@ patchesStrategicMerge:
5759
- patches/cainjection_in_awsmanagedclustertemplates.yaml
5860
- patches/cainjection_in_eksconfigs.yaml
5961
- patches/cainjection_in_eksconfigtemplates.yaml
62+
- patches/cainjection_in_rosanetworks.yaml
6063
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
6164

6265
# [LABEL] To enable label, uncomment all the sections with [LABEL] prefix.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: rosanetworks.infrastructure.cluster.x-k8s.io
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: rosanetworks.infrastructure.cluster.x-k8s.io
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ rules:
176176
- awsfargateprofiles/status
177177
- rosaclusters/status
178178
- rosamachinepools/status
179+
- rosanetworks/status
179180
verbs:
180181
- get
181182
- patch
@@ -197,6 +198,7 @@ rules:
197198
- infrastructure.cluster.x-k8s.io
198199
resources:
199200
- awsmachines
201+
- rosanetworks
200202
verbs:
201203
- create
202204
- delete

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/rosacontrolplane_webhook.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (*rosaControlPlaneWebhook) ValidateCreate(_ context.Context, obj runtime.Ob
6161
allErrs = append(allErrs, r.validateNetwork()...)
6262
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
6363

64+
if err := r.validateROSANetwork(); err != nil {
65+
allErrs = append(allErrs, err)
66+
}
67+
6468
if len(allErrs) == 0 {
6569
return nil, nil
6670
}
@@ -179,6 +183,23 @@ func (r *ROSAControlPlane) validateExternalAuthProviders() *field.Error {
179183
return nil
180184
}
181185

186+
func (r *ROSAControlPlane) validateROSANetwork() *field.Error {
187+
if r.Spec.ROSANetworkRef != nil {
188+
if r.Spec.Subnets != nil {
189+
return field.Forbidden(field.NewPath("spec.rosaNetworkRef"), "spec.subnets and spec.rosaNetworkRef are mutually exclusive")
190+
}
191+
if r.Spec.AvailabilityZones != nil {
192+
return field.Forbidden(field.NewPath("spec.rosaNetworkRef"), "spec.availabilityZones and spec.rosaNetworkRef are mutually exclusive")
193+
}
194+
}
195+
196+
if r.Spec.ROSANetworkRef == nil && (r.Spec.Subnets == nil || r.Spec.AvailabilityZones == nil) {
197+
return field.Required(field.NewPath("spec.subnets"), "spec.subnets and spec.availabilityZones cannot be empty when spec.rosaNetworkRef is unspecified")
198+
}
199+
200+
return nil
201+
}
202+
182203
// Default implements admission.Defaulter.
183204
func (*rosaControlPlaneWebhook) Default(_ context.Context, obj runtime.Object) error {
184205
r, ok := obj.(*ROSAControlPlane)

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.

0 commit comments

Comments
 (0)