Skip to content

Commit

Permalink
sandbox: add Sandboxer field to sandbox metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Abel Feng <[email protected]>
  • Loading branch information
abel-von authored and f00589305 committed Oct 16, 2023
1 parent 69e501e commit 8b35976
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions metadata/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
10 changes: 10 additions & 0 deletions metadata/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 9 additions & 4 deletions metadata/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
},
}

Expand Down Expand Up @@ -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",
},
}

Expand Down
2 changes: 2 additions & 0 deletions sandbox/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions sandbox/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b35976

Please sign in to comment.