Skip to content

Commit ee149fa

Browse files
authored
Merge pull request #2908 from dims/prototype-stripping-containerd/containerd-out
Depend only on containerd API and avoid vendoring unnecessary things from containerd
2 parents b0be1ac + d27911b commit ee149fa

22 files changed

+1341
-10
lines changed

container/containerd/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
containersapi "github.com/containerd/containerd/api/services/containers/v1"
2525
tasksapi "github.com/containerd/containerd/api/services/tasks/v1"
2626
versionapi "github.com/containerd/containerd/api/services/version/v1"
27-
"github.com/containerd/containerd/containers"
28-
"github.com/containerd/containerd/errdefs"
29-
"github.com/containerd/containerd/pkg/dialer"
3027
ptypes "github.com/gogo/protobuf/types"
28+
"github.com/google/cadvisor/container/containerd/containers"
29+
"github.com/google/cadvisor/container/containerd/errdefs"
30+
"github.com/google/cadvisor/container/containerd/pkg/dialer"
3131
"google.golang.org/grpc"
3232
"google.golang.org/grpc/backoff"
3333
)

container/containerd/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020

21-
"github.com/containerd/containerd/containers"
21+
"github.com/google/cadvisor/container/containerd/containers"
2222
)
2323

2424
type containerdClientMock struct {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
/*
15+
Copyright The containerd Authors.
16+
17+
Licensed under the Apache License, Version 2.0 (the "License");
18+
you may not use this file except in compliance with the License.
19+
You may obtain a copy of the License at
20+
21+
http://www.apache.org/licenses/LICENSE-2.0
22+
23+
Unless required by applicable law or agreed to in writing, software
24+
distributed under the License is distributed on an "AS IS" BASIS,
25+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
See the License for the specific language governing permissions and
27+
limitations under the License.
28+
*/
29+
30+
package containers
31+
32+
import (
33+
"context"
34+
"time"
35+
36+
"github.com/gogo/protobuf/types"
37+
)
38+
39+
// Container represents the set of data pinned by a container. Unless otherwise
40+
// noted, the resources here are considered in use by the container.
41+
//
42+
// The resources specified in this object are used to create tasks from the container.
43+
type Container struct {
44+
// ID uniquely identifies the container in a namespace.
45+
//
46+
// This property is required and cannot be changed after creation.
47+
ID string
48+
49+
// Labels provide metadata extension for a container.
50+
//
51+
// These are optional and fully mutable.
52+
Labels map[string]string
53+
54+
// Image specifies the image reference used for a container.
55+
//
56+
// This property is optional and mutable.
57+
Image string
58+
59+
// Runtime specifies which runtime should be used when launching container
60+
// tasks.
61+
//
62+
// This property is required and immutable.
63+
Runtime RuntimeInfo
64+
65+
// Spec should carry the runtime specification used to implement the
66+
// container.
67+
//
68+
// This field is required but mutable.
69+
Spec *types.Any
70+
71+
// SnapshotKey specifies the snapshot key to use for the container's root
72+
// filesystem. When starting a task from this container, a caller should
73+
// look up the mounts from the snapshot service and include those on the
74+
// task create request.
75+
//
76+
// This field is not required but mutable.
77+
SnapshotKey string
78+
79+
// Snapshotter specifies the snapshotter name used for rootfs
80+
//
81+
// This field is not required but immutable.
82+
Snapshotter string
83+
84+
// CreatedAt is the time at which the container was created.
85+
CreatedAt time.Time
86+
87+
// UpdatedAt is the time at which the container was updated.
88+
UpdatedAt time.Time
89+
90+
// Extensions stores client-specified metadata
91+
Extensions map[string]types.Any
92+
}
93+
94+
// RuntimeInfo holds runtime specific information
95+
type RuntimeInfo struct {
96+
Name string
97+
Options *types.Any
98+
}
99+
100+
// Store interacts with the underlying container storage
101+
type Store interface {
102+
// Get a container using the id.
103+
//
104+
// Container object is returned on success. If the id is not known to the
105+
// store, an error will be returned.
106+
Get(ctx context.Context, id string) (Container, error)
107+
108+
// List returns containers that match one or more of the provided filters.
109+
List(ctx context.Context, filters ...string) ([]Container, error)
110+
111+
// Create a container in the store from the provided container.
112+
Create(ctx context.Context, container Container) (Container, error)
113+
114+
// Update the container with the provided container object. ID must be set.
115+
//
116+
// If one or more fieldpaths are provided, only the field corresponding to
117+
// the fieldpaths will be mutated.
118+
Update(ctx context.Context, container Container, fieldpaths ...string) (Container, error)
119+
120+
// Delete a container using the id.
121+
//
122+
// nil will be returned on success. If the container is not known to the
123+
// store, ErrNotFound will be returned.
124+
Delete(ctx context.Context, id string) error
125+
}
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
/*
15+
Copyright The containerd Authors.
16+
17+
Licensed under the Apache License, Version 2.0 (the "License");
18+
you may not use this file except in compliance with the License.
19+
You may obtain a copy of the License at
20+
21+
http://www.apache.org/licenses/LICENSE-2.0
22+
23+
Unless required by applicable law or agreed to in writing, software
24+
distributed under the License is distributed on an "AS IS" BASIS,
25+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
See the License for the specific language governing permissions and
27+
limitations under the License.
28+
*/
29+
30+
// Package errdefs defines the common errors used throughout containerd
31+
// packages.
32+
//
33+
// Use with errors.Wrap and error.Wrapf to add context to an error.
34+
//
35+
// To detect an error class, use the IsXXX functions to tell whether an error
36+
// is of a certain type.
37+
//
38+
// The functions ToGRPC and FromGRPC can be used to map server-side and
39+
// client-side errors to the correct types.
40+
package errdefs
41+
42+
import (
43+
"context"
44+
45+
"github.com/pkg/errors"
46+
)
47+
48+
// Definitions of common error types used throughout containerd. All containerd
49+
// errors returned by most packages will map into one of these errors classes.
50+
// Packages should return errors of these types when they want to instruct a
51+
// client to take a particular action.
52+
//
53+
// For the most part, we just try to provide local grpc errors. Most conditions
54+
// map very well to those defined by grpc.
55+
var (
56+
ErrUnknown = errors.New("unknown") // used internally to represent a missed mapping.
57+
ErrInvalidArgument = errors.New("invalid argument")
58+
ErrNotFound = errors.New("not found")
59+
ErrAlreadyExists = errors.New("already exists")
60+
ErrFailedPrecondition = errors.New("failed precondition")
61+
ErrUnavailable = errors.New("unavailable")
62+
ErrNotImplemented = errors.New("not implemented") // represents not supported and unimplemented
63+
)
64+
65+
// IsInvalidArgument returns true if the error is due to an invalid argument
66+
func IsInvalidArgument(err error) bool {
67+
return errors.Is(err, ErrInvalidArgument)
68+
}
69+
70+
// IsNotFound returns true if the error is due to a missing object
71+
func IsNotFound(err error) bool {
72+
return errors.Is(err, ErrNotFound)
73+
}
74+
75+
// IsAlreadyExists returns true if the error is due to an already existing
76+
// metadata item
77+
func IsAlreadyExists(err error) bool {
78+
return errors.Is(err, ErrAlreadyExists)
79+
}
80+
81+
// IsFailedPrecondition returns true if an operation could not proceed to the
82+
// lack of a particular condition
83+
func IsFailedPrecondition(err error) bool {
84+
return errors.Is(err, ErrFailedPrecondition)
85+
}
86+
87+
// IsUnavailable returns true if the error is due to a resource being unavailable
88+
func IsUnavailable(err error) bool {
89+
return errors.Is(err, ErrUnavailable)
90+
}
91+
92+
// IsNotImplemented returns true if the error is due to not being implemented
93+
func IsNotImplemented(err error) bool {
94+
return errors.Is(err, ErrNotImplemented)
95+
}
96+
97+
// IsCanceled returns true if the error is due to `context.Canceled`.
98+
func IsCanceled(err error) bool {
99+
return errors.Is(err, context.Canceled)
100+
}
101+
102+
// IsDeadlineExceeded returns true if the error is due to
103+
// `context.DeadlineExceeded`.
104+
func IsDeadlineExceeded(err error) bool {
105+
return errors.Is(err, context.DeadlineExceeded)
106+
}

0 commit comments

Comments
 (0)