Skip to content

Commit adbe3c5

Browse files
committed
Add ID field to HCloudNetwork and change other fields to pointers
1 parent c05f7aa commit adbe3c5

File tree

6 files changed

+79
-42
lines changed

6 files changed

+79
-42
lines changed

api/v1beta1/types.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,39 @@ type LoadBalancerTarget struct {
217217

218218
// HCloudNetworkSpec defines the desired state of the HCloud Private Network.
219219
type HCloudNetworkSpec struct {
220+
// ID is the id of the Network to adopt.
221+
// Mutually exclusive with CIDRBlock, SubnetCIDRBlock and NetworkZone.
222+
// +optional
223+
ID *int64 `json:"id,omitempty"`
224+
220225
// Enabled defines whether the network should be enabled or not.
221226
Enabled bool `json:"enabled"`
222227

223-
// CIDRBlock defines the cidrBlock of the HCloud Network. If omitted, default "10.0.0.0/16" will be used.
224-
// +kubebuilder:default="10.0.0.0/16"
228+
// CIDRBlock defines the cidrBlock of the HCloud Network.
229+
// Defaults to "10.0.0.0/16".
230+
// Mutually exclusive with ID.
225231
// +optional
226-
CIDRBlock string `json:"cidrBlock,omitempty"`
232+
CIDRBlock *string `json:"cidrBlock,omitempty"`
227233

228234
// SubnetCIDRBlock defines the cidrBlock for the subnet of the HCloud Network.
235+
// Defaults to "10.0.0.0/24".
236+
// Mutually exclusive with ID.
229237
// Note: A subnet is required.
230-
// +kubebuilder:default="10.0.0.0/24"
231238
// +optional
232-
SubnetCIDRBlock string `json:"subnetCidrBlock,omitempty"`
239+
SubnetCIDRBlock *string `json:"subnetCidrBlock,omitempty"`
233240

234241
// NetworkZone specifies the HCloud network zone of the private network.
235-
// The zones must be one of eu-central, us-east, or us-west. The default is eu-central.
236-
// +kubebuilder:validation:Enum=eu-central;us-east;us-west;ap-southeast
237-
// +kubebuilder:default=eu-central
242+
// The zones must be one of eu-central, us-east, or us-west.
243+
// Defaults to "eu-central".
244+
// Mutually exclusive with ID.
238245
// +optional
239-
NetworkZone HCloudNetworkZone `json:"networkZone,omitempty"`
246+
NetworkZone *HCloudNetworkZone `json:"networkZone,omitempty"`
240247
}
241248

242249
// NetworkStatus defines the observed state of the HCloud Private Network.
243250
type NetworkStatus struct {
244251
ID int64 `json:"id,omitempty"`
245-
Labels map[string]string `json:"-"`
252+
Labels map[string]string `json:"labels,omitempty"`
246253
AttachedServers []int64 `json:"attachedServers,omitempty"`
247254
}
248255

@@ -255,10 +262,10 @@ type HCloudNetworkZone string
255262

256263
// IsZero returns true if a private Network is set.
257264
func (s *HCloudNetworkSpec) IsZero() bool {
258-
if s.CIDRBlock != "" {
265+
if s.CIDRBlock != nil {
259266
return false
260267
}
261-
if s.SubnetCIDRBlock != "" {
268+
if s.SubnetCIDRBlock != nil {
262269
return false
263270
}
264271
return true

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_hetznerclusters.yaml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,29 +190,33 @@ spec:
190190
for Hetzner Cloud. If left empty, no private Network is configured.
191191
properties:
192192
cidrBlock:
193-
default: 10.0.0.0/16
194-
description: CIDRBlock defines the cidrBlock of the HCloud Network.
195-
If omitted, default "10.0.0.0/16" will be used.
193+
description: |-
194+
CIDRBlock defines the cidrBlock of the HCloud Network.
195+
Defaults to "10.0.0.0/16".
196+
Mutually exclusive with ID.
196197
type: string
197198
enabled:
198199
description: Enabled defines whether the network should be enabled
199200
or not.
200201
type: boolean
202+
id:
203+
description: |-
204+
ID is the id of the Network to adopt.
205+
Mutually exclusive with CIDRBlock, SubnetCIDRBlock and NetworkZone.
206+
format: int64
207+
type: integer
201208
networkZone:
202-
default: eu-central
203209
description: |-
204210
NetworkZone specifies the HCloud network zone of the private network.
205-
The zones must be one of eu-central, us-east, or us-west. The default is eu-central.
206-
enum:
207-
- eu-central
208-
- us-east
209-
- us-west
210-
- ap-southeast
211+
The zones must be one of eu-central, us-east, or us-west.
212+
Defaults to "eu-central".
213+
Mutually exclusive with ID.
211214
type: string
212215
subnetCidrBlock:
213-
default: 10.0.0.0/24
214216
description: |-
215217
SubnetCIDRBlock defines the cidrBlock for the subnet of the HCloud Network.
218+
Defaults to "10.0.0.0/24".
219+
Mutually exclusive with ID.
216220
Note: A subnet is required.
217221
type: string
218222
required:
@@ -466,6 +470,10 @@ spec:
466470
id:
467471
format: int64
468472
type: integer
473+
labels:
474+
additionalProperties:
475+
type: string
476+
type: object
469477
type: object
470478
ready:
471479
default: false

config/crd/bases/infrastructure.cluster.x-k8s.io_hetznerclustertemplates.yaml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,33 @@ spec:
221221
is configured.
222222
properties:
223223
cidrBlock:
224-
default: 10.0.0.0/16
225-
description: CIDRBlock defines the cidrBlock of the HCloud
226-
Network. If omitted, default "10.0.0.0/16" will be used.
224+
description: |-
225+
CIDRBlock defines the cidrBlock of the HCloud Network.
226+
Defaults to "10.0.0.0/16".
227+
Mutually exclusive with ID.
227228
type: string
228229
enabled:
229230
description: Enabled defines whether the network should
230231
be enabled or not.
231232
type: boolean
233+
id:
234+
description: |-
235+
ID is the id of the Network to adopt.
236+
Mutually exclusive with CIDRBlock, SubnetCIDRBlock and NetworkZone.
237+
format: int64
238+
type: integer
232239
networkZone:
233-
default: eu-central
234240
description: |-
235241
NetworkZone specifies the HCloud network zone of the private network.
236-
The zones must be one of eu-central, us-east, or us-west. The default is eu-central.
237-
enum:
238-
- eu-central
239-
- us-east
240-
- us-west
241-
- ap-southeast
242+
The zones must be one of eu-central, us-east, or us-west.
243+
Defaults to "eu-central".
244+
Mutually exclusive with ID.
242245
type: string
243246
subnetCidrBlock:
244-
default: 10.0.0.0/24
245247
description: |-
246248
SubnetCIDRBlock defines the cidrBlock for the subnet of the HCloud Network.
249+
Defaults to "10.0.0.0/24".
250+
Mutually exclusive with ID.
247251
Note: A subnet is required.
248252
type: string
249253
required:

controllers/controllers_suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ func getDefaultHetznerClusterSpec() infrav1.HetznerClusterSpec {
160160
ControlPlaneEndpoint: &clusterv1.APIEndpoint{},
161161
ControlPlaneRegions: []infrav1.Region{"fsn1"},
162162
HCloudNetwork: infrav1.HCloudNetworkSpec{
163-
CIDRBlock: "10.0.0.0/16",
164-
Enabled: true,
165-
NetworkZone: "eu-central",
166-
SubnetCIDRBlock: "10.0.0.0/24",
163+
Enabled: true,
167164
},
168165
HCloudPlacementGroups: []infrav1.HCloudPlacementGroupSpec{
169166
{

test/helpers/defaults.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
corev1 "k8s.io/api/core/v1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/utils/ptr"
2526
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2627

2728
infrav1 "github.com/syself/cluster-api-provider-hetzner/api/v1beta1"
@@ -199,10 +200,10 @@ func GetDefaultHetznerClusterSpec() infrav1.HetznerClusterSpec {
199200
ControlPlaneEndpoint: &clusterv1.APIEndpoint{},
200201
ControlPlaneRegions: []infrav1.Region{"fsn1"},
201202
HCloudNetwork: infrav1.HCloudNetworkSpec{
202-
CIDRBlock: "10.0.0.0/16",
203+
CIDRBlock: ptr.To(infrav1.DefaultCIDRBlock),
203204
Enabled: true,
204-
NetworkZone: "eu-central",
205-
SubnetCIDRBlock: "10.0.0.0/24",
205+
NetworkZone: ptr.To[infrav1.HCloudNetworkZone](infrav1.DefaultNetworkZone),
206+
SubnetCIDRBlock: ptr.To(infrav1.DefaultSubnetCIDRBlock),
206207
},
207208
HCloudPlacementGroups: []infrav1.HCloudPlacementGroupSpec{
208209
{

0 commit comments

Comments
 (0)