From 61ea7f8015fbc741addefbdee4fce12d9a7ec6d2 Mon Sep 17 00:00:00 2001 From: Engin Diri Date: Thu, 12 Sep 2024 17:28:03 +0200 Subject: [PATCH] feat: add sshkeys handling --- pkg/cloud/packet/client.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/cloud/packet/client.go b/pkg/cloud/packet/client.go index 8e20bb3f..855df85a 100644 --- a/pkg/cloud/packet/client.go +++ b/pkg/cloud/packet/client.go @@ -180,6 +180,26 @@ func (p *Client) NewDevice(ctx context.Context, req CreateDeviceRequest) (*metal serverCreateOpts := metal.CreateDeviceRequest{} + var sshKeyInput []metal.SSHKeyInput + if len(packetMachineSpec.SSHKeys) > 0 { + for _, key := range packetMachineSpec.SSHKeys { + sshKeyInput = append(sshKeyInput, metal.SSHKeyInput{ + Label: metal.PtrString(fmt.Sprintf("cluster-api-provider-packet-%s", req.MachineScope.Name())), + Key: metal.PtrString(key), + }) + } + } + + /* + var sshKeyInput metal.SSHKeyInput + if len(packetMachineSpec.SSHKeys) > 0 { + sshKeyInput = metal.SSHKeyInput{ + Label: metal.PtrString("cluster-api-provider-packet"), + Key: metal.PtrString(packetMachineSpec.SSHKeys[0]), + } + } + */ + if facility != "" { serverCreateOpts.DeviceCreateInFacilityInput = &metal.DeviceCreateInFacilityInput{ Hostname: &hostname, @@ -188,6 +208,7 @@ func (p *Client) NewDevice(ctx context.Context, req CreateDeviceRequest) (*metal Plan: req.MachineScope.PacketMachine.Spec.MachineType, OperatingSystem: req.MachineScope.PacketMachine.Spec.OS, IpxeScriptUrl: &req.MachineScope.PacketMachine.Spec.IPXEUrl, + SshKeys: sshKeyInput, Tags: tags, Userdata: &userData, } @@ -199,6 +220,7 @@ func (p *Client) NewDevice(ctx context.Context, req CreateDeviceRequest) (*metal Plan: req.MachineScope.PacketMachine.Spec.MachineType, OperatingSystem: req.MachineScope.PacketMachine.Spec.OS, IpxeScriptUrl: &req.MachineScope.PacketMachine.Spec.IPXEUrl, + SshKeys: sshKeyInput, Tags: tags, Userdata: &userData, }