@@ -10,17 +10,15 @@ import (
1010 "text/tabwriter"
1111 "time"
1212
13- corev1 "k8s.io/api/core/v1"
14- "k8s.io/apimachinery/pkg/api/errors"
1513 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1614 "k8s.io/apimachinery/pkg/util/wait"
1715 "k8s.io/client-go/kubernetes"
1816 "k8s.io/kubernetes/test/e2e/framework"
1917
2018 configv1 "github.com/openshift/api/config/v1"
2119 configv1client "github.com/openshift/client-go/config/clientset/versioned"
20+ "github.com/openshift/origin/test/extended/util"
2221 "github.com/openshift/origin/test/extended/util/disruption"
23- "github.com/openshift/origin/test/extended/util/image"
2422)
2523
2624type versionMonitor struct {
@@ -189,13 +187,13 @@ func (m *versionMonitor) Describe(f *framework.Framework) {
189187}
190188
191189func (m * versionMonitor ) Disrupt (ctx context.Context , kubeClient kubernetes.Interface , rebootPolicy string ) {
192- rebootHard := false
190+ rebootFunc := util . TriggerNodeRebootGraceful
193191 switch rebootPolicy {
194192 case "graceful" :
195193 framework .Logf ("Periodically reboot master nodes with clean shutdown" )
196194 case "force" :
197195 framework .Logf ("Periodically reboot master nodes without allowing for clean shutdown" )
198- rebootHard = true
196+ rebootFunc = util . TriggerNodeRebootUngraceful
199197 case "" :
200198 return
201199 }
@@ -212,7 +210,7 @@ func (m *versionMonitor) Disrupt(ctx context.Context, kubeClient kubernetes.Inte
212210 rand .Shuffle (len (nodes .Items ), func (i , j int ) { nodes .Items [i ], nodes .Items [j ] = nodes .Items [j ], nodes .Items [i ] })
213211 name := nodes .Items [0 ].Name
214212 framework .Logf ("DISRUPTION: Triggering reboot of %s" , name )
215- if err := triggerReboot (kubeClient , name , 0 , rebootHard ); err != nil {
213+ if err := rebootFunc (kubeClient , name ); err != nil {
216214 framework .Logf ("Failed to reboot %s: %v" , name , err )
217215 continue
218216 }
@@ -317,62 +315,3 @@ func versionString(update configv1.Update) string {
317315 return "<empty>"
318316 }
319317}
320-
321- func triggerReboot (kubeClient kubernetes.Interface , target string , attempt int , rebootHard bool ) error {
322- command := "echo 'reboot in 1 minute'; exec chroot /host shutdown -r 1"
323- if rebootHard {
324- command = "echo 'reboot in 1 minute'; exec chroot /host sudo systemd-run sh -c 'sleep 60 && reboot --force --force'"
325- }
326- isTrue := true
327- zero := int64 (0 )
328- name := fmt .Sprintf ("reboot-%s-%d" , target , attempt )
329- _ , err := kubeClient .CoreV1 ().Pods ("kube-system" ).Create (context .Background (), & corev1.Pod {
330- ObjectMeta : metav1.ObjectMeta {
331- Name : name ,
332- Annotations : map [string ]string {
333- "test.openshift.io/upgrades-target" : target ,
334- },
335- },
336- Spec : corev1.PodSpec {
337- HostPID : true ,
338- RestartPolicy : corev1 .RestartPolicyNever ,
339- NodeName : target ,
340- Volumes : []corev1.Volume {
341- {
342- Name : "host" ,
343- VolumeSource : corev1.VolumeSource {
344- HostPath : & corev1.HostPathVolumeSource {
345- Path : "/" ,
346- },
347- },
348- },
349- },
350- Containers : []corev1.Container {
351- {
352- Name : "reboot" ,
353- SecurityContext : & corev1.SecurityContext {
354- RunAsUser : & zero ,
355- Privileged : & isTrue ,
356- },
357- Image : image .ShellImage (),
358- Command : []string {
359- "/bin/bash" ,
360- "-c" ,
361- command ,
362- },
363- TerminationMessagePolicy : corev1 .TerminationMessageFallbackToLogsOnError ,
364- VolumeMounts : []corev1.VolumeMount {
365- {
366- MountPath : "/host" ,
367- Name : "host" ,
368- },
369- },
370- },
371- },
372- },
373- }, metav1.CreateOptions {})
374- if errors .IsAlreadyExists (err ) {
375- return triggerReboot (kubeClient , target , attempt + 1 , rebootHard )
376- }
377- return err
378- }
0 commit comments