@@ -249,7 +249,11 @@ func (o *consoleOptions) run(cmd *cobra.Command, argv []string) error {
249
249
if err != nil {
250
250
return err
251
251
}
252
-
252
+ //Perform a cleanup before starting a new console
253
+ err = o .beforeStartCleanUp (ce )
254
+ if err != nil {
255
+ return err
256
+ }
253
257
done := make (chan bool )
254
258
errs := make (chan error )
255
259
@@ -644,6 +648,35 @@ func (o *consoleOptions) printURL() error {
644
648
return nil
645
649
}
646
650
651
+ func (o * consoleOptions ) beforeStartCleanUp (ce containerEngineInterface ) error {
652
+ clusterID , err := getClusterID ()
653
+ if err != nil {
654
+ return fmt .Errorf ("error getting cluster ID: %v" , err )
655
+ }
656
+ containersToCleanUp := []string {
657
+ fmt .Sprintf ("monitoring-plugin-%s" , clusterID ),
658
+ fmt .Sprintf ("console-%s" , clusterID ),
659
+ }
660
+
661
+ logger .Infoln ("Starting initial cleanup of containers" )
662
+
663
+ for _ , c := range containersToCleanUp {
664
+ exist , err := ce .containerIsExist (c )
665
+ if err != nil {
666
+ return fmt .Errorf ("failed to check if container %s exists: %v" , c , err )
667
+ }
668
+ if exist {
669
+ err := ce .stopContainer (c )
670
+ if err != nil {
671
+ return fmt .Errorf ("failed to stop container %s during the cleanup process: %v" , c , err )
672
+ }
673
+ } else {
674
+ logger .Infof ("Container %s does not exist, no need to clean up" , c )
675
+ }
676
+ }
677
+ return nil
678
+ }
679
+
647
680
func (o * consoleOptions ) cleanUp (ce containerEngineInterface ) error {
648
681
clusterID , err := getClusterID ()
649
682
if err != nil {
0 commit comments