Skip to content

Commit a4af53f

Browse files
committed
build: consume cocoon's exported json namespace declarations (#24)
cocoon now exports JSONNamespace() on the cloudimg and cni backends (cocoonstack/cocoon#165), so drop the two hand-copied namespace declarations and the drift-guard test that pinned them — the layout can no longer diverge from cocoon's by construction.
1 parent 59b5ec1 commit a4af53f

5 files changed

Lines changed: 5 additions & 83 deletions

File tree

cmd/vm/net_linux.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/cocoonstack/cocoon/cmd/cliutil"
1818
"github.com/cocoonstack/cocoon/config"
1919
metajson "github.com/cocoonstack/cocoon/meta/json"
20-
"github.com/cocoonstack/cocoon/meta/tombstone"
2120
"github.com/cocoonstack/cocoon/network"
2221
"github.com/cocoonstack/cocoon/network/bridge"
2322
"github.com/cocoonstack/cocoon/network/cni"
@@ -37,7 +36,7 @@ func newProvider(cmd *cobra.Command, r *record) (network.Network, error) {
3736
}
3837
switch r.NetMode {
3938
case netCNI:
40-
store, err := metajson.Open(cniNamespace(conf))
39+
store, err := metajson.Open(cni.NewConfig(conf).JSONNamespace())
4140
if err != nil {
4241
return nil, fmt.Errorf("open meta store: %w", err)
4342
}
@@ -54,21 +53,6 @@ func newProvider(cmd *cobra.Command, r *record) (network.Network, error) {
5453
return nil, fmt.Errorf("unknown --net mode %q (want user|tap|cni|bridge)", r.NetMode)
5554
}
5655

57-
// cniNamespace mirrors cocoon's own cni json namespace (cmd/core
58-
// MetaJSONNamespaces) so both binaries read the same network state.
59-
func cniNamespace(conf *config.Config) metajson.Namespace {
60-
c := cni.NewConfig(conf)
61-
return metajson.Namespace{
62-
Name: cni.NamespaceName,
63-
FilePath: c.IndexFile(),
64-
LockPath: c.IndexLock(),
65-
Codec: metajson.TableCodec{Specs: []metajson.TableSpec{
66-
{Key: "networks", Table: cni.TableRecords},
67-
{Key: tombstone.TableName, Table: tombstone.TableName, Optional: true},
68-
}},
69-
}
70-
}
71-
7256
// provisionNet auto-creates a TAP via cocoon — the SAME forwarding plane as cocoon's CH/FC VMs.
7357
func provisionNet(cmd *cobra.Command, r *record) (tap, netns, mac string, err error) {
7458
provider, err := newProvider(cmd, r)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cocoonstack/cocoon-macos
33
go 1.26.5
44

55
require (
6-
github.com/cocoonstack/cocoon v0.5.5
6+
github.com/cocoonstack/cocoon v0.5.6-0.20260723121642-d95fdb8f906d
77
github.com/docker/go-units v0.5.0
88
github.com/opencontainers/image-spec v1.1.1
99
github.com/projecteru2/core v0.0.0-20241016125006-ff909eefe04c

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZe
88
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
99
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
1010
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
11-
github.com/cocoonstack/cocoon v0.5.5 h1:gmyYE3ptHiwV2o2t3W0Rwx4SYA5ZAKpGmjeIMU3UPbM=
12-
github.com/cocoonstack/cocoon v0.5.5/go.mod h1:mpfFhJrev0f2NH80niMRIiv8OPa7ZyecyWWmIJPPK4Q=
11+
github.com/cocoonstack/cocoon v0.5.6-0.20260723121642-d95fdb8f906d h1:kvSmXI2wAh5tAKiEVYTRpO1iDA2S1thTOBdgUGuNQt0=
12+
github.com/cocoonstack/cocoon v0.5.6-0.20260723121642-d95fdb8f906d/go.mod h1:mpfFhJrev0f2NH80niMRIiv8OPa7ZyecyWWmIJPPK4Q=
1313
github.com/containernetworking/cni v1.3.0 h1:v6EpN8RznAZj9765HhXQrtXgX+ECGebEYEmnuFjskwo=
1414
github.com/containernetworking/cni v1.3.0/go.mod h1:Bs8glZjjFfGPHMw6hQu82RUgEPNGEaBb9KS5KtNMnJ4=
1515
github.com/containernetworking/plugins v1.9.0 h1:Mg3SXBdRGkdXyFC4lcwr6u2ZB2SDeL6LC3U+QrEANuQ=

home/home.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import (
1111
"github.com/spf13/cobra"
1212

1313
"github.com/cocoonstack/cocoon/cmd/cliutil"
14-
"github.com/cocoonstack/cocoon/images"
1514
"github.com/cocoonstack/cocoon/images/cloudimg"
1615
metajson "github.com/cocoonstack/cocoon/meta/json"
17-
"github.com/cocoonstack/cocoon/meta/tombstone"
1816
)
1917

2018
// Default is the state root when neither --state-dir nor $COCOON_MACOS_HOME is set.
@@ -44,7 +42,7 @@ func VMDir(cmd *cobra.Command, name string) string {
4442
// OpenStore opens the cloudimg store at the resolved state dir, returning the command context with it.
4543
func OpenStore(cmd *cobra.Command) (context.Context, *cloudimg.CloudImg, error) {
4644
ctx := cliutil.CommandContext(cmd)
47-
metaStore, err := metajson.Open(cloudimgNamespace(Dir(cmd)))
45+
metaStore, err := metajson.Open(cloudimg.NewConfig(Dir(cmd), 0).JSONNamespace())
4846
if err != nil {
4947
return ctx, nil, fmt.Errorf("open meta store: %w", err)
5048
}
@@ -54,19 +52,3 @@ func OpenStore(cmd *cobra.Command) (context.Context, *cloudimg.CloudImg, error)
5452
}
5553
return ctx, s, nil
5654
}
57-
58-
// cloudimgNamespace mirrors cocoon's own cloudimg json namespace (cmd/core
59-
// MetaJSONNamespaces); the layout is cocoon's, so on-disk state stays readable
60-
// by both binaries.
61-
func cloudimgNamespace(rootDir string) metajson.Namespace {
62-
conf := cloudimg.NewConfig(rootDir, 0)
63-
return metajson.Namespace{
64-
Name: cloudimg.NamespaceName,
65-
FilePath: conf.IndexFile(),
66-
LockPath: conf.IndexLock(),
67-
Codec: metajson.TableCodec{Specs: []metajson.TableSpec{
68-
{Key: "images", Table: images.TableRecords},
69-
{Key: tombstone.TableName, Table: tombstone.TableName, Optional: true},
70-
}},
71-
}
72-
}

home/home_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,11 @@
11
package home
22

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

76
"github.com/spf13/cobra"
8-
9-
"github.com/cocoonstack/cocoon/images"
10-
"github.com/cocoonstack/cocoon/images/cloudimg"
11-
metajson "github.com/cocoonstack/cocoon/meta/json"
12-
"github.com/cocoonstack/cocoon/meta/tombstone"
137
)
148

15-
// TestCloudimgNamespace pins the namespace to cocoon's layout: a drifting key
16-
// or path would leave cocoon-written state unreadable here.
17-
func TestCloudimgNamespace(t *testing.T) {
18-
root := t.TempDir()
19-
ns := cloudimgNamespace(root)
20-
conf := cloudimg.NewConfig(root, 0)
21-
22-
if ns.Name != cloudimg.NamespaceName {
23-
t.Errorf("name = %q, want %q", ns.Name, cloudimg.NamespaceName)
24-
}
25-
if ns.FilePath != conf.IndexFile() {
26-
t.Errorf("file = %q, want %q", ns.FilePath, conf.IndexFile())
27-
}
28-
if ns.LockPath != conf.IndexLock() {
29-
t.Errorf("lock = %q, want %q", ns.LockPath, conf.IndexLock())
30-
}
31-
if got, want := filepath.Dir(ns.FilePath), filepath.Dir(ns.LockPath); got != want {
32-
t.Errorf("file dir %q != lock dir %q", got, want)
33-
}
34-
35-
codec, ok := ns.Codec.(metajson.TableCodec)
36-
if !ok {
37-
t.Fatalf("codec type = %T, want metajson.TableCodec", ns.Codec)
38-
}
39-
want := []metajson.TableSpec{
40-
{Key: "images", Table: images.TableRecords},
41-
{Key: "tombstones", Table: tombstone.TableName, Optional: true},
42-
}
43-
if len(codec.Specs) != len(want) {
44-
t.Fatalf("specs = %v, want %v", codec.Specs, want)
45-
}
46-
for i, w := range want {
47-
if codec.Specs[i] != w {
48-
t.Errorf("spec[%d] = %+v, want %+v", i, codec.Specs[i], w)
49-
}
50-
}
51-
}
52-
539
// TestOpenStoreEmpty covers the full OpenStore path on a fresh state dir.
5410
func TestOpenStoreEmpty(t *testing.T) {
5511
cmd := newTestCmd(t)

0 commit comments

Comments
 (0)