@@ -56,18 +56,18 @@ var _ = SIGDescribe(feature.StandaloneMode, func() {
56
56
staticPodName = "static-pod-" + string (uuid .NewUUID ())
57
57
podPath = kubeletCfg .StaticPodPath
58
58
59
- err := createBasicStaticPod (podPath , staticPodName , ns )
59
+ err := scheduleStaticPod (podPath , staticPodName , ns , createBasicStaticPodSpec ( staticPodName , ns ) )
60
60
framework .ExpectNoError (err )
61
61
62
62
gomega .Eventually (ctx , func (ctx context.Context ) error {
63
63
pod , err := getPodFromStandaloneKubelet (ctx , ns , staticPodName )
64
64
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 )
66
66
}
67
67
68
68
isReady , err := testutils .PodRunningReady (pod )
69
69
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 )
71
71
}
72
72
if ! isReady {
73
73
return fmt .Errorf ("pod (%v/%v) is not running" , ns , staticPodName )
@@ -76,6 +76,124 @@ var _ = SIGDescribe(feature.StandaloneMode, func() {
76
76
}, f .Timeouts .PodStart , time .Second * 5 ).Should (gomega .BeNil ())
77
77
})
78
78
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
+
79
197
ginkgo .AfterEach (func (ctx context.Context ) {
80
198
ginkgo .By (fmt .Sprintf ("delete the static pod (%v/%v)" , ns , staticPodName ))
81
199
err := deleteStaticPod (podPath , staticPodName , ns )
@@ -94,7 +212,7 @@ var _ = SIGDescribe(feature.StandaloneMode, func() {
94
212
})
95
213
})
96
214
97
- func createBasicStaticPod ( dir , name , namespace string ) error {
215
+ func createBasicStaticPodSpec ( name , namespace string ) * v1. Pod {
98
216
podSpec := & v1.Pod {
99
217
TypeMeta : metav1.TypeMeta {
100
218
Kind : "Pod" ,
@@ -135,6 +253,10 @@ func createBasicStaticPod(dir, name, namespace string) error {
135
253
},
136
254
}
137
255
256
+ return podSpec
257
+ }
258
+
259
+ func scheduleStaticPod (dir , name , namespace string , podSpec * v1.Pod ) error {
138
260
file := staticPodPath (dir , name , namespace )
139
261
f , err := os .OpenFile (file , os .O_RDWR | os .O_TRUNC | os .O_CREATE , 0666 )
140
262
if err != nil {
0 commit comments