mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Remove CRI v1alpha2
After the removal of dockershim we can finally also drop support for CRI v1alpha2. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
parent
98742f9d77
commit
f9707064cf
2
hack/testdata/levee/levee-config.yaml
vendored
2
hack/testdata/levee/levee-config.yaml
vendored
@ -53,7 +53,7 @@ Sources:
|
||||
FieldRE: "KeyData"
|
||||
|
||||
# The following fields are tagged in #95600
|
||||
- PackageRE: "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
- PackageRE: "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
TypeRE: "AuthConfig"
|
||||
FieldRE: "Password|IdentityToken|RegistryToken"
|
||||
|
||||
|
@ -25,7 +25,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
KUBE_REMOTE_RUNTIME_ROOT="${KUBE_ROOT}/staging/src/k8s.io/cri-api/pkg/apis/runtime/"
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
runtime_versions=("v1alpha2" "v1")
|
||||
runtime_versions=("v1")
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
|
@ -27,7 +27,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
KUBE_REMOTE_RUNTIME_ROOT="${KUBE_ROOT}/staging/src/k8s.io/cri-api/pkg/apis/runtime/"
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
runtime_versions=("v1alpha2" "v1")
|
||||
runtime_versions=("v1")
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
Copyright 2021 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 remote
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
)
|
||||
|
||||
func fromV1alpha2VersionResponse(from *v1alpha2.VersionResponse) *runtimeapi.VersionResponse {
|
||||
return (*runtimeapi.VersionResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2PodSandboxStatusResponse(from *v1alpha2.PodSandboxStatusResponse) *runtimeapi.PodSandboxStatusResponse {
|
||||
return (*runtimeapi.PodSandboxStatusResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ListPodSandboxResponse(from *v1alpha2.ListPodSandboxResponse) *runtimeapi.ListPodSandboxResponse {
|
||||
return (*runtimeapi.ListPodSandboxResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ListContainersResponse(from *v1alpha2.ListContainersResponse) *runtimeapi.ListContainersResponse {
|
||||
return (*runtimeapi.ListContainersResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ContainerStatusResponse(from *v1alpha2.ContainerStatusResponse) *runtimeapi.ContainerStatusResponse {
|
||||
return (*runtimeapi.ContainerStatusResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ExecResponse(from *v1alpha2.ExecResponse) *runtimeapi.ExecResponse {
|
||||
// If this function changes, also adapt the corresponding Exec code in
|
||||
// pkg/kubelet/cri/remote/remote_runtime.go
|
||||
return (*runtimeapi.ExecResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2AttachResponse(from *v1alpha2.AttachResponse) *runtimeapi.AttachResponse {
|
||||
// If this function changes, also adapt the corresponding Attach code in
|
||||
// pkg/kubelet/cri/remote/remote_runtime.go
|
||||
return (*runtimeapi.AttachResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2PortForwardResponse(from *v1alpha2.PortForwardResponse) *runtimeapi.PortForwardResponse {
|
||||
// If this function changes, also adapt the corresponding PortForward code in
|
||||
// pkg/kubelet/cri/remote/remote_runtime.go
|
||||
return (*runtimeapi.PortForwardResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2StatusResponse(from *v1alpha2.StatusResponse) *runtimeapi.StatusResponse {
|
||||
return (*runtimeapi.StatusResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ContainerStats(from *v1alpha2.ContainerStats) *runtimeapi.ContainerStats {
|
||||
return (*runtimeapi.ContainerStats)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ImageFsInfoResponse(from *v1alpha2.ImageFsInfoResponse) *runtimeapi.ImageFsInfoResponse {
|
||||
return (*runtimeapi.ImageFsInfoResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ListContainerStatsResponse(from *v1alpha2.ListContainerStatsResponse) *runtimeapi.ListContainerStatsResponse {
|
||||
return (*runtimeapi.ListContainerStatsResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2PodSandboxStats(from *v1alpha2.PodSandboxStats) *runtimeapi.PodSandboxStats {
|
||||
return (*runtimeapi.PodSandboxStats)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ListPodSandboxStatsResponse(from *v1alpha2.ListPodSandboxStatsResponse) *runtimeapi.ListPodSandboxStatsResponse {
|
||||
return (*runtimeapi.ListPodSandboxStatsResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ImageStatusResponse(from *v1alpha2.ImageStatusResponse) *runtimeapi.ImageStatusResponse {
|
||||
return (*runtimeapi.ImageStatusResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func fromV1alpha2ListImagesResponse(from *v1alpha2.ListImagesResponse) *runtimeapi.ListImagesResponse {
|
||||
return (*runtimeapi.ListImagesResponse)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2PodSandboxConfig(from *runtimeapi.PodSandboxConfig) *v1alpha2.PodSandboxConfig {
|
||||
return (*v1alpha2.PodSandboxConfig)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2PodSandboxFilter(from *runtimeapi.PodSandboxFilter) *v1alpha2.PodSandboxFilter {
|
||||
return (*v1alpha2.PodSandboxFilter)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2ContainerConfig(from *runtimeapi.ContainerConfig) *v1alpha2.ContainerConfig {
|
||||
return (*v1alpha2.ContainerConfig)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2ContainerFilter(from *runtimeapi.ContainerFilter) *v1alpha2.ContainerFilter {
|
||||
return (*v1alpha2.ContainerFilter)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2LinuxContainerResources(from *runtimeapi.LinuxContainerResources) *v1alpha2.LinuxContainerResources {
|
||||
return (*v1alpha2.LinuxContainerResources)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2WindowsContainerResources(from *runtimeapi.WindowsContainerResources) *v1alpha2.WindowsContainerResources {
|
||||
return (*v1alpha2.WindowsContainerResources)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2ExecRequest(from *runtimeapi.ExecRequest) *v1alpha2.ExecRequest {
|
||||
// If this function changes, also adapt the corresponding Exec code in
|
||||
// pkg/kubelet/cri/remote/remote_runtime.go
|
||||
return (*v1alpha2.ExecRequest)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2AttachRequest(from *runtimeapi.AttachRequest) *v1alpha2.AttachRequest {
|
||||
// If this function changes, also adapt the corresponding Attach code in
|
||||
// pkg/kubelet/cri/remote/remote_runtime.go
|
||||
return (*v1alpha2.AttachRequest)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2PortForwardRequest(from *runtimeapi.PortForwardRequest) *v1alpha2.PortForwardRequest {
|
||||
// If this function changes, also adapt the corresponding PortForward code in
|
||||
// pkg/kubelet/cri/remote/remote_runtime.go
|
||||
return (*v1alpha2.PortForwardRequest)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2RuntimeConfig(from *runtimeapi.RuntimeConfig) *v1alpha2.RuntimeConfig {
|
||||
return (*v1alpha2.RuntimeConfig)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2ContainerStatsFilter(from *runtimeapi.ContainerStatsFilter) *v1alpha2.ContainerStatsFilter {
|
||||
return (*v1alpha2.ContainerStatsFilter)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2PodSandboxStatsFilter(from *runtimeapi.PodSandboxStatsFilter) *v1alpha2.PodSandboxStatsFilter {
|
||||
return (*v1alpha2.PodSandboxStatsFilter)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2ImageFilter(from *runtimeapi.ImageFilter) *v1alpha2.ImageFilter {
|
||||
return (*v1alpha2.ImageFilter)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2ImageSpec(from *runtimeapi.ImageSpec) *v1alpha2.ImageSpec {
|
||||
return (*v1alpha2.ImageSpec)(unsafe.Pointer(from))
|
||||
}
|
||||
|
||||
func v1alpha2AuthConfig(from *runtimeapi.AuthConfig) *v1alpha2.AuthConfig {
|
||||
return (*v1alpha2.AuthConfig)(unsafe.Pointer(from))
|
||||
}
|
@ -1,409 +0,0 @@
|
||||
/*
|
||||
Copyright 2021 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 remote
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
)
|
||||
|
||||
func TestMemoryEqual(t *testing.T) {
|
||||
testcases := []struct {
|
||||
a interface{}
|
||||
b interface{}
|
||||
}{
|
||||
{runtimeapi.VersionResponse{}, v1alpha2.VersionResponse{}},
|
||||
{runtimeapi.PodSandboxConfig{}, v1alpha2.PodSandboxConfig{}},
|
||||
{runtimeapi.PodSandboxFilter{}, v1alpha2.PodSandboxFilter{}},
|
||||
{runtimeapi.ContainerConfig{}, v1alpha2.ContainerConfig{}},
|
||||
{runtimeapi.ContainerFilter{}, v1alpha2.ContainerFilter{}},
|
||||
{runtimeapi.LinuxContainerResources{}, v1alpha2.LinuxContainerResources{}},
|
||||
{runtimeapi.ExecRequest{}, v1alpha2.ExecRequest{}},
|
||||
{runtimeapi.AttachRequest{}, v1alpha2.AttachRequest{}},
|
||||
{runtimeapi.PortForwardRequest{}, v1alpha2.PortForwardRequest{}},
|
||||
{runtimeapi.RuntimeConfig{}, v1alpha2.RuntimeConfig{}},
|
||||
{runtimeapi.ContainerStatsFilter{}, v1alpha2.ContainerStatsFilter{}},
|
||||
{runtimeapi.PodSandboxStatsFilter{}, v1alpha2.PodSandboxStatsFilter{}},
|
||||
{runtimeapi.ImageFilter{}, v1alpha2.ImageFilter{}},
|
||||
{runtimeapi.ImageSpec{}, v1alpha2.ImageSpec{}},
|
||||
{runtimeapi.AuthConfig{}, v1alpha2.AuthConfig{}},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
aType := reflect.TypeOf(tc.a)
|
||||
bType := reflect.TypeOf(tc.b)
|
||||
t.Run(aType.String(), func(t *testing.T) {
|
||||
assertEqualTypes(t, nil, aType, bType)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertEqualTypes(t *testing.T, path []string, a, b reflect.Type) {
|
||||
if a == b {
|
||||
return
|
||||
}
|
||||
|
||||
if a.Kind() != b.Kind() {
|
||||
fatalTypeError(t, path, a, b, "mismatched Kind")
|
||||
}
|
||||
|
||||
switch a.Kind() {
|
||||
case reflect.Struct:
|
||||
aFields := a.NumField()
|
||||
bFields := b.NumField()
|
||||
if aFields != bFields {
|
||||
fatalTypeError(t, path, a, b, "mismatched field count")
|
||||
}
|
||||
for i := 0; i < aFields; i++ {
|
||||
aField := a.Field(i)
|
||||
bField := b.Field(i)
|
||||
if aField.Name != bField.Name {
|
||||
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field name %d: %s %s", i, aField.Name, bField.Name))
|
||||
}
|
||||
if aTag, bTag := stripEnum(aField.Tag), stripEnum(bField.Tag); aTag != bTag {
|
||||
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field tag %d:\n%s\n%s\n", i, aTag, bTag))
|
||||
}
|
||||
if aField.Offset != bField.Offset {
|
||||
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field offset %d: %v %v", i, aField.Offset, bField.Offset))
|
||||
}
|
||||
if aField.Anonymous != bField.Anonymous {
|
||||
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field anonymous %d: %v %v", i, aField.Anonymous, bField.Anonymous))
|
||||
}
|
||||
if !reflect.DeepEqual(aField.Index, bField.Index) {
|
||||
fatalTypeError(t, path, a, b, fmt.Sprintf("mismatched field index %d: %v %v", i, aField.Index, bField.Index))
|
||||
}
|
||||
path = append(path, aField.Name)
|
||||
assertEqualTypes(t, path, aField.Type, bField.Type)
|
||||
path = path[:len(path)-1]
|
||||
}
|
||||
|
||||
case reflect.Pointer, reflect.Slice:
|
||||
aElemType := a.Elem()
|
||||
bElemType := b.Elem()
|
||||
assertEqualTypes(t, path, aElemType, bElemType)
|
||||
|
||||
case reflect.Int32:
|
||||
if a.Kind() != b.Kind() {
|
||||
fatalTypeError(t, path, a, b, "incompatible types")
|
||||
}
|
||||
|
||||
default:
|
||||
fatalTypeError(t, path, a, b, "unhandled kind")
|
||||
}
|
||||
}
|
||||
|
||||
// strip the enum value from the protobuf tag, since that doesn't impact the wire serialization and differs by package
|
||||
func stripEnum(tagValue reflect.StructTag) reflect.StructTag {
|
||||
return reflect.StructTag(regexp.MustCompile(",enum=[^,]+").ReplaceAllString(string(tagValue), ""))
|
||||
}
|
||||
|
||||
func fatalTypeError(t *testing.T, path []string, a, b reflect.Type, message string) {
|
||||
t.Helper()
|
||||
t.Fatalf("%s: %s: %s %s", strings.Join(path, ""), message, a, b)
|
||||
}
|
||||
|
||||
func fillFields(s interface{}) {
|
||||
fillFieldsOffset(s, 0)
|
||||
}
|
||||
|
||||
func fillFieldsOffset(s interface{}, offset int) {
|
||||
reflectType := reflect.TypeOf(s).Elem()
|
||||
reflectValue := reflect.ValueOf(s).Elem()
|
||||
|
||||
for i := 0; i < reflectType.NumField(); i++ {
|
||||
field := reflectValue.Field(i)
|
||||
typeName := reflectType.Field(i).Name
|
||||
|
||||
// Skipping protobuf internal values
|
||||
if strings.HasPrefix(typeName, "XXX_") {
|
||||
continue
|
||||
}
|
||||
|
||||
fillField(field, i+offset)
|
||||
}
|
||||
}
|
||||
|
||||
func fillField(field reflect.Value, v int) {
|
||||
switch field.Kind() {
|
||||
case reflect.Bool:
|
||||
field.SetBool(true)
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
field.SetFloat(float64(v))
|
||||
|
||||
case reflect.String:
|
||||
field.SetString(fmt.Sprint(v))
|
||||
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
field.SetInt(int64(v))
|
||||
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
field.SetUint(uint64(v))
|
||||
|
||||
case reflect.Map:
|
||||
field.Set(reflect.MakeMap(field.Type()))
|
||||
|
||||
case reflect.Array, reflect.Slice:
|
||||
slice := reflect.MakeSlice(field.Type(), 1, 1)
|
||||
field.Set(slice)
|
||||
first := slice.Index(0)
|
||||
|
||||
if first.Type().Kind() == reflect.Pointer {
|
||||
first.Set(reflect.New(first.Type().Elem()))
|
||||
fillFieldsOffset(first.Interface(), v)
|
||||
} else {
|
||||
fillField(first, v)
|
||||
}
|
||||
|
||||
case reflect.Pointer:
|
||||
val := reflect.New(field.Type().Elem())
|
||||
field.Set(val)
|
||||
fillFieldsOffset(field.Interface(), v)
|
||||
|
||||
case reflect.Struct:
|
||||
fillFieldsOffset(field.Addr().Interface(), v)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func assertEqual(t *testing.T, a, b proto.Message) {
|
||||
aBytes, err := proto.Marshal(a)
|
||||
assert.Nil(t, err)
|
||||
|
||||
bBytes, err := proto.Marshal(b)
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, aBytes, bBytes)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2VersionResponse(t *testing.T) {
|
||||
from := &v1alpha2.VersionResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2VersionResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2PodSandboxStatusResponse(t *testing.T) {
|
||||
from := &v1alpha2.PodSandboxStatusResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2PodSandboxStatusResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ListPodSandboxResponse(t *testing.T) {
|
||||
from := &v1alpha2.ListPodSandboxResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ListPodSandboxResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ListContainersResponse(t *testing.T) {
|
||||
from := &v1alpha2.ListContainersResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ListContainersResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ContainerStatusResponse(t *testing.T) {
|
||||
from := &v1alpha2.ContainerStatusResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ContainerStatusResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ExecResponse(t *testing.T) {
|
||||
from := &v1alpha2.ExecResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ExecResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2AttachResponse(t *testing.T) {
|
||||
from := &v1alpha2.AttachResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2AttachResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2PortForwardResponse(t *testing.T) {
|
||||
from := &v1alpha2.PortForwardResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2PortForwardResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2StatusResponse(t *testing.T) {
|
||||
from := &v1alpha2.StatusResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2StatusResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ContainerStats(t *testing.T) {
|
||||
from := &v1alpha2.ContainerStats{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ContainerStats(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ImageFsInfoResponse(t *testing.T) {
|
||||
from := &v1alpha2.ImageFsInfoResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ImageFsInfoResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ListContainerStatsResponse(t *testing.T) {
|
||||
from := &v1alpha2.ListContainerStatsResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ListContainerStatsResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2PodSandboxStats(t *testing.T) {
|
||||
from := &v1alpha2.PodSandboxStats{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2PodSandboxStats(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ListPodSandboxStatsResponse(t *testing.T) {
|
||||
from := &v1alpha2.ListPodSandboxStatsResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ListPodSandboxStatsResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ImageStatusResponse(t *testing.T) {
|
||||
from := &v1alpha2.ImageStatusResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ImageStatusResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestFromV1alpha2ListImagesResponse(t *testing.T) {
|
||||
from := &v1alpha2.ListImagesResponse{}
|
||||
fillFields(from)
|
||||
to := fromV1alpha2ListImagesResponse(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2PodSandboxConfig(t *testing.T) {
|
||||
from := &runtimeapi.PodSandboxConfig{}
|
||||
fillFields(from)
|
||||
to := v1alpha2PodSandboxConfig(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2PodSandboxFilter(t *testing.T) {
|
||||
from := &runtimeapi.PodSandboxFilter{}
|
||||
fillFields(from)
|
||||
to := v1alpha2PodSandboxFilter(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2ContainerConfig(t *testing.T) {
|
||||
from := &runtimeapi.ContainerConfig{}
|
||||
fillFields(from)
|
||||
to := v1alpha2ContainerConfig(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2ContainerFilter(t *testing.T) {
|
||||
from := &runtimeapi.ContainerFilter{}
|
||||
fillFields(from)
|
||||
to := v1alpha2ContainerFilter(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2LinuxContainerResources(t *testing.T) {
|
||||
from := &runtimeapi.LinuxContainerResources{}
|
||||
fillFields(from)
|
||||
to := v1alpha2LinuxContainerResources(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2ExecRequest(t *testing.T) {
|
||||
from := &runtimeapi.ExecRequest{}
|
||||
fillFields(from)
|
||||
to := v1alpha2ExecRequest(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2AttachRequest(t *testing.T) {
|
||||
from := &runtimeapi.AttachRequest{}
|
||||
fillFields(from)
|
||||
to := v1alpha2AttachRequest(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2PortForwardRequest(t *testing.T) {
|
||||
from := &runtimeapi.PortForwardRequest{}
|
||||
fillFields(from)
|
||||
to := v1alpha2PortForwardRequest(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2RuntimeConfig(t *testing.T) {
|
||||
from := &runtimeapi.RuntimeConfig{}
|
||||
fillFields(from)
|
||||
to := v1alpha2RuntimeConfig(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2ContainerStatsFilter(t *testing.T) {
|
||||
from := &runtimeapi.ContainerStatsFilter{}
|
||||
fillFields(from)
|
||||
to := v1alpha2ContainerStatsFilter(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2PodSandboxStatsFilter(t *testing.T) {
|
||||
from := &runtimeapi.PodSandboxStatsFilter{}
|
||||
fillFields(from)
|
||||
to := v1alpha2PodSandboxStatsFilter(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2ImageFilter(t *testing.T) {
|
||||
from := &runtimeapi.ImageFilter{}
|
||||
fillFields(from)
|
||||
to := v1alpha2ImageFilter(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2ImageSpec(t *testing.T) {
|
||||
from := &runtimeapi.ImageSpec{}
|
||||
fillFields(from)
|
||||
to := v1alpha2ImageSpec(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
||||
|
||||
func TestV1alpha2AuthConfig(t *testing.T) {
|
||||
from := &runtimeapi.AuthConfig{}
|
||||
fillFields(from)
|
||||
to := v1alpha2AuthConfig(from)
|
||||
assertEqual(t, from, to)
|
||||
}
|
@ -34,16 +34,14 @@ import (
|
||||
|
||||
internalapi "k8s.io/cri-api/pkg/apis"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
runtimeapiV1alpha2 "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util"
|
||||
)
|
||||
|
||||
// remoteImageService is a gRPC implementation of internalapi.ImageManagerService.
|
||||
type remoteImageService struct {
|
||||
timeout time.Duration
|
||||
imageClient runtimeapi.ImageServiceClient
|
||||
imageClientV1alpha2 runtimeapiV1alpha2.ImageServiceClient
|
||||
timeout time.Duration
|
||||
imageClient runtimeapi.ImageServiceClient
|
||||
}
|
||||
|
||||
// NewRemoteImageService creates a new internalapi.ImageManagerService.
|
||||
@ -82,43 +80,28 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration, tp
|
||||
|
||||
service := &remoteImageService{timeout: connectionTimeout}
|
||||
|
||||
if err := service.determineAPIVersion(conn, endpoint); err != nil {
|
||||
return nil, err
|
||||
if err := service.validateServiceConnection(conn, endpoint); err != nil {
|
||||
return nil, fmt.Errorf("validate service connection: %w", err)
|
||||
}
|
||||
|
||||
return service, nil
|
||||
|
||||
}
|
||||
|
||||
// useV1API returns true if the v1 CRI API should be used instead of v1alpha2.
|
||||
func (r *remoteImageService) useV1API() bool {
|
||||
return r.imageClientV1alpha2 == nil
|
||||
}
|
||||
|
||||
// determineAPIVersion tries to connect to the remote image service by using the
|
||||
// highest available API version.
|
||||
//
|
||||
// A GRPC redial will always use the initially selected (or automatically
|
||||
// determined) CRI API version. If the redial was due to the container runtime
|
||||
// being upgraded, then the container runtime must also support the initially
|
||||
// selected version or the redial is expected to fail, which requires a restart
|
||||
// of kubelet.
|
||||
func (r *remoteImageService) determineAPIVersion(conn *grpc.ClientConn, endpoint string) error {
|
||||
// validateServiceConnection tries to connect to the remote image service by
|
||||
// using the CRI v1 API version and fails if that's not possible.
|
||||
func (r *remoteImageService) validateServiceConnection(conn *grpc.ClientConn, endpoint string) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
klog.V(4).InfoS("Finding the CRI API image version")
|
||||
klog.V(4).InfoS("Validating the CRI v1 API image version")
|
||||
r.imageClient = runtimeapi.NewImageServiceClient(conn)
|
||||
|
||||
if _, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{}); err == nil {
|
||||
klog.V(2).InfoS("Using CRI v1 image API")
|
||||
klog.V(2).InfoS("Validated CRI v1 image API")
|
||||
|
||||
} else if status.Code(err) == codes.Unimplemented {
|
||||
klog.V(2).InfoS("Falling back to CRI v1alpha2 image API (deprecated)")
|
||||
r.imageClientV1alpha2 = runtimeapiV1alpha2.NewImageServiceClient(conn)
|
||||
|
||||
} else {
|
||||
return fmt.Errorf("unable to determine image API version with %q, or API is not implemented: %w", endpoint, err)
|
||||
return fmt.Errorf("CRI v1 image API is not implemented for endpoint %q: %w", endpoint, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -129,22 +112,7 @@ func (r *remoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runt
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.listImagesV1(ctx, filter)
|
||||
}
|
||||
|
||||
return r.listImagesV1alpha2(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) listImagesV1alpha2(ctx context.Context, filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
resp, err := r.imageClientV1alpha2.ListImages(ctx, &runtimeapiV1alpha2.ListImagesRequest{
|
||||
Filter: v1alpha2ImageFilter(filter),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ListImages with filter from image service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
return fromV1alpha2ListImagesResponse(resp).Images, nil
|
||||
return r.listImagesV1(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) listImagesV1(ctx context.Context, filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
@ -164,37 +132,7 @@ func (r *remoteImageService) ImageStatus(image *runtimeapi.ImageSpec, verbose bo
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
// TODO: for refactoring common code blocks between the cri versions into
|
||||
// one code block in the internal where possible examples:
|
||||
// https://github.com/kubernetes/kubernetes/pull/104575/files#r705600987
|
||||
// https://github.com/kubernetes/kubernetes/pull/104575/files#r696793706
|
||||
if r.useV1API() {
|
||||
return r.imageStatusV1(ctx, image, verbose)
|
||||
}
|
||||
|
||||
return r.imageStatusV1alpha2(ctx, image, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) imageStatusV1alpha2(ctx context.Context, image *runtimeapi.ImageSpec, verbose bool) (*runtimeapi.ImageStatusResponse, error) {
|
||||
resp, err := r.imageClientV1alpha2.ImageStatus(ctx, &runtimeapiV1alpha2.ImageStatusRequest{
|
||||
Image: v1alpha2ImageSpec(image),
|
||||
Verbose: verbose,
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Get ImageStatus from image service failed", "image", image.Image)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Image != nil {
|
||||
if resp.Image.Id == "" || resp.Image.Size_ == 0 {
|
||||
errorMessage := fmt.Sprintf("Id or size of image %q is not set", image.Image)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "ImageStatus failed", "image", image.Image)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return fromV1alpha2ImageStatusResponse(resp), nil
|
||||
return r.imageStatusV1(ctx, image, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) imageStatusV1(ctx context.Context, image *runtimeapi.ImageSpec, verbose bool) (*runtimeapi.ImageStatusResponse, error) {
|
||||
@ -224,31 +162,7 @@ func (r *remoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtim
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.pullImageV1(ctx, image, auth, podSandboxConfig)
|
||||
}
|
||||
|
||||
return r.pullImageV1alpha2(ctx, image, auth, podSandboxConfig)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) pullImageV1alpha2(ctx context.Context, image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
resp, err := r.imageClientV1alpha2.PullImage(ctx, &runtimeapiV1alpha2.PullImageRequest{
|
||||
Image: v1alpha2ImageSpec(image),
|
||||
Auth: v1alpha2AuthConfig(auth),
|
||||
SandboxConfig: v1alpha2PodSandboxConfig(podSandboxConfig),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "PullImage from image service failed", "image", image.Image)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.ImageRef == "" {
|
||||
klog.ErrorS(errors.New("PullImage failed"), "ImageRef of image is not set", "image", image.Image)
|
||||
errorMessage := fmt.Sprintf("imageRef of image %q is not set", image.Image)
|
||||
return "", errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp.ImageRef, nil
|
||||
return r.pullImageV1(ctx, image, auth, podSandboxConfig)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) pullImageV1(ctx context.Context, image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
@ -276,16 +190,9 @@ func (r *remoteImageService) RemoveImage(image *runtimeapi.ImageSpec) (err error
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.imageClient.RemoveImage(ctx, &runtimeapi.RemoveImageRequest{
|
||||
Image: image,
|
||||
})
|
||||
} else {
|
||||
_, err = r.imageClientV1alpha2.RemoveImage(ctx, &runtimeapiV1alpha2.RemoveImageRequest{
|
||||
Image: v1alpha2ImageSpec(image),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err = r.imageClient.RemoveImage(ctx, &runtimeapi.RemoveImageRequest{
|
||||
Image: image,
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "RemoveImage from image service failed", "image", image.Image)
|
||||
return err
|
||||
}
|
||||
@ -300,20 +207,7 @@ func (r *remoteImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.imageFsInfoV1(ctx)
|
||||
}
|
||||
|
||||
return r.imageFsInfoV1alpha2(ctx)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) imageFsInfoV1alpha2(ctx context.Context) ([]*runtimeapi.FilesystemUsage, error) {
|
||||
resp, err := r.imageClientV1alpha2.ImageFsInfo(ctx, &runtimeapiV1alpha2.ImageFsInfoRequest{})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ImageFsInfo from image service failed")
|
||||
return nil, err
|
||||
}
|
||||
return fromV1alpha2ImageFsInfoResponse(resp).GetImageFilesystems(), nil
|
||||
return r.imageFsInfoV1(ctx)
|
||||
}
|
||||
|
||||
func (r *remoteImageService) imageFsInfoV1(ctx context.Context) ([]*runtimeapi.FilesystemUsage, error) {
|
||||
|
@ -34,7 +34,6 @@ import (
|
||||
tracing "k8s.io/component-base/tracing"
|
||||
internalapi "k8s.io/cri-api/pkg/apis"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
runtimeapiV1alpha2 "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util"
|
||||
@ -44,9 +43,8 @@ import (
|
||||
|
||||
// remoteRuntimeService is a gRPC implementation of internalapi.RuntimeService.
|
||||
type remoteRuntimeService struct {
|
||||
timeout time.Duration
|
||||
runtimeClient runtimeapi.RuntimeServiceClient
|
||||
runtimeClientV1alpha2 runtimeapiV1alpha2.RuntimeServiceClient
|
||||
timeout time.Duration
|
||||
runtimeClient runtimeapi.RuntimeServiceClient
|
||||
// Cache last per-container error message to reduce log spam
|
||||
logReduction *logreduction.LogReduction
|
||||
}
|
||||
@ -66,9 +64,6 @@ var ErrContainerStatusNil = errors.New("container status is nil")
|
||||
const (
|
||||
// CRIVersionV1 references the v1 CRI API.
|
||||
CRIVersionV1 CRIVersion = "v1"
|
||||
|
||||
// CRIVersionV1alpha2 references the v1alpha2 CRI API.
|
||||
CRIVersionV1alpha2 CRIVersion = "v1alpha2"
|
||||
)
|
||||
|
||||
// NewRemoteRuntimeService creates a new internalapi.RuntimeService.
|
||||
@ -108,42 +103,27 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration, t
|
||||
logReduction: logreduction.NewLogReduction(identicalErrorDelay),
|
||||
}
|
||||
|
||||
if err := service.determineAPIVersion(conn, endpoint); err != nil {
|
||||
return nil, err
|
||||
if err := service.validateServiceConnection(conn, endpoint); err != nil {
|
||||
return nil, fmt.Errorf("validate service connection: %w", err)
|
||||
}
|
||||
|
||||
return service, nil
|
||||
}
|
||||
|
||||
// useV1API returns true if the v1 CRI API should be used instead of v1alpha2.
|
||||
func (r *remoteRuntimeService) useV1API() bool {
|
||||
return r.runtimeClientV1alpha2 == nil
|
||||
}
|
||||
|
||||
// determineAPIVersion tries to connect to the remote runtime by using the
|
||||
// highest available API version.
|
||||
//
|
||||
// A GRPC redial will always use the initially selected (or automatically
|
||||
// determined) CRI API version. If the redial was due to the container runtime
|
||||
// being upgraded, then the container runtime must also support the initially
|
||||
// selected version or the redial is expected to fail, which requires a restart
|
||||
// of kubelet.
|
||||
func (r *remoteRuntimeService) determineAPIVersion(conn *grpc.ClientConn, endpoint string) error {
|
||||
// validateServiceConnection tries to connect to the remote runtime service by
|
||||
// using the CRI v1 API version and fails if that's not possible.
|
||||
func (r *remoteRuntimeService) validateServiceConnection(conn *grpc.ClientConn, endpoint string) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
klog.V(4).InfoS("Finding the CRI API runtime version")
|
||||
klog.V(4).InfoS("Validating the CRI v1 API runtime version")
|
||||
r.runtimeClient = runtimeapi.NewRuntimeServiceClient(conn)
|
||||
|
||||
if _, err := r.runtimeClient.Version(ctx, &runtimeapi.VersionRequest{}); err == nil {
|
||||
klog.V(2).InfoS("Using CRI v1 runtime API")
|
||||
klog.V(2).InfoS("Validated CRI v1 runtime API")
|
||||
|
||||
} else if status.Code(err) == codes.Unimplemented {
|
||||
klog.V(2).InfoS("Falling back to CRI v1alpha2 runtime API (deprecated)")
|
||||
r.runtimeClientV1alpha2 = runtimeapiV1alpha2.NewRuntimeServiceClient(conn)
|
||||
|
||||
} else {
|
||||
return fmt.Errorf("unable to determine runtime API version with %q, or API is not implemented: %w", endpoint, err)
|
||||
return fmt.Errorf("CRI v1 runtime API is not implemented for endpoint %q: %w", endpoint, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -156,11 +136,7 @@ func (r *remoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.versionV1(ctx, apiVersion)
|
||||
}
|
||||
|
||||
return r.versionV1alpha2(ctx, apiVersion)
|
||||
return r.versionV1(ctx, apiVersion)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) versionV1(ctx context.Context, apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
@ -181,24 +157,6 @@ func (r *remoteRuntimeService) versionV1(ctx context.Context, apiVersion string)
|
||||
return typedVersion, err
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) versionV1alpha2(ctx context.Context, apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
typedVersion, err := r.runtimeClientV1alpha2.Version(ctx, &runtimeapiV1alpha2.VersionRequest{
|
||||
Version: apiVersion,
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Version from runtime service failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Version Response", "apiVersion", typedVersion)
|
||||
|
||||
if typedVersion.Version == "" || typedVersion.RuntimeName == "" || typedVersion.RuntimeApiVersion == "" || typedVersion.RuntimeVersion == "" {
|
||||
return nil, fmt.Errorf("not all fields are set in VersionResponse (%q)", *typedVersion)
|
||||
}
|
||||
|
||||
return fromV1alpha2VersionResponse(typedVersion), err
|
||||
}
|
||||
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
||||
// the sandbox is in ready state.
|
||||
func (r *remoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
|
||||
@ -211,31 +169,18 @@ func (r *remoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
|
||||
ctx, cancel := getContextWithTimeout(timeout)
|
||||
defer cancel()
|
||||
|
||||
var podSandboxID string
|
||||
if r.useV1API() {
|
||||
resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
|
||||
Config: config,
|
||||
RuntimeHandler: runtimeHandler,
|
||||
})
|
||||
resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
|
||||
Config: config,
|
||||
RuntimeHandler: runtimeHandler,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "RunPodSandbox from runtime service failed")
|
||||
return "", err
|
||||
}
|
||||
podSandboxID = resp.PodSandboxId
|
||||
} else {
|
||||
resp, err := r.runtimeClientV1alpha2.RunPodSandbox(ctx, &runtimeapiV1alpha2.RunPodSandboxRequest{
|
||||
Config: v1alpha2PodSandboxConfig(config),
|
||||
RuntimeHandler: runtimeHandler,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "RunPodSandbox from runtime service failed")
|
||||
return "", err
|
||||
}
|
||||
podSandboxID = resp.PodSandboxId
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "RunPodSandbox from runtime service failed")
|
||||
return "", err
|
||||
}
|
||||
|
||||
podSandboxID := resp.PodSandboxId
|
||||
|
||||
if podSandboxID == "" {
|
||||
errorMessage := fmt.Sprintf("PodSandboxId is not set for sandbox %q", config.Metadata)
|
||||
err := errors.New(errorMessage)
|
||||
@ -256,16 +201,9 @@ func (r *remoteRuntimeService) StopPodSandbox(podSandBoxID string) (err error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.StopPodSandbox(ctx, &runtimeapi.StopPodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.StopPodSandbox(ctx, &runtimeapiV1alpha2.StopPodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.StopPodSandbox(ctx, &runtimeapi.StopPodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "StopPodSandbox from runtime service failed", "podSandboxID", podSandBoxID)
|
||||
return err
|
||||
}
|
||||
@ -282,16 +220,9 @@ func (r *remoteRuntimeService) RemovePodSandbox(podSandBoxID string) (err error)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.RemovePodSandbox(ctx, &runtimeapi.RemovePodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.RemovePodSandbox(ctx, &runtimeapiV1alpha2.RemovePodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.RemovePodSandbox(ctx, &runtimeapi.RemovePodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "RemovePodSandbox from runtime service failed", "podSandboxID", podSandBoxID)
|
||||
return err
|
||||
}
|
||||
@ -307,32 +238,7 @@ func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string, verbose boo
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.podSandboxStatusV1(ctx, podSandBoxID, verbose)
|
||||
}
|
||||
|
||||
return r.podSandboxStatusV1alpha2(ctx, podSandBoxID, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) podSandboxStatusV1alpha2(ctx context.Context, podSandBoxID string, verbose bool) (*runtimeapi.PodSandboxStatusResponse, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.PodSandboxStatus(ctx, &runtimeapiV1alpha2.PodSandboxStatusRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
Verbose: verbose,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PodSandboxStatus Response", "podSandboxID", podSandBoxID, "status", resp.Status)
|
||||
|
||||
res := fromV1alpha2PodSandboxStatusResponse(resp)
|
||||
if res.Status != nil {
|
||||
if err := verifySandboxStatus(res.Status); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
return r.podSandboxStatusV1(ctx, podSandBoxID, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) podSandboxStatusV1(ctx context.Context, podSandBoxID string, verbose bool) (*runtimeapi.PodSandboxStatusResponse, error) {
|
||||
@ -362,25 +268,7 @@ func (r *remoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilte
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.listPodSandboxV1(ctx, filter)
|
||||
}
|
||||
|
||||
return r.listPodSandboxV1alpha2(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listPodSandboxV1alpha2(ctx context.Context, filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.ListPodSandbox(ctx, &runtimeapiV1alpha2.ListPodSandboxRequest{
|
||||
Filter: v1alpha2PodSandboxFilter(filter),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ListPodSandbox with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListPodSandbox Response", "filter", filter, "items", resp.Items)
|
||||
|
||||
return fromV1alpha2ListPodSandboxResponse(resp).Items, nil
|
||||
return r.listPodSandboxV1(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listPodSandboxV1(ctx context.Context, filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
@ -403,33 +291,7 @@ func (r *remoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.createContainerV1(ctx, podSandBoxID, config, sandboxConfig)
|
||||
}
|
||||
|
||||
return r.createContainerV1alpha2(ctx, podSandBoxID, config, sandboxConfig)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) createContainerV1alpha2(ctx context.Context, podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.CreateContainer(ctx, &runtimeapiV1alpha2.CreateContainerRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
Config: v1alpha2ContainerConfig(config),
|
||||
SandboxConfig: v1alpha2PodSandboxConfig(sandboxConfig),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "CreateContainer in sandbox from runtime service failed", "podSandboxID", podSandBoxID)
|
||||
return "", err
|
||||
}
|
||||
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] CreateContainer", "podSandboxID", podSandBoxID, "containerID", resp.ContainerId)
|
||||
if resp.ContainerId == "" {
|
||||
errorMessage := fmt.Sprintf("ContainerId is not set for container %q", config.Metadata)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "CreateContainer failed")
|
||||
return "", err
|
||||
}
|
||||
|
||||
return resp.ContainerId, nil
|
||||
return r.createContainerV1(ctx, podSandBoxID, config, sandboxConfig)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) createContainerV1(ctx context.Context, podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
@ -460,17 +322,9 @@ func (r *remoteRuntimeService) StartContainer(containerID string) (err error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.StartContainer(ctx, &runtimeapi.StartContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.StartContainer(ctx, &runtimeapiV1alpha2.StartContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.StartContainer(ctx, &runtimeapi.StartContainerRequest{
|
||||
ContainerId: containerID,
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "StartContainer from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
@ -490,18 +344,10 @@ func (r *remoteRuntimeService) StopContainer(containerID string, timeout int64)
|
||||
|
||||
r.logReduction.ClearID(containerID)
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.StopContainer(ctx, &runtimeapi.StopContainerRequest{
|
||||
ContainerId: containerID,
|
||||
Timeout: timeout,
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.StopContainer(ctx, &runtimeapiV1alpha2.StopContainerRequest{
|
||||
ContainerId: containerID,
|
||||
Timeout: timeout,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.StopContainer(ctx, &runtimeapi.StopContainerRequest{
|
||||
ContainerId: containerID,
|
||||
Timeout: timeout,
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "StopContainer from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
@ -518,16 +364,9 @@ func (r *remoteRuntimeService) RemoveContainer(containerID string) (err error) {
|
||||
defer cancel()
|
||||
|
||||
r.logReduction.ClearID(containerID)
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.RemoveContainer(ctx, &runtimeapi.RemoveContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.RemoveContainer(ctx, &runtimeapiV1alpha2.RemoveContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.RemoveContainer(ctx, &runtimeapi.RemoveContainerRequest{
|
||||
ContainerId: containerID,
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "RemoveContainer from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
@ -542,24 +381,7 @@ func (r *remoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.listContainersV1(ctx, filter)
|
||||
}
|
||||
|
||||
return r.listContainersV1alpha2(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listContainersV1alpha2(ctx context.Context, filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.ListContainers(ctx, &runtimeapiV1alpha2.ListContainersRequest{
|
||||
Filter: v1alpha2ContainerFilter(filter),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ListContainers with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListContainers Response", "filter", filter, "containers", resp.Containers)
|
||||
|
||||
return fromV1alpha2ListContainersResponse(resp).Containers, nil
|
||||
return r.listContainersV1(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listContainersV1(ctx context.Context, filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
@ -581,37 +403,7 @@ func (r *remoteRuntimeService) ContainerStatus(containerID string, verbose bool)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.containerStatusV1(ctx, containerID, verbose)
|
||||
}
|
||||
|
||||
return r.containerStatusV1alpha2(ctx, containerID, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) containerStatusV1alpha2(ctx context.Context, containerID string, verbose bool) (*runtimeapi.ContainerStatusResponse, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.ContainerStatus(ctx, &runtimeapiV1alpha2.ContainerStatusRequest{
|
||||
ContainerId: containerID,
|
||||
Verbose: verbose,
|
||||
})
|
||||
if err != nil {
|
||||
// Don't spam the log with endless messages about the same failure.
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), containerID) {
|
||||
klog.ErrorS(err, "ContainerStatus from runtime service failed", "containerID", containerID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
r.logReduction.ClearID(containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStatus Response", "containerID", containerID, "status", resp.Status)
|
||||
|
||||
res := fromV1alpha2ContainerStatusResponse(resp)
|
||||
if resp.Status != nil {
|
||||
if err := verifyContainerStatus(res.Status); err != nil {
|
||||
klog.ErrorS(err, "verify ContainerStatus failed", "containerID", containerID)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
return r.containerStatusV1(ctx, containerID, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) containerStatusV1(ctx context.Context, containerID string, verbose bool) (*runtimeapi.ContainerStatusResponse, error) {
|
||||
@ -646,20 +438,11 @@ func (r *remoteRuntimeService) UpdateContainerResources(containerID string, reso
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.UpdateContainerResources(ctx, &runtimeapi.UpdateContainerResourcesRequest{
|
||||
ContainerId: containerID,
|
||||
Linux: resources.GetLinux(),
|
||||
Windows: resources.GetWindows(),
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.UpdateContainerResources(ctx, &runtimeapiV1alpha2.UpdateContainerResourcesRequest{
|
||||
ContainerId: containerID,
|
||||
Linux: v1alpha2LinuxContainerResources(resources.GetLinux()),
|
||||
Windows: v1alpha2WindowsContainerResources(resources.GetWindows()),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.UpdateContainerResources(ctx, &runtimeapi.UpdateContainerResourcesRequest{
|
||||
ContainerId: containerID,
|
||||
Linux: resources.GetLinux(),
|
||||
Windows: resources.GetWindows(),
|
||||
}); err != nil {
|
||||
klog.ErrorS(err, "UpdateContainerResources from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
@ -684,42 +467,7 @@ func (r *remoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.execSyncV1(ctx, containerID, cmd, timeout)
|
||||
}
|
||||
|
||||
return r.execSyncV1alpha2(ctx, containerID, cmd, timeout)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) execSyncV1alpha2(ctx context.Context, containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
|
||||
timeoutSeconds := int64(timeout.Seconds())
|
||||
req := &runtimeapiV1alpha2.ExecSyncRequest{
|
||||
ContainerId: containerID,
|
||||
Cmd: cmd,
|
||||
Timeout: timeoutSeconds,
|
||||
}
|
||||
resp, err := r.runtimeClientV1alpha2.ExecSync(ctx, req)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ExecSync cmd from runtime service failed", "containerID", containerID, "cmd", cmd)
|
||||
|
||||
// interpret DeadlineExceeded gRPC errors as timedout probes
|
||||
if status.Code(err) == codes.DeadlineExceeded {
|
||||
err = exec.NewTimeoutError(fmt.Errorf("command %q timed out", strings.Join(cmd, " ")), timeout)
|
||||
}
|
||||
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ExecSync Response", "containerID", containerID, "exitCode", resp.ExitCode)
|
||||
err = nil
|
||||
if resp.ExitCode != 0 {
|
||||
err = utilexec.CodeExitError{
|
||||
Err: fmt.Errorf("command '%s' exited with %d: %s", strings.Join(cmd, " "), resp.ExitCode, resp.Stderr),
|
||||
Code: int(resp.ExitCode),
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Stdout, resp.Stderr, err
|
||||
return r.execSyncV1(ctx, containerID, cmd, timeout)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) execSyncV1(ctx context.Context, containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
|
||||
@ -759,29 +507,7 @@ func (r *remoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.execV1(ctx, req)
|
||||
}
|
||||
|
||||
return r.execV1alpha2(ctx, req)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) execV1alpha2(ctx context.Context, req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.Exec(ctx, v1alpha2ExecRequest(req))
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Exec cmd from runtime service failed", "containerID", req.ContainerId, "cmd", req.Cmd)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Exec Response")
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "Exec failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fromV1alpha2ExecResponse(resp), nil
|
||||
return r.execV1(ctx, req)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) execV1(ctx context.Context, req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
@ -808,28 +534,7 @@ func (r *remoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.attachV1(ctx, req)
|
||||
}
|
||||
|
||||
return r.attachV1alpha2(ctx, req)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) attachV1alpha2(ctx context.Context, req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.Attach(ctx, v1alpha2AttachRequest(req))
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Attach container from runtime service failed", "containerID", req.ContainerId)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Attach Response", "containerID", req.ContainerId)
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "Attach failed")
|
||||
return nil, err
|
||||
}
|
||||
return fromV1alpha2AttachResponse(resp), nil
|
||||
return r.attachV1(ctx, req)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) attachV1(ctx context.Context, req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
||||
@ -855,29 +560,7 @@ func (r *remoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.portForwardV1(ctx, req)
|
||||
}
|
||||
|
||||
return r.portForwardV1alpha2(ctx, req)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) portForwardV1alpha2(ctx context.Context, req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.PortForward(ctx, v1alpha2PortForwardRequest(req))
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "PortForward from runtime service failed", "podSandboxID", req.PodSandboxId)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PortForward Response", "podSandboxID", req.PodSandboxId)
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "PortForward failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fromV1alpha2PortForwardResponse(resp), nil
|
||||
return r.portForwardV1(ctx, req)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) portForwardV1(ctx context.Context, req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
|
||||
@ -909,17 +592,9 @@ func (r *remoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.Run
|
||||
// Response doesn't contain anything of interest. This translates to an
|
||||
// Event notification to the network plugin, which can't fail, so we're
|
||||
// really looking to surface destination unreachable.
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.UpdateRuntimeConfig(ctx, &runtimeapi.UpdateRuntimeConfigRequest{
|
||||
RuntimeConfig: runtimeConfig,
|
||||
})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.UpdateRuntimeConfig(ctx, &runtimeapiV1alpha2.UpdateRuntimeConfigRequest{
|
||||
RuntimeConfig: v1alpha2RuntimeConfig(runtimeConfig),
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.UpdateRuntimeConfig(ctx, &runtimeapi.UpdateRuntimeConfigRequest{
|
||||
RuntimeConfig: runtimeConfig,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] UpdateRuntimeConfig Response", "runtimeConfig", runtimeConfig)
|
||||
@ -933,32 +608,7 @@ func (r *remoteRuntimeService) Status(verbose bool) (*runtimeapi.StatusResponse,
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.statusV1(ctx, verbose)
|
||||
}
|
||||
|
||||
return r.statusV1alpha2(ctx, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) statusV1alpha2(ctx context.Context, verbose bool) (*runtimeapi.StatusResponse, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.Status(ctx, &runtimeapiV1alpha2.StatusRequest{
|
||||
Verbose: verbose,
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Status from runtime service failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Status Response", "status", resp.Status)
|
||||
|
||||
if resp.Status == nil || len(resp.Status.Conditions) < 2 {
|
||||
errorMessage := "RuntimeReady or NetworkReady condition are not set"
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "Status failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fromV1alpha2StatusResponse(resp), nil
|
||||
return r.statusV1(ctx, verbose)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) statusV1(ctx context.Context, verbose bool) (*runtimeapi.StatusResponse, error) {
|
||||
@ -988,27 +638,7 @@ func (r *remoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.containerStatsV1(ctx, containerID)
|
||||
}
|
||||
|
||||
return r.containerStatsV1alpha2(ctx, containerID)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) containerStatsV1alpha2(ctx context.Context, containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.ContainerStats(ctx, &runtimeapiV1alpha2.ContainerStatsRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), containerID) {
|
||||
klog.ErrorS(err, "ContainerStats from runtime service failed", "containerID", containerID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
r.logReduction.ClearID(containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStats Response", "containerID", containerID, "stats", resp.GetStats())
|
||||
|
||||
return fromV1alpha2ContainerStats(resp.GetStats()), nil
|
||||
return r.containerStatsV1(ctx, containerID)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) containerStatsV1(ctx context.Context, containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
@ -1035,24 +665,7 @@ func (r *remoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.listContainerStatsV1(ctx, filter)
|
||||
}
|
||||
|
||||
return r.listContainerStatsV1alpha2(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listContainerStatsV1alpha2(ctx context.Context, filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.ListContainerStats(ctx, &runtimeapiV1alpha2.ListContainerStatsRequest{
|
||||
Filter: v1alpha2ContainerStatsFilter(filter),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ListContainerStats with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListContainerStats Response", "filter", filter, "stats", resp.GetStats())
|
||||
|
||||
return fromV1alpha2ListContainerStatsResponse(resp).GetStats(), nil
|
||||
return r.listContainerStatsV1(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listContainerStatsV1(ctx context.Context, filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
@ -1074,27 +687,7 @@ func (r *remoteRuntimeService) PodSandboxStats(podSandboxID string) (*runtimeapi
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.podSandboxStatsV1(ctx, podSandboxID)
|
||||
}
|
||||
|
||||
return r.podSandboxStatsV1alpha2(ctx, podSandboxID)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) podSandboxStatsV1alpha2(ctx context.Context, podSandboxID string) (*runtimeapi.PodSandboxStats, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.PodSandboxStats(ctx, &runtimeapiV1alpha2.PodSandboxStatsRequest{
|
||||
PodSandboxId: podSandboxID,
|
||||
})
|
||||
if err != nil {
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), podSandboxID) {
|
||||
klog.ErrorS(err, "PodSandbox from runtime service failed", "podSandboxID", podSandboxID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
r.logReduction.ClearID(podSandboxID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PodSandbox Response", "podSandboxID", podSandboxID, "stats", resp.GetStats())
|
||||
|
||||
return fromV1alpha2PodSandboxStats(resp.GetStats()), nil
|
||||
return r.podSandboxStatsV1(ctx, podSandboxID)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) podSandboxStatsV1(ctx context.Context, podSandboxID string) (*runtimeapi.PodSandboxStats, error) {
|
||||
@ -1120,24 +713,7 @@ func (r *remoteRuntimeService) ListPodSandboxStats(filter *runtimeapi.PodSandbox
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
return r.listPodSandboxStatsV1(ctx, filter)
|
||||
}
|
||||
|
||||
return r.listPodSandboxStatsV1alpha2(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listPodSandboxStatsV1alpha2(ctx context.Context, filter *runtimeapi.PodSandboxStatsFilter) ([]*runtimeapi.PodSandboxStats, error) {
|
||||
resp, err := r.runtimeClientV1alpha2.ListPodSandboxStats(ctx, &runtimeapiV1alpha2.ListPodSandboxStatsRequest{
|
||||
Filter: v1alpha2PodSandboxStatsFilter(filter),
|
||||
})
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "ListPodSandboxStats with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListPodSandboxStats Response", "filter", filter, "stats", resp.GetStats())
|
||||
|
||||
return fromV1alpha2ListPodSandboxStatsResponse(resp).GetStats(), nil
|
||||
return r.listPodSandboxStatsV1(ctx, filter)
|
||||
}
|
||||
|
||||
func (r *remoteRuntimeService) listPodSandboxStatsV1(ctx context.Context, filter *runtimeapi.PodSandboxStatsFilter) ([]*runtimeapi.PodSandboxStats, error) {
|
||||
@ -1159,12 +735,7 @@ func (r *remoteRuntimeService) ReopenContainerLog(containerID string) (err error
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
if r.useV1API() {
|
||||
_, err = r.runtimeClient.ReopenContainerLog(ctx, &runtimeapi.ReopenContainerLogRequest{ContainerId: containerID})
|
||||
} else {
|
||||
_, err = r.runtimeClientV1alpha2.ReopenContainerLog(ctx, &runtimeapiV1alpha2.ReopenContainerLogRequest{ContainerId: containerID})
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := r.runtimeClient.ReopenContainerLog(ctx, &runtimeapi.ReopenContainerLogRequest{ContainerId: containerID}); err != nil {
|
||||
klog.ErrorS(err, "ReopenContainerLog from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
@ -1183,10 +754,6 @@ func (r *remoteRuntimeService) CheckpointContainer(options *runtimeapi.Checkpoin
|
||||
if options == nil {
|
||||
return errors.New("CheckpointContainer requires non-nil CheckpointRestoreOptions parameter")
|
||||
}
|
||||
if !r.useV1API() {
|
||||
return errors.New("CheckpointContainer is only supported in the CRI v1 runtime API")
|
||||
}
|
||||
|
||||
if options.Timeout < 0 {
|
||||
return errors.New("CheckpointContainer requires the timeout value to be > 0")
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,55 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 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 v1alpha2
|
||||
|
||||
// This file contains all constants defined in CRI.
|
||||
|
||||
// Required runtime condition type.
|
||||
const (
|
||||
// RuntimeReady means the runtime is up and ready to accept basic containers.
|
||||
RuntimeReady = "RuntimeReady"
|
||||
// NetworkReady means the runtime network is up and ready to accept containers which require network.
|
||||
NetworkReady = "NetworkReady"
|
||||
)
|
||||
|
||||
// LogStreamType is the type of the stream in CRI container log.
|
||||
type LogStreamType string
|
||||
|
||||
const (
|
||||
// Stdout is the stream type for stdout.
|
||||
Stdout LogStreamType = "stdout"
|
||||
// Stderr is the stream type for stderr.
|
||||
Stderr LogStreamType = "stderr"
|
||||
)
|
||||
|
||||
// LogTag is the tag of a log line in CRI container log.
|
||||
// Currently defined log tags:
|
||||
// * First tag: Partial/Full - P/F.
|
||||
// The field in the container log format can be extended to include multiple
|
||||
// tags by using a delimiter, but changes should be rare. If it becomes clear
|
||||
// that better extensibility is desired, a more extensible format (e.g., json)
|
||||
// should be adopted as a replacement and/or addition.
|
||||
type LogTag string
|
||||
|
||||
const (
|
||||
// LogTagPartial means the line is part of multiple lines.
|
||||
LogTagPartial LogTag = "P"
|
||||
// LogTagFull means the line is a single full line or the end of multiple lines.
|
||||
LogTagFull LogTag = "F"
|
||||
// LogTagDelimiter is the delimiter for different log tags.
|
||||
LogTagDelimiter = ":"
|
||||
)
|
1
vendor/modules.txt
vendored
1
vendor/modules.txt
vendored
@ -2027,7 +2027,6 @@ k8s.io/controller-manager/pkg/leadermigration/options
|
||||
## explicit; go 1.19
|
||||
k8s.io/cri-api/pkg/apis
|
||||
k8s.io/cri-api/pkg/apis/runtime/v1
|
||||
k8s.io/cri-api/pkg/apis/runtime/v1alpha2
|
||||
k8s.io/cri-api/pkg/apis/testing
|
||||
k8s.io/cri-api/pkg/errors
|
||||
# k8s.io/csi-translation-lib v0.0.0 => ./staging/src/k8s.io/csi-translation-lib
|
||||
|
Loading…
Reference in New Issue
Block a user