@@ -281,24 +281,6 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
281
281
return errors .Wrap (err , "command runner" )
282
282
}
283
283
284
- crName := cc .KubernetesConfig .ContainerRuntime
285
- cr , err := cruntime .New (cruntime.Config {Type : crName , Runner : runner })
286
- if err != nil {
287
- return errors .Wrap (err , "container runtime" )
288
- }
289
- runtimePaused , err := cluster .CheckIfPaused (cr , []string {"kube-system" })
290
- if err != nil {
291
- return errors .Wrap (err , "check paused" )
292
- }
293
- if runtimePaused {
294
- action := "disable"
295
- if enable {
296
- action = "enable"
297
- }
298
- msg := fmt .Sprintf ("can't %s addon on a paused cluster, please unpause the cluster firstly." , action )
299
- out .Styled (style .Shrug , msg )
300
- return errors .New (msg )
301
- }
302
284
bail , err := addonSpecificChecks (cc , name , enable , runner )
303
285
if err != nil {
304
286
return err
@@ -590,3 +572,59 @@ func UpdateConfig(cc *config.ClusterConfig, enabled []string) {
590
572
}
591
573
}
592
574
}
575
+
576
+ // CheckPaused checks whether the cluster is paused before enable/disable an addon.
577
+ func CheckPaused (profile string , val string ) error {
578
+ klog .Info ("checking whether the cluster is paused" )
579
+
580
+ enable , err := strconv .ParseBool (val )
581
+ if err != nil {
582
+ return errors .Wrapf (err , "parsing bool: %s" , val )
583
+ }
584
+
585
+ cc , err := config .Load (profile )
586
+ if err != nil {
587
+ return errors .Wrap (err , "loading profile" )
588
+ }
589
+
590
+ api , err := machine .NewAPIClient ()
591
+ if err != nil {
592
+ return errors .Wrap (err , "machine client" )
593
+ }
594
+ defer api .Close ()
595
+
596
+ cp , err := config .PrimaryControlPlane (cc )
597
+ if err != nil {
598
+ exit .Error (reason .GuestCpConfig , "Error getting primary control plane" , err )
599
+ }
600
+
601
+ host , err := machine .LoadHost (api , config .MachineName (* cc , cp ))
602
+ if err != nil {
603
+ exit .Error (reason .GuestLoadHost , "Error getting host" , err )
604
+ }
605
+
606
+ runner , err := machine .CommandRunner (host )
607
+ if err != nil {
608
+ return errors .Wrap (err , "command runner" )
609
+ }
610
+
611
+ crName := cc .KubernetesConfig .ContainerRuntime
612
+ cr , err := cruntime .New (cruntime.Config {Type : crName , Runner : runner })
613
+ if err != nil {
614
+ return errors .Wrap (err , "container runtime" )
615
+ }
616
+ runtimePaused , err := cluster .CheckIfPaused (cr , []string {"kube-system" })
617
+ if err != nil {
618
+ return errors .Wrap (err , "check paused" )
619
+ }
620
+ if runtimePaused {
621
+ action := "disable"
622
+ if enable {
623
+ action = "enable"
624
+ }
625
+ msg := fmt .Sprintf ("can't %s addon on a paused cluster, please unpause the cluster firstly." , action )
626
+ out .Styled (style .Shrug , msg )
627
+ return errors .New (msg )
628
+ }
629
+ return nil
630
+ }
0 commit comments