|
| 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 validate |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + |
| 22 | + "github.com/google/uuid" |
| 23 | + . "github.com/onsi/ginkgo/v2" |
| 24 | + . "github.com/onsi/gomega" |
| 25 | + internalapi "k8s.io/cri-api/pkg/apis" |
| 26 | + |
| 27 | + "sigs.k8s.io/cri-tools/pkg/framework" |
| 28 | +) |
| 29 | + |
| 30 | +var _ = framework.KubeDescribe("Idempotence", func() { |
| 31 | + f := framework.NewDefaultCRIFramework() |
| 32 | + c := context.Background() |
| 33 | + |
| 34 | + var ( |
| 35 | + rc internalapi.RuntimeService |
| 36 | + ic internalapi.ImageManagerService |
| 37 | + ) |
| 38 | + |
| 39 | + BeforeEach(func() { |
| 40 | + rc = f.CRIClient.CRIRuntimeClient |
| 41 | + ic = f.CRIClient.CRIImageClient |
| 42 | + }) |
| 43 | + |
| 44 | + // https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L45-L46 |
| 45 | + Context("StopPodSandbox", func() { |
| 46 | + It("should not return an error if not found", func() { |
| 47 | + By("stop not existing sandbox") |
| 48 | + Expect(rc.StopPodSandbox(c, uuid.New().String())).NotTo(HaveOccurred()) |
| 49 | + }) |
| 50 | + |
| 51 | + It("should not return an error if already stopped", func() { |
| 52 | + By("run PodSandbox") |
| 53 | + podID := framework.RunDefaultPodSandbox(rc, "idempotence-pod-") |
| 54 | + |
| 55 | + By("stop sandbox") |
| 56 | + testStopPodSandbox(rc, podID) |
| 57 | + |
| 58 | + By("stop sandbox again") |
| 59 | + testStopPodSandbox(rc, podID) |
| 60 | + }) |
| 61 | + }) |
| 62 | + |
| 63 | + // https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L53-L54 |
| 64 | + It("RemovePodSandbox should not return an error if not found", func() { |
| 65 | + By("remove not existing sandbox") |
| 66 | + Expect(rc.RemovePodSandbox(c, uuid.New().String())).NotTo(HaveOccurred()) |
| 67 | + }) |
| 68 | + |
| 69 | + // https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L67-L68 |
| 70 | + Context("StopContainer", func() { |
| 71 | + It("should not return an error if not found", func() { |
| 72 | + By("test stop not existing container") |
| 73 | + Expect(rc.StopContainer(c, uuid.New().String(), 0)).NotTo(HaveOccurred()) |
| 74 | + }) |
| 75 | + |
| 76 | + It("should not return an error if already stopped", func() { |
| 77 | + By("create sandbox") |
| 78 | + podID, podConfig := framework.CreatePodSandboxForContainer(rc) |
| 79 | + |
| 80 | + By("create container") |
| 81 | + containerID := framework.CreatePauseContainer(rc, ic, podID, podConfig, "idempotence-container-") |
| 82 | + |
| 83 | + By("start container") |
| 84 | + startContainer(rc, containerID) |
| 85 | + |
| 86 | + By("stop container") |
| 87 | + testStopContainer(rc, containerID) |
| 88 | + |
| 89 | + By("remove container") |
| 90 | + removeContainer(rc, containerID) |
| 91 | + |
| 92 | + By("remove container again") |
| 93 | + removeContainer(rc, containerID) |
| 94 | + }) |
| 95 | + }) |
| 96 | + |
| 97 | + // https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L74-L75 |
| 98 | + It("RemoveContainer should not return an error if not found", func() { |
| 99 | + By("remove not existing comtainer") |
| 100 | + Expect(rc.RemoveContainer(c, uuid.New().String())).NotTo(HaveOccurred()) |
| 101 | + }) |
| 102 | +}) |
0 commit comments