Skip to content

Commit a376ae5

Browse files
authored
Merge pull request kubernetes#128845 from SergeyKanzhelev/staticPodUpgrade
static pod upgrade test with hostNetwork
2 parents 28ba942 + a9c311b commit a376ae5

File tree

2 files changed

+129
-5
lines changed

2 files changed

+129
-5
lines changed

test/e2e/feature/feature.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ var (
456456
// TODO: document the feature (owning SIG, when to use this feature for a test)
457457
StackdriverMonitoring = framework.WithFeature(framework.ValidFeatures.Add("StackdriverMonitoring"))
458458

459-
// TODO: document the feature (owning SIG, when to use this feature for a test)
459+
// Tests marked with this feature require the kubelet to be running in standalone mode (--standalone-mode=true) like this:
460+
// make test-e2e-node PARALLELISM=1 FOCUS="StandaloneMode" TEST_ARGS='--kubelet-flags="--fail-swap-on=false" --standalone-mode=true'
461+
// Tests validating the behavior of kubelet when running without the API server.
460462
StandaloneMode = framework.WithFeature(framework.ValidFeatures.Add("StandaloneMode"))
461463

462464
// TODO: document the feature (owning SIG, when to use this feature for a test)

test/e2e_node/standalone_test.go

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ var _ = SIGDescribe(feature.StandaloneMode, func() {
5656
staticPodName = "static-pod-" + string(uuid.NewUUID())
5757
podPath = kubeletCfg.StaticPodPath
5858

59-
err := createBasicStaticPod(podPath, staticPodName, ns)
59+
err := scheduleStaticPod(podPath, staticPodName, ns, createBasicStaticPodSpec(staticPodName, ns))
6060
framework.ExpectNoError(err)
6161

6262
gomega.Eventually(ctx, func(ctx context.Context) error {
6363
pod, err := getPodFromStandaloneKubelet(ctx, ns, staticPodName)
6464
if err != nil {
65-
return fmt.Errorf("error getting pod(%v/%v) from standalone kubelet: %v", ns, staticPodName, err)
65+
return fmt.Errorf("error getting pod(%v/%v) from standalone kubelet: %w", ns, staticPodName, err)
6666
}
6767

6868
isReady, err := testutils.PodRunningReady(pod)
6969
if err != nil {
70-
return fmt.Errorf("error checking if pod (%v/%v) is running ready: %v", ns, staticPodName, err)
70+
return fmt.Errorf("error checking if pod (%v/%v) is running ready: %w", ns, staticPodName, err)
7171
}
7272
if !isReady {
7373
return fmt.Errorf("pod (%v/%v) is not running", ns, staticPodName)
@@ -76,6 +76,124 @@ var _ = SIGDescribe(feature.StandaloneMode, func() {
7676
}, f.Timeouts.PodStart, time.Second*5).Should(gomega.BeNil())
7777
})
7878

79+
ginkgo.It("the pod with the port on host network should be running and can be upgraded when the container name changes", func(ctx context.Context) {
80+
ns = f.Namespace.Name
81+
staticPodName = "static-pod-" + string(uuid.NewUUID())
82+
podPath = kubeletCfg.StaticPodPath
83+
84+
podSpec := createBasicStaticPodSpec(staticPodName, ns)
85+
podSpec.Spec.HostNetwork = true
86+
podSpec.Spec.Containers[0].Ports = []v1.ContainerPort{
87+
{
88+
Name: "tcp",
89+
ContainerPort: 4534,
90+
Protocol: v1.ProtocolTCP,
91+
},
92+
}
93+
err := scheduleStaticPod(podPath, staticPodName, ns, podSpec)
94+
framework.ExpectNoError(err)
95+
96+
gomega.Eventually(ctx, func(ctx context.Context) error {
97+
pod, err := getPodFromStandaloneKubelet(ctx, ns, staticPodName)
98+
if err != nil {
99+
return fmt.Errorf("error getting pod(%v/%v) from standalone kubelet: %w", ns, staticPodName, err)
100+
}
101+
102+
isReady, err := testutils.PodRunningReady(pod)
103+
if err != nil {
104+
return fmt.Errorf("error checking if pod (%v/%v) is running ready: %w", ns, staticPodName, err)
105+
}
106+
if !isReady {
107+
return fmt.Errorf("pod (%v/%v) is not running", ns, staticPodName)
108+
}
109+
return nil
110+
}, f.Timeouts.PodStart, time.Second*5).Should(gomega.BeNil())
111+
112+
// Upgrade the pod
113+
podSpec.Spec.Containers[0].Name = "upgraded"
114+
err = scheduleStaticPod(podPath, staticPodName, ns, podSpec)
115+
framework.ExpectNoError(err)
116+
117+
gomega.Eventually(ctx, func(ctx context.Context) error {
118+
pod, err := getPodFromStandaloneKubelet(ctx, ns, staticPodName)
119+
if err != nil {
120+
return fmt.Errorf("error getting pod(%v/%v) from standalone kubelet: %w", ns, staticPodName, err)
121+
}
122+
123+
if pod.Spec.Containers[0].Name != "upgraded" {
124+
return fmt.Errorf("pod (%v/%v) is not upgraded", ns, staticPodName)
125+
}
126+
127+
isReady, err := testutils.PodRunningReady(pod)
128+
if err != nil {
129+
return fmt.Errorf("error checking if pod (%v/%v) is running ready: %w", ns, staticPodName, err)
130+
}
131+
if !isReady {
132+
return fmt.Errorf("pod (%v/%v) is not running", ns, staticPodName)
133+
}
134+
return nil
135+
}, f.Timeouts.PodStart, time.Second*5).Should(gomega.BeNil())
136+
})
137+
138+
// the test below is not working - pod update fails with the "Predicate NodePorts failed: node(s) didn't have free ports for the requested pod ports"
139+
// ginkgo.It("the pod with the port on host network should be running and can be upgraded when namespace of a Pod changes", func(ctx context.Context) {
140+
// ns = f.Namespace.Name
141+
// staticPodName = "static-pod-" + string(uuid.NewUUID())
142+
// podPath = kubeletCfg.StaticPodPath
143+
144+
// podSpec := createBasicStaticPodSpec(staticPodName, ns)
145+
// podSpec.Spec.HostNetwork = true
146+
// podSpec.Spec.Containers[0].Ports = []v1.ContainerPort{
147+
// {
148+
// Name: "tcp",
149+
// ContainerPort: 4534,
150+
// Protocol: v1.ProtocolTCP,
151+
// },
152+
// }
153+
// err := scheduleStaticPod(podPath, staticPodName, ns, podSpec)
154+
// framework.ExpectNoError(err)
155+
156+
// gomega.Eventually(ctx, func(ctx context.Context) error {
157+
// pod, err := getPodFromStandaloneKubelet(ctx, ns, staticPodName)
158+
// if err != nil {
159+
// return fmt.Errorf("error getting pod(%v/%v) from standalone kubelet: %w", ns, staticPodName, err)
160+
// }
161+
162+
// isReady, err := testutils.PodRunningReady(pod)
163+
// if err != nil {
164+
// return fmt.Errorf("error checking if pod (%v/%v) is running ready: %w", ns, staticPodName, err)
165+
// }
166+
// if !isReady {
167+
// return fmt.Errorf("pod (%v/%v) is not running", ns, staticPodName)
168+
// }
169+
// return nil
170+
// }, f.Timeouts.PodStart, time.Second*5).Should(gomega.BeNil())
171+
172+
// // Upgrade the pod
173+
// upgradedNs := ns + "-upgraded"
174+
// podSpec.Namespace = upgradedNs
175+
176+
// // use old namespace as it uses ns in a file name
177+
// err = scheduleStaticPod(podPath, staticPodName, ns, podSpec)
178+
// framework.ExpectNoError(err)
179+
180+
// gomega.Eventually(ctx, func(ctx context.Context) error {
181+
// pod, err := getPodFromStandaloneKubelet(ctx, upgradedNs, staticPodName)
182+
// if err != nil {
183+
// return fmt.Errorf("error getting pod(%v/%v) from standalone kubelet: %w", upgradedNs, staticPodName, err)
184+
// }
185+
186+
// isReady, err := testutils.PodRunningReady(pod)
187+
// if err != nil {
188+
// return fmt.Errorf("error checking if pod (%v/%v) is running ready: %w", upgradedNs, staticPodName, err)
189+
// }
190+
// if !isReady {
191+
// return fmt.Errorf("pod (%v/%v) is not running", upgradedNs, staticPodName)
192+
// }
193+
// return nil
194+
// }, f.Timeouts.PodStart, time.Second*5).Should(gomega.BeNil())
195+
// })
196+
79197
ginkgo.AfterEach(func(ctx context.Context) {
80198
ginkgo.By(fmt.Sprintf("delete the static pod (%v/%v)", ns, staticPodName))
81199
err := deleteStaticPod(podPath, staticPodName, ns)
@@ -94,7 +212,7 @@ var _ = SIGDescribe(feature.StandaloneMode, func() {
94212
})
95213
})
96214

97-
func createBasicStaticPod(dir, name, namespace string) error {
215+
func createBasicStaticPodSpec(name, namespace string) *v1.Pod {
98216
podSpec := &v1.Pod{
99217
TypeMeta: metav1.TypeMeta{
100218
Kind: "Pod",
@@ -135,6 +253,10 @@ func createBasicStaticPod(dir, name, namespace string) error {
135253
},
136254
}
137255

256+
return podSpec
257+
}
258+
259+
func scheduleStaticPod(dir, name, namespace string, podSpec *v1.Pod) error {
138260
file := staticPodPath(dir, name, namespace)
139261
f, err := os.OpenFile(file, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0666)
140262
if err != nil {

0 commit comments

Comments
 (0)