sandbox: add Sandboxer field to sandbox metadata

Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
Abel Feng 2023-06-05 21:01:31 +08:00 committed by f00589305
parent 69e501e7cd
commit 8b35976850
5 changed files with 25 additions and 4 deletions

View File

@ -114,6 +114,7 @@
createdat : <binary time> - Created at createdat : <binary time> - Created at
updatedat : <binary time> - Updated at updatedat : <binary time> - Updated at
spec : <binary> - Proto marshaled spec spec : <binary> - Proto marshaled spec
sandboxer : <string> - Sandboxer name
runtime runtime
name : <string> - Runtime name name : <string> - Runtime name
options : <binary> - Proto marshaled options options : <binary> - Proto marshaled options
@ -173,6 +174,7 @@ var (
bucketKeyRef = []byte("ref") bucketKeyRef = []byte("ref")
bucketKeyExpireAt = []byte("expireat") bucketKeyExpireAt = []byte("expireat")
bucketKeySandboxID = []byte("sandboxid") bucketKeySandboxID = []byte("sandboxid")
bucketKeySandboxer = []byte("sandboxer")
deprecatedBucketKeyObjectIngest = []byte("ingest") // stores ingest links, deprecated in v1.2 deprecatedBucketKeyObjectIngest = []byte("ingest") // stores ingest links, deprecated in v1.2
) )

View File

@ -292,6 +292,10 @@ func (s *sandboxStore) write(parent *bbolt.Bucket, instance *api.Sandbox, overwr
return err return err
} }
if err := bucket.Put(bucketKeySandboxer, []byte(instance.Sandboxer)); err != nil {
return err
}
runtimeBucket, err := bucket.CreateBucketIfNotExists(bucketKeyRuntime) runtimeBucket, err := bucket.CreateBucketIfNotExists(bucketKeyRuntime)
if err != nil { if err != nil {
return err return err
@ -350,6 +354,12 @@ func (s *sandboxStore) read(parent *bbolt.Bucket, id []byte) (api.Sandbox, error
if err != nil { if err != nil {
return api.Sandbox{}, err return api.Sandbox{}, err
} }
sandboxer := bucket.Get(bucketKeySandboxer)
if sandboxer == nil {
inst.Sandboxer = ""
} else {
inst.Sandboxer = string(sandboxer)
}
return inst, nil return inst, nil
} }

View File

@ -43,6 +43,7 @@ func TestSandboxCreate(t *testing.T) {
Name: "test", Name: "test",
Options: &types.Any{TypeUrl: "url/3", Value: []byte{4, 5, 6}}, Options: &types.Any{TypeUrl: "url/3", Value: []byte{4, 5, 6}},
}, },
Sandboxer: "test-sandboxer",
} }
_, err := store.Create(ctx, in) _, err := store.Create(ctx, in)
@ -92,6 +93,7 @@ func TestSandboxUpdate(t *testing.T) {
"ext2": &types.Any{TypeUrl: "url2", Value: []byte{4, 5, 6}}, // will append `ext1` "ext2": &types.Any{TypeUrl: "url2", Value: []byte{4, 5, 6}}, // will append `ext1`
}, },
Runtime: api.RuntimeOpts{Name: "test"}, // no change Runtime: api.RuntimeOpts{Name: "test"}, // no change
Sandboxer: "test-sandboxer", // no change
}); err != nil { }); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -121,6 +123,7 @@ func TestSandboxUpdate(t *testing.T) {
"ext2": &types.Any{TypeUrl: "url2", Value: []byte{4, 5, 6}}, "ext2": &types.Any{TypeUrl: "url2", Value: []byte{4, 5, 6}},
}, },
Runtime: api.RuntimeOpts{Name: "test"}, Runtime: api.RuntimeOpts{Name: "test"},
Sandboxer: "test-sandboxer",
} }
assertEqualInstances(t, out, expected) assertEqualInstances(t, out, expected)
@ -159,6 +162,7 @@ func TestSandboxList(t *testing.T) {
Value: []byte{9}, Value: []byte{9},
}}, }},
Runtime: api.RuntimeOpts{Name: "test"}, Runtime: api.RuntimeOpts{Name: "test"},
Sandboxer: "test-sandboxer",
}, },
} }
@ -204,6 +208,7 @@ func TestSandboxListWithFilter(t *testing.T) {
Value: []byte{9}, Value: []byte{9},
}}, }},
Runtime: api.RuntimeOpts{Name: "test"}, Runtime: api.RuntimeOpts{Name: "test"},
Sandboxer: "test-sandboxer",
}, },
} }

View File

@ -35,6 +35,7 @@ func ToProto(sandbox *Sandbox) *types.Sandbox {
Name: sandbox.Runtime.Name, Name: sandbox.Runtime.Name,
Options: protobuf.FromAny(sandbox.Runtime.Options), Options: protobuf.FromAny(sandbox.Runtime.Options),
}, },
Sandboxer: sandbox.Sandboxer,
Labels: sandbox.Labels, Labels: sandbox.Labels,
CreatedAt: protobuf.ToTimestamp(sandbox.CreatedAt), CreatedAt: protobuf.ToTimestamp(sandbox.CreatedAt),
UpdatedAt: protobuf.ToTimestamp(sandbox.UpdatedAt), UpdatedAt: protobuf.ToTimestamp(sandbox.UpdatedAt),
@ -61,6 +62,7 @@ func FromProto(sandboxpb *types.Sandbox) Sandbox {
Labels: sandboxpb.Labels, Labels: sandboxpb.Labels,
Runtime: runtime, Runtime: runtime,
Spec: sandboxpb.Spec, Spec: sandboxpb.Spec,
Sandboxer: sandboxpb.Sandboxer,
CreatedAt: protobuf.FromTimestamp(sandboxpb.CreatedAt), CreatedAt: protobuf.FromTimestamp(sandboxpb.CreatedAt),
UpdatedAt: protobuf.FromTimestamp(sandboxpb.UpdatedAt), UpdatedAt: protobuf.FromTimestamp(sandboxpb.UpdatedAt),
Extensions: extensions, Extensions: extensions,

View File

@ -35,6 +35,8 @@ type Sandbox struct {
Runtime RuntimeOpts Runtime RuntimeOpts
// Spec carries the runtime specification used to implement the sandbox // Spec carries the runtime specification used to implement the sandbox
Spec typeurl.Any Spec typeurl.Any
// Sandboxer is the sandbox controller who manages the sandbox
Sandboxer string
// CreatedAt is the time at which the sandbox was created // CreatedAt is the time at which the sandbox was created
CreatedAt time.Time CreatedAt time.Time
// UpdatedAt is the time at which the sandbox was updated // UpdatedAt is the time at which the sandbox was updated