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

Ssh key #788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions pkg/cloud/packet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@

serverCreateOpts := metal.CreateDeviceRequest{}

var sshKeyInput []metal.SSHKeyInput
if len(packetMachineSpec.SSHKeys) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave out the if conditional. The for loop will only append sshKeyInput if SSHKeys exist (and are >0).
Likewise, if the SSHKeys are nil or 0, sshKeyInput will be nil when sent to the Request object.

for _, key := range packetMachineSpec.SSHKeys {
sshKeyInput = append(sshKeyInput, metal.SSHKeyInput{
Label: metal.PtrString(fmt.Sprintf("cluster-api-provider-packet-%s", req.MachineScope.Name())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All SSHKeys will have the same label per machine. Should we use a tag for the repeated values and a unique value per label? I'm pretty sure labels are optional. If we can't find a meaningful unique label, we could omit them. The tag would tell us what we need to know about the SSHKey. If Label is required, perhaps it could suffix the label you've provided with some tail bytes of the SSH Key? (not the comment section of the key).

Key: metal.PtrString(key),
})
}
}

/*

Check failure on line 193 in pkg/cloud/packet/client.go

View workflow job for this annotation

GitHub Actions / Validate lint

commentedOutCode: may want to remove commented-out code (gocritic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the unused code

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,
Expand All @@ -188,6 +208,7 @@
Plan: req.MachineScope.PacketMachine.Spec.MachineType,
OperatingSystem: req.MachineScope.PacketMachine.Spec.OS,
IpxeScriptUrl: &req.MachineScope.PacketMachine.Spec.IPXEUrl,
SshKeys: sshKeyInput,
Tags: tags,
Userdata: &userData,
}
Expand All @@ -199,6 +220,7 @@
Plan: req.MachineScope.PacketMachine.Spec.MachineType,
OperatingSystem: req.MachineScope.PacketMachine.Spec.OS,
IpxeScriptUrl: &req.MachineScope.PacketMachine.Spec.IPXEUrl,
SshKeys: sshKeyInput,
Tags: tags,
Userdata: &userData,
}
Expand Down
Loading