Skip to content

Commit

Permalink
Use defaults package for listing namespace labels
Browse files Browse the repository at this point in the history
Labels that are used for configuring defaults are moved to defaults package

Signed-off-by: Nikhil Soni <krsoninikhil@gmail.com>
  • Loading branch information
krsoninikhil committed Feb 11, 2019
1 parent da2ab86 commit 6a21728
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
namespaces := c.NamespaceService()
ctx := context.Background()
if labels, err := namespaces.Labels(ctx, copts.defaultns); err == nil {
if defaultRuntime, ok := labels["containerd.io/defaults/runtime"]; ok {
if defaultRuntime, ok := labels[defaults.DefaultRuntimeNSLabel]; ok {
c.runtime = defaultRuntime
}
} else {
Expand Down Expand Up @@ -174,7 +174,7 @@ func NewWithConn(conn *grpc.ClientConn, opts ...ClientOpt) (*Client, error) {
namespaces := c.NamespaceService()
ctx := context.Background()
if labels, err := namespaces.Labels(ctx, copts.defaultns); err == nil {
if defaultRuntime, ok := labels["containerd.io/defaults/runtime"]; ok {
if defaultRuntime, ok := labels[defaults.DefaultRuntimeNSLabel]; ok {
c.runtime = defaultRuntime
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"testing"
"time"

"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
Expand Down Expand Up @@ -405,7 +406,7 @@ func TestDefaultRuntimeWithNamespaceLabels(t *testing.T) {
defer cancel()
namespaces := client.NamespaceService()
testRuntime := "testRuntime"
runtimeLabel := "containerd.io/defaults/runtime"
runtimeLabel := defaults.DefaultRuntimeNSLabel
if err := namespaces.SetLabel(ctx, testNamespace, runtimeLabel, testRuntime); err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion container_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"
Expand Down Expand Up @@ -172,7 +173,7 @@ func setSnapshotterIfEmpty(ctx context.Context, client *Client, c *containers.Co
namespaceService := client.NamespaceService()
if ns, err := namespaces.NamespaceRequired(ctx); err == nil {
if labels, err := namespaceService.Labels(ctx, ns); err == nil {
if snapshotLabel, ok := labels["containerd.io/defaults/snapshotter"]; ok {
if snapshotLabel, ok := labels[defaults.DefaultSnapshotterNSLabel]; ok {
defaultSnapshotter = snapshotLabel
}
}
Expand Down
6 changes: 6 additions & 0 deletions defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ const (
// DefaultMaxSendMsgSize defines the default maximum message size for
// sending protobufs passed over the GRPC API.
DefaultMaxSendMsgSize = 16 << 20
// DefaultRuntimeNSLabel defines the namespace label to check for
// default runtime
DefaultRuntimeNSLabel = "containerd.io/defaults/runtime"
// DefaultSnapshotterNSLabel defines the namespances label to check for
// default snapshotter
DefaultSnapshotterNSLabel = "containerd.io/defaults/snapshotter"
)

0 comments on commit 6a21728

Please sign in to comment.