Skip to content

Commit d483d1b

Browse files
authored
Merge pull request #41 from liquidmetal-dev/ssh_import_id
feat: add ssh_import_id support
2 parents 7c2b01a + b797764 commit d483d1b

File tree

13 files changed

+177
-273
lines changed

13 files changed

+177
-273
lines changed

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ toolchain go1.23.4
66

77
require (
88
github.com/liquidmetal-dev/flintlock/api v0.0.0-20250217152353-bad227d30da4
9-
github.com/liquidmetal-dev/flintlock/client v0.0.0-20250217152353-bad227d30da4
9+
github.com/liquidmetal-dev/flintlock/client v0.0.0-20251026183057-22744608d206
1010
github.com/moby/moby v27.4.1+incompatible
11-
github.com/urfave/cli/v2 v2.27.5
11+
github.com/spf13/cobra v1.10.1
1212
github.com/yitsushi/macpot v1.0.3
1313
go.uber.org/zap v1.27.0
1414
google.golang.org/grpc v1.69.2
1515
gopkg.in/yaml.v2 v2.4.0
1616
)
1717

1818
require (
19-
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
2019
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
20+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2121
github.com/rogpeppe/go-internal v1.13.1 // indirect
22-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
23-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
22+
github.com/spf13/pflag v1.0.10 // indirect
2423
go.uber.org/multierr v1.10.0 // indirect
2524
golang.org/x/net v0.30.0 // indirect
2625
golang.org/x/sys v0.26.0 // indirect

go.sum

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
2-
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
32
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
43
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
54
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
@@ -14,6 +13,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1413
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1514
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
1615
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
16+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
17+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1718
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1819
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1920
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -22,20 +23,22 @@ github.com/liquidmetal-dev/flintlock/api v0.0.0-20250217152353-bad227d30da4 h1:O
2223
github.com/liquidmetal-dev/flintlock/api v0.0.0-20250217152353-bad227d30da4/go.mod h1:aocJfIjHYMXrTvuISK75KQz3SEm1Xd+4BGIZike1jhI=
2324
github.com/liquidmetal-dev/flintlock/client v0.0.0-20250217152353-bad227d30da4 h1:DRhe5/c9koEB76yiAykdMhm2GLzWSSj9BUJHhhRJJR8=
2425
github.com/liquidmetal-dev/flintlock/client v0.0.0-20250217152353-bad227d30da4/go.mod h1:NChE0jzlpZA1395punDaV+5hJbVeVhoCcPHriNC0SUQ=
26+
github.com/liquidmetal-dev/flintlock/client v0.0.0-20251026183057-22744608d206 h1:NftnNmCtCQygUrkdEJyCwzxcuv+ZG9MNcQqwUs4ljEs=
27+
github.com/liquidmetal-dev/flintlock/client v0.0.0-20251026183057-22744608d206/go.mod h1:NChE0jzlpZA1395punDaV+5hJbVeVhoCcPHriNC0SUQ=
2528
github.com/moby/moby v27.4.1+incompatible h1:z6detzbcLRt7U+w4ovHV+8oYpJfpHKTmUbFWPG6cudA=
2629
github.com/moby/moby v27.4.1+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc=
2730
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2831
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2932
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
3033
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
31-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
3234
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
35+
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
36+
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
37+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
38+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
39+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
3340
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
3441
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
35-
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
36-
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
37-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
38-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
3942
github.com/yitsushi/macpot v1.0.3 h1:pINAfemjAvndfvzVG2yjgxl+jiW9VtbEBrRdImQthco=
4043
github.com/yitsushi/macpot v1.0.3/go.mod h1:qYmz54t8Ci34VKW5SlkHqWo6RVq/OQ31aFY2E7YLOko=
4144
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=

internal/cmd/app.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

internal/cmd/microvm/create.go

Lines changed: 34 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
"github.com/urfave/cli/v2"
7+
"github.com/spf13/cobra"
88
"go.uber.org/zap"
99

1010
"github.com/liquidmetal-dev/fl/pkg/app"
@@ -14,21 +14,18 @@ const (
1414
defaultNamespace = "default"
1515
defaultVCPU = 2
1616
defaultMemoryMb = 2048
17-
defaultKernelImage = "ghcr.io/liquidmetal-dev/firecracker-kernel-k8s:6.1"
17+
defaultKernelImage = "ghcr.io/liquidmetal-dev/firecracker-kernel:6.1"
1818
defaultKernelFile = "vmlinux"
19-
defaultRootImage = "ghcr.io/liquidmetal-dev/ubuntu:22.04"
19+
defaultRootImage = "ghcr.io/liquidmetal-dev/ubuntu:24.04"
2020
)
2121

22-
func newCreateCommand() *cli.Command {
22+
func newCreateCommand() *cobra.Command {
2323
createInput := &app.CreateInput{}
24-
networkInterfaces := &cli.StringSlice{}
25-
metadataFromFile := &cli.StringSlice{}
26-
containerVolumes := &cli.StringSlice{}
2724

28-
cmd := &cli.Command{
29-
Name: "create",
30-
Usage: "create a new microvm",
31-
Before: func(ctx *cli.Context) error {
25+
cmd := &cobra.Command{
26+
Use: "create",
27+
Short: "create a new microvm",
28+
PreRunE: func(cmd *cobra.Command, args []string) error {
3229
if createInput.Name != "" && createInput.NameAutogenerate {
3330
return errors.New("only one of --name or --name-autoegenarate can be specified")
3431
}
@@ -39,133 +36,41 @@ func newCreateCommand() *cli.Command {
3936

4037
return nil
4138
},
42-
Action: func(ctx *cli.Context) error {
39+
RunE: func(cmd *cobra.Command, args []string) error {
4340
a := app.New(zap.S().With("action", "create"))
4441

45-
createInput.NetworkInterfaces = networkInterfaces.Value()
46-
createInput.MetadataFromFile = metadataFromFile.Value()
47-
createInput.AdditionalContainerVolumes = containerVolumes.Value()
48-
49-
if err := a.Create(ctx.Context, createInput); err != nil {
42+
if err := a.Create(cmd.Context(), createInput); err != nil {
5043
return fmt.Errorf("creating microvm: %s", err)
5144
}
5245

5346
return nil
5447
},
55-
Flags: []cli.Flag{
56-
&cli.StringFlag{
57-
Name: "host",
58-
Usage: "the flintlock host to create the microvm on",
59-
Destination: &createInput.Host,
60-
Required: true,
61-
},
62-
&cli.StringFlag{
63-
Name: "name",
64-
Usage: "the name of the microvm, cannot be specified if using name-autogenerate",
65-
Destination: &createInput.Name,
66-
},
67-
&cli.BoolFlag{
68-
Name: "name-autogenerate",
69-
Usage: "if true a name is autogenerated for the microvm",
70-
Value: false,
71-
Destination: &createInput.NameAutogenerate,
72-
},
73-
&cli.StringFlag{
74-
Name: "namespace",
75-
Usage: "the namespace for the microvm",
76-
Destination: &createInput.Namespace,
77-
Value: defaultNamespace,
78-
},
79-
&cli.IntFlag{
80-
Name: "vcpu",
81-
Usage: "the number of vcpus",
82-
Value: defaultVCPU,
83-
Destination: &createInput.VCPU,
84-
},
85-
&cli.IntFlag{
86-
Name: "memory",
87-
Usage: "the memory in mb",
88-
Value: defaultMemoryMb,
89-
Destination: &createInput.MemoryInMb,
90-
},
91-
&cli.StringFlag{
92-
Name: "kernel-image",
93-
Usage: "the image to use for the kernel",
94-
Destination: &createInput.KernelImage,
95-
Value: defaultKernelImage,
96-
},
97-
&cli.BoolFlag{
98-
Name: "add-netconf",
99-
Usage: "automatically add network configuration to the kernel cmd line",
100-
Destination: &createInput.KernelAddNetConf,
101-
Value: true,
102-
},
103-
&cli.StringFlag{
104-
Name: "kernel-filename",
105-
Usage: "name of the kernel file in the image",
106-
Destination: &createInput.KernelFileName,
107-
Value: defaultKernelFile,
108-
},
109-
&cli.StringFlag{
110-
Name: "root-image",
111-
Usage: "the image to use for the root volume",
112-
Destination: &createInput.RootImage,
113-
Value: defaultRootImage,
114-
},
115-
&cli.StringFlag{
116-
Name: "initrd-image",
117-
Usage: "the image to use for the initial ramdisk",
118-
Destination: &createInput.InitrdImage,
119-
},
120-
&cli.StringFlag{
121-
Name: "initrd-filename",
122-
Usage: "name of the file in the image to use for the initial ramdisk",
123-
Destination: &createInput.InitrdFilename,
124-
},
125-
&cli.StringSliceFlag{
126-
Name: "network-interface",
127-
Usage: "specify the network interfaces to attach. In the following format: name:type:[macaddress]:[ipaddress]",
128-
Destination: networkInterfaces,
129-
},
130-
&cli.StringSliceFlag{
131-
Name: "metadata-from-file",
132-
Usage: "specify metadata to be available to your microvm. In the following format key=pathtofile",
133-
Destination: metadataFromFile,
134-
},
135-
&cli.StringFlag{
136-
Name: "metadata-hostname",
137-
Usage: "the hostname of the the microvm",
138-
Destination: &createInput.Metadata.Hostname,
139-
},
140-
&cli.StringFlag{
141-
Name: "metadata-ssh-key-file",
142-
Usage: "an ssh key to use",
143-
Destination: &createInput.Metadata.SSHKeyFile,
144-
},
145-
&cli.BoolFlag{
146-
Name: "metadata-resolvd-fix",
147-
Usage: "include a systemd-resolvd fix for container root volumes",
148-
Destination: &createInput.Metadata.ResolvdFix,
149-
Value: true,
150-
},
151-
&cli.StringFlag{
152-
Name: "metadata-final-message",
153-
Usage: "set the cloud-init final message",
154-
Destination: &createInput.Metadata.Message,
155-
},
156-
&cli.StringSliceFlag{
157-
Name: "container-volume",
158-
Usage: "attach additional volumes using a container image, The following format: name=containerimage=mountpoint",
159-
Destination: containerVolumes,
160-
},
161-
&cli.StringFlag{
162-
Name: "virtiofs-volume",
163-
Usage: "attach an additional volume using virtiofs, use the following format: name=localpath=mountpoint",
164-
Destination: &createInput.AdditionalVirtioFSVolume,
165-
},
166-
},
16748
}
16849

50+
cmd.MarkFlagRequired("host")
51+
52+
cmd.Flags().StringVar(&createInput.Host, "host", "", "the flintlock host to create the microvm on")
53+
cmd.Flags().StringVar(&createInput.Name, "name", "", "the name of the microvm, cannot be specified if using name-autogenerate")
54+
cmd.Flags().BoolVar(&createInput.NameAutogenerate, "name-autogenerate", false, "if true a name is autogenerated for the microvm")
55+
cmd.Flags().StringVar(&createInput.Namespace, "namespace", defaultNamespace, "the namespace for the microvm")
56+
cmd.Flags().IntVar(&createInput.VCPU, "vcpu", defaultVCPU, "the number of vcpus")
57+
cmd.Flags().IntVar(&createInput.MemoryInMb, "memory", defaultMemoryMb, "the memory in mb")
58+
cmd.Flags().StringVar(&createInput.KernelImage, "kernel-image", defaultKernelImage, "the image to use for the kernel")
59+
cmd.Flags().BoolVar(&createInput.KernelAddNetConf, "add-netconf", true, "automatically add network configuration to the kernel cmd line")
60+
cmd.Flags().StringVar(&createInput.KernelFileName, "kernel-filename", defaultKernelFile, "name of the kernel file in the image")
61+
cmd.Flags().StringVar(&createInput.RootImage, "root-image", defaultRootImage, "the image to use for the root volume")
62+
cmd.Flags().StringVar(&createInput.InitrdImage, "initrd-image", "", "the image to use for the initial ramdisk")
63+
cmd.Flags().StringVar(&createInput.InitrdFilename, "initrd-filename", "", "name of the file in the image to use for the initial ramdisk")
64+
cmd.Flags().StringSliceVar(&createInput.NetworkInterfaces, "network-interface", []string{}, "specify the network interfaces to attach. In the following format: name:type:[macaddress]:[ipaddress]")
65+
cmd.Flags().StringSliceVar(&createInput.MetadataFromFile, "metadata-from-file", []string{}, "specify metadata to be available to your microvm. In the following format key=pathtofile")
66+
cmd.Flags().StringVar(&createInput.Metadata.Hostname, "metadata-hostname", "", "the hostname of the the microvm")
67+
cmd.Flags().StringVar(&createInput.Metadata.SSHKeyFile, "metadata-ssh-key-file", "", "an ssh key to use")
68+
cmd.Flags().StringSliceVar(&createInput.Metadata.SshImportIds, "metadata-ssh-import-id", []string{}, "ssh keys to import. The keyserver can be specified by prepending either lp: for Launchpad or gh: for GitHub to the username.")
69+
cmd.Flags().BoolVar(&createInput.Metadata.ResolvdFix, "metadata-resolvd-fix", true, "include a systemd-resolvd fix for container root volumes")
70+
cmd.Flags().StringVar(&createInput.Metadata.Message, "metadata-final-message", "", "set the cloud-init final message")
71+
cmd.Flags().StringSliceVar(&createInput.AdditionalContainerVolumes, "container-volume", []string{}, "attach additional volumes using a container image, The following format: name=containerimage=mountpoint")
72+
cmd.Flags().StringVar(&createInput.AdditionalVirtioFSVolume, "virtiofs-volume", "", "attach an additional volume using virtiofs, use the following format: name=localpath=mountpoint")
73+
16974
// TODO: additional command line args for kernel
17075
// TODO: add additional volumes
17176

internal/cmd/microvm/delete.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
"github.com/urfave/cli/v2"
7+
"github.com/spf13/cobra"
88
"go.uber.org/zap"
99

1010
"github.com/liquidmetal-dev/fl/pkg/app"
@@ -17,35 +17,32 @@ fl microvm delete --host host1:9090 01FZZJV1XD2FKH2KY0NDB4MBRQ
1717
`
1818
)
1919

20-
func newDeleteCommand() *cli.Command {
20+
func newDeleteCommand() *cobra.Command {
2121
deleteInput := &app.DeleteInput{}
2222

23-
cmd := &cli.Command{
24-
Name: "delete",
25-
Usage: "delete a microvm from a host",
26-
Action: func(ctx *cli.Context) error {
27-
if ctx.Args().Len() == 0 {
23+
cmd := &cobra.Command{
24+
Use: "delete [vmid]",
25+
Short: "delete a microvm from a host",
26+
Args: cobra.ExactArgs(1),
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
if len(args) == 0 {
2829
return errors.New("you must supply the uid as an argument")
2930
}
30-
deleteInput.UID = ctx.Args().Get(0)
31+
deleteInput.UID = args[0]
3132

3233
a := app.New(zap.S().With("action", "delete"))
33-
err := a.Delete(ctx.Context, deleteInput)
34+
err := a.Delete(cmd.Context(), deleteInput)
3435
if err != nil {
3536
return fmt.Errorf("deleting microvm: %w", err)
3637
}
3738

3839
return nil
3940
},
40-
Flags: []cli.Flag{
41-
&cli.StringFlag{
42-
Name: "host",
43-
Usage: "the flintlock host to delete the microvm on",
44-
Destination: &deleteInput.Host,
45-
Required: true,
46-
},
47-
},
4841
}
4942

43+
cmd.Flags().StringVar(&deleteInput.Host, "host", "", "the flintlock host to delete the microvm on")
44+
45+
cmd.MarkFlagRequired("host")
46+
5047
return cmd
5148
}

0 commit comments

Comments
 (0)