This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
teardown.go
49 lines (44 loc) · 1.48 KB
/
teardown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sandbox
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/enescakir/emoji"
sandboxCmdConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/sandbox"
"github.com/flyteorg/flytectl/pkg/configutil"
"github.com/flyteorg/flytectl/pkg/docker"
"github.com/flyteorg/flytectl/pkg/k8s"
"github.com/flyteorg/flytectl/pkg/util"
)
func Teardown(ctx context.Context, cli docker.Docker, teardownFlags *sandboxCmdConfig.TeardownFlags) error {
c, err := docker.GetSandbox(ctx, cli)
if err != nil {
return err
}
if c != nil {
if err := cli.ContainerRemove(context.Background(), c.ID, types.ContainerRemoveOptions{
Force: true,
}); err != nil {
return err
}
}
if err := configutil.ConfigCleanup(); err != nil {
fmt.Printf("Config cleanup failed. Which Failed due to %v\n", err)
}
if err := removeSandboxKubeContext(); err != nil {
fmt.Printf("Kubecontext cleanup failed. Which Failed due to %v\n", err)
}
// Teardown volume if option is specified
if teardownFlags.Volume {
if err := cli.VolumeRemove(ctx, docker.FlyteSandboxVolumeName, true); err != nil {
fmt.Printf("Volume cleanup failed. Which Failed due to %v\n", err)
}
}
fmt.Printf("%v %v Sandbox cluster is removed successfully.\n", emoji.Broom, emoji.Broom)
util.PrintSandboxTeardownMessage(util.SandBoxConsolePort, docker.SandboxKubeconfig)
return nil
}
func removeSandboxKubeContext() error {
k8sCtxMgr := k8s.NewK8sContextManager()
return k8sCtxMgr.RemoveContext(sandboxContextName)
}