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

Commit 8b269d2

Browse files
authored
Merge pull request #137 from packethost/add/hardwareReservationID
Hardware reservation support for machine
2 parents 9e8dafc + e567596 commit 8b269d2

File tree

5 files changed

+101
-8
lines changed

5 files changed

+101
-8
lines changed

api/v1alpha3/packetmachine_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ type PacketMachineSpec struct {
4141
BillingCycle string `json:"billingCycle"`
4242
MachineType string `json:"machineType"`
4343
SshKeys []string `json:"sshKeys,omitempty"`
44+
45+
// HardwareReservationID is the unique device hardware reservation ID or `next-available` to
46+
// automatically let the Packet api determine one.
47+
// +optional
48+
HardwareReservationID string `json:"hardwareReservationID,omitempty"`
49+
4450
// ProviderID is the unique identifier as specified by the cloud provider.
4551
// +optional
4652
ProviderID *string `json:"providerID,omitempty"`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ spec:
6767
items:
6868
type: string
6969
type: array
70+
hardwareReservationID:
71+
description: HardwareReservationID is the unique device hardware reservation
72+
ID or `next-available` to automatically let the Packet api determine
73+
one.
74+
type: string
7075
machineType:
7176
type: string
7277
providerID:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ spec:
5353
items:
5454
type: string
5555
type: array
56+
hardwareReservationID:
57+
description: HardwareReservationID is the unique device hardware
58+
reservation ID or `next-available` to automatically let the
59+
Packet api determine one.
60+
type: string
5661
machineType:
5762
type: string
5863
providerID:

docs/concepts/machine.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
PacketMachine is the name of the resource that identifies a
2+
[Device](packetDeviceAPI) on Packet.
3+
4+
This is an example of it:
5+
6+
```yaml
7+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
8+
kind: PacketMachine
9+
metadata:
10+
name: "qa-master-0"
11+
spec:
12+
OS: "ubuntu_18_04"
13+
facility:
14+
- "dfw2"
15+
billingCycle: hourly
16+
machineType: "t2.small"
17+
sshKeys:
18+
- "your-sshkey-name"
19+
tags: []
20+
```
21+
22+
It is a [Kubernetes Custom Resource Definition (CRD)](crd-docs) as everything
23+
else in the cluster-api land.
24+
25+
The reported fields in the example are the most common one but you can see the
26+
full list of supported parameters as part of the OpenAPI definition available
27+
[here](config/resources/crd/bases/infrastructure.cluster.x-k8s.io_packetmachines.yaml)
28+
searching for `kind: PacketMachine`.
29+
30+
## Reserved instances
31+
32+
Packet provides the possibility to [reserve
33+
hardware](packet-docs-reserved-hardware) in order to have to power you need
34+
always available.
35+
36+
> Reserved hardware gives you the ability to reserve specific servers for a
37+
> committed period of time. Unlike hourly on-demand, once you reserve hardware,
38+
> you will have access to that specific hardware for the duration of the
39+
> reservation.
40+
41+
You can specify the reservation ID using the field `hardwareReservationID`:
42+
43+
```
44+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
45+
kind: PacketMachine
46+
metadata:
47+
name: "qa-master-0"
48+
spec:
49+
OS: "ubuntu_18_04"
50+
facility:
51+
- "dfw2"
52+
billingCycle: hourly
53+
machineType: "t2.small"
54+
sshKeys:
55+
- "your-sshkey-name"
56+
hardwareReservationID: "d3cb029a-c5e4-4e2b-bafc-56266639685f"
57+
tags: []
58+
```
59+
60+
### pros and cons
61+
62+
Hardware reservation is a great feature, this chapter is about the feature
63+
described above and nothing more.
64+
It covers a very simple use case, you have a set of machines that you created
65+
statically in the YAML and you like to have them using a reservation ID.
66+
67+
It does not work in combination of PacketMachineTemplate and MachineDeployment
68+
where the pool of PacketMachine is dynamically managed by the cluster-api
69+
controllers. You can track progress on this scenario subscribing to the issue
70+
["Add support for reservation IDs with MachineDeployment #136"](github-issue-resid-dynamic) on GitHub.
71+
72+
[packetDeviceAPI]: https://www.packet.com/developers/api/devices/#devices-createDevice
73+
[crd-docs]: https://github.com/packethost/cluster-api-provider-packet/blob/master/config/resources/crd/bases/infrastructure.cluster.x-k8s.io_packetmachines.yaml
74+
[openapi-types]: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/
75+
[packet-docs-reserved-hardware]: https://www.packet.com/developers/docs/getting-started/deployment-options/reserved-hardware/
76+
[github-issue-resid-dynamic]: https://github.com/packethost/cluster-api-provider-packet/issues/136

pkg/cloud/packet/client.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ func (p *PacketClient) NewDevice(hostname, project string, machineScope *scope.M
8888
tags = append(tags, infrastructurev1alpha3.WorkerTag)
8989
}
9090
serverCreateOpts := &packngo.DeviceCreateRequest{
91-
Hostname: hostname,
92-
ProjectID: project,
93-
Facility: machineScope.PacketMachine.Spec.Facility,
94-
BillingCycle: machineScope.PacketMachine.Spec.BillingCycle,
95-
Plan: machineScope.PacketMachine.Spec.MachineType,
96-
OS: machineScope.PacketMachine.Spec.OS,
97-
Tags: tags,
98-
UserData: userData,
91+
Hostname: hostname,
92+
ProjectID: project,
93+
Facility: machineScope.PacketMachine.Spec.Facility,
94+
BillingCycle: machineScope.PacketMachine.Spec.BillingCycle,
95+
HardwareReservationID: machineScope.PacketMachine.Spec.HardwareReservationID,
96+
Plan: machineScope.PacketMachine.Spec.MachineType,
97+
OS: machineScope.PacketMachine.Spec.OS,
98+
Tags: tags,
99+
UserData: userData,
99100
}
100101

101102
dev, _, err := p.Client.Devices.Create(serverCreateOpts)

0 commit comments

Comments
 (0)