libvirt: replace use of deprecated types

This commit is contained in:
Malte Poll 2024-02-21 10:29:55 +01:00
parent 6a467e5594
commit ffdf23e3f2

View file

@ -55,7 +55,7 @@ func (r *Runner) Start(ctx context.Context, name, imageName string) error {
// check for an existing container // check for an existing container
if containerName, err := r.file.Read(r.nameFile); err == nil { if containerName, err := r.file.Read(r.nameFile); err == nil {
// check if a container with the same name already exists // check if a container with the same name already exists
containers, err := docker.ContainerList(ctx, types.ContainerListOptions{ containers, err := docker.ContainerList(ctx, container.ListOptions{
Filters: filters.NewArgs( Filters: filters.NewArgs(
filters.KeyValuePair{ filters.KeyValuePair{
Key: "name", Key: "name",
@ -86,7 +86,7 @@ func (r *Runner) Start(ctx context.Context, name, imageName string) error {
} }
// container exists but is not running, remove it // container exists but is not running, remove it
// so we can start a new one // so we can start a new one
if err := docker.ContainerRemove(ctx, containers[0].ID, types.ContainerRemoveOptions{Force: true}); err != nil { if err := docker.ContainerRemove(ctx, containers[0].ID, container.RemoveOptions{Force: true}); err != nil {
return err return err
} }
} }
@ -140,14 +140,14 @@ func (r *Runner) startNewContainer(ctx context.Context, docker *docker.Client, c
); err != nil { ); err != nil {
return fmt.Errorf("failed to create container: %w", err) return fmt.Errorf("failed to create container: %w", err)
} }
if err := docker.ContainerStart(ctx, containerName, types.ContainerStartOptions{}); err != nil { if err := docker.ContainerStart(ctx, containerName, container.StartOptions{}); err != nil {
_ = docker.ContainerRemove(ctx, containerName, types.ContainerRemoveOptions{Force: true}) _ = docker.ContainerRemove(ctx, containerName, container.RemoveOptions{Force: true})
return fmt.Errorf("failed to start container: %w", err) return fmt.Errorf("failed to start container: %w", err)
} }
// write the name of the container to a file so we can remove it later // write the name of the container to a file so we can remove it later
if err := r.file.Write(r.nameFile, []byte(containerName)); err != nil { if err := r.file.Write(r.nameFile, []byte(containerName)); err != nil {
_ = docker.ContainerRemove(ctx, containerName, types.ContainerRemoveOptions{Force: true}) _ = docker.ContainerRemove(ctx, containerName, container.RemoveOptions{Force: true})
return err return err
} }
@ -169,7 +169,7 @@ func (r *Runner) Stop(ctx context.Context) error {
return err return err
} }
defer docker.Close() defer docker.Close()
if err := docker.ContainerRemove(ctx, string(name), types.ContainerRemoveOptions{Force: true}); err != nil { if err := docker.ContainerRemove(ctx, string(name), container.RemoveOptions{Force: true}); err != nil {
return err return err
} }