Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Make IP addresses of PacketMachine(Template) configurable #484

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions api/v1beta1/packetmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"github.com/packethost/packngo"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -51,6 +52,29 @@ const (
WaitingForBootstrapDataReason = "WaitingForBootstrapData"
)

// +kubebuilder:object:generate=false
type IPAddressCreateRequest struct {
packngo.IPAddressCreateRequest `json:"ipAddressCreateRequest"`
}

func (in *IPAddressCreateRequest) DeepCopyInto(out *IPAddressCreateRequest) {
*out = *in
if in.Reservations != nil {
in, out := &in.IPAddressCreateRequest.Reservations, &out.IPAddressCreateRequest.Reservations
*out = make([]string, len(*in))
copy(*out, *in)
}
}

func (in *IPAddressCreateRequest) DeepCopy() *IPAddressCreateRequest {
if in == nil {
return nil
}
out := new(IPAddressCreateRequest)
in.DeepCopyInto(out)
return out
}

// PacketMachineSpec defines the desired state of PacketMachine
type PacketMachineSpec struct {
OS string `json:"os"`
Expand Down Expand Up @@ -80,6 +104,11 @@ type PacketMachineSpec struct {
// Tags is an optional set of tags to add to Packet resources managed by the Packet provider.
// +optional
Tags Tags `json:"tags,omitempty"`

// Optional IP Address list to use when default (1 private IPv4, 1 public IPv4 and 1 public IPv6)
// is not desired
// +optional
IPAddresses []IPAddressCreateRequest `json:"ipAddresses,omitempty"`
}

// PacketMachineStatus defines the observed state of PacketMachine
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,37 @@ spec:
ID, a comma separated list of hardware reservation IDs, or `next-available`
to automatically let the Packet api determine one.
type: string
ipAddresses:
description: Optional IP Address list to use when default (1 private
IPv4, 1 public IPv4 and 1 public IPv6) is not desired
items:
properties:
ipAddressCreateRequest:
properties:
address_family:
description: Address Family for IP Address
type: integer
cidr:
description: CIDR Size for the IP Block created. Valid values
depends on the operating system provisioned.
type: integer
ip_reservations:
description: Reservations are UUIDs of any IP reservations
to use when assigning IPs
items:
type: string
type: array
public:
description: Address Type for IP Address
type: boolean
required:
- address_family
- public
type: object
required:
- ipAddressCreateRequest
type: object
type: array
ipxeURL:
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,38 @@ spec:
IDs, or `next-available` to automatically let the Packet
api determine one.
type: string
ipAddresses:
description: Optional IP Address list to use when default
(1 private IPv4, 1 public IPv4 and 1 public IPv6) is not
desired
items:
properties:
ipAddressCreateRequest:
properties:
address_family:
description: Address Family for IP Address
type: integer
cidr:
description: CIDR Size for the IP Block created.
Valid values depends on the operating system provisioned.
type: integer
ip_reservations:
description: Reservations are UUIDs of any IP reservations
to use when assigning IPs
items:
type: string
type: array
public:
description: Address Type for IP Address
type: boolean
required:
- address_family
- public
type: object
required:
- ipAddressCreateRequest
type: object
type: array
ipxeURL:
description: IPXEUrl can be used to set the pxe boot url when
using custom OSes with this provider. Note that OS should
Expand Down
6 changes: 6 additions & 0 deletions pkg/cloud/packet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func (p *Client) NewDevice(ctx context.Context, req CreateDeviceRequest) (*packn
facility = req.MachineScope.PacketMachine.Spec.Facility
}

ipAddressCreateRequests := []packngo.IPAddressCreateRequest{}
for _, machine := range req.MachineScope.PacketMachine.Spec.IPAddresses {
ipAddressCreateRequests = append(ipAddressCreateRequests, machine.IPAddressCreateRequest)
}

serverCreateOpts := &packngo.DeviceCreateRequest{
Hostname: req.MachineScope.Name(),
ProjectID: req.MachineScope.PacketCluster.Spec.ProjectID,
Expand All @@ -154,6 +159,7 @@ func (p *Client) NewDevice(ctx context.Context, req CreateDeviceRequest) (*packn
IPXEScriptURL: req.MachineScope.PacketMachine.Spec.IPXEUrl,
Tags: tags,
UserData: userData,
IPAddresses: ipAddressCreateRequests,
}

reservationIDs := strings.Split(req.MachineScope.PacketMachine.Spec.HardwareReservationID, ",")
Expand Down