-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathnode.go
More file actions
330 lines (290 loc) · 12.2 KB
/
node.go
File metadata and controls
330 lines (290 loc) · 12.2 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
package node
import (
"context"
"fmt"
"path/filepath"
"regexp"
"strings"
"time"
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
e2e "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
nodeutils "github.com/openshift/origin/test/extended/node"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("[sig-node] [Jira:Node/Kubelet] Kubelet, CRI-O, CPU manager", func() {
var (
oc = exutil.NewCLIWithoutNamespace("node")
nodeE2EBaseDir = exutil.FixturePath("testdata", "node", "node_e2e")
podDevFuseYAML = filepath.Join(nodeE2EBaseDir, "pod-dev-fuse.yaml")
)
// Skip all tests on MicroShift clusters as MachineConfig resources are not available
g.BeforeEach(func() {
var isMicroShift bool
var err error
// Retry check for robustness - OpenShift should eventually respond
pollErr := wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
isMicroShift, err = exutil.IsMicroShiftCluster(oc.AdminKubeClient())
if err != nil {
e2e.Logf("Failed to check if cluster is MicroShift: %v, retrying...", err)
return false, nil
}
return true, nil
})
if pollErr != nil {
e2e.Logf("Setup failed: unable to determine if cluster is MicroShift after retries: %v", err)
g.Fail("Setup failed: unable to determine cluster type - this is an infrastructure/connectivity issue, not a test failure")
}
if isMicroShift {
g.Skip("Skipping test on MicroShift cluster - MachineConfig resources are not available")
}
})
//author: [email protected]
g.It("[OTP] validate KUBELET_LOG_LEVEL", func() {
var kubeservice string
var kubelet string
var err error
g.By("Polling to check kubelet log level on ready nodes")
waitErr := wait.Poll(10*time.Second, 1*time.Minute, func() (bool, error) {
g.By("Getting all node names in the cluster")
nodeName, nodeErr := oc.AsAdmin().Run("get").Args("nodes", "-o=jsonpath={.items[*].metadata.name}").Output()
o.Expect(nodeErr).NotTo(o.HaveOccurred())
e2e.Logf("\nNode Names are %v", nodeName)
nodes := strings.Fields(nodeName)
for _, node := range nodes {
g.By("Checking if node " + node + " is Ready")
nodeStatus, statusErr := oc.AsAdmin().Run("get").Args("nodes", node, "-o=jsonpath={.status.conditions[?(@.type=='Ready')].status}").Output()
o.Expect(statusErr).NotTo(o.HaveOccurred())
e2e.Logf("\nNode %s Status is %s\n", node, nodeStatus)
if nodeStatus == "True" {
g.By("Checking KUBELET_LOG_LEVEL in kubelet.service on node " + node)
kubeservice, err = nodeutils.ExecOnNodeWithChroot(oc, node, "/bin/bash", "-c", "systemctl show kubelet.service | grep KUBELET_LOG_LEVEL")
o.Expect(err).NotTo(o.HaveOccurred())
g.By("Checking kubelet process for --v=2 flag on node " + node)
kubelet, err = nodeutils.ExecOnNodeWithChroot(oc, node, "/bin/bash", "-c", "ps aux | grep [k]ubelet")
o.Expect(err).NotTo(o.HaveOccurred())
g.By("Verifying KUBELET_LOG_LEVEL is set and kubelet is running with --v=2")
if strings.Contains(kubeservice, "KUBELET_LOG_LEVEL") && strings.Contains(kubelet, "--v=2") {
e2e.Logf("KUBELET_LOG_LEVEL is 2.\n")
return true, nil
} else {
e2e.Logf("KUBELET_LOG_LEVEL is not 2.\n")
return false, nil
}
} else {
e2e.Logf("\nNode %s is not Ready, Skipping\n", node)
}
}
return false, nil
})
if waitErr != nil {
e2e.Logf("Kubelet Log level is:\n %v\n", kubeservice)
e2e.Logf("Running Process of kubelet are:\n %v\n", kubelet)
}
o.Expect(waitErr).NotTo(o.HaveOccurred(), "KUBELET_LOG_LEVEL is not expected, timed out")
})
//author: [email protected]
g.It("[OTP] validate cgroupv2 is default [OCP-80983]", func() {
g.By("Check cgroup version on all Ready worker nodes")
nodeNames, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("nodes", "-l", "node-role.kubernetes.io/worker", "-o=jsonpath={.items[*].metadata.name}").Output()
o.Expect(err).NotTo(o.HaveOccurred())
workers := strings.Fields(nodeNames)
o.Expect(workers).NotTo(o.BeEmpty(), "No worker nodes found")
for _, worker := range workers {
nodeStatus, err := oc.AsAdmin().Run("get").Args("nodes", worker, "-o=jsonpath={.status.conditions[?(@.type=='Ready')].status}").Output()
o.Expect(err).NotTo(o.HaveOccurred())
if nodeStatus != "True" {
e2e.Logf("Skipping worker node %s (not Ready)", worker)
continue
}
cgroupV, err := nodeutils.ExecOnNodeWithChroot(oc, worker, "/bin/bash", "-c", "stat -c %T -f /sys/fs/cgroup")
o.Expect(err).NotTo(o.HaveOccurred())
e2e.Logf("cgroup version on node %s: [%v]", worker, cgroupV)
o.Expect(cgroupV).To(o.ContainSubstring("cgroup2fs"), "Node %s does not have cgroupv2", worker)
}
g.By("Changing cgroup from v2 to v1 should result in error")
output, err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("nodes.config.openshift.io", "cluster", "-p", `{"spec": {"cgroupMode": "v1"}}`, "--type=merge").Output()
o.Expect(err).Should(o.HaveOccurred())
o.Expect(output).To(o.ContainSubstring("spec.cgroupMode: Unsupported value: \"v1\": supported values: \"v2\", \"\""))
})
//author: [email protected]
g.It("[OTP] Allow dev fuse by default in CRI-O [OCP-70987]", func() {
podName := "pod-devfuse"
ns := "devfuse-test"
g.By("Create a test namespace")
err := oc.AsAdmin().WithoutNamespace().Run("create").Args("namespace", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("namespace", ns, "--ignore-not-found").Execute()
g.By("Create a pod with dev fuse annotation")
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", podDevFuseYAML, "-n", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("Wait for pod to be ready")
err = wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) {
status, pollErr := oc.AsAdmin().WithoutNamespace().Run("get").Args("pod", podName, "-n", ns, "-o=jsonpath={.status.conditions[?(@.type=='Ready')].status}").Output()
if pollErr != nil {
e2e.Logf("Error polling pod status: %v", pollErr)
return false, nil
}
return status == "True", nil
})
if err != nil {
podStatus, _ := oc.AsAdmin().WithoutNamespace().Run("get").Args("pod", podName, "-n", ns, "-o=jsonpath={.status}").Output()
e2e.Logf("Pod status on timeout: %s", podStatus)
}
o.Expect(err).NotTo(o.HaveOccurred(), "pod did not become ready")
g.By("Check /dev/fuse is mounted inside the pod")
output, err := oc.AsAdmin().WithoutNamespace().Run("exec").Args(podName, "-n", ns, "--", "stat", "/dev/fuse").Output()
o.Expect(err).NotTo(o.HaveOccurred())
e2e.Logf("/dev/fuse mount output: %s", output)
o.Expect(output).To(o.ContainSubstring("fuse"), "dev fuse is not mounted inside pod")
})
})
var _ = g.Describe("[sig-node] [Jira:Node/Kubelet] NODE initContainer policy,volume,readiness,quota", func() {
defer g.GinkgoRecover()
var (
oc = exutil.NewCLI("node-initcontainer")
)
// Skip all tests on MicroShift clusters as MachineConfig resources are not available
g.BeforeEach(func() {
var isMicroShift bool
var err error
// Retry check for robustness - OpenShift should eventually respond
pollErr := wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
isMicroShift, err = exutil.IsMicroShiftCluster(oc.AdminKubeClient())
if err != nil {
e2e.Logf("Failed to check if cluster is MicroShift: %v, retrying...", err)
return false, nil
}
return true, nil
})
if pollErr != nil {
e2e.Logf("Setup failed: unable to determine if cluster is MicroShift after retries: %v", err)
g.Fail("Setup failed: unable to determine cluster type - this is an infrastructure/connectivity issue, not a test failure")
}
if isMicroShift {
g.Skip("Skipping test on MicroShift cluster - MachineConfig resources are not available")
}
})
//author: [email protected]
g.It("[OTP] Init containers should not restart when the exited init container is removed from node [OCP-38271]", func() {
g.By("Test for case OCP-38271")
oc.SetupProject()
podName := "initcon-pod"
namespace := oc.Namespace()
ctx := context.Background()
g.By("Create a pod with init container")
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Namespace: namespace,
},
Spec: corev1.PodSpec{
InitContainers: []corev1.Container{
{
Name: "inittest",
Image: "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f",
Command: []string{"/bin/sh", "-ec", "echo running >> /mnt/data/test"},
VolumeMounts: []corev1.VolumeMount{
{
Name: "data",
MountPath: "/mnt/data",
},
},
},
},
Containers: []corev1.Container{
{
Name: "hello-test",
Image: "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f",
Command: []string{"/bin/sh", "-c", "sleep 3600"},
VolumeMounts: []corev1.VolumeMount{
{
Name: "data",
MountPath: "/mnt/data",
},
},
},
},
Volumes: []corev1.Volume{
{
Name: "data",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
},
RestartPolicy: corev1.RestartPolicyNever,
},
}
_, err := oc.KubeClient().CoreV1().Pods(namespace).Create(ctx, pod, metav1.CreateOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
defer func() {
oc.KubeClient().CoreV1().Pods(namespace).Delete(ctx, podName, metav1.DeleteOptions{})
}()
g.By("Check pod status")
err = e2epod.WaitForPodRunningInNamespace(ctx, oc.KubeClient(), pod)
o.Expect(err).NotTo(o.HaveOccurred(), "pod is not running")
g.By("Check init container exit normally")
err = wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) {
pod, err := oc.KubeClient().CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
return false, err
}
for _, status := range pod.Status.InitContainerStatuses {
if status.Name == "inittest" {
if status.State.Terminated != nil && status.State.Terminated.ExitCode == 0 {
e2e.Logf("Init container exited with code 0")
return true, nil
}
}
}
return false, nil
})
o.Expect(err).NotTo(o.HaveOccurred(), "container not exit normally")
g.By("Get node where pod is running")
pod, err = oc.KubeClient().CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
nodeName := pod.Spec.NodeName
o.Expect(nodeName).NotTo(o.BeEmpty(), "pod node name is empty")
g.By("Get init container ID from pod status")
var containerID string
for _, status := range pod.Status.InitContainerStatuses {
if status.Name == "inittest" {
containerID = status.ContainerID
break
}
}
o.Expect(containerID).NotTo(o.BeEmpty(), "init container ID is empty")
// Extract the actual container ID (remove prefix like "cri-o://")
containerIDPattern := regexp.MustCompile(`^[^/]+://(.+)$`)
matches := containerIDPattern.FindStringSubmatch(containerID)
o.Expect(matches).To(o.HaveLen(2), "failed to parse container ID")
actualContainerID := matches[1]
g.By("Delete init container from node")
output, err := nodeutils.ExecOnNodeWithChroot(oc, nodeName, "crictl", "rm", actualContainerID)
o.Expect(err).NotTo(o.HaveOccurred(), "fail to delete container")
e2e.Logf("Container deletion output: %s", output)
g.By("Check init container not restart again")
err = wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) {
pod, err := oc.KubeClient().CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
return false, err
}
for _, status := range pod.Status.InitContainerStatuses {
if status.Name == "inittest" {
if status.RestartCount > 0 {
e2e.Logf("Init container restarted, restart count: %d", status.RestartCount)
return true, fmt.Errorf("init container restarted")
}
}
}
e2e.Logf("Init container has not restarted")
return false, nil
})
o.Expect(err).To(o.Equal(wait.ErrWaitTimeout), "expected timeout while waiting confirms init container did not restart")
})
})