Skip to content

Commit a1a0bb5

Browse files
fix(unikontainers): warn on vAccel misconfiguration
Introduce ErrVAccelDisabled to distinguish missing vAccel config from actual misconfiguration. Log Warn instead of Debug on error. Fixes: #698 Signed-off-by: Chennamma-Hotkar <channuhotkar@gmail.com>
1 parent 154fc9e commit a1a0bb5

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

pkg/unikontainers/unikontainers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,9 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
528528
// vAccel setup
529529
vAccelType, vsockSocketPath, rpcAddress, err := resolveVAccelConfig(u.State.Annotations[annotHypervisor], u.Spec.Annotations)
530530
if err != nil {
531-
uniklog.Debugf("vAccel config: %v", err)
531+
if !errors.Is(err, ErrVAccelDisabled) {
532+
uniklog.Warnf("vAccel misconfiguration: %v", err)
533+
}
532534
}
533535

534536
if vAccelType == "vsock" && err == nil {

pkg/unikontainers/vaccel.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
package unikontainers
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"regexp"
2021

2122
"golang.org/x/sys/unix"
2223
)
2324

25+
// ErrVAccelDisabled is returned by resolveVAccelConfig when the vAccel
26+
// annotation is absent. This is an expected condition, not a misconfiguration.
27+
var ErrVAccelDisabled = errors.New("vaccel is disabled")
28+
2429
// idToGuestCID generates a deterministic guest CID (Context Identifier)
2530
// for vsock communication based on a container or VM ID.
2631
func idToGuestCID(id string) int {
@@ -87,8 +92,7 @@ func resolveVAccelConfig(hypervisor string, annotations map[string]string) (stri
8792
return vAccelType, "", "", err
8893
}
8994
} else {
90-
err = fmt.Errorf("vaccel is disabled")
91-
return vAccelType, "", "", err
95+
return "", "", "", ErrVAccelDisabled
9296
}
9397

9498
if vAccelType == "vsock" {

pkg/unikontainers/vaccel_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package unikontainers
1616

1717
import (
18+
"errors"
1819
"testing"
1920

2021
"github.com/stretchr/testify/assert"
@@ -168,3 +169,46 @@ func TestIsValidVSockAddress(t *testing.T) {
168169
})
169170
}
170171
}
172+
173+
func TestResolveVAccelConfig(t *testing.T) {
174+
t.Run("vaccel disabled returns ErrVAccelDisabled", func(t *testing.T) {
175+
t.Parallel()
176+
annotations := map[string]string{}
177+
_, _, _, err := resolveVAccelConfig("qemu", annotations)
178+
assert.ErrorIs(t, err, ErrVAccelDisabled)
179+
})
180+
181+
t.Run("vaccel enabled but rpc address missing returns error", func(t *testing.T) {
182+
t.Parallel()
183+
annotations := map[string]string{
184+
"com.urunc.unikernel.vAccel": "vsock",
185+
}
186+
_, _, _, err := resolveVAccelConfig("qemu", annotations)
187+
assert.Error(t, err)
188+
assert.False(t, errors.Is(err, ErrVAccelDisabled), "missing rpc address should not be ErrVAccelDisabled")
189+
})
190+
191+
t.Run("vaccel enabled with malformed rpc address returns error", func(t *testing.T) {
192+
t.Parallel()
193+
annotations := map[string]string{
194+
"com.urunc.unikernel.vAccel": "vsock",
195+
"com.urunc.unikernel.RPCAddress": "invalid-address",
196+
}
197+
_, _, _, err := resolveVAccelConfig("qemu", annotations)
198+
assert.Error(t, err)
199+
assert.False(t, errors.Is(err, ErrVAccelDisabled), "malformed address should not be ErrVAccelDisabled")
200+
})
201+
202+
t.Run("vaccel enabled with valid qemu vsock address succeeds", func(t *testing.T) {
203+
t.Parallel()
204+
annotations := map[string]string{
205+
"com.urunc.unikernel.vAccel": "vsock",
206+
"com.urunc.unikernel.RPCAddress": "vsock://2:1234",
207+
}
208+
vAccelType, _, addr, err := resolveVAccelConfig("qemu", annotations)
209+
assert.NoError(t, err)
210+
assert.Equal(t, "vsock", vAccelType)
211+
assert.Equal(t, "vsock://2:1234", addr)
212+
})
213+
}
214+

0 commit comments

Comments
 (0)