Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7be2ace

Browse files
committedJun 22, 2024
use Marshal funcs from containerd and fix typeurl
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
1 parent e0a41a6 commit 7be2ace

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed
 

‎cmd/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
8888
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
8989
github.com/containerd/ttrpc v1.2.4 h1:eQCQK4h9dxDmpOb9QOOMh2NHTfzroH1IkmHiKZi05Oo=
9090
github.com/containerd/ttrpc v1.2.4/go.mod h1:ojvb8SJBSch0XkqNO0L0YX/5NxR3UnVk2LzFKBK0upc=
91-
github.com/containerd/typeurl v1.0.2 h1:Chlt8zIieDbzQFzXzAeBEF92KhExuE4p9p92/QmY7aY=
92-
github.com/containerd/typeurl v1.0.2/go.mod h1:9trJWW2sRlGub4wZJRTW83VtbOLS6hwcDZXTn6oPz9s=
91+
github.com/containerd/typeurl/v2 v2.1.1 h1:3Q4Pt7i8nYwy2KmQWIw2+1hTvwTE/6w9FqcttATPO/4=
92+
github.com/containerd/typeurl/v2 v2.1.1/go.mod h1:IDp2JFvbwZ31H8dQbEIY7sDl2L3o3HZj1hsSQlywkQ0=
9393
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U=
9494
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
9595
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=

‎container/containerd/factory_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package containerd
1717
import (
1818
"testing"
1919

20-
"github.com/containerd/typeurl"
2120
"github.com/google/cadvisor/container/containerd/containers"
2221
specs "github.com/opencontainers/runtime-spec/specs-go"
2322
"github.com/stretchr/testify/assert"
@@ -52,7 +51,7 @@ func TestCanHandleAndAccept(t *testing.T) {
5251
Labels: map[string]string{"io.cri-containerd.kind": "sandbox"},
5352
}
5453
spec := &specs.Spec{Root: &specs.Root{Path: "/test/"}, Process: &specs.Process{}}
55-
testContainer.Spec, _ = typeurl.MarshalAny(spec)
54+
testContainer.Spec, _ = MarshalAnyToProto(spec)
5655
testContainers["40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"] = testContainer
5756

5857
f := &containerdFactory{

‎container/containerd/handler_test.go

+34-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package containerd
1818
import (
1919
"testing"
2020

21-
"github.com/containerd/typeurl"
21+
"github.com/containerd/typeurl/v2"
22+
"google.golang.org/protobuf/types/known/anypb"
23+
2224
specs "github.com/opencontainers/runtime-spec/specs-go"
2325
"github.com/stretchr/testify/assert"
2426

@@ -42,6 +44,36 @@ func (m *mockedMachineInfo) GetVersionInfo() (*info.VersionInfo, error) {
4244
return &info.VersionInfo{}, nil
4345
}
4446

47+
// Copied from https://github.com/containerd/containerd/blob/main/pkg/protobuf/any.go
48+
// FromAny converts typeurl.Any to github.com/containerd/containerd/protobuf/types.Any.
49+
//
50+
// TODO: vendor these functions once they are moved to github.com/containerd/typeurl.
51+
//
52+
// Currently they are copied over so as not to introduce a dependency on containerd/containerd again
53+
func FromAny(from typeurl.Any) *anypb.Any {
54+
if from == nil {
55+
return nil
56+
}
57+
58+
if pbany, ok := from.(*anypb.Any); ok {
59+
return pbany
60+
}
61+
62+
return &anypb.Any{
63+
TypeUrl: from.GetTypeUrl(),
64+
Value: from.GetValue(),
65+
}
66+
}
67+
68+
// MarshalAnyToProto converts an arbitrary interface to github.com/containerd/containerd/protobuf/types.Any.
69+
func MarshalAnyToProto(from interface{}) (*anypb.Any, error) {
70+
anyType, err := typeurl.MarshalAny(from)
71+
if err != nil {
72+
return nil, err
73+
}
74+
return FromAny(anyType), nil
75+
}
76+
4577
func TestHandler(t *testing.T) {
4678
as := assert.New(t)
4779
type testCase struct {
@@ -65,7 +97,7 @@ func TestHandler(t *testing.T) {
6597
Labels: map[string]string{"io.cri-containerd.kind": "sandbox"},
6698
}
6799
spec := &specs.Spec{Root: &specs.Root{Path: "/test/"}, Process: &specs.Process{Env: []string{"TEST_REGION=FRA", "TEST_ZONE=A", "HELLO=WORLD"}}}
68-
testContainer.Spec, _ = typeurl.MarshalAny(spec)
100+
testContainer.Spec, _ = MarshalAnyToProto(spec)
69101
testContainers["40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"] = testContainer
70102
for _, ts := range []testCase{
71103
{

‎go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ require (
99
github.com/blang/semver/v4 v4.0.0
1010
github.com/containerd/containerd/api v1.8.0-rc.2
1111
github.com/containerd/ttrpc v1.2.4
12-
github.com/containerd/typeurl v1.0.2
12+
github.com/containerd/typeurl/v2 v2.1.1
1313
github.com/docker/docker v27.0.0+incompatible
1414
github.com/docker/go-connections v0.5.0
1515
github.com/docker/go-units v0.5.0
1616
github.com/euank/go-kmsg-parser v2.0.0+incompatible
17-
github.com/gogo/protobuf v1.3.2
1817
github.com/karrick/godirwalk v1.17.0
1918
github.com/mistifyio/go-zfs v2.1.1+incompatible
2019
github.com/moby/sys/mountinfo v0.7.1
@@ -28,6 +27,7 @@ require (
2827
golang.org/x/net v0.26.0
2928
golang.org/x/sys v0.21.0
3029
google.golang.org/grpc v1.64.0
30+
google.golang.org/protobuf v1.34.1
3131
k8s.io/klog/v2 v2.100.1
3232
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
3333
)
@@ -48,6 +48,7 @@ require (
4848
github.com/go-logr/logr v1.4.1 // indirect
4949
github.com/go-logr/stdr v1.2.2 // indirect
5050
github.com/godbus/dbus/v5 v5.0.6 // indirect
51+
github.com/gogo/protobuf v1.3.2 // indirect
5152
github.com/golang/protobuf v1.5.4 // indirect
5253
github.com/jmespath/go-jmespath v0.4.0 // indirect
5354
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
@@ -74,7 +75,6 @@ require (
7475
go.opentelemetry.io/otel/trace v1.27.0 // indirect
7576
golang.org/x/text v0.16.0 // indirect
7677
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
77-
google.golang.org/protobuf v1.34.1 // indirect
7878
gopkg.in/yaml.v3 v3.0.1 // indirect
7979
gotest.tools/v3 v3.0.2 // indirect
8080
)

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
7878
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
7979
github.com/containerd/ttrpc v1.2.4 h1:eQCQK4h9dxDmpOb9QOOMh2NHTfzroH1IkmHiKZi05Oo=
8080
github.com/containerd/ttrpc v1.2.4/go.mod h1:ojvb8SJBSch0XkqNO0L0YX/5NxR3UnVk2LzFKBK0upc=
81-
github.com/containerd/typeurl v1.0.2 h1:Chlt8zIieDbzQFzXzAeBEF92KhExuE4p9p92/QmY7aY=
82-
github.com/containerd/typeurl v1.0.2/go.mod h1:9trJWW2sRlGub4wZJRTW83VtbOLS6hwcDZXTn6oPz9s=
81+
github.com/containerd/typeurl/v2 v2.1.1 h1:3Q4Pt7i8nYwy2KmQWIw2+1hTvwTE/6w9FqcttATPO/4=
82+
github.com/containerd/typeurl/v2 v2.1.1/go.mod h1:IDp2JFvbwZ31H8dQbEIY7sDl2L3o3HZj1hsSQlywkQ0=
8383
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
8484
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
8585
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=

0 commit comments

Comments
 (0)
Please sign in to comment.