Skip to content

Commit 0acf2f0

Browse files
authored
Merge pull request kubernetes#90320 from neolit123/1.19-kubeadm-dont-use-sleep-on-upgrade
kubeadm: do not use /bin/sleep during upgrade pre-pull
2 parents 613cd04 + 425552f commit 0acf2f0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

cmd/kubeadm/app/phases/upgrade/prepull.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func (d *DaemonSetPrepuller) CreateFunc(component string) error {
6868
} else {
6969
image = images.GetKubernetesImage(component, d.cfg)
7070
}
71-
ds := buildPrePullDaemonSet(component, image)
71+
pauseImage := images.GetPauseImage(d.cfg)
72+
ds := buildPrePullDaemonSet(component, image, pauseImage)
7273

7374
// Create the DaemonSet in the API Server
7475
if err := apiclient.CreateOrUpdateDaemonSet(d.client, ds); err != nil {
@@ -155,8 +156,7 @@ func addPrepullPrefix(component string) string {
155156
}
156157

157158
// buildPrePullDaemonSet builds the DaemonSet that ensures the control plane image is available
158-
func buildPrePullDaemonSet(component, image string) *apps.DaemonSet {
159-
var gracePeriodSecs int64
159+
func buildPrePullDaemonSet(component, image, pauseImage string) *apps.DaemonSet {
160160
return &apps.DaemonSet{
161161
ObjectMeta: metav1.ObjectMeta{
162162
Name: addPrepullPrefix(component),
@@ -175,18 +175,32 @@ func buildPrePullDaemonSet(component, image string) *apps.DaemonSet {
175175
},
176176
},
177177
Spec: v1.PodSpec{
178-
Containers: []v1.Container{
178+
// Use an init container to prepull the target component image.
179+
// Once the prepull completes, the "component --version" command is executed
180+
// to get an exit code of 0.
181+
// After the init container completes a regular container with "pause"
182+
// will start to get this Pod in Running state with a blocking container process.
183+
// Note that DaemonSet Pods can only use RestartPolicy of Always, so there has
184+
// to be a blocking process to achieve the Running state.
185+
InitContainers: []v1.Container{
179186
{
180187
Name: component,
181188
Image: image,
182-
Command: []string{"/bin/sleep", "3600"},
189+
Command: []string{component, "--version"},
190+
},
191+
},
192+
Containers: []v1.Container{
193+
{
194+
Name: "pause",
195+
Image: pauseImage,
196+
Command: []string{"/pause"},
183197
},
184198
},
185199
NodeSelector: map[string]string{
186200
constants.LabelNodeRoleMaster: "",
187201
},
188202
Tolerations: []v1.Toleration{constants.ControlPlaneToleration},
189-
TerminationGracePeriodSeconds: &gracePeriodSecs,
203+
TerminationGracePeriodSeconds: utilpointer.Int64Ptr(0),
190204
// Explicitly add a PodSecurityContext to allow these Pods to run as non-root.
191205
// This prevents restrictive PSPs from blocking the Pod creation.
192206
SecurityContext: &v1.PodSecurityContext{

0 commit comments

Comments
 (0)