Skip to content

Commit c6594b1

Browse files
authoredDec 6, 2022
Merge pull request #1011 from ktock/cri-v1
Support CRI v1 API
2 parents aaa46a7 + c8dcd54 commit c6594b1

File tree

18 files changed

+43340
-203
lines changed

18 files changed

+43340
-203
lines changed
 

‎cmd/containerd-stargz-grpc/main.go

+31-16
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ import (
5757
"google.golang.org/grpc"
5858
"google.golang.org/grpc/backoff"
5959
"google.golang.org/grpc/credentials/insecure"
60-
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
60+
runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
61+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
62+
"github.com/containerd/stargz-snapshotter/service/keychain/crialpha"
6163
)
6264

6365
const (
@@ -152,28 +154,24 @@ func main() {
152154
criAddr = cp
153155
}
154156
connectCRI := func() (runtime.ImageServiceClient, error) {
155-
// TODO: make gRPC options configurable from config.toml
156-
backoffConfig := backoff.DefaultConfig
157-
backoffConfig.MaxDelay = 3 * time.Second
158-
connParams := grpc.ConnectParams{
159-
Backoff: backoffConfig,
160-
}
161-
gopts := []grpc.DialOption{
162-
grpc.WithTransportCredentials(insecure.NewCredentials()),
163-
grpc.WithConnectParams(connParams),
164-
grpc.WithContextDialer(dialer.ContextDialer),
165-
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
166-
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
167-
}
168-
conn, err := grpc.Dial(dialer.DialAddress(criAddr), gopts...)
157+
conn, err := newCRIConn(criAddr)
169158
if err != nil {
170159
return nil, err
171160
}
172161
return runtime.NewImageServiceClient(conn), nil
173162
}
163+
connectAlphaCRI := func() (runtime_alpha.ImageServiceClient, error) {
164+
conn, err := newCRIConn(criAddr)
165+
if err != nil {
166+
return nil, err
167+
}
168+
return runtime_alpha.NewImageServiceClient(conn), nil
169+
}
174170
f, criServer := cri.NewCRIKeychain(ctx, connectCRI)
171+
fAlpha, criAlphaServer := crialpha.NewCRIAlphaKeychain(ctx, connectAlphaCRI)
175172
runtime.RegisterImageServiceServer(rpc, criServer)
176-
credsFuncs = append(credsFuncs, f)
173+
runtime_alpha.RegisterImageServiceServer(rpc, criAlphaServer)
174+
credsFuncs = append(credsFuncs, f, fAlpha)
177175
}
178176
fsOpts := []fs.Option{fs.WithMetricsLogLevel(logrus.InfoLevel)}
179177
if config.IPFS {
@@ -313,3 +311,20 @@ func getMetadataStore(rootDir string, config snapshotterConfig) (metadata.Store,
313311
config.MetadataStore, memoryMetadataType, dbMetadataType)
314312
}
315313
}
314+
315+
func newCRIConn(criAddr string) (*grpc.ClientConn, error) {
316+
// TODO: make gRPC options configurable from config.toml
317+
backoffConfig := backoff.DefaultConfig
318+
backoffConfig.MaxDelay = 3 * time.Second
319+
connParams := grpc.ConnectParams{
320+
Backoff: backoffConfig,
321+
}
322+
gopts := []grpc.DialOption{
323+
grpc.WithTransportCredentials(insecure.NewCredentials()),
324+
grpc.WithConnectParams(connParams),
325+
grpc.WithContextDialer(dialer.ContextDialer),
326+
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
327+
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
328+
}
329+
return grpc.Dial(dialer.DialAddress(criAddr), gopts...)
330+
}

‎cmd/go.mod

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/containerd/stargz-snapshotter/cmd
33
go 1.16
44

55
require (
6-
github.com/containerd/containerd v1.6.10
6+
github.com/containerd/containerd v1.7.0-beta.0.0.20221118211334-792294ce06bf
77
github.com/containerd/go-cni v1.1.7
88
github.com/containerd/stargz-snapshotter v0.13.0
99
github.com/containerd/stargz-snapshotter/estargz v0.13.0
@@ -16,17 +16,17 @@ require (
1616
github.com/ipfs/interface-go-ipfs-core v0.7.0
1717
github.com/klauspost/compress v1.15.12
1818
github.com/opencontainers/go-digest v1.0.0
19-
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
19+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
2020
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
2121
github.com/pelletier/go-toml v1.9.5
2222
github.com/rs/xid v1.4.0
2323
github.com/sirupsen/logrus v1.9.0
24-
github.com/urfave/cli v1.22.5
24+
github.com/urfave/cli v1.22.9
2525
go.etcd.io/bbolt v1.3.6
26-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
26+
golang.org/x/sync v0.1.0
2727
golang.org/x/sys v0.2.0
2828
google.golang.org/grpc v1.50.1
29-
k8s.io/cri-api v0.26.0-alpha.3
29+
k8s.io/cri-api v0.27.0-alpha.0
3030
)
3131

3232
replace (

‎cmd/go.sum

+567-33
Large diffs are not rendered by default.

‎go.mod

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@ go 1.16
44

55
require (
66
github.com/containerd/console v1.0.3
7-
github.com/containerd/containerd v1.6.10
7+
github.com/containerd/containerd v1.7.0-beta.0.0.20221118211334-792294ce06bf
88
github.com/containerd/continuity v0.3.0
99
github.com/containerd/stargz-snapshotter/estargz v0.13.0
1010
github.com/docker/cli v20.10.21+incompatible
1111
github.com/docker/docker v20.10.7+incompatible // indirect
1212
github.com/docker/docker-credential-helpers v0.6.4 // indirect
1313
github.com/docker/go-metrics v0.0.1
14+
github.com/gogo/protobuf v1.3.2
1415
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
1516
github.com/hanwen/go-fuse/v2 v2.1.1-0.20220112183258-f57e95bda82d
1617
github.com/hashicorp/go-multierror v1.1.1
1718
github.com/hashicorp/go-retryablehttp v0.7.1
1819
github.com/klauspost/compress v1.15.12
1920
github.com/moby/sys/mountinfo v0.6.2
2021
github.com/opencontainers/go-digest v1.0.0
21-
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
22+
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
2223
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
2324
github.com/pelletier/go-toml v1.9.4 // indirect
2425
github.com/prometheus/client_golang v1.14.0
2526
github.com/rs/xid v1.4.0
2627
github.com/sirupsen/logrus v1.9.0
27-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
28+
golang.org/x/sync v0.1.0
2829
golang.org/x/sys v0.2.0
2930
google.golang.org/grpc v1.50.1
3031
k8s.io/api v0.25.4
3132
k8s.io/apimachinery v0.25.4
3233
k8s.io/client-go v0.25.4
33-
k8s.io/cri-api v0.26.0-alpha.3
34+
k8s.io/cri-api v0.27.0-alpha.0
3435
)
3536

3637
replace (

‎go.sum

+562-30
Large diffs are not rendered by default.

‎script/k3s-argo-workflow/run.sh

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ cat <<EOF >> "${TMP_K3S_REPO}/go.mod"
126126
replace github.com/containerd/stargz-snapshotter => "$(realpath ${REPO})"
127127
replace github.com/containerd/stargz-snapshotter/estargz => "$(realpath ${REPO}/estargz)"
128128
EOF
129+
130+
# k3s doesn't imports the latest version of containerd that includes their own
131+
# CRI v1alpha API fork (github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2).
132+
# So we bring our own CRI v1alpha API fork in our k3s test.
133+
#
134+
# TODO: Once k3s bring contianerd version to newer than 234bf990dca4e81e89f549448aa6b555286eaa7a, we can switch import
135+
# to github.com/containerd/stargz-snapshotter/service/plugin
136+
sed -i "s|github.com/containerd/stargz-snapshotter/service/plugin|github.com/containerd/stargz-snapshotter/service/pluginforked|g" "${TMP_K3S_REPO}/pkg/containerd/builtins_linux.go"
137+
129138
sed -i -E 's|(ENV DAPPER_RUN_ARGS .*)|\1 -v '"$(realpath ${REPO})":"$(realpath ${REPO})"':ro|g' "${TMP_K3S_REPO}/Dockerfile.dapper"
130139
sed -i -E 's|(ENV DAPPER_ENV .*)|\1 DOCKER_BUILDKIT|g' "${TMP_K3S_REPO}/Dockerfile.dapper"
131140
(

‎script/k3s/run-k3s.sh

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ cat <<EOF >> "${TMP_K3S_REPO}/go.mod"
5555
replace github.com/containerd/stargz-snapshotter => "$(realpath ${REPO})"
5656
replace github.com/containerd/stargz-snapshotter/estargz => "$(realpath ${REPO}/estargz)"
5757
EOF
58+
59+
# k3s doesn't imports the latest version of containerd that includes their own
60+
# CRI v1alpha API fork (github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2).
61+
# So we bring our own CRI v1alpha API fork in our k3s test.
62+
#
63+
# TODO: Once k3s bring contianerd version to newer than 234bf990dca4e81e89f549448aa6b555286eaa7a, we can switch import
64+
# to github.com/containerd/stargz-snapshotter/service/plugin
65+
sed -i "s|github.com/containerd/stargz-snapshotter/service/plugin|github.com/containerd/stargz-snapshotter/service/pluginforked|g" "${TMP_K3S_REPO}/pkg/containerd/builtins_linux.go"
66+
5867
sed -i -E 's|(ENV DAPPER_RUN_ARGS .*)|\1 -v '"$(realpath ${REPO})":"$(realpath ${REPO})"':ro|g' "${TMP_K3S_REPO}/Dockerfile.dapper"
5968
sed -i -E 's|(ENV DAPPER_ENV .*)|\1 DOCKER_BUILDKIT|g' "${TMP_K3S_REPO}/Dockerfile.dapper"
6069
(

‎service/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Note about importing of `github.com/containerd/stargz-snapshotter/service/plugin`
2+
3+
`github.com/containerd/stargz-snapshotter/service/plugin` registeres our stargz snapshotter plugin to the containerd plugin system.
4+
This depends on containerd newer than [234bf990dca4e81e89f549448aa6b555286eaa7a](https://github.com/containerd/containerd/commit/234bf990dca4e81e89f549448aa6b555286eaa7a) which contains CRI v1alpha API fork.
5+
6+
If you import this plugin to the tool that imports older version of containerd, import `github.com/containerd/stargz-snapshotter/service/pluginforked` instead.
7+
This plugin contains our forked CRI v1alpha API.
8+
9+
Once you upgrade containerd to newer than 234bf990dca4e81e89f549448aa6b555286eaa7a, you can't use `github.com/containerd/stargz-snapshotter/service/pluginforked` and protobuf code fails with the error e.g. `proto: duplicate enum registered: runtime.v1alpha2.Protocol`. In this case, use `github.com/containerd/stargz-snapshotter/service/plugin`.

‎service/keychain/cri/cri.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/containerd/containerd/reference"
2828
distribution "github.com/containerd/containerd/reference/docker"
2929
"github.com/containerd/stargz-snapshotter/service/resolver"
30-
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
30+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
3131
)
3232

3333
// NewCRIKeychain provides creds passed through CRI PullImage API.

‎service/keychain/crialpha/crialpha.go

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package crialpha
18+
19+
import (
20+
"context"
21+
"errors"
22+
"fmt"
23+
"sync"
24+
"time"
25+
26+
"github.com/containerd/containerd/log"
27+
"github.com/containerd/containerd/reference"
28+
distribution "github.com/containerd/containerd/reference/docker"
29+
"github.com/containerd/stargz-snapshotter/service/resolver"
30+
31+
runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
32+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
33+
)
34+
35+
// containerd newer than 234bf990dca4e81e89f549448aa6b555286eaa7a is required for this plugin.
36+
// If not, use "github.com/containerd/stargz-snapshotter/service/keychain/crialphaforked" instead.
37+
38+
// NewAlphaCRIKeychain provides creds passed through CRI PullImage API.
39+
// Same as NewCRIKeychain but for CRI v1alpha API.
40+
// Containerd doesn't drop v1alpha API support so our proxy also exposes this API as well.
41+
func NewCRIAlphaKeychain(ctx context.Context, connectCRI func() (runtime_alpha.ImageServiceClient, error)) (resolver.Credential, runtime_alpha.ImageServiceServer) {
42+
server := &instrumentedAlphaService{config: make(map[string]*runtime_alpha.AuthConfig)}
43+
go func() {
44+
log.G(ctx).Debugf("Waiting for CRI service is started...")
45+
for i := 0; i < 100; i++ {
46+
client, err := connectCRI()
47+
if err == nil {
48+
server.criMu.Lock()
49+
server.cri = client
50+
server.criMu.Unlock()
51+
log.G(ctx).Info("connected to backend CRI service")
52+
return
53+
}
54+
log.G(ctx).WithError(err).Warnf("failed to connect to CRI")
55+
time.Sleep(10 * time.Second)
56+
}
57+
log.G(ctx).Warnf("no connection is available to CRI")
58+
}()
59+
return server.credentials, server
60+
}
61+
62+
type instrumentedAlphaService struct {
63+
cri runtime_alpha.ImageServiceClient
64+
criMu sync.Mutex
65+
66+
config map[string]*runtime_alpha.AuthConfig
67+
configMu sync.Mutex
68+
}
69+
70+
func (in *instrumentedAlphaService) credentials(host string, refspec reference.Spec) (string, string, error) {
71+
if host == "docker.io" || host == "registry-1.docker.io" {
72+
// Creds of "docker.io" is stored keyed by "https://index.docker.io/v1/".
73+
host = "index.docker.io"
74+
}
75+
in.configMu.Lock()
76+
defer in.configMu.Unlock()
77+
if cfg, ok := in.config[refspec.String()]; ok {
78+
var v1cfg runtime.AuthConfig
79+
if err := alphaReqToV1Req(cfg, &v1cfg); err != nil {
80+
return "", "", err
81+
}
82+
return resolver.ParseAuth(&v1cfg, host)
83+
}
84+
return "", "", nil
85+
}
86+
87+
func (in *instrumentedAlphaService) getCRI() (c runtime_alpha.ImageServiceClient) {
88+
in.criMu.Lock()
89+
c = in.cri
90+
in.criMu.Unlock()
91+
return
92+
}
93+
94+
func (in *instrumentedAlphaService) ListImages(ctx context.Context, r *runtime_alpha.ListImagesRequest) (res *runtime_alpha.ListImagesResponse, err error) {
95+
cri := in.getCRI()
96+
if cri == nil {
97+
return nil, errors.New("server is not initialized yet")
98+
}
99+
return cri.ListImages(ctx, r)
100+
}
101+
102+
func (in *instrumentedAlphaService) ImageStatus(ctx context.Context, r *runtime_alpha.ImageStatusRequest) (res *runtime_alpha.ImageStatusResponse, err error) {
103+
cri := in.getCRI()
104+
if cri == nil {
105+
return nil, errors.New("server is not initialized yet")
106+
}
107+
return cri.ImageStatus(ctx, r)
108+
}
109+
110+
func (in *instrumentedAlphaService) PullImage(ctx context.Context, r *runtime_alpha.PullImageRequest) (res *runtime_alpha.PullImageResponse, err error) {
111+
cri := in.getCRI()
112+
if cri == nil {
113+
return nil, errors.New("server is not initialized yet")
114+
}
115+
refspec, err := parseReference(r.GetImage().GetImage())
116+
if err != nil {
117+
return nil, err
118+
}
119+
in.configMu.Lock()
120+
in.config[refspec.String()] = r.GetAuth()
121+
in.configMu.Unlock()
122+
return cri.PullImage(ctx, r)
123+
}
124+
125+
func (in *instrumentedAlphaService) RemoveImage(ctx context.Context, r *runtime_alpha.RemoveImageRequest) (_ *runtime_alpha.RemoveImageResponse, err error) {
126+
cri := in.getCRI()
127+
if cri == nil {
128+
return nil, errors.New("server is not initialized yet")
129+
}
130+
refspec, err := parseReference(r.GetImage().GetImage())
131+
if err != nil {
132+
return nil, err
133+
}
134+
in.configMu.Lock()
135+
delete(in.config, refspec.String())
136+
in.configMu.Unlock()
137+
return cri.RemoveImage(ctx, r)
138+
}
139+
140+
func (in *instrumentedAlphaService) ImageFsInfo(ctx context.Context, r *runtime_alpha.ImageFsInfoRequest) (res *runtime_alpha.ImageFsInfoResponse, err error) {
141+
cri := in.getCRI()
142+
if cri == nil {
143+
return nil, errors.New("server is not initialized yet")
144+
}
145+
return cri.ImageFsInfo(ctx, r)
146+
}
147+
148+
// NOTE: Ported from https://github.com/containerd/containerd/blob/792294ce06bfbd1fe07b458bfa066e6ef8b17046/pkg/cri/server/instrumented_service.go#L1704-L1717
149+
func alphaReqToV1Req(
150+
alphar interface{ Marshal() ([]byte, error) },
151+
v1r interface{ Unmarshal(_ []byte) error },
152+
) error {
153+
p, err := alphar.Marshal()
154+
if err != nil {
155+
return err
156+
}
157+
158+
if err = v1r.Unmarshal(p); err != nil {
159+
return err
160+
}
161+
return nil
162+
}
163+
164+
func parseReference(ref string) (reference.Spec, error) {
165+
namedRef, err := distribution.ParseDockerRef(ref)
166+
if err != nil {
167+
return reference.Spec{}, fmt.Errorf("failed to parse image reference %q: %w", ref, err)
168+
}
169+
return reference.Parse(namedRef.String())
170+
}
+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package crialphaforked
18+
19+
import (
20+
"context"
21+
"errors"
22+
"fmt"
23+
"sync"
24+
"time"
25+
26+
"github.com/containerd/containerd/log"
27+
"github.com/containerd/containerd/reference"
28+
distribution "github.com/containerd/containerd/reference/docker"
29+
"github.com/containerd/stargz-snapshotter/service/resolver"
30+
31+
// We have our own fork to enable to be imported to tools that don't import the recent commit of containerd (e.g. k3s).
32+
runtime_alpha "github.com/containerd/stargz-snapshotter/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
33+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
34+
)
35+
36+
// This plugin provides the forked CRI v1alpha API. This should be used if this plugin is imported to tools that
37+
// doesn't import containerd newer than 234bf990dca4e81e89f549448aa6b555286eaa7a.
38+
39+
// NewAlphaCRIKeychain provides creds passed through CRI PullImage API.
40+
// Same as NewCRIKeychain but for CRI v1alpha API.
41+
// Containerd doesn't drop v1alpha API support so our proxy also exposes this API as well.
42+
func NewCRIAlphaKeychain(ctx context.Context, connectCRI func() (runtime_alpha.ImageServiceClient, error)) (resolver.Credential, runtime_alpha.ImageServiceServer) {
43+
server := &instrumentedAlphaService{config: make(map[string]*runtime_alpha.AuthConfig)}
44+
go func() {
45+
log.G(ctx).Debugf("Waiting for CRI service is started...")
46+
for i := 0; i < 100; i++ {
47+
client, err := connectCRI()
48+
if err == nil {
49+
server.criMu.Lock()
50+
server.cri = client
51+
server.criMu.Unlock()
52+
log.G(ctx).Info("connected to backend CRI service")
53+
return
54+
}
55+
log.G(ctx).WithError(err).Warnf("failed to connect to CRI")
56+
time.Sleep(10 * time.Second)
57+
}
58+
log.G(ctx).Warnf("no connection is available to CRI")
59+
}()
60+
return server.credentials, server
61+
}
62+
63+
type instrumentedAlphaService struct {
64+
cri runtime_alpha.ImageServiceClient
65+
criMu sync.Mutex
66+
67+
config map[string]*runtime_alpha.AuthConfig
68+
configMu sync.Mutex
69+
}
70+
71+
func (in *instrumentedAlphaService) credentials(host string, refspec reference.Spec) (string, string, error) {
72+
if host == "docker.io" || host == "registry-1.docker.io" {
73+
// Creds of "docker.io" is stored keyed by "https://index.docker.io/v1/".
74+
host = "index.docker.io"
75+
}
76+
in.configMu.Lock()
77+
defer in.configMu.Unlock()
78+
if cfg, ok := in.config[refspec.String()]; ok {
79+
var v1cfg runtime.AuthConfig
80+
if err := alphaReqToV1Req(cfg, &v1cfg); err != nil {
81+
return "", "", err
82+
}
83+
return resolver.ParseAuth(&v1cfg, host)
84+
}
85+
return "", "", nil
86+
}
87+
88+
func (in *instrumentedAlphaService) getCRI() (c runtime_alpha.ImageServiceClient) {
89+
in.criMu.Lock()
90+
c = in.cri
91+
in.criMu.Unlock()
92+
return
93+
}
94+
95+
func (in *instrumentedAlphaService) ListImages(ctx context.Context, r *runtime_alpha.ListImagesRequest) (res *runtime_alpha.ListImagesResponse, err error) {
96+
cri := in.getCRI()
97+
if cri == nil {
98+
return nil, errors.New("server is not initialized yet")
99+
}
100+
return cri.ListImages(ctx, r)
101+
}
102+
103+
func (in *instrumentedAlphaService) ImageStatus(ctx context.Context, r *runtime_alpha.ImageStatusRequest) (res *runtime_alpha.ImageStatusResponse, err error) {
104+
cri := in.getCRI()
105+
if cri == nil {
106+
return nil, errors.New("server is not initialized yet")
107+
}
108+
return cri.ImageStatus(ctx, r)
109+
}
110+
111+
func (in *instrumentedAlphaService) PullImage(ctx context.Context, r *runtime_alpha.PullImageRequest) (res *runtime_alpha.PullImageResponse, err error) {
112+
cri := in.getCRI()
113+
if cri == nil {
114+
return nil, errors.New("server is not initialized yet")
115+
}
116+
refspec, err := parseReference(r.GetImage().GetImage())
117+
if err != nil {
118+
return nil, err
119+
}
120+
in.configMu.Lock()
121+
in.config[refspec.String()] = r.GetAuth()
122+
in.configMu.Unlock()
123+
return cri.PullImage(ctx, r)
124+
}
125+
126+
func (in *instrumentedAlphaService) RemoveImage(ctx context.Context, r *runtime_alpha.RemoveImageRequest) (_ *runtime_alpha.RemoveImageResponse, err error) {
127+
cri := in.getCRI()
128+
if cri == nil {
129+
return nil, errors.New("server is not initialized yet")
130+
}
131+
refspec, err := parseReference(r.GetImage().GetImage())
132+
if err != nil {
133+
return nil, err
134+
}
135+
in.configMu.Lock()
136+
delete(in.config, refspec.String())
137+
in.configMu.Unlock()
138+
return cri.RemoveImage(ctx, r)
139+
}
140+
141+
func (in *instrumentedAlphaService) ImageFsInfo(ctx context.Context, r *runtime_alpha.ImageFsInfoRequest) (res *runtime_alpha.ImageFsInfoResponse, err error) {
142+
cri := in.getCRI()
143+
if cri == nil {
144+
return nil, errors.New("server is not initialized yet")
145+
}
146+
return cri.ImageFsInfo(ctx, r)
147+
}
148+
149+
// NOTE: Ported from https://github.com/containerd/containerd/blob/792294ce06bfbd1fe07b458bfa066e6ef8b17046/pkg/cri/server/instrumented_service.go#L1704-L1717
150+
func alphaReqToV1Req(
151+
alphar interface{ Marshal() ([]byte, error) },
152+
v1r interface{ Unmarshal(_ []byte) error },
153+
) error {
154+
p, err := alphar.Marshal()
155+
if err != nil {
156+
return err
157+
}
158+
159+
if err = v1r.Unmarshal(p); err != nil {
160+
return err
161+
}
162+
return nil
163+
}
164+
165+
func parseReference(ref string) (reference.Spec, error) {
166+
namedRef, err := distribution.ParseDockerRef(ref)
167+
if err != nil {
168+
return reference.Spec{}, fmt.Errorf("failed to parse image reference %q: %w", ref, err)
169+
}
170+
return reference.Parse(namedRef.String())
171+
}

‎service/plugin/plugin.go

+37-113
Original file line numberDiff line numberDiff line change
@@ -17,130 +17,54 @@
1717
package plugin
1818

1919
import (
20-
"errors"
21-
"fmt"
22-
"net"
23-
"os"
24-
"path/filepath"
20+
"context"
2521
"time"
2622

2723
"github.com/containerd/containerd/defaults"
28-
"github.com/containerd/containerd/log"
2924
"github.com/containerd/containerd/pkg/dialer"
30-
"github.com/containerd/containerd/platforms"
31-
ctdplugin "github.com/containerd/containerd/plugin"
32-
"github.com/containerd/stargz-snapshotter/service"
33-
"github.com/containerd/stargz-snapshotter/service/keychain/cri"
34-
"github.com/containerd/stargz-snapshotter/service/keychain/dockerconfig"
35-
"github.com/containerd/stargz-snapshotter/service/keychain/kubeconfig"
36-
"github.com/containerd/stargz-snapshotter/service/resolver"
3725
grpc "google.golang.org/grpc"
3826
"google.golang.org/grpc/backoff"
3927
"google.golang.org/grpc/credentials/insecure"
40-
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
41-
)
42-
43-
// Config represents configuration for the stargz snapshotter plugin.
44-
type Config struct {
45-
service.Config
4628

47-
// RootPath is the directory for the plugin
48-
RootPath string `toml:"root_path"`
29+
runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
30+
"github.com/containerd/stargz-snapshotter/service/keychain/crialpha"
31+
"github.com/containerd/stargz-snapshotter/service/plugincore"
32+
"github.com/containerd/stargz-snapshotter/service/resolver"
33+
)
4934

50-
// CRIKeychainImageServicePath is the path to expose CRI service wrapped by CRI keychain
51-
CRIKeychainImageServicePath string `toml:"cri_keychain_image_service_path"`
52-
53-
// Registry is CRI-plugin-compatible registry configuration
54-
Registry resolver.Registry `toml:"registry"`
55-
}
35+
// This plugin requires containerd newer than 234bf990dca4e81e89f549448aa6b555286eaa7a.
36+
// If not, use "github.com/containerd/stargz-snapshotter/service/pluginforked" instead.
5637

5738
func init() {
58-
ctdplugin.Register(&ctdplugin.Registration{
59-
Type: ctdplugin.SnapshotPlugin,
60-
ID: "stargz",
61-
Config: &Config{},
62-
InitFn: func(ic *ctdplugin.InitContext) (interface{}, error) {
63-
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
64-
ctx := ic.Context
65-
66-
config, ok := ic.Config.(*Config)
67-
if !ok {
68-
return nil, errors.New("invalid stargz snapshotter configuration")
69-
}
70-
71-
root := ic.Root
72-
if config.RootPath != "" {
73-
root = config.RootPath
74-
}
75-
ic.Meta.Exports["root"] = root
39+
plugincore.RegisterPlugin(registerCRIAlphaServer)
40+
}
7641

77-
// Configure keychain
78-
credsFuncs := []resolver.Credential{dockerconfig.NewDockerconfigKeychain(ctx)}
79-
if config.Config.KubeconfigKeychainConfig.EnableKeychain {
80-
var opts []kubeconfig.Option
81-
if kcp := config.Config.KubeconfigKeychainConfig.KubeconfigPath; kcp != "" {
82-
opts = append(opts, kubeconfig.WithKubeconfigPath(kcp))
83-
}
84-
credsFuncs = append(credsFuncs, kubeconfig.NewKubeconfigKeychain(ctx, opts...))
85-
}
86-
if addr := config.CRIKeychainImageServicePath; config.Config.CRIKeychainConfig.EnableKeychain && addr != "" {
87-
// connects to the backend CRI service (defaults to containerd socket)
88-
criAddr := ic.Address
89-
if cp := config.Config.CRIKeychainConfig.ImageServicePath; cp != "" {
90-
criAddr = cp
91-
}
92-
if criAddr == "" {
93-
return nil, errors.New("backend CRI service address is not specified")
94-
}
95-
connectCRI := func() (runtime.ImageServiceClient, error) {
96-
// TODO: make gRPC options configurable from config.toml
97-
backoffConfig := backoff.DefaultConfig
98-
backoffConfig.MaxDelay = 3 * time.Second
99-
connParams := grpc.ConnectParams{
100-
Backoff: backoffConfig,
101-
}
102-
gopts := []grpc.DialOption{
103-
grpc.WithTransportCredentials(insecure.NewCredentials()),
104-
grpc.WithConnectParams(connParams),
105-
grpc.WithContextDialer(dialer.ContextDialer),
106-
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
107-
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
108-
}
109-
conn, err := grpc.Dial(dialer.DialAddress(criAddr), gopts...)
110-
if err != nil {
111-
return nil, err
112-
}
113-
return runtime.NewImageServiceClient(conn), nil
114-
}
115-
criCreds, criServer := cri.NewCRIKeychain(ctx, connectCRI)
116-
// Create a gRPC server
117-
rpc := grpc.NewServer()
118-
runtime.RegisterImageServiceServer(rpc, criServer)
119-
// Prepare the directory for the socket
120-
if err := os.MkdirAll(filepath.Dir(addr), 0700); err != nil {
121-
return nil, fmt.Errorf("failed to create directory %q: %w", filepath.Dir(addr), err)
122-
}
123-
// Try to remove the socket file to avoid EADDRINUSE
124-
if err := os.RemoveAll(addr); err != nil {
125-
return nil, fmt.Errorf("failed to remove %q: %w", addr, err)
126-
}
127-
// Listen and serve
128-
l, err := net.Listen("unix", addr)
129-
if err != nil {
130-
return nil, fmt.Errorf("error on listen socket %q: %w", addr, err)
131-
}
132-
go func() {
133-
if err := rpc.Serve(l); err != nil {
134-
log.G(ctx).WithError(err).Warnf("error on serving via socket %q", addr)
135-
}
136-
}()
137-
credsFuncs = append(credsFuncs, criCreds)
138-
}
42+
func registerCRIAlphaServer(ctx context.Context, criAddr string, rpc *grpc.Server) resolver.Credential {
43+
connectAlphaCRI := func() (runtime_alpha.ImageServiceClient, error) {
44+
conn, err := newCRIConn(criAddr)
45+
if err != nil {
46+
return nil, err
47+
}
48+
return runtime_alpha.NewImageServiceClient(conn), nil
49+
}
50+
criAlphaCreds, criAlphaServer := crialpha.NewCRIAlphaKeychain(ctx, connectAlphaCRI)
51+
runtime_alpha.RegisterImageServiceServer(rpc, criAlphaServer)
52+
return criAlphaCreds
53+
}
13954

140-
// TODO(ktock): print warn if old configuration is specified.
141-
// TODO(ktock): should we respect old configuration?
142-
return service.NewStargzSnapshotterService(ctx, root, &config.Config,
143-
service.WithCustomRegistryHosts(resolver.RegistryHostsFromCRIConfig(ctx, config.Registry, credsFuncs...)))
144-
},
145-
})
55+
func newCRIConn(criAddr string) (*grpc.ClientConn, error) {
56+
// TODO: make gRPC options configurable from config.toml
57+
backoffConfig := backoff.DefaultConfig
58+
backoffConfig.MaxDelay = 3 * time.Second
59+
connParams := grpc.ConnectParams{
60+
Backoff: backoffConfig,
61+
}
62+
gopts := []grpc.DialOption{
63+
grpc.WithTransportCredentials(insecure.NewCredentials()),
64+
grpc.WithConnectParams(connParams),
65+
grpc.WithContextDialer(dialer.ContextDialer),
66+
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
67+
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
68+
}
69+
return grpc.Dial(dialer.DialAddress(criAddr), gopts...)
14670
}

‎service/plugincore/plugin.go

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package plugincore
18+
19+
import (
20+
"context"
21+
"errors"
22+
"fmt"
23+
"net"
24+
"os"
25+
"path/filepath"
26+
"time"
27+
28+
"github.com/containerd/containerd/defaults"
29+
"github.com/containerd/containerd/log"
30+
"github.com/containerd/containerd/pkg/dialer"
31+
"github.com/containerd/containerd/platforms"
32+
ctdplugin "github.com/containerd/containerd/plugin"
33+
"github.com/containerd/stargz-snapshotter/service"
34+
"github.com/containerd/stargz-snapshotter/service/keychain/cri"
35+
"github.com/containerd/stargz-snapshotter/service/keychain/dockerconfig"
36+
"github.com/containerd/stargz-snapshotter/service/keychain/kubeconfig"
37+
"github.com/containerd/stargz-snapshotter/service/resolver"
38+
grpc "google.golang.org/grpc"
39+
"google.golang.org/grpc/backoff"
40+
"google.golang.org/grpc/credentials/insecure"
41+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
42+
)
43+
44+
// Config represents configuration for the stargz snapshotter plugin.
45+
type Config struct {
46+
service.Config
47+
48+
// RootPath is the directory for the plugin
49+
RootPath string `toml:"root_path"`
50+
51+
// CRIKeychainImageServicePath is the path to expose CRI service wrapped by CRI keychain
52+
CRIKeychainImageServicePath string `toml:"cri_keychain_image_service_path"`
53+
54+
// Registry is CRI-plugin-compatible registry configuration
55+
Registry resolver.Registry `toml:"registry"`
56+
}
57+
58+
func RegisterPlugin(registerCRIAlphaServer func(ctx context.Context, criAddr string, rpc *grpc.Server) resolver.Credential) {
59+
ctdplugin.Register(&ctdplugin.Registration{
60+
Type: ctdplugin.SnapshotPlugin,
61+
ID: "stargz",
62+
Config: &Config{},
63+
InitFn: func(ic *ctdplugin.InitContext) (interface{}, error) {
64+
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
65+
ctx := ic.Context
66+
67+
config, ok := ic.Config.(*Config)
68+
if !ok {
69+
return nil, errors.New("invalid stargz snapshotter configuration")
70+
}
71+
72+
root := ic.Root
73+
if config.RootPath != "" {
74+
root = config.RootPath
75+
}
76+
ic.Meta.Exports["root"] = root
77+
78+
// Configure keychain
79+
credsFuncs := []resolver.Credential{dockerconfig.NewDockerconfigKeychain(ctx)}
80+
if config.Config.KubeconfigKeychainConfig.EnableKeychain {
81+
var opts []kubeconfig.Option
82+
if kcp := config.Config.KubeconfigKeychainConfig.KubeconfigPath; kcp != "" {
83+
opts = append(opts, kubeconfig.WithKubeconfigPath(kcp))
84+
}
85+
credsFuncs = append(credsFuncs, kubeconfig.NewKubeconfigKeychain(ctx, opts...))
86+
}
87+
if addr := config.CRIKeychainImageServicePath; config.Config.CRIKeychainConfig.EnableKeychain && addr != "" {
88+
// connects to the backend CRI service (defaults to containerd socket)
89+
criAddr := ic.Address
90+
if cp := config.Config.CRIKeychainConfig.ImageServicePath; cp != "" {
91+
criAddr = cp
92+
}
93+
if criAddr == "" {
94+
return nil, errors.New("backend CRI service address is not specified")
95+
}
96+
connectCRI := func() (runtime.ImageServiceClient, error) {
97+
conn, err := newCRIConn(criAddr)
98+
if err != nil {
99+
return nil, err
100+
}
101+
return runtime.NewImageServiceClient(conn), nil
102+
}
103+
criCreds, criServer := cri.NewCRIKeychain(ctx, connectCRI)
104+
// Create a gRPC server
105+
rpc := grpc.NewServer()
106+
runtime.RegisterImageServiceServer(rpc, criServer)
107+
criAlphaCreds := registerCRIAlphaServer(ctx, criAddr, rpc)
108+
// Prepare the directory for the socket
109+
if err := os.MkdirAll(filepath.Dir(addr), 0700); err != nil {
110+
return nil, fmt.Errorf("failed to create directory %q: %w", filepath.Dir(addr), err)
111+
}
112+
// Try to remove the socket file to avoid EADDRINUSE
113+
if err := os.RemoveAll(addr); err != nil {
114+
return nil, fmt.Errorf("failed to remove %q: %w", addr, err)
115+
}
116+
// Listen and serve
117+
l, err := net.Listen("unix", addr)
118+
if err != nil {
119+
return nil, fmt.Errorf("error on listen socket %q: %w", addr, err)
120+
}
121+
go func() {
122+
if err := rpc.Serve(l); err != nil {
123+
log.G(ctx).WithError(err).Warnf("error on serving via socket %q", addr)
124+
}
125+
}()
126+
credsFuncs = append(credsFuncs, criAlphaCreds, criCreds)
127+
}
128+
129+
// TODO(ktock): print warn if old configuration is specified.
130+
// TODO(ktock): should we respect old configuration?
131+
return service.NewStargzSnapshotterService(ctx, root, &config.Config,
132+
service.WithCustomRegistryHosts(resolver.RegistryHostsFromCRIConfig(ctx, config.Registry, credsFuncs...)))
133+
},
134+
})
135+
}
136+
137+
func newCRIConn(criAddr string) (*grpc.ClientConn, error) {
138+
// TODO: make gRPC options configurable from config.toml
139+
backoffConfig := backoff.DefaultConfig
140+
backoffConfig.MaxDelay = 3 * time.Second
141+
connParams := grpc.ConnectParams{
142+
Backoff: backoffConfig,
143+
}
144+
gopts := []grpc.DialOption{
145+
grpc.WithTransportCredentials(insecure.NewCredentials()),
146+
grpc.WithConnectParams(connParams),
147+
grpc.WithContextDialer(dialer.ContextDialer),
148+
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
149+
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
150+
}
151+
return grpc.Dial(dialer.DialAddress(criAddr), gopts...)
152+
}

‎service/pluginforked/plugin.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package pluginfroked
18+
19+
import (
20+
"context"
21+
"time"
22+
23+
"github.com/containerd/containerd/defaults"
24+
"github.com/containerd/containerd/pkg/dialer"
25+
grpc "google.golang.org/grpc"
26+
"google.golang.org/grpc/backoff"
27+
"google.golang.org/grpc/credentials/insecure"
28+
29+
"github.com/containerd/stargz-snapshotter/service/plugincore"
30+
"github.com/containerd/stargz-snapshotter/service/resolver"
31+
32+
// We have our own fork to enable to be imported to tools that don't import the recent commit of containerd (e.g. k3s).
33+
runtime_alpha "github.com/containerd/stargz-snapshotter/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
34+
35+
// We use CRI keychain that depends on our own CRI v1alpha fork.
36+
"github.com/containerd/stargz-snapshotter/service/keychain/crialphaforked"
37+
)
38+
39+
// NOTE: When containerd >= 234bf990dca4e81e89f549448aa6b555286eaa7a can be imported,
40+
// use "github.com/containerd/stargz-snapshotter/service/plugin" instead.
41+
//
42+
// This plugin provides the forked CRI v1alpha API. This should be used if this plugin is imported to tools that
43+
// doesn't import containerd newer than 234bf990dca4e81e89f549448aa6b555286eaa7a.
44+
45+
func init() {
46+
plugincore.RegisterPlugin(registerCRIAlphaServer)
47+
}
48+
49+
func registerCRIAlphaServer(ctx context.Context, criAddr string, rpc *grpc.Server) resolver.Credential {
50+
connectAlphaCRI := func() (runtime_alpha.ImageServiceClient, error) {
51+
conn, err := newCRIConn(criAddr)
52+
if err != nil {
53+
return nil, err
54+
}
55+
return runtime_alpha.NewImageServiceClient(conn), nil
56+
}
57+
criAlphaCreds, criAlphaServer := crialphaforked.NewCRIAlphaKeychain(ctx, connectAlphaCRI)
58+
runtime_alpha.RegisterImageServiceServer(rpc, criAlphaServer)
59+
return criAlphaCreds
60+
}
61+
62+
func newCRIConn(criAddr string) (*grpc.ClientConn, error) {
63+
// TODO: make gRPC options configurable from config.toml
64+
backoffConfig := backoff.DefaultConfig
65+
backoffConfig.MaxDelay = 3 * time.Second
66+
connParams := grpc.ConnectParams{
67+
Backoff: backoffConfig,
68+
}
69+
gopts := []grpc.DialOption{
70+
grpc.WithTransportCredentials(insecure.NewCredentials()),
71+
grpc.WithConnectParams(connParams),
72+
grpc.WithContextDialer(dialer.ContextDialer),
73+
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
74+
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
75+
}
76+
return grpc.Dial(dialer.DialAddress(criAddr), gopts...)
77+
}

‎service/resolver/cri.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
dconfig "github.com/containerd/containerd/remotes/docker/config"
4343
"github.com/containerd/stargz-snapshotter/fs/source"
4444
rhttp "github.com/hashicorp/go-retryablehttp"
45-
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
45+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
4646
)
4747

4848
// Registry is registry settings configured

‎third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.pb.go

+39,907
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.proto

+1,556
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
Copyright 2016 The Kubernetes Authors.
19+
20+
Licensed under the Apache License, Version 2.0 (the "License");
21+
you may not use this file except in compliance with the License.
22+
You may obtain a copy of the License at
23+
24+
http://www.apache.org/licenses/LICENSE-2.0
25+
26+
Unless required by applicable law or agreed to in writing, software
27+
distributed under the License is distributed on an "AS IS" BASIS,
28+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
See the License for the specific language governing permissions and
30+
limitations under the License.
31+
*/
32+
33+
package v1alpha2
34+
35+
// This file contains all constants defined in CRI.
36+
37+
// Required runtime condition type.
38+
const (
39+
// RuntimeReady means the runtime is up and ready to accept basic containers.
40+
RuntimeReady = "RuntimeReady"
41+
// NetworkReady means the runtime network is up and ready to accept containers which require network.
42+
NetworkReady = "NetworkReady"
43+
)
44+
45+
// LogStreamType is the type of the stream in CRI container log.
46+
type LogStreamType string
47+
48+
const (
49+
// Stdout is the stream type for stdout.
50+
Stdout LogStreamType = "stdout"
51+
// Stderr is the stream type for stderr.
52+
Stderr LogStreamType = "stderr"
53+
)
54+
55+
// LogTag is the tag of a log line in CRI container log.
56+
// Currently defined log tags:
57+
// * First tag: Partial/Full - P/F.
58+
// The field in the container log format can be extended to include multiple
59+
// tags by using a delimiter, but changes should be rare. If it becomes clear
60+
// that better extensibility is desired, a more extensible format (e.g., json)
61+
// should be adopted as a replacement and/or addition.
62+
type LogTag string
63+
64+
const (
65+
// LogTagPartial means the line is part of multiple lines.
66+
LogTagPartial LogTag = "P"
67+
// LogTagFull means the line is a single full line or the end of multiple lines.
68+
LogTagFull LogTag = "F"
69+
// LogTagDelimiter is the delimiter for different log tags.
70+
LogTagDelimiter = ":"
71+
)

0 commit comments

Comments
 (0)
Please sign in to comment.