Skip to content

Commit 2e182e7

Browse files
committed
feat: Add cri proxy for e2e_node
add example of using CRI proxy fix: Invalid function call fix: Optimize getPodImagePullDuration fix: Return error if the CRI Proxy is undefined chore: add a document
1 parent a0db55c commit 2e182e7

File tree

8 files changed

+887
-1
lines changed

8 files changed

+887
-1
lines changed

test/e2e/feature/feature.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ var (
363363
// (used for testing fine-grained SupplementalGroups control <https://kep.k8s.io/3619>)
364364
SupplementalGroupsPolicy = framework.WithFeature(framework.ValidFeatures.Add("SupplementalGroupsPolicy"))
365365

366+
// Owner: sig-node
367+
// Tests marked with this feature MUST run with the CRI Proxy configured so errors can be injected into the kubelet's CRI calls.
368+
// This is useful for testing how the kubelet handles various error conditions in its CRI interactions.
369+
// test-infra jobs:
370+
// - pull-kubernetes-node-e2e-cri-proxy-serial (need manual trigger)
371+
// - ci-kubernetes-node-e2e-cri-proxy-serial
372+
CriProxy = framework.WithFeature(framework.ValidFeatures.Add("CriProxy"))
373+
366374
// Owner: sig-network
367375
// Marks tests that require a cluster with Topology Hints enabled.
368376
TopologyHints = framework.WithFeature(framework.ValidFeatures.Add("Topology Hints"))

test/e2e/framework/test_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ type NodeTestContextType struct {
277277
ExtraEnvs map[string]string
278278
// StandaloneMode indicates whether the test is running kubelet in a standalone mode.
279279
StandaloneMode bool
280+
// CriProxyEnabled indicates whether enable CRI API proxy for failure injection.
281+
CriProxyEnabled bool
280282
}
281283

282284
// CloudConfig holds the cloud configuration for e2e test suites.

test/e2e_node/criproxy/endpoint.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package criproxy
18+
19+
import (
20+
"fmt"
21+
22+
"k8s.io/apimachinery/pkg/util/rand"
23+
)
24+
25+
const (
26+
defaultUnixEndpoint = "unix:///tmp/kubelet_remote_proxy_%v.sock"
27+
)
28+
29+
// GenerateEndpoint generates a new unix socket server of grpc server.
30+
func GenerateEndpoint() (string, error) {
31+
// use random int be a part fo file name
32+
return fmt.Sprintf(defaultUnixEndpoint, rand.Int()), nil
33+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package criproxy
18+
19+
import (
20+
"context"
21+
22+
kubeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
23+
)
24+
25+
const (
26+
ListImages = "ListImages"
27+
ImageStatus = "ImageStatus"
28+
PullImage = "PullImage"
29+
RemoveImage = "RemoveImage"
30+
ImageFsInfo = "ImageFsInfo"
31+
)
32+
33+
// ListImages lists existing images.
34+
func (p *RemoteRuntime) ListImages(ctx context.Context, req *kubeapi.ListImagesRequest) (*kubeapi.ListImagesResponse, error) {
35+
if err := p.runInjectors(ListImages); err != nil {
36+
return nil, err
37+
}
38+
39+
images, err := p.imageService.ListImages(ctx, req.Filter)
40+
if err != nil {
41+
return nil, err
42+
}
43+
return &kubeapi.ListImagesResponse{
44+
Images: images,
45+
}, nil
46+
}
47+
48+
// ImageStatus returns the status of the image. If the image is not
49+
// present, returns a response with ImageStatusResponse.Image set to
50+
// nil.
51+
func (p *RemoteRuntime) ImageStatus(ctx context.Context, req *kubeapi.ImageStatusRequest) (*kubeapi.ImageStatusResponse, error) {
52+
if err := p.runInjectors(ImageStatus); err != nil {
53+
return nil, err
54+
}
55+
56+
resp, err := p.imageService.ImageStatus(ctx, req.Image, false)
57+
if err != nil {
58+
return nil, err
59+
}
60+
return resp, nil
61+
}
62+
63+
// PullImage pulls an image with authentication config.
64+
func (p *RemoteRuntime) PullImage(ctx context.Context, req *kubeapi.PullImageRequest) (*kubeapi.PullImageResponse, error) {
65+
if err := p.runInjectors(PullImage); err != nil {
66+
return nil, err
67+
}
68+
69+
image, err := p.imageService.PullImage(ctx, req.Image, req.Auth, req.SandboxConfig)
70+
if err != nil {
71+
return nil, err
72+
}
73+
return &kubeapi.PullImageResponse{
74+
ImageRef: image,
75+
}, nil
76+
}
77+
78+
// RemoveImage removes the image.
79+
// This call is idempotent, and must not return an error if the image has
80+
// already been removed.
81+
func (p *RemoteRuntime) RemoveImage(ctx context.Context, req *kubeapi.RemoveImageRequest) (*kubeapi.RemoveImageResponse, error) {
82+
if err := p.runInjectors(RemoveImage); err != nil {
83+
return nil, err
84+
}
85+
86+
err := p.imageService.RemoveImage(ctx, req.Image)
87+
if err != nil {
88+
return nil, err
89+
}
90+
return &kubeapi.RemoveImageResponse{}, nil
91+
}
92+
93+
// ImageFsInfo returns information of the filesystem that is used to store images.
94+
func (p *RemoteRuntime) ImageFsInfo(ctx context.Context, req *kubeapi.ImageFsInfoRequest) (*kubeapi.ImageFsInfoResponse, error) {
95+
if err := p.runInjectors(ImageFsInfo); err != nil {
96+
return nil, err
97+
}
98+
99+
resp, err := p.imageService.ImageFsInfo(ctx)
100+
if err != nil {
101+
return nil, err
102+
}
103+
return resp, nil
104+
}

0 commit comments

Comments
 (0)