Skip to content

Commit 40e5350

Browse files
feat: add mkosi based AL2023 images (#1716)
* Changes - disable sshOverVsock for VZ driver - update finch-core to latest main consume al2023 images & lima 2.1.0-beta - add a test for rosetta emulation Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> * fix rosetta config Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> * update golangci-lint to v2.11.3 Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> * fix lint issues Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> * bump finch-core submodule again to consume new lima builds with symlink patch applied Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> * skip rosetta emulation on macos < 26 Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> * add warning for rosetta on macos < 26 Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com> --------- Signed-off-by: Swapnanil-Gupta <swpnlg@amazon.com>
1 parent 69a7b90 commit 40e5350

27 files changed

+373
-191
lines changed

.github/workflows/ci-docs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
# Pin the version in case all the builds start to fail at the same time.
114114
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
115115
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
116-
version: v2.7.0
116+
version: v2.11.3
117117
args: --fix=false --timeout=5m
118118
- name: set GOOS env to darwin
119119
run: |
@@ -124,7 +124,7 @@ jobs:
124124
# Pin the version in case all the builds start to fail at the same time.
125125
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
126126
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
127-
version: v2.7.0
127+
version: v2.11.3
128128
args: --fix=false --timeout=5m --skip-dirs="(^|/)deps($|/)"
129129
go-mod-tidy-check:
130130
runs-on: ubuntu-latest

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138
# Pin the version in case all the builds start to fail at the same time.
139139
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
140140
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
141-
version: v2.7.0
141+
version: v2.11.3
142142
args: --fix=false --timeout=5m
143143
- name: set GOOS env to darwin
144144
run: |
@@ -149,7 +149,7 @@ jobs:
149149
# Pin the version in case all the builds start to fail at the same time.
150150
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
151151
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
152-
version: v2.7.0
152+
version: v2.11.3
153153
args: --fix=false --timeout=5m --skip-dirs="(^|/)deps($|/)"
154154
shellcheck:
155155
name: ShellCheck

cmd/credserver/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"net/http"
1616
"os"
1717
"os/signal"
18+
"path/filepath"
1819
"strings"
1920
"syscall"
2021
"time"
@@ -31,9 +32,9 @@ func main() {
3132
if len(os.Args) < 4 {
3233
logrus.Fatal("Usage: credserver <socket-path> <pid-file> <log-file>")
3334
}
34-
socketPath := os.Args[1]
35-
pidFile := os.Args[2]
36-
logPath := os.Args[3]
35+
socketPath := filepath.Clean(os.Args[1])
36+
pidFile := filepath.Clean(os.Args[2])
37+
logPath := filepath.Clean(os.Args[3])
3738

3839
// Setup file logging with rotation
3940
// #nosec G302 -- Log file needs to be readable for debugging
@@ -162,7 +163,7 @@ func handleCredentials(w http.ResponseWriter, r *http.Request) {
162163

163164
// Encode credentials to JSON
164165
var buf bytes.Buffer
165-
if err := json.NewEncoder(&buf).Encode(creds); err != nil {
166+
if err := json.NewEncoder(&buf).Encode(creds); err != nil { //nolint:gosec // G117: intentional
166167
logrus.Errorf("Failed to encode credentials to JSON: %v", err)
167168
http.Error(w, "Failed to encode credentials", http.StatusInternalServerError)
168169
return

cmd/credserver/main_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77

88
import (
99
"encoding/json"
10+
"fmt"
1011
"net/http"
1112
"net/http/httptest"
1213
"testing"
@@ -106,7 +107,7 @@ func TestHandleCredentials(t *testing.T) {
106107
t.Parallel()
107108
req := httptest.NewRequest(http.MethodGet, "/credentials?server=registry.example.com", nil)
108109
for i := 0; i < 100; i++ {
109-
req.Header.Set("X-Finch-Env-"+string(rune('A'+i)), "value")
110+
req.Header.Set(fmt.Sprintf("X-Finch-Env-%c", 'A'+i), "value")
110111
}
111112
w := httptest.NewRecorder()
112113

@@ -163,7 +164,7 @@ func TestHandleCredentials(t *testing.T) {
163164
for i := 0; i < numRequests; i++ {
164165
go func(id int) {
165166
req := httptest.NewRequest(http.MethodGet, "/credentials?server=registry.example.com", nil)
166-
req.Header.Set("X-Finch-Env-ID", string(rune('0'+id)))
167+
req.Header.Set("X-Finch-Env-ID", fmt.Sprintf("%d", id))
167168
w := httptest.NewRecorder()
168169

169170
handleCredentials(w, req)

cmd/finch/virtual_machine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,6 @@ func virtualMachineCommands(
127127
fp,
128128
fs,
129129
disk.NewUserDataDiskManager(ncc, ecc, &afero.OsFs{}, fp, finchRootPath, fc, logger),
130+
fc,
130131
)
131132
}

cmd/finch/virtual_machine_darwin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func newVirtualMachineCommand(
4242
fp path.Finch,
4343
fs afero.Fs,
4444
diskManager disk.UserDataDiskManager,
45+
finchConfig *config.Finch,
4546
) *cobra.Command {
4647
virtualMachineCommand := &cobra.Command{
4748
Use: virtualMachineRootCmd,
@@ -54,7 +55,7 @@ func newVirtualMachineCommand(
5455
newRemoveVMCommand(limaCmdCreator, diskManager, logger),
5556
newStatusVMCommand(limaCmdCreator, logger, os.Stdout),
5657
newInitVMCommand(limaCmdCreator, logger, optionalDepGroups, lca, nca, fp.BaseYamlFilePath(), fs,
57-
fp.LimaSSHPrivateKeyPath(), diskManager),
58+
fp.LimaSSHPrivateKeyPath(), diskManager, finchConfig),
5859
newSettingsVMCommand(logger, lca, fs, os.Stdout),
5960
newDiskVMCommand(limaCmdCreator, logger),
6061
)

cmd/finch/virtual_machine_init.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ func newInitVMCommand(
3131
fs afero.Fs,
3232
privateKeyPath string,
3333
diskManager disk.UserDataDiskManager,
34+
finchConfig *config.Finch,
3435
) *cobra.Command {
3536
initVMCommand := &cobra.Command{
3637
Use: "init",
3738
Short: "Initialize the virtual machine",
38-
RunE: newInitVMAction(ncc, logger, optionalDepGroups, lca, baseYamlFilePath, diskManager).runAdapter,
39+
RunE: newInitVMAction(ncc, logger, optionalDepGroups, lca, baseYamlFilePath, diskManager, finchConfig).runAdapter,
3940
PostRunE: newPostVMStartInitAction(logger, ncc, fs, privateKeyPath, nca).runAdapter,
4041
}
4142

@@ -49,6 +50,7 @@ type initVMAction struct {
4950
optionalDepGroups []*dependency.Group
5051
limaConfigApplier config.LimaConfigApplier
5152
diskManager disk.UserDataDiskManager
53+
finchConfig *config.Finch
5254
}
5355

5456
func newInitVMAction(
@@ -58,6 +60,7 @@ func newInitVMAction(
5860
lca config.LimaConfigApplier,
5961
baseYamlFilePath string,
6062
diskManager disk.UserDataDiskManager,
63+
finchConfig *config.Finch,
6164
) *initVMAction {
6265
return &initVMAction{
6366
creator: creator,
@@ -66,6 +69,7 @@ func newInitVMAction(
6669
limaConfigApplier: lca,
6770
baseYamlFilePath: baseYamlFilePath,
6871
diskManager: diskManager,
72+
finchConfig: finchConfig,
6973
}
7074
}
7175

@@ -79,7 +83,7 @@ func (iva *initVMAction) run() error {
7983
return err
8084
}
8185

82-
err = iva.limaConfigApplier.ConfigureDefaultLimaYaml()
86+
err = iva.limaConfigApplier.ConfigureDefaultLimaYaml(iva.logger)
8387
if err != nil {
8488
return err
8589
}
@@ -103,7 +107,15 @@ func (iva *initVMAction) run() error {
103107
}
104108

105109
instanceName := fmt.Sprintf("--name=%v", limaInstanceName)
106-
limaCmd := iva.creator.CreateWithoutStdio("start", instanceName, iva.baseYamlFilePath, "--tty=false")
110+
startOpts := []string{"start", instanceName, iva.baseYamlFilePath, "--tty=false"}
111+
if iva.finchConfig == nil || *iva.finchConfig.VMType == "vz" {
112+
// Starting with 2.0, Lima uses ssh over vsock by default on systemd >= 256 (https://github.com/lima-vm/lima/pull/3979)
113+
// which is causing a ssh "permission denied" issue with VZ driver.
114+
// So, disabling this feature for VZ driver for now.
115+
// This still works with QEMU driver.
116+
startOpts = append(startOpts, "--set", ".ssh.overVsock=false")
117+
}
118+
limaCmd := iva.creator.CreateWithoutStdio(startOpts...)
107119

108120
iva.logger.Info("Initializing and starting Finch virtual machine...")
109121
logs, err := limaCmd.CombinedOutput()

cmd/finch/virtual_machine_init_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const mockBaseYamlFilePath = "/os/os.yaml"
2525
func TestNewInitVMCommand(t *testing.T) {
2626
t.Parallel()
2727

28-
cmd := newInitVMCommand(nil, nil, nil, nil, nil, "", nil, "", nil)
28+
cmd := newInitVMCommand(nil, nil, nil, nil, nil, "", nil, "", nil, nil)
2929
assert.Equal(t, cmd.Name(), "init")
3030
}
3131

@@ -75,12 +75,12 @@ func TestInitVMAction_runAdapter(t *testing.T) {
7575
logger.EXPECT().Debugf("Status of virtual machine: %s", "")
7676

7777
command := mocks.NewCommand(ctrl)
78-
lca.EXPECT().ConfigureDefaultLimaYaml().Return(nil)
78+
lca.EXPECT().ConfigureDefaultLimaYaml(logger).Return(nil)
7979
lca.EXPECT().ConfigureOverrideLimaYaml().Return(nil)
8080
dm.EXPECT().DetachUserDataDisk().Return(nil)
8181
dm.EXPECT().EnsureUserDataDisk().Return(nil)
8282
ncc.EXPECT().CreateWithoutStdio("start", fmt.Sprintf("--name=%s", limaInstanceName),
83-
mockBaseYamlFilePath, "--tty=false").Return(command)
83+
mockBaseYamlFilePath, "--tty=false", "--set", ".ssh.overVsock=false").Return(command)
8484
command.EXPECT().CombinedOutput()
8585

8686
logger.EXPECT().Info("Initializing and starting Finch virtual machine...")
@@ -107,7 +107,7 @@ func TestInitVMAction_runAdapter(t *testing.T) {
107107
groups := tc.groups(ctrl)
108108
tc.mockSvc(ncc, logger, lca, dm, ctrl)
109109

110-
assert.NoError(t, newInitVMAction(ncc, logger, groups, lca, mockBaseYamlFilePath, dm).runAdapter(tc.command, tc.args))
110+
assert.NoError(t, newInitVMAction(ncc, logger, groups, lca, mockBaseYamlFilePath, dm, nil).runAdapter(tc.command, tc.args))
111111
})
112112
}
113113
}
@@ -145,14 +145,14 @@ func TestInitVMAction_run(t *testing.T) {
145145
getVMStatusC.EXPECT().Output().Return([]byte(""), nil)
146146
logger.EXPECT().Debugf("Status of virtual machine: %s", "")
147147

148-
lca.EXPECT().ConfigureDefaultLimaYaml().Return(nil)
148+
lca.EXPECT().ConfigureDefaultLimaYaml(logger).Return(nil)
149149
lca.EXPECT().ConfigureOverrideLimaYaml().Return(nil)
150150
dm.EXPECT().DetachUserDataDisk().Return(nil)
151151
dm.EXPECT().EnsureUserDataDisk().Return(nil)
152152

153153
command := mocks.NewCommand(ctrl)
154154
ncc.EXPECT().CreateWithoutStdio("start", fmt.Sprintf("--name=%s", limaInstanceName),
155-
mockBaseYamlFilePath, "--tty=false").Return(command)
155+
mockBaseYamlFilePath, "--tty=false", "--set", ".ssh.overVsock=false").Return(command)
156156
command.EXPECT().CombinedOutput()
157157

158158
logger.EXPECT().Info("Initializing and starting Finch virtual machine...")
@@ -269,7 +269,7 @@ func TestInitVMAction_run(t *testing.T) {
269269
getVMStatusC.EXPECT().Output().Return([]byte(""), nil)
270270
logger.EXPECT().Debugf("Status of virtual machine: %s", "")
271271

272-
lca.EXPECT().ConfigureDefaultLimaYaml().Return(nil)
272+
lca.EXPECT().ConfigureDefaultLimaYaml(logger).Return(nil)
273273
lca.EXPECT().ConfigureOverrideLimaYaml().Return(nil)
274274

275275
logger.EXPECT().Errorf("Dependency error: %v",
@@ -282,7 +282,7 @@ func TestInitVMAction_run(t *testing.T) {
282282

283283
command := mocks.NewCommand(ctrl)
284284
ncc.EXPECT().CreateWithoutStdio("start", fmt.Sprintf("--name=%s", limaInstanceName),
285-
mockBaseYamlFilePath, "--tty=false").Return(command)
285+
mockBaseYamlFilePath, "--tty=false", "--set", ".ssh.overVsock=false").Return(command)
286286
command.EXPECT().CombinedOutput()
287287

288288
logger.EXPECT().Info("Initializing and starting Finch virtual machine...")
@@ -314,7 +314,7 @@ func TestInitVMAction_run(t *testing.T) {
314314
getVMStatusC.EXPECT().Output().Return([]byte(""), nil)
315315
logger.EXPECT().Debugf("Status of virtual machine: %s", "")
316316

317-
lca.EXPECT().ConfigureDefaultLimaYaml().Return(errors.New("load config fails"))
317+
lca.EXPECT().ConfigureDefaultLimaYaml(logger).Return(errors.New("load config fails"))
318318
},
319319
},
320320

@@ -336,7 +336,7 @@ func TestInitVMAction_run(t *testing.T) {
336336
getVMStatusC.EXPECT().Output().Return([]byte(""), nil)
337337
logger.EXPECT().Debugf("Status of virtual machine: %s", "")
338338

339-
lca.EXPECT().ConfigureDefaultLimaYaml().Return(nil)
339+
lca.EXPECT().ConfigureDefaultLimaYaml(logger).Return(nil)
340340
lca.EXPECT().ConfigureOverrideLimaYaml().Return(nil)
341341
dm.EXPECT().DetachUserDataDisk().Return(nil)
342342
dm.EXPECT().EnsureUserDataDisk().Return(nil)
@@ -345,7 +345,7 @@ func TestInitVMAction_run(t *testing.T) {
345345
command := mocks.NewCommand(ctrl)
346346
command.EXPECT().CombinedOutput().Return(logs, errors.New("failed to init instance"))
347347
ncc.EXPECT().CreateWithoutStdio("start", fmt.Sprintf("--name=%s", limaInstanceName),
348-
mockBaseYamlFilePath, "--tty=false").Return(command)
348+
mockBaseYamlFilePath, "--tty=false", "--set", ".ssh.overVsock=false").Return(command)
349349

350350
logger.EXPECT().Info("Initializing and starting Finch virtual machine...")
351351
logger.EXPECT().SetFormatter(flog.TextWithoutTruncation)
@@ -369,7 +369,7 @@ func TestInitVMAction_run(t *testing.T) {
369369
groups := tc.groups(ctrl)
370370
tc.mockSvc(ncc, logger, lca, dm, ctrl)
371371

372-
err := newInitVMAction(ncc, logger, groups, lca, mockBaseYamlFilePath, dm).run()
372+
err := newInitVMAction(ncc, logger, groups, lca, mockBaseYamlFilePath, dm, nil).run()
373373
assert.Equal(t, err, tc.wantErr)
374374
})
375375
}

cmd/finch/virtual_machine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
func TestVirtualMachineCommand(t *testing.T) {
2121
t.Parallel()
2222

23-
cmd := newVirtualMachineCommand(nil, nil, nil, nil, nil, "", nil, nil)
23+
cmd := newVirtualMachineCommand(nil, nil, nil, nil, nil, "", nil, nil, nil)
2424
assert.Equal(t, cmd.Use, virtualMachineRootCmd)
2525

2626
// check the number of subcommand for vm

cmd/finch/virtual_machine_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func newVirtualMachineCommand(
2828
fp path.Finch,
2929
fs afero.Fs,
3030
diskManager disk.UserDataDiskManager,
31+
finchConfig *config.Finch,
3132
) *cobra.Command {
3233
virtualMachineCommand := &cobra.Command{
3334
Use: virtualMachineRootCmd,
@@ -40,7 +41,7 @@ func newVirtualMachineCommand(
4041
newRemoveVMCommand(limaCmdCreator, diskManager, logger),
4142
newStatusVMCommand(limaCmdCreator, logger, os.Stdout),
4243
newInitVMCommand(limaCmdCreator, logger, optionalDepGroups, lca, nca, fp.BaseYamlFilePath(), fs,
43-
fp.LimaSSHPrivateKeyPath(), diskManager),
44+
fp.LimaSSHPrivateKeyPath(), diskManager, finchConfig),
4445
newSettingsVMCommand(logger, lca, fs, os.Stdout),
4546
)
4647

0 commit comments

Comments
 (0)