Skip to content

Commit 951f8b0

Browse files
committed
feat(machine/xen): Introduce Xen support
Signed-off-by: Andrei Stan <[email protected]>
1 parent 1cbcbcf commit 951f8b0

File tree

7 files changed

+824
-0
lines changed

7 files changed

+824
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ require (
7878
oras.land/oras-go/v2 v2.5.0
7979
sdk.kraft.cloud v0.5.5-0.20240410102038-8d0f0333b17a
8080
sigs.k8s.io/kustomize/kyaml v0.14.3
81+
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240402142354-17cf285d87e2
8182
)
8283

8384
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,3 +1695,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
16951695
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
16961696
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
16971697
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
1698+
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240402142354-17cf285d87e2 h1:f3OAMM0NgzlqWqZnuTIz6B6HPK1pGGfgKH6S94kYEWY=
1699+
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240402142354-17cf285d87e2/go.mod h1:tbZ4iMnk8RWkXPxTiCGdAw3hCOa3feShlf3sBh50uIc=

machine/platform/register_linux.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"kraftkit.sh/internal/set"
1515
"kraftkit.sh/machine/firecracker"
1616
"kraftkit.sh/store"
17+
"kraftkit.sh/machine/xen"
1718
)
1819

1920
var firecrackerV1alpha1Driver = func(ctx context.Context, opts ...any) (machinev1alpha1.MachineService, error) {
@@ -43,6 +44,30 @@ var firecrackerV1alpha1Driver = func(ctx context.Context, opts ...any) (machinev
4344
)
4445
}
4546

47+
var xenV1alpha1Driver = func(ctx context.Context, opts ...any) (machinev1alpha1.MachineService, error) {
48+
service, err := xen.NewMachineV1alpha1Service(ctx)
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
embeddedStore, err := store.NewEmbeddedStore[machinev1alpha1.MachineSpec, machinev1alpha1.MachineStatus](
54+
filepath.Join(
55+
config.G[config.KraftKit](ctx).RuntimeDir,
56+
"machinev1alpha1",
57+
),
58+
)
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
return machinev1alpha1.NewMachineServiceHandler(
64+
ctx,
65+
service,
66+
zip.WithStore[machinev1alpha1.MachineSpec, machinev1alpha1.MachineStatus](embeddedStore, zip.StoreRehydrationSpecNil),
67+
zip.WithBefore(storePlatformFilter(PlatformXen)),
68+
)
69+
}
70+
4671
func unixVariantStrategies() map[Platform]*Strategy {
4772
// TODO(jake-ciolek): The firecracker driver has a dependency on github.com/containernetworking/plugins/pkg/ns via
4873
// github.com/firecracker-microvm/firecracker-go-sdk
@@ -51,5 +76,8 @@ func unixVariantStrategies() map[Platform]*Strategy {
5176
PlatformFirecracker: {
5277
NewMachineV1alpha1: firecrackerV1alpha1Driver,
5378
},
79+
PlatformXen: {
80+
NewMachineV1alpha1: xenV1alpha1Driver,
81+
},
5482
}
5583
}

machine/xen/init.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2024, Unikraft GmbH and The KraftKit Authors.
3+
// Licensed under the BSD-3-Clause License (the "License").
4+
// You may not use this file except in compliance with the License.
5+
6+
//go:build xen
7+
// +build xen
8+
9+
package xen
10+
11+
import (
12+
"encoding/gob"
13+
14+
"xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight"
15+
)
16+
17+
func init() {
18+
gob.Register(xenlight.Domid(0))
19+
}

machine/xen/stub.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2024, Unikraft GmbH and The KraftKit Authors.
3+
// Licensed under the BSD-3-Clause License (the "License").
4+
// You may not use this file except in compliance with the License.
5+
6+
//go:build !xen
7+
// +build !xen
8+
9+
package xen
10+
11+
import (
12+
"context"
13+
"fmt"
14+
15+
machinev1alpha1 "kraftkit.sh/api/machine/v1alpha1"
16+
)
17+
18+
func NewMachineV1alpha1Service(ctx context.Context) (machinev1alpha1.MachineService, error) {
19+
return nil, fmt.Errorf("xen support is not enabled")
20+
}

0 commit comments

Comments
 (0)