sandbox: add Sandboxer field to sandbox metadata
Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
parent
69e501e7cd
commit
8b35976850
@ -114,6 +114,7 @@
|
||||
│ ├──createdat : <binary time> - Created at
|
||||
│ ├──updatedat : <binary time> - Updated at
|
||||
│ ├──spec : <binary> - Proto marshaled spec
|
||||
│ ├──sandboxer : <string> - Sandboxer name
|
||||
│ ├──runtime
|
||||
│ │ ├──name : <string> - Runtime name
|
||||
│ │ └──options : <binary> - Proto marshaled options
|
||||
@ -173,6 +174,7 @@ var (
|
||||
bucketKeyRef = []byte("ref")
|
||||
bucketKeyExpireAt = []byte("expireat")
|
||||
bucketKeySandboxID = []byte("sandboxid")
|
||||
bucketKeySandboxer = []byte("sandboxer")
|
||||
|
||||
deprecatedBucketKeyObjectIngest = []byte("ingest") // stores ingest links, deprecated in v1.2
|
||||
)
|
||||
|
@ -292,6 +292,10 @@ func (s *sandboxStore) write(parent *bbolt.Bucket, instance *api.Sandbox, overwr
|
||||
return err
|
||||
}
|
||||
|
||||
if err := bucket.Put(bucketKeySandboxer, []byte(instance.Sandboxer)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
runtimeBucket, err := bucket.CreateBucketIfNotExists(bucketKeyRuntime)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -350,6 +354,12 @@ func (s *sandboxStore) read(parent *bbolt.Bucket, id []byte) (api.Sandbox, error
|
||||
if err != nil {
|
||||
return api.Sandbox{}, err
|
||||
}
|
||||
sandboxer := bucket.Get(bucketKeySandboxer)
|
||||
if sandboxer == nil {
|
||||
inst.Sandboxer = ""
|
||||
} else {
|
||||
inst.Sandboxer = string(sandboxer)
|
||||
}
|
||||
|
||||
return inst, nil
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ func TestSandboxCreate(t *testing.T) {
|
||||
Name: "test",
|
||||
Options: &types.Any{TypeUrl: "url/3", Value: []byte{4, 5, 6}},
|
||||
},
|
||||
Sandboxer: "test-sandboxer",
|
||||
}
|
||||
|
||||
_, err := store.Create(ctx, in)
|
||||
@ -91,7 +92,8 @@ func TestSandboxUpdate(t *testing.T) {
|
||||
Extensions: map[string]typeurl.Any{
|
||||
"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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -120,7 +122,8 @@ func TestSandboxUpdate(t *testing.T) {
|
||||
"ext1": &types.Any{TypeUrl: "url1", Value: []byte{1, 2}},
|
||||
"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)
|
||||
@ -158,7 +161,8 @@ func TestSandboxList(t *testing.T) {
|
||||
TypeUrl: "test",
|
||||
Value: []byte{9},
|
||||
}},
|
||||
Runtime: api.RuntimeOpts{Name: "test"},
|
||||
Runtime: api.RuntimeOpts{Name: "test"},
|
||||
Sandboxer: "test-sandboxer",
|
||||
},
|
||||
}
|
||||
|
||||
@ -203,7 +207,8 @@ func TestSandboxListWithFilter(t *testing.T) {
|
||||
TypeUrl: "test",
|
||||
Value: []byte{9},
|
||||
}},
|
||||
Runtime: api.RuntimeOpts{Name: "test"},
|
||||
Runtime: api.RuntimeOpts{Name: "test"},
|
||||
Sandboxer: "test-sandboxer",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ func ToProto(sandbox *Sandbox) *types.Sandbox {
|
||||
Name: sandbox.Runtime.Name,
|
||||
Options: protobuf.FromAny(sandbox.Runtime.Options),
|
||||
},
|
||||
Sandboxer: sandbox.Sandboxer,
|
||||
Labels: sandbox.Labels,
|
||||
CreatedAt: protobuf.ToTimestamp(sandbox.CreatedAt),
|
||||
UpdatedAt: protobuf.ToTimestamp(sandbox.UpdatedAt),
|
||||
@ -61,6 +62,7 @@ func FromProto(sandboxpb *types.Sandbox) Sandbox {
|
||||
Labels: sandboxpb.Labels,
|
||||
Runtime: runtime,
|
||||
Spec: sandboxpb.Spec,
|
||||
Sandboxer: sandboxpb.Sandboxer,
|
||||
CreatedAt: protobuf.FromTimestamp(sandboxpb.CreatedAt),
|
||||
UpdatedAt: protobuf.FromTimestamp(sandboxpb.UpdatedAt),
|
||||
Extensions: extensions,
|
||||
|
@ -35,6 +35,8 @@ type Sandbox struct {
|
||||
Runtime RuntimeOpts
|
||||
// Spec carries the runtime specification used to implement the sandbox
|
||||
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 time.Time
|
||||
// UpdatedAt is the time at which the sandbox was updated
|
||||
|
Loading…
Reference in New Issue
Block a user