forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#8 from Random-Liu/add-image-poc-impleme…
…ntation Add image POC implementation.
- Loading branch information
Showing
16 changed files
with
1,624 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package containerdshim | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
runtimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" | ||
) | ||
|
||
// NOTE: To run the test, please make sure `dist` is in $PATH. | ||
func TestXxx(t *testing.T) { | ||
const ( | ||
storePath = ".content" | ||
image = "docker.io/library/redis" | ||
) | ||
// Make sure there is no exsiting image. | ||
if _, err := os.Stat(storePath); err == nil { | ||
os.RemoveAll(storePath) | ||
} | ||
cs := NewContainerdService(nil) | ||
|
||
t.Logf("Should be able to pull image") | ||
digest, err := cs.PullImage(&runtimeapi.ImageSpec{Image: image}, nil) | ||
assert.NoError(t, err) | ||
t.Logf("Should be able to list new images") | ||
imgs, err := cs.ListImages(nil) | ||
assert.NoError(t, err) | ||
assert.Len(t, imgs, 1) | ||
assert.Equal(t, digest, imgs[0].Id) | ||
t.Logf("Should be able to get new image status with name") | ||
img, err := cs.ImageStatus(&runtimeapi.ImageSpec{Image: image}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, imgs[0], img) | ||
t.Logf("Should be able to get new image status with digest") | ||
img, err = cs.ImageStatus(&runtimeapi.ImageSpec{Image: digest}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, imgs[0], img) | ||
t.Logf("Should be able to see the image in content store") | ||
_, err = os.Stat(storePath) | ||
assert.NoError(t, err) | ||
output, err := exec.Command("sh", "-c", fmt.Sprintf("ls %s/blobs | wc -l", storePath)).Output() | ||
assert.NoError(t, err) | ||
layerNum, err := strconv.Atoi(strings.TrimSpace(string(output))) | ||
assert.NoError(t, err) | ||
assert.NotZero(t, layerNum) | ||
|
||
t.Logf("Should has the same digest and pull no new layer if we pull the same image") | ||
newDigest, err := cs.PullImage(&runtimeapi.ImageSpec{Image: image}, nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, digest, newDigest) | ||
output, err = exec.Command("sh", "-c", fmt.Sprintf("ls %s/blobs | wc -l", storePath)).Output() | ||
assert.NoError(t, err) | ||
newLayerNum, err := strconv.Atoi(strings.TrimSpace(string(output))) | ||
assert.NoError(t, err) | ||
assert.Equal(t, layerNum, newLayerNum) | ||
|
||
t.Logf("Should be able to remove image") | ||
err = cs.RemoveImage(&runtimeapi.ImageSpec{Image: digest}) | ||
assert.NoError(t, err) | ||
imgs, err = cs.ListImages(nil) | ||
assert.NoError(t, err) | ||
assert.Empty(t, imgs) | ||
img, err = cs.ImageStatus(&runtimeapi.ImageSpec{Image: image}) | ||
assert.NoError(t, err) | ||
assert.Nil(t, img) | ||
|
||
os.RemoveAll(storePath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.