mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
feat: auto-remove container
This commit is contained in:
@@ -226,16 +226,24 @@ func (d *Options) Main(ctx context.Context, tempContainerConfig *containerConfig
|
||||
type ConfigList []*RunConfig
|
||||
|
||||
func (l ConfigList) Remove(ctx context.Context, cli *client.Client) error {
|
||||
var remove = false
|
||||
for _, runConfig := range l {
|
||||
if runConfig.hostConfig.AutoRemove {
|
||||
remove = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !remove {
|
||||
return nil
|
||||
}
|
||||
for _, runConfig := range l {
|
||||
err := cli.NetworkDisconnect(ctx, runConfig.containerName, runConfig.containerName, true)
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
if runConfig.hostConfig.AutoRemove {
|
||||
err = cli.ContainerRemove(ctx, runConfig.containerName, types.ContainerRemoveOptions{Force: true})
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
err = cli.ContainerRemove(ctx, runConfig.containerName, types.ContainerRemoveOptions{Force: true})
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
}
|
||||
i, err := cli.NetworkInspect(ctx, config.ConfigMapPodTrafficManager, types.NetworkInspectOptions{})
|
||||
|
||||
@@ -132,12 +132,6 @@ func run(ctx context.Context, runConfig *RunConfig, cli *client.Client, c *comma
|
||||
func runFirst(ctx context.Context, runConfig *RunConfig, cli *apiclient.Client, dockerCli *command.DockerCli) (id string, err error) {
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
defer func() {
|
||||
if err != nil && runConfig.hostConfig.AutoRemove {
|
||||
_ = cli.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true})
|
||||
}
|
||||
}()
|
||||
|
||||
stdout, stderr := dockerCli.Out(), dockerCli.Err()
|
||||
client := dockerCli.Client()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user