Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit f739d68

Browse files
authored
Merge pull request #229 from jhead-slg/feat/facilityOverride
✨ Allow overriding facility
2 parents 75079d4 + 57cdc8e commit f739d68

File tree

6 files changed

+49
-69
lines changed

6 files changed

+49
-69
lines changed

api/v1alpha3/packetmachine_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ type PacketMachineSpec struct {
3838
MachineType string `json:"machineType"`
3939
SshKeys []string `json:"sshKeys,omitempty"`
4040

41+
// Facility represents the Packet facility for this cluster.
42+
// Override from the PacketCluster spec.
43+
// +optional
44+
Facility string `json:"facility,omitempty"`
45+
4146
// IPXEUrl can be used to set the pxe boot url when using custom OSes with this provider.
4247
// Note that OS should also be set to "custom_ipxe" if using this value.
4348
// +optional

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
---
13
apiVersion: apiextensions.k8s.io/v1
24
kind: CustomResourceDefinition
35
metadata:
@@ -20,23 +22,18 @@ spec:
2022
description: PacketCluster is the Schema for the packetclusters API
2123
properties:
2224
apiVersion:
23-
description: 'APIVersion defines the versioned schema of this representation
24-
of an object. Servers should convert recognized schemas to the latest
25-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
25+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
2626
type: string
2727
kind:
28-
description: 'Kind is a string value representing the REST resource this
29-
object represents. Servers may infer this from the endpoint the client
30-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
28+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
3129
type: string
3230
metadata:
3331
type: object
3432
spec:
3533
description: PacketClusterSpec defines the desired state of PacketCluster
3634
properties:
3735
controlPlaneEndpoint:
38-
description: ControlPlaneEndpoint represents the endpoint used to
39-
communicate with the control plane.
36+
description: ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
4037
properties:
4138
host:
4239
description: The hostname on which the API server is serving.
@@ -53,8 +50,7 @@ spec:
5350
description: Facility represents the Packet facility for this cluster
5451
type: string
5552
projectID:
56-
description: ProjectID represents the Packet Project where this cluster
57-
will be placed into
53+
description: ProjectID represents the Packet Project where this cluster will be placed into
5854
type: string
5955
required:
6056
- projectID

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

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
---
13
apiVersion: apiextensions.k8s.io/v1
24
kind: CustomResourceDefinition
35
metadata:
@@ -43,14 +45,10 @@ spec:
4345
description: PacketMachine is the Schema for the packetmachines API
4446
properties:
4547
apiVersion:
46-
description: 'APIVersion defines the versioned schema of this representation
47-
of an object. Servers should convert recognized schemas to the latest
48-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
48+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
4949
type: string
5050
kind:
51-
description: 'Kind is a string value representing the REST resource this
52-
object represents. Servers may infer this from the endpoint the client
53-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
51+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
5452
type: string
5553
metadata:
5654
type: object
@@ -61,29 +59,26 @@ spec:
6159
type: string
6260
billingCycle:
6361
type: string
62+
facility:
63+
description: Facility represents the Packet facility for this cluster. Override from the PacketCluster spec.
64+
type: string
6465
hardwareReservationID:
65-
description: HardwareReservationID is the unique device hardware reservation
66-
ID or `next-available` to automatically let the Packet api determine
67-
one.
66+
description: HardwareReservationID is the unique device hardware reservation ID or `next-available` to automatically let the Packet api determine one.
6867
type: string
6968
ipxeURL:
70-
description: IPXEUrl can be used to set the pxe boot url when using
71-
custom OSes with this provider. Note that OS should also be set
72-
to "custom_ipxe" if using this value.
69+
description: IPXEUrl can be used to set the pxe boot url when using custom OSes with this provider. Note that OS should also be set to "custom_ipxe" if using this value.
7370
type: string
7471
machineType:
7572
type: string
7673
providerID:
77-
description: ProviderID is the unique identifier as specified by the
78-
cloud provider.
74+
description: ProviderID is the unique identifier as specified by the cloud provider.
7975
type: string
8076
sshKeys:
8177
items:
8278
type: string
8379
type: array
8480
tags:
85-
description: Tags is an optional set of tags to add to Packet resources
86-
managed by the Packet provider.
81+
description: Tags is an optional set of tags to add to Packet resources managed by the Packet provider.
8782
items:
8883
type: string
8984
type: array
@@ -104,37 +99,21 @@ spec:
10499
description: The node address.
105100
type: string
106101
type:
107-
description: Node address type, one of Hostname, ExternalIP
108-
or InternalIP.
102+
description: Node address type, one of Hostname, ExternalIP or InternalIP.
109103
type: string
110104
required:
111105
- address
112106
- type
113107
type: object
114108
type: array
115109
errorMessage:
116-
description: "ErrorMessage will be set in the event that there is
117-
a terminal problem reconciling the Machine and will contain a more
118-
verbose string suitable for logging and human consumption. \n This
119-
field should not be set for transitive errors that a controller
120-
faces that are expected to be fixed automatically over time (like
121-
service outages), but instead indicate that something is fundamentally
122-
wrong with the Machine's spec or the configuration of the controller,
123-
and that manual intervention is required. Examples of terminal errors
124-
would be invalid combinations of settings in the spec, values that
125-
are unsupported by the controller, or the responsible controller
126-
itself being critically misconfigured. \n Any transient errors that
127-
occur during the reconciliation of Machines can be added as events
128-
to the Machine object and/or logged in the controller's output."
110+
description: "ErrorMessage will be set in the event that there is a terminal problem reconciling the Machine and will contain a more verbose string suitable for logging and human consumption. \n This field should not be set for transitive errors that a controller faces that are expected to be fixed automatically over time (like service outages), but instead indicate that something is fundamentally wrong with the Machine's spec or the configuration of the controller, and that manual intervention is required. Examples of terminal errors would be invalid combinations of settings in the spec, values that are unsupported by the controller, or the responsible controller itself being critically misconfigured. \n Any transient errors that occur during the reconciliation of Machines can be added as events to the Machine object and/or logged in the controller's output."
129111
type: string
130112
errorReason:
131-
description: Any transient errors that occur during the reconciliation
132-
of Machines can be added as events to the Machine object and/or
133-
logged in the controller's output.
113+
description: Any transient errors that occur during the reconciliation of Machines can be added as events to the Machine object and/or logged in the controller's output.
134114
type: string
135115
instanceStatus:
136-
description: InstanceStatus is the status of the Packet device instance
137-
for this machine.
116+
description: InstanceStatus is the status of the Packet device instance for this machine.
138117
type: string
139118
ready:
140119
description: Ready is true when the provider resource is ready.

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
---
13
apiVersion: apiextensions.k8s.io/v1
24
kind: CustomResourceDefinition
35
metadata:
@@ -19,59 +21,49 @@ spec:
1921
- name: v1alpha3
2022
schema:
2123
openAPIV3Schema:
22-
description: PacketMachineTemplate is the Schema for the packetmachinetemplates
23-
API
24+
description: PacketMachineTemplate is the Schema for the packetmachinetemplates API
2425
properties:
2526
apiVersion:
26-
description: 'APIVersion defines the versioned schema of this representation
27-
of an object. Servers should convert recognized schemas to the latest
28-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
2928
type: string
3029
kind:
31-
description: 'Kind is a string value representing the REST resource this
32-
object represents. Servers may infer this from the endpoint the client
33-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
3431
type: string
3532
metadata:
3633
type: object
3734
spec:
3835
description: PacketMachineTemplateSpec defines the desired state of PacketMachineTemplate
3936
properties:
4037
template:
41-
description: PacketMachineTemplateResource describes the data needed
42-
to create am PacketMachine from a template
38+
description: PacketMachineTemplateResource describes the data needed to create am PacketMachine from a template
4339
properties:
4440
spec:
45-
description: Spec is the specification of the desired behavior
46-
of the machine.
41+
description: Spec is the specification of the desired behavior of the machine.
4742
properties:
4843
OS:
4944
type: string
5045
billingCycle:
5146
type: string
47+
facility:
48+
description: Facility represents the Packet facility for this cluster. Override from the PacketCluster spec.
49+
type: string
5250
hardwareReservationID:
53-
description: HardwareReservationID is the unique device hardware
54-
reservation ID or `next-available` to automatically let
55-
the Packet api determine one.
51+
description: HardwareReservationID is the unique device hardware reservation ID or `next-available` to automatically let the Packet api determine one.
5652
type: string
5753
ipxeURL:
58-
description: IPXEUrl can be used to set the pxe boot url when
59-
using custom OSes with this provider. Note that OS should
60-
also be set to "custom_ipxe" if using this value.
54+
description: IPXEUrl can be used to set the pxe boot url when using custom OSes with this provider. Note that OS should also be set to "custom_ipxe" if using this value.
6155
type: string
6256
machineType:
6357
type: string
6458
providerID:
65-
description: ProviderID is the unique identifier as specified
66-
by the cloud provider.
59+
description: ProviderID is the unique identifier as specified by the cloud provider.
6760
type: string
6861
sshKeys:
6962
items:
7063
type: string
7164
type: array
7265
tags:
73-
description: Tags is an optional set of tags to add to Packet
74-
resources managed by the Packet provider.
66+
description: Tags is an optional set of tags to add to Packet resources managed by the Packet provider.
7567
items:
7668
type: string
7769
type: array

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
---
13
apiVersion: rbac.authorization.k8s.io/v1
24
kind: ClusterRole
35
metadata:

pkg/cloud/packet/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ func (p *PacketClient) NewDevice(req CreateDeviceRequest) (*packngo.Device, erro
112112

113113
userData = stringWriter.String()
114114

115+
// Allow to override the facility for each PacketMachineTemplate
116+
var facility = req.MachineScope.PacketCluster.Spec.Facility
117+
if req.MachineScope.PacketMachine.Spec.Facility != "" {
118+
facility = req.MachineScope.PacketMachine.Spec.Facility
119+
}
120+
115121
serverCreateOpts := &packngo.DeviceCreateRequest{
116122
Hostname: req.MachineScope.Name(),
117123
ProjectID: req.MachineScope.PacketCluster.Spec.ProjectID,
118-
Facility: []string{req.MachineScope.PacketCluster.Spec.Facility},
124+
Facility: []string{facility},
119125
BillingCycle: req.MachineScope.PacketMachine.Spec.BillingCycle,
120126
HardwareReservationID: req.MachineScope.PacketMachine.Spec.HardwareReservationID,
121127
Plan: req.MachineScope.PacketMachine.Spec.MachineType,

0 commit comments

Comments
 (0)