Skip to content

Commit

Permalink
Support CRI v1 API
Browse files Browse the repository at this point in the history
This commit adds support for CRI v1 API for CRI proxy.
We still support CRI v1alpha API because containerd supports it.
We'll drop that API once containerd drops that API.

Signed-off-by: Kohei Tokunaga <[email protected]>
  • Loading branch information
ktock committed Nov 30, 2022
1 parent aaa46a7 commit 03fc518
Show file tree
Hide file tree
Showing 17 changed files with 43,315 additions and 219 deletions.
47 changes: 31 additions & 16 deletions cmd/containerd-stargz-grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
"github.com/containerd/stargz-snapshotter/service/keychain/crialpha"
)

const (
Expand Down Expand Up @@ -152,28 +154,24 @@ func main() {
criAddr = cp
}
connectCRI := func() (runtime.ImageServiceClient, error) {
// TODO: make gRPC options configurable from config.toml
backoffConfig := backoff.DefaultConfig
backoffConfig.MaxDelay = 3 * time.Second
connParams := grpc.ConnectParams{
Backoff: backoffConfig,
}
gopts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithConnectParams(connParams),
grpc.WithContextDialer(dialer.ContextDialer),
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
}
conn, err := grpc.Dial(dialer.DialAddress(criAddr), gopts...)
conn, err := newCRIConn(criAddr)
if err != nil {
return nil, err
}
return runtime.NewImageServiceClient(conn), nil
}
connectAlphaCRI := func() (runtime_alpha.ImageServiceClient, error) {
conn, err := newCRIConn(criAddr)
if err != nil {
return nil, err
}
return runtime_alpha.NewImageServiceClient(conn), nil
}
f, criServer := cri.NewCRIKeychain(ctx, connectCRI)
fAlpha, criAlphaServer := crialpha.NewCRIAlphaKeychain(ctx, connectAlphaCRI)
runtime.RegisterImageServiceServer(rpc, criServer)
credsFuncs = append(credsFuncs, f)
runtime_alpha.RegisterImageServiceServer(rpc, criAlphaServer)
credsFuncs = append(credsFuncs, f, fAlpha)
}
fsOpts := []fs.Option{fs.WithMetricsLogLevel(logrus.InfoLevel)}
if config.IPFS {
Expand Down Expand Up @@ -313,3 +311,20 @@ func getMetadataStore(rootDir string, config snapshotterConfig) (metadata.Store,
config.MetadataStore, memoryMetadataType, dbMetadataType)
}
}

func newCRIConn(criAddr string) (*grpc.ClientConn, error) {
// TODO: make gRPC options configurable from config.toml
backoffConfig := backoff.DefaultConfig
backoffConfig.MaxDelay = 3 * time.Second
connParams := grpc.ConnectParams{
Backoff: backoffConfig,
}
gopts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithConnectParams(connParams),
grpc.WithContextDialer(dialer.ContextDialer),
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
}
return grpc.Dial(dialer.DialAddress(criAddr), gopts...)
}
10 changes: 5 additions & 5 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/containerd/stargz-snapshotter/cmd
go 1.16

require (
github.com/containerd/containerd v1.6.10
github.com/containerd/containerd v1.7.0-beta.0.0.20221118211334-792294ce06bf
github.com/containerd/go-cni v1.1.7
github.com/containerd/stargz-snapshotter v0.13.0
github.com/containerd/stargz-snapshotter/estargz v0.13.0
Expand All @@ -16,17 +16,17 @@ require (
github.com/ipfs/interface-go-ipfs-core v0.7.0
github.com/klauspost/compress v1.15.12
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/pelletier/go-toml v1.9.5
github.com/rs/xid v1.4.0
github.com/sirupsen/logrus v1.9.0
github.com/urfave/cli v1.22.5
github.com/urfave/cli v1.22.9
go.etcd.io/bbolt v1.3.6
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/sync v0.1.0
golang.org/x/sys v0.2.0
google.golang.org/grpc v1.50.1
k8s.io/cri-api v0.26.0-alpha.3
k8s.io/cri-api v0.27.0-alpha.0
)

replace (
Expand Down
600 changes: 567 additions & 33 deletions cmd/go.sum

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@ go 1.16

require (
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.10
github.com/containerd/containerd v1.7.0-beta.0.0.20221118211334-792294ce06bf
github.com/containerd/continuity v0.3.0
github.com/containerd/stargz-snapshotter/estargz v0.13.0
github.com/docker/cli v20.10.21+incompatible
github.com/docker/docker v20.10.7+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-metrics v0.0.1
github.com/gogo/protobuf v1.3.2
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/hanwen/go-fuse/v2 v2.1.1-0.20220112183258-f57e95bda82d
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/klauspost/compress v1.15.12
github.com/moby/sys/mountinfo v0.6.2
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/prometheus/client_golang v1.14.0
github.com/rs/xid v1.4.0
github.com/sirupsen/logrus v1.9.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/sync v0.1.0
golang.org/x/sys v0.2.0
google.golang.org/grpc v1.50.1
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
k8s.io/cri-api v0.26.0-alpha.3
k8s.io/cri-api v0.27.0-alpha.0
)

replace (
Expand Down
Loading

0 comments on commit 03fc518

Please sign in to comment.