Delete volumes created by kic
parent
a4ee4186bd
commit
a007c0790c
|
@ -32,6 +32,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
|
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
|
||||||
|
"k8s.io/minikube/pkg/drivers/kic/oci"
|
||||||
"k8s.io/minikube/pkg/minikube/cluster"
|
"k8s.io/minikube/pkg/minikube/cluster"
|
||||||
"k8s.io/minikube/pkg/minikube/config"
|
"k8s.io/minikube/pkg/minikube/config"
|
||||||
pkg_config "k8s.io/minikube/pkg/minikube/config"
|
pkg_config "k8s.io/minikube/pkg/minikube/config"
|
||||||
|
@ -97,7 +98,7 @@ func runDelete(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
validProfiles, invalidProfiles, err := pkg_config.ListProfiles()
|
validProfiles, invalidProfiles, err := pkg_config.ListProfiles()
|
||||||
profilesToDelete := append(validProfiles, invalidProfiles...)
|
profilesToDelete := append(validProfiles, invalidProfiles...)
|
||||||
|
glog.Infof("error listing profiless %v", err)
|
||||||
// If the purge flag is set, go ahead and delete the .minikube directory.
|
// If the purge flag is set, go ahead and delete the .minikube directory.
|
||||||
if purge && len(profilesToDelete) > 1 && !deleteAll {
|
if purge && len(profilesToDelete) > 1 && !deleteAll {
|
||||||
out.ErrT(out.Notice, "Multiple minikube profiles were found - ")
|
out.ErrT(out.Notice, "Multiple minikube profiles were found - ")
|
||||||
|
@ -112,8 +113,9 @@ func runDelete(cmd *cobra.Command, args []string) {
|
||||||
exit.UsageT("usage: minikube delete --all")
|
exit.UsageT("usage: minikube delete --all")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
err := oci.DeleteAllVolumesByLabel(oci.Docker, fmt.Sprintf("%s=%s", oci.CreatedByLabelKey, "=true"))
|
||||||
exit.WithError("Error getting profiles to delete", err)
|
if err != nil { // if there is no volume there won't be any error
|
||||||
|
glog.Warningf("error deleting left docker volumes. To see the list of volumes run: 'docker volume ls' \n:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := DeleteProfiles(profilesToDelete)
|
errs := DeleteProfiles(profilesToDelete)
|
||||||
|
@ -177,6 +179,10 @@ func DeleteProfiles(profiles []*pkg_config.Profile) []error {
|
||||||
|
|
||||||
func deleteProfile(profile *pkg_config.Profile) error {
|
func deleteProfile(profile *pkg_config.Profile) error {
|
||||||
viper.Set(pkg_config.MachineProfile, profile.Name)
|
viper.Set(pkg_config.MachineProfile, profile.Name)
|
||||||
|
err := oci.DeleteAllVolumesByLabel(oci.Docker, fmt.Sprintf("%s=%s", oci.ProfileLabelKey, profile.Name))
|
||||||
|
if err != nil { // if there is no volume there wont be any error
|
||||||
|
glog.Warningf("error deleting left docker volumes. To see the list of volumes run: 'docker volume ls' \n:%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
api, err := machine.NewAPIClient()
|
api, err := machine.NewAPIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -113,20 +113,6 @@ func CreateContainerNode(p CreateParams) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// createDockerVolume creates a docker volume to be attached to the container with correct labels and prefixes based on profile name
|
|
||||||
// Caution ! if volume already exists does NOT return an error and will not apply the minikube labels on it.
|
|
||||||
// TODO: this should be fixed as a part of https://github.com/kubernetes/minikube/issues/6530
|
|
||||||
func createDockerVolume(name string) error {
|
|
||||||
if err := PointToHostDockerDaemon(); err != nil {
|
|
||||||
return errors.Wrap(err, "point host docker-daemon")
|
|
||||||
}
|
|
||||||
cmd := exec.Command(Docker, "volume", "create", name, "--label", "name.minikube.sigs.k8s.io="+name, "--label", "craeted_by_minikube.minikube.sigs.k8s.io=true")
|
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
return errors.Wrapf(err, "output %s", string(out))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateContainer creates a container with "docker/podman run"
|
// CreateContainer creates a container with "docker/podman run"
|
||||||
func createContainer(ociBinary string, image string, opts ...createOpt) ([]string, error) {
|
func createContainer(ociBinary string, image string, opts ...createOpt) ([]string, error) {
|
||||||
if err := PointToHostDockerDaemon(); err != nil {
|
if err := PointToHostDockerDaemon(); err != nil {
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package oci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DeleteAllVolumesByLabel delets all volumes that have a specific label
|
||||||
|
// example: docker volume prune -f --filter label=name.minikube.sigs.k8s.io=minikube
|
||||||
|
func DeleteAllVolumesByLabel(ociBin string, label string) error {
|
||||||
|
if ociBin == Docker {
|
||||||
|
if err := PointToHostDockerDaemon(); err != nil {
|
||||||
|
return errors.Wrap(err, "point host docker-daemon")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd := exec.Command(ociBin, "volume", "prune", "-f", "--filter", label)
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
return errors.Wrapf(err, "output %s", string(out))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// createDockerVolume creates a docker volume to be attached to the container with correct labels and prefixes based on profile name
|
||||||
|
// Caution ! if volume already exists does NOT return an error and will not apply the minikube labels on it.
|
||||||
|
// TODO: this should be fixed as a part of https://github.com/kubernetes/minikube/issues/6530
|
||||||
|
func createDockerVolume(name string) error {
|
||||||
|
if err := PointToHostDockerDaemon(); err != nil {
|
||||||
|
return errors.Wrap(err, "point host docker-daemon")
|
||||||
|
}
|
||||||
|
cmd := exec.Command(Docker, "volume", "create", name, "--label", "name.minikube.sigs.k8s.io="+name, "--label", "craeted_by_minikube.minikube.sigs.k8s.io=true")
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
return errors.Wrapf(err, "output %s", string(out))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue