Skip to content

Commit

Permalink
Merge pull request #137 from packethost/add/hardwareReservationID
Browse files Browse the repository at this point in the history
Hardware reservation support for machine
  • Loading branch information
gianarb authored Jun 24, 2020
2 parents 9e8dafc + e567596 commit 8b269d2
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha3/packetmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ type PacketMachineSpec struct {
BillingCycle string `json:"billingCycle"`
MachineType string `json:"machineType"`
SshKeys []string `json:"sshKeys,omitempty"`

// HardwareReservationID is the unique device hardware reservation ID or `next-available` to
// automatically let the Packet api determine one.
// +optional
HardwareReservationID string `json:"hardwareReservationID,omitempty"`

// ProviderID is the unique identifier as specified by the cloud provider.
// +optional
ProviderID *string `json:"providerID,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ spec:
items:
type: string
type: array
hardwareReservationID:
description: HardwareReservationID is the unique device hardware reservation
ID or `next-available` to automatically let the Packet api determine
one.
type: string
machineType:
type: string
providerID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ spec:
items:
type: string
type: array
hardwareReservationID:
description: HardwareReservationID is the unique device hardware
reservation ID or `next-available` to automatically let the
Packet api determine one.
type: string
machineType:
type: string
providerID:
Expand Down
76 changes: 76 additions & 0 deletions docs/concepts/machine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
PacketMachine is the name of the resource that identifies a
[Device](packetDeviceAPI) on Packet.

This is an example of it:

```yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachine
metadata:
name: "qa-master-0"
spec:
OS: "ubuntu_18_04"
facility:
- "dfw2"
billingCycle: hourly
machineType: "t2.small"
sshKeys:
- "your-sshkey-name"
tags: []
```
It is a [Kubernetes Custom Resource Definition (CRD)](crd-docs) as everything
else in the cluster-api land.
The reported fields in the example are the most common one but you can see the
full list of supported parameters as part of the OpenAPI definition available
[here](config/resources/crd/bases/infrastructure.cluster.x-k8s.io_packetmachines.yaml)
searching for `kind: PacketMachine`.

## Reserved instances

Packet provides the possibility to [reserve
hardware](packet-docs-reserved-hardware) in order to have to power you need
always available.

> Reserved hardware gives you the ability to reserve specific servers for a
> committed period of time. Unlike hourly on-demand, once you reserve hardware,
> you will have access to that specific hardware for the duration of the
> reservation.

You can specify the reservation ID using the field `hardwareReservationID`:

```
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachine
metadata:
name: "qa-master-0"
spec:
OS: "ubuntu_18_04"
facility:
- "dfw2"
billingCycle: hourly
machineType: "t2.small"
sshKeys:
- "your-sshkey-name"
hardwareReservationID: "d3cb029a-c5e4-4e2b-bafc-56266639685f"
tags: []
```

### pros and cons

Hardware reservation is a great feature, this chapter is about the feature
described above and nothing more.
It covers a very simple use case, you have a set of machines that you created
statically in the YAML and you like to have them using a reservation ID.

It does not work in combination of PacketMachineTemplate and MachineDeployment
where the pool of PacketMachine is dynamically managed by the cluster-api
controllers. You can track progress on this scenario subscribing to the issue
["Add support for reservation IDs with MachineDeployment #136"](github-issue-resid-dynamic) on GitHub.

[packetDeviceAPI]: https://www.packet.com/developers/api/devices/#devices-createDevice
[crd-docs]: https://github.com/packethost/cluster-api-provider-packet/blob/master/config/resources/crd/bases/infrastructure.cluster.x-k8s.io_packetmachines.yaml
[openapi-types]: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/
[packet-docs-reserved-hardware]: https://www.packet.com/developers/docs/getting-started/deployment-options/reserved-hardware/
[github-issue-resid-dynamic]: https://github.com/packethost/cluster-api-provider-packet/issues/136
17 changes: 9 additions & 8 deletions pkg/cloud/packet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ func (p *PacketClient) NewDevice(hostname, project string, machineScope *scope.M
tags = append(tags, infrastructurev1alpha3.WorkerTag)
}
serverCreateOpts := &packngo.DeviceCreateRequest{
Hostname: hostname,
ProjectID: project,
Facility: machineScope.PacketMachine.Spec.Facility,
BillingCycle: machineScope.PacketMachine.Spec.BillingCycle,
Plan: machineScope.PacketMachine.Spec.MachineType,
OS: machineScope.PacketMachine.Spec.OS,
Tags: tags,
UserData: userData,
Hostname: hostname,
ProjectID: project,
Facility: machineScope.PacketMachine.Spec.Facility,
BillingCycle: machineScope.PacketMachine.Spec.BillingCycle,
HardwareReservationID: machineScope.PacketMachine.Spec.HardwareReservationID,
Plan: machineScope.PacketMachine.Spec.MachineType,
OS: machineScope.PacketMachine.Spec.OS,
Tags: tags,
UserData: userData,
}

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

0 comments on commit 8b269d2

Please sign in to comment.