/
image.go
125 lines (100 loc) · 3.86 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
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 benchmark
import (
"runtime"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const (
defaultImagePullTimeoutSeconds = 1
defaultImageStatusTimeoutSeconds = 2
defaultImageRemoveTimeoutSeconds = 2
defaultImageListTimeoutSeconds = 2
)
var _ = framework.KubeDescribe("Container", func() {
f := framework.NewDefaultCRIFramework()
var ic internalapi.ImageManagerService
BeforeEach(func() {
ic = f.CRIClient.CRIImageClient
})
Context("benchmark about operations on Image", func() {
var err error
var testImageList []string
if runtime.GOARCH == "amd64" {
testImageList = []string{
"busybox:1.26.2-glibc",
"busybox:1-uclibc",
"busybox:1",
"busybox:1-glibc",
"busybox:1-musl",
}
} else {
testImageList = []string{
"busybox:1",
"busybox:1-glibc",
"busybox:1-musl",
}
}
AfterEach(func() {
for _, imageName := range testImageList {
imageSpec := &runtimeapi.ImageSpec{
Image: imageName,
}
ic.RemoveImage(imageSpec)
}
})
imagePullTimeoutSeconds := defaultImagePullTimeoutSeconds
imageStatusTimeoutSeconds := defaultImageStatusTimeoutSeconds
imageRemoveTimeoutSeconds := defaultImageRemoveTimeoutSeconds
imageListTimeoutSeconds := defaultImageListTimeoutSeconds
if framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds > 0 {
imagePullTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds
imageStatusTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds
imageRemoveTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds
imageListTimeoutSeconds = framework.TestContext.BenchmarkingParams.ImageBenchmarkTimeoutSeconds
}
Measure("benchmark about basic operations on Image", func(b Benchmarker) {
imageSpec := &runtimeapi.ImageSpec{
Image: testImageList[0],
}
operation := b.Time("pull Image", func() {
framework.PullPublicImage(ic, testImageList[0], nil)
})
Expect(operation.Minutes()).Should(BeNumerically("<", imagePullTimeoutSeconds), "pull Image shouldn't take too long.")
operation = b.Time("Image status", func() {
_, err = ic.ImageStatus(imageSpec, false)
})
framework.ExpectNoError(err, "failed to get image status: %v", err)
Expect(operation.Seconds()).Should(BeNumerically("<", imageStatusTimeoutSeconds), "get image status shouldn't take too long.")
operation = b.Time("remove Image", func() {
err = ic.RemoveImage(imageSpec)
})
framework.ExpectNoError(err, "failed to remove image: %v", err)
Expect(operation.Seconds()).Should(BeNumerically("<", imageRemoveTimeoutSeconds), "remove Image shouldn't take too long.")
}, defaultOperationTimes)
Measure("benchmark about listing Image", func(b Benchmarker) {
for _, imageName := range testImageList {
framework.PullPublicImage(ic, imageName, nil)
}
operation := b.Time("list Container", func() {
_, err = ic.ListImages(nil)
})
framework.ExpectNoError(err, "failed to list Image: %v", err)
Expect(operation.Seconds()).Should(BeNumerically("<", imageListTimeoutSeconds), "list Image shouldn't take too long.")
}, defaultOperationTimes)
})
})