Skip to content

Commit f112f33

Browse files
authored
k3s: preload images for all platforms. Fixes #219 (#298)
* ssh: fix possible edge case * cli: add mountType to status * k3s: preload images for all platforms. Fixes #219
1 parent 6538eaf commit f112f33

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

app/app.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -216,24 +216,25 @@ func (c colimaApp) SSH(layer bool, args ...string) error {
216216
return c.guest.RunInteractive(args...)
217217
}
218218

219-
cmdArgs, layer, err := lima.ShowSSH(config.CurrentProfile().ID, layer, "args")
219+
resp, err := lima.ShowSSH(config.CurrentProfile().ID, layer, "args")
220220
if err != nil {
221221
return fmt.Errorf("error getting ssh config: %w", err)
222222
}
223-
224-
if !layer {
223+
if !resp.Layer {
225224
return c.guest.RunInteractive(args...)
226225
}
227226

227+
cmdArgs := resp.Output
228+
228229
wd, err := os.Getwd()
229230
if err != nil {
230231
log.Debug(fmt.Errorf("cannot get working dir: %w", err))
231232
}
232233

233234
if len(args) > 0 {
234-
args = append([]string{"-q", "-t", "127.0.0.1", "--"}, args...)
235+
args = append([]string{"-q", "-t", resp.IPAddress, "--"}, args...)
235236
} else if wd != "" {
236-
args = []string{"-q", "-t", "127.0.0.1", "--", "cd " + wd + " 2> /dev/null; bash --login"}
237+
args = []string{"-q", "-t", resp.IPAddress, "--", "cd " + wd + " 2> /dev/null; bash --login"}
237238
}
238239

239240
args = append(strings.Fields(cmdArgs), args...)
@@ -255,6 +256,9 @@ func (c colimaApp) Status() error {
255256
log.Println(config.CurrentProfile().DisplayName, "is running")
256257
log.Println("arch:", c.guest.Arch())
257258
log.Println("runtime:", currentRuntime)
259+
if conf, err := lima.InstanceConfig(); err == nil {
260+
log.Println("mountType:", conf.MountType)
261+
}
258262
if currentRuntime == docker.Name {
259263
log.Println("socket:", "unix://"+docker.HostSocketFile())
260264
}

cmd/ssh-config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ var sshConfigCmd = &cobra.Command{
1616
Long: `Show configuration of the SSH connection to the VM.`,
1717
Args: cobra.MaximumNArgs(1),
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
out, _, err := lima.ShowSSH(config.CurrentProfile().ID, sshConfigCmdArgs.layer, sshConfigCmdArgs.format)
19+
resp, err := lima.ShowSSH(config.CurrentProfile().ID, sshConfigCmdArgs.layer, sshConfigCmdArgs.format)
2020
if err == nil {
21-
fmt.Println(out)
21+
fmt.Println(resp.Output)
2222
}
2323
return err
2424
},

environment/container/docker/context.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package docker
22

33
import (
4-
"fmt"
54
"path/filepath"
65

76
"github.com/abiosoft/colima/config"
@@ -14,8 +13,7 @@ func LegacyDefaultHostSocketFile() string {
1413
}
1514

1615
func (d dockerRuntime) isContextCreated() bool {
17-
command := fmt.Sprintf(`docker context ls -q | grep "^%s$"`, config.CurrentProfile().ID)
18-
return d.host.RunQuiet("sh", "-c", command) == nil
16+
return d.host.RunQuiet("docker", "context", "inspect", config.CurrentProfile().ID) == nil
1917
}
2018

2119
func (d dockerRuntime) setupContext() error {

environment/container/kubernetes/k3s.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func installK3sCache(
8181
case containerd.Name:
8282
a.Stage("loading oci images")
8383
a.Add(func() error {
84-
if err := guest.Run("sudo", "ctr", "-n", "k8s.io", "images", "import", downloadPathTar); err != nil {
84+
if err := guest.Run("sudo", "ctr", "-n", "k8s.io", "images", "import", "--all-platforms", downloadPathTar); err != nil {
8585
log.Warnln(fmt.Errorf("error loading oci images: %w", err))
8686
log.Warnln("startup may delay a bit as images will be pulled from oci registry")
8787
}

environment/vm/lima/cmds.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ func getRuntime(conf config.Config) string {
190190
}
191191

192192
// IPAddress returns the ip address for profile.
193-
// It returns the PTP address if networking is enabled or falls back to 127.0.0.1
193+
// It returns the PTP address if networking is enabled or falls back to 127.0.0.1.
194+
// It is guaranteed to return a value.
194195
// TODO: unnecessary round-trip is done to get instance details from Lima.
195196
func IPAddress(profileID string) string {
196197
// profile = toUserFriendlyName(profile)
@@ -210,14 +211,18 @@ func IPAddress(profileID string) string {
210211

211212
// ShowSSH runs the show-ssh command in Lima.
212213
// returns the ssh output, if in layer, and an error if any
213-
func ShowSSH(profileID string, layer bool, format string) (string, bool, error) {
214+
func ShowSSH(profileID string, layer bool, format string) (resp struct {
215+
Output string
216+
IPAddress string
217+
Layer bool
218+
}, err error) {
214219
var buf bytes.Buffer
215220
cmd := cli.Command("limactl", "show-ssh", "--format", format, profileID)
216221
cmd.Stdout = &buf
217222
cmd.Stderr = os.Stderr
218223

219224
if err := cmd.Run(); err != nil {
220-
return "", false, fmt.Errorf("error retrieving ssh config: %w", err)
225+
return resp, fmt.Errorf("error retrieving ssh config: %w", err)
221226
}
222227

223228
ip := IPAddress(profileID)
@@ -239,10 +244,13 @@ func ShowSSH(profileID string, layer bool, format string) (string, bool, error)
239244
case "cmd", "args":
240245
out = replaceSSHCmd(out, profileID, ip, port)
241246
default:
242-
return "", false, fmt.Errorf("unsupported format '%v'", format)
247+
return resp, fmt.Errorf("unsupported format '%v'", format)
243248
}
244249

245-
return out, port > 0, nil
250+
resp.Output = out
251+
resp.IPAddress = ip
252+
resp.Layer = port > 0
253+
return resp, nil
246254
}
247255

248256
func replaceSSHCmd(cmd string, name string, ip string, port int) string {

0 commit comments

Comments
 (0)