098a44c07f
Finish the refactor which was partially completed with commit
34536c498d
, passing around IdentityMapping structs instead of pairs of
[]IDMap slices.
Existing code which uses []IDMap relies on zero-valued fields to be
valid, empty mappings. So in order to successfully finish the
refactoring without introducing bugs, their replacement therefore also
needs to have a useful zero value which represents an empty mapping.
Change IdentityMapping to be a pass-by-value type so that there are no
nil pointers to worry about.
The functionality provided by the deprecated NewIDMappingsFromMaps
function is required by unit tests to to construct arbitrary
IdentityMapping values. And the daemon will always need to access the
mappings to pass them to the Linux kernel. Accommodate these use cases
by exporting the struct fields instead. BuildKit currently depends on
the UIDs and GIDs methods so we cannot get rid of them yet.
Signed-off-by: Cory Snider <csnider@mirantis.com>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package graphdriver // import "github.com/docker/docker/daemon/graphdriver"
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/pkg/idtools"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestGraphDriverInitRequestIsCompatible(t *testing.T) {
|
|
// Graph driver plugins may unmarshal into this version of the init
|
|
// request struct. Verify that the serialization of
|
|
// graphDriverInitRequest is fully backwards compatible.
|
|
|
|
type graphDriverInitRequestV1 struct {
|
|
Home string
|
|
Opts []string `json:"Opts"`
|
|
UIDMaps []idtools.IDMap `json:"UIDMaps"`
|
|
GIDMaps []idtools.IDMap `json:"GIDMaps"`
|
|
}
|
|
|
|
args := graphDriverInitRequest{
|
|
Home: "homedir",
|
|
Opts: []string{"option1", "option2"},
|
|
IdentityMapping: idtools.IdentityMapping{
|
|
UIDMaps: []idtools.IDMap{{ContainerID: 123, HostID: 456, Size: 42}},
|
|
GIDMaps: []idtools.IDMap{{ContainerID: 789, HostID: 1011, Size: 16}},
|
|
},
|
|
}
|
|
v, err := json.Marshal(&args)
|
|
assert.NilError(t, err)
|
|
|
|
var got graphDriverInitRequestV1
|
|
assert.NilError(t, json.Unmarshal(v, &got))
|
|
want := graphDriverInitRequestV1{
|
|
Home: args.Home,
|
|
Opts: args.Opts,
|
|
UIDMaps: args.UIDMaps,
|
|
GIDMaps: args.GIDMaps,
|
|
}
|
|
assert.DeepEqual(t, got, want)
|
|
}
|