Skip to content

Commit 75aab2b

Browse files
committed
Merge branch 'cri-compatibility' of github.com:Starnop/pouch into cri-compatibility
2 parents 5c8993b + 2f2e9c1 commit 75aab2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1541
-668
lines changed

INSTALLATION.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ sudo apt-get install curl apt-transport-https ca-certificates software-propertie
3636
curl -fsSL http://mirrors.aliyun.com/opsx/pouch/linux/debian/[email protected] | sudo apt-key add -
3737
```
3838

39-
Verify that you now have the key with the fingerprint `B615 DDD7 90C7 0912 582D DC2D D7AE A5ED 439A E9EC`, by searching for the last 8 characters of the fingerprint.
39+
Verify that you now have the key with the fingerprint `F443 EDD0 4A58 7E8B F645 9C40 CF68 F84A BE2F 475F`, by searching for the last 8 characters of the fingerprint.
4040

4141
``` bash
42-
$ apt-key fingerprint 439AE9EC
43-
pub 2048R/439AE9EC 2018-01-31
44-
Key fingerprint = B615 DDD7 90C7 0912 582D DC2D D7AE A5ED 439A E9EC
45-
uid Pouch Release <[email protected]>
46-
sub 2048R/B3D2A915 2018-01-31
42+
$ apt-key fingerprint BE2F475F
43+
pub 4096R/BE2F475F 2018-02-28
44+
Key fingerprint = F443 EDD0 4A58 7E8B F645 9C40 CF68 F84A BE2F 475F
45+
uid opsx-admin <[email protected]>
4746
```
4847

4948
**2. Set up the pouch repository**

cli/common_flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func addCommonFlags(flagSet *pflag.FlagSet) *container {
8484

8585
flagSet.StringVarP(&c.workdir, "workdir", "w", "", "Set the working directory in a container")
8686
flagSet.Var(&c.ulimit, "ulimit", "Set container ulimit")
87+
flagSet.Int64Var(&c.pidsLimit, "pids-limit", -1, "Set container pids limit, -1 for unlimited")
8788

8889
flagSet.BoolVar(&c.rich, "rich", false, "Start container in rich container mode. (default false)")
8990
flagSet.StringVar(&c.richMode, "rich-mode", "", "Choose one rich container mode. dumb-init(default), systemd, sbin-init")

cli/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type container struct {
6969
specAnnotation []string
7070
cgroupParent string
7171
ulimit Ulimit
72+
pidsLimit int64
7273

7374
//add for rich container mode
7475
rich bool
@@ -223,6 +224,7 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
223224
IntelRdtL3Cbm: intelRdtL3Cbm,
224225
CgroupParent: c.cgroupParent,
225226
Ulimits: c.ulimit.value(),
227+
PidsLimit: c.pidsLimit,
226228
},
227229
EnableLxcfs: c.enableLxcfs,
228230
Privileged: c.privileged,

cri/v1alpha1/cri.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path"
1010
"path/filepath"
1111
"reflect"
12-
"strings"
1312
"time"
1413

1514
apitypes "github.com/alibaba/pouch/apis/types"
@@ -648,7 +647,7 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt
648647
labels, annotations := extractLabels(container.Config.Labels)
649648

650649
imageRef := container.Image
651-
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(imageRef, "sha256:"))
650+
imageInfo, err := c.ImageMgr.GetImage(ctx, imageRef)
652651
if err != nil {
653652
return nil, fmt.Errorf("failed to get image %s: %v", imageRef, err)
654653
}
@@ -825,7 +824,7 @@ func (c *CriManager) ListImages(ctx context.Context, r *runtime.ListImagesReques
825824
continue
826825
}
827826
// NOTE: we should query image cache to get the correct image info.
828-
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(i.ID, "sha256:"))
827+
imageInfo, err := c.ImageMgr.GetImage(ctx, i.ID)
829828
if err != nil {
830829
continue
831830
}
@@ -849,7 +848,7 @@ func (c *CriManager) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequ
849848
return nil, err
850849
}
851850

852-
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(ref.String(), "sha256:"))
851+
imageInfo, err := c.ImageMgr.GetImage(ctx, ref.String())
853852
if err != nil {
854853
// TODO: separate ErrImageNotFound with others.
855854
// Now we just return empty if the error occurred.
@@ -893,7 +892,7 @@ func (c *CriManager) PullImage(ctx context.Context, r *runtime.PullImageRequest)
893892

894893
// RemoveImage removes the image.
895894
func (c *CriManager) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (*runtime.RemoveImageResponse, error) {
896-
imageRef := strings.TrimPrefix(r.GetImage().GetImage(), "sha256:")
895+
imageRef := r.GetImage().GetImage()
897896

898897
if err := c.ImageMgr.RemoveImage(ctx, imageRef, false); err != nil {
899898
if errtypes.IsNotfound(err) {

cri/v1alpha2/cri.go

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path"
1010
"path/filepath"
1111
"reflect"
12-
"strings"
1312
"time"
1413

1514
apitypes "github.com/alibaba/pouch/apis/types"
@@ -54,7 +53,7 @@ const (
5453
// Address and port of stream server.
5554
// TODO: specify them in the parameters of pouchd.
5655
streamServerAddress = ""
57-
streamServerPort = "10010"
56+
streamServerPort = "10011"
5857

5958
namespaceModeHost = "host"
6059
namespaceModeNone = "none"
@@ -371,8 +370,8 @@ func (c *CriManager) PodSandboxStatus(ctx context.Context, r *runtime.PodSandbox
371370
}
372371
labels, annotations := extractLabels(sandbox.Config.Labels)
373372

374-
securityContext := sandboxMeta.Config.GetLinux().GetSecurityContext()
375-
hostNet := securityContext.GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE
373+
nsOpts := sandboxMeta.Config.GetLinux().GetSecurityContext().GetNamespaceOptions()
374+
hostNet := nsOpts.GetNetwork() == runtime.NamespaceMode_NODE
376375

377376
var ip string
378377
// No need to get ip for host network mode.
@@ -392,7 +391,15 @@ func (c *CriManager) PodSandboxStatus(ctx context.Context, r *runtime.PodSandbox
392391
Labels: labels,
393392
Annotations: annotations,
394393
Network: &runtime.PodSandboxNetworkStatus{Ip: ip},
395-
// TODO: linux specific pod status.
394+
Linux: &runtime.LinuxPodSandboxStatus{
395+
Namespaces: &runtime.Namespace{
396+
Options: &runtime.NamespaceOption{
397+
Network: nsOpts.GetNetwork(),
398+
Pid: nsOpts.GetPid(),
399+
Ipc: nsOpts.GetIpc(),
400+
},
401+
},
402+
},
396403
}
397404

398405
return &runtime.PodSandboxStatusResponse{Status: status}, nil
@@ -440,8 +447,7 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
440447

441448
image := ""
442449
if iSpec := config.GetImage(); iSpec != nil {
443-
temp := strings.Split(iSpec.Image, ":")
444-
image = temp[len(temp)-1]
450+
image = iSpec.Image
445451
}
446452
createConfig := &apitypes.ContainerCreateConfig{
447453
ContainerConfig: apitypes.ContainerConfig{
@@ -638,7 +644,7 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt
638644
labels, annotations := extractLabels(container.Config.Labels)
639645

640646
imageRef := container.Image
641-
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(imageRef, "sha256:"))
647+
imageInfo, err := c.ImageMgr.GetImage(ctx, imageRef)
642648
if err != nil {
643649
return nil, fmt.Errorf("failed to get image %s: %v", imageRef, err)
644650
}
@@ -689,23 +695,7 @@ func (c *CriManager) UpdateContainerResources(ctx context.Context, r *runtime.Up
689695
// to either create a new log file and return nil, or return an error.
690696
// Once it returns error, new container log file MUST NOT be created.
691697
func (c *CriManager) ReopenContainerLog(ctx context.Context, r *runtime.ReopenContainerLogRequest) (*runtime.ReopenContainerLogResponse, error) {
692-
containerID := r.GetContainerId()
693-
container, err := c.ContainerMgr.Get(ctx, containerID)
694-
if err != nil {
695-
return nil, fmt.Errorf("failed to get container of %q: %v", containerID, err)
696-
}
697-
if container.State.Status != apitypes.StatusRunning {
698-
return nil, fmt.Errorf("container %q is not running", containerID)
699-
}
700-
c.ContainerMgr.(*mgr.ContainerManager).IOs.Remove(containerID)
701-
if container.LogPath != "" {
702-
logPath := container.LogPath
703-
err := c.attachLog(logPath, containerID)
704-
if err != nil {
705-
return nil, err
706-
}
707-
}
708-
return &runtime.ReopenContainerLogResponse{}, nil
698+
return nil, fmt.Errorf("UpdateContainerResources Not Implemented Yet")
709699
}
710700

711701
// ExecSync executes a command in the container, and returns the stdout output.
@@ -840,7 +830,7 @@ func (c *CriManager) ListImages(ctx context.Context, r *runtime.ListImagesReques
840830
continue
841831
}
842832
// NOTE: we should query image cache to get the correct image info.
843-
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(i.ID, "sha256:"))
833+
imageInfo, err := c.ImageMgr.GetImage(ctx, i.ID)
844834
if err != nil {
845835
continue
846836
}
@@ -864,7 +854,7 @@ func (c *CriManager) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequ
864854
return nil, err
865855
}
866856

867-
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(ref.String(), "sha256:"))
857+
imageInfo, err := c.ImageMgr.GetImage(ctx, ref.String())
868858
if err != nil {
869859
// TODO: separate ErrImageNotFound with others.
870860
// Now we just return empty if the error occurred.
@@ -908,7 +898,7 @@ func (c *CriManager) PullImage(ctx context.Context, r *runtime.PullImageRequest)
908898

909899
// RemoveImage removes the image.
910900
func (c *CriManager) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (*runtime.RemoveImageResponse, error) {
911-
imageRef := strings.TrimPrefix(r.GetImage().GetImage(), "sha256:")
901+
imageRef := r.GetImage().GetImage()
912902

913903
if err := c.ImageMgr.RemoveImage(ctx, imageRef, false); err != nil {
914904
if errtypes.IsNotfound(err) {

cri/v1alpha2/cri_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ func modifyContainerNamespaceOptions(nsOpts *runtime.NamespaceOption, podSandbox
451451
if n.hostMode {
452452
*n.nsMode = namespaceModeHost
453453
} else {
454-
if n.nsMode == &hostConfig.PidMode && nsOpts.GetPid() == runtime.NamespaceMode_CONTAINER {
455-
continue
456-
}
454+
//if n.nsMode == &hostConfig.PidMode && nsOpts.GetPid() == runtime.NamespaceMode_CONTAINER {
455+
// continue
456+
//}
457457
*n.nsMode = sandboxNSMode
458458
}
459459
}

daemon/mgr/container.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/go-openapi/strfmt"
3737
"github.com/imdario/mergo"
3838
"github.com/magiconair/properties"
39-
digest "github.com/opencontainers/go-digest"
4039
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
4140
"github.com/pkg/errors"
4241
"github.com/sirupsen/logrus"
@@ -1919,7 +1918,7 @@ func (mgr *ContainerManager) getMountPointFromImage(ctx context.Context, meta *C
19191918
var err error
19201919

19211920
// parse volumes from image
1922-
image, err := mgr.ImageMgr.GetImage(ctx, strings.TrimPrefix(meta.Image, digest.Canonical.String()+":"))
1921+
image, err := mgr.ImageMgr.GetImage(ctx, meta.Image)
19231922
if err != nil {
19241923
return errors.Wrapf(err, "failed to get image: %s", meta.Image)
19251924
}

daemon/mgr/image.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"strings"
78
"time"
89

910
"github.com/alibaba/pouch/apis/types"
@@ -178,8 +179,11 @@ func (mgr *ImageManager) RemoveImage(ctx context.Context, idOrRef string, force
178179
return err
179180
}
180181

181-
// should remove all the references if the reference is Named Only
182-
if reference.IsNamedOnly(namedRef) {
182+
// should remove all the references if the reference is ID (Named Only)
183+
// or Digest ID (Tagged Named)
184+
if reference.IsNamedOnly(namedRef) ||
185+
strings.HasPrefix(id.String(), namedRef.String()) {
186+
183187
// NOTE: the user maybe use the following references to pull one image
184188
//
185189
// busybox:1.25
@@ -257,9 +261,11 @@ func (mgr *ImageManager) CheckReference(ctx context.Context, idOrRef string) (ac
257261
}
258262
}
259263

260-
// NOTE: if the actualRef is short ID or ID, the primaryRef is first one of
261-
// primary reference
262-
if reference.IsNamedOnly(actualRef) {
264+
// NOTE: if the actualRef is ID (Named Only) or Digest ID (Tagged Named)
265+
// the primaryRef is first one of primary reference
266+
if reference.IsNamedOnly(actualRef) ||
267+
strings.HasPrefix(actualID.String(), actualRef.String()) {
268+
263269
refs := mgr.localStore.GetPrimaryReferences(actualID)
264270
if len(refs) == 0 {
265271
err = errtypes.ErrNotfound

daemon/mgr/image_store.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package mgr
22

33
import (
4+
"fmt"
5+
"strings"
46
"sync"
57

68
"github.com/alibaba/pouch/pkg/errtypes"
@@ -141,34 +143,41 @@ func (store *imageStore) Search(ref reference.Named) (digest.Digest, reference.N
141143

142144
// if the reference is short ID or ID
143145
//
144-
// NOTE: by default, use the sha256 as the digest algorithm
145-
id, err := store.searchIDs(digest.Canonical.String(), ref.String())
146+
// NOTE: by default, use the sha256 as the digest algorithm if missing
147+
// algorithm header.
148+
id, err := store.searchIDs(ref.String())
146149
if err != nil {
147150
return "", nil, err
148151
}
149152
return id, ref, nil
150153
}
151154

152-
func (store *imageStore) searchIDs(algo string, prefixID string) (digest.Digest, error) {
155+
func (store *imageStore) searchIDs(refID string) (digest.Digest, error) {
153156
var ids []digest.Digest
157+
var id string
158+
159+
id = refID
160+
if !strings.HasPrefix(refID, digest.Canonical.String()) {
161+
id = fmt.Sprintf("%s:%s", digest.Canonical.String(), refID)
162+
}
154163

155164
fn := func(_ patricia.Prefix, item patricia.Item) error {
156165
if got, ok := item.(digest.Digest); ok {
157166
ids = append(ids, got)
158167
}
159168

160169
if len(ids) > 1 {
161-
return pkgerrors.Wrap(errtypes.ErrTooMany, "image: "+prefixID)
170+
return pkgerrors.Wrap(errtypes.ErrTooMany, "image: "+refID)
162171
}
163172
return nil
164173
}
165174

166-
if err := store.idSet.VisitSubtree(patricia.Prefix(algo+":"+prefixID), fn); err != nil {
175+
if err := store.idSet.VisitSubtree(patricia.Prefix(id), fn); err != nil {
167176
return "", err
168177
}
169178

170179
if len(ids) == 0 {
171-
return "", pkgerrors.Wrap(errtypes.ErrNotfound, "image: "+prefixID)
180+
return "", pkgerrors.Wrap(errtypes.ErrNotfound, "image: "+refID)
172181
}
173182
return ids[0], nil
174183
}

daemon/mgr/image_store_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestSearch(t *testing.T) {
112112

113113
// search
114114
{
115-
// should return id if the reference is id
115+
// should return id if the reference is id without algorithm header
116116
{
117117
namedStr := id.Hex()
118118

@@ -127,6 +127,21 @@ func TestSearch(t *testing.T) {
127127
assert.Equal(t, gotRef.String(), namedRef.String())
128128
}
129129

130+
// should return id if the reference is digest id
131+
{
132+
namedStr := id.String()
133+
134+
namedRef, err := reference.Parse(namedStr)
135+
if err != nil {
136+
t.Fatalf("unexpected error during parse reference %v: %v", namedStr, err)
137+
}
138+
139+
gotID, gotRef, err := store.Search(namedRef)
140+
assert.Equal(t, err, nil)
141+
assert.Equal(t, gotID.String(), id.String())
142+
assert.Equal(t, gotRef.String(), namedRef.String())
143+
}
144+
130145
// should return busybox:latest if the reference is busybox
131146
{
132147
namedStr := "busybox"
@@ -202,7 +217,7 @@ func TestSearch(t *testing.T) {
202217

203218
// should return ErrTooMany if the reference is commonPart
204219
{
205-
namedStr := id.Hex()[:20]
220+
namedStr := id.String()[:20]
206221

207222
namedRef, err := reference.Parse(namedStr)
208223
if err != nil {

0 commit comments

Comments
 (0)