delete all cleans up stale kic profiles
parent
8e0ffdf1cf
commit
58b637b05f
|
@ -35,18 +35,6 @@ import (
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultPodCIDR is The CIDR to be used for pods inside the node.
|
|
||||||
const DefaultPodCIDR = "10.244.0.0/16"
|
|
||||||
|
|
||||||
// DefaultBindIPV4 is The default IP the container will bind to.
|
|
||||||
const DefaultBindIPV4 = "127.0.0.1"
|
|
||||||
|
|
||||||
// BaseImage is the base image is used to spin up kic containers created by kind.
|
|
||||||
const BaseImage = "gcr.io/k8s-minikube/kicbase:v0.0.3@sha256:34db5e30f8830c0d5e49b62f3ea6b2844f805980592fe0084cbea799bfb12664"
|
|
||||||
|
|
||||||
// OverlayImage is the cni plugin used for overlay image, created by kind.
|
|
||||||
const OverlayImage = "kindest/kindnetd:0.5.3"
|
|
||||||
|
|
||||||
// Driver represents a kic driver https://minikube.sigs.k8s.io/docs/reference/drivers/kic/
|
// Driver represents a kic driver https://minikube.sigs.k8s.io/docs/reference/drivers/kic/
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
*drivers.BaseDriver
|
*drivers.BaseDriver
|
||||||
|
@ -76,7 +64,7 @@ func (d *Driver) Create() error {
|
||||||
params := createConfig{
|
params := createConfig{
|
||||||
Name: d.NodeConfig.MachineName,
|
Name: d.NodeConfig.MachineName,
|
||||||
Image: d.NodeConfig.ImageDigest,
|
Image: d.NodeConfig.ImageDigest,
|
||||||
ClusterLabel: ClusterLabelKey + "=" + d.MachineName,
|
ClusterLabel: oci.ClusterLabelKey + "=" + d.MachineName,
|
||||||
CPUs: strconv.Itoa(d.NodeConfig.CPU),
|
CPUs: strconv.Itoa(d.NodeConfig.CPU),
|
||||||
Memory: strconv.Itoa(d.NodeConfig.Memory) + "mb",
|
Memory: strconv.Itoa(d.NodeConfig.Memory) + "mb",
|
||||||
Envs: d.NodeConfig.Envs,
|
Envs: d.NodeConfig.Envs,
|
||||||
|
@ -334,7 +322,7 @@ func createNode(p createConfig) error {
|
||||||
// label the node with the cluster ID
|
// label the node with the cluster ID
|
||||||
"--label", p.ClusterLabel,
|
"--label", p.ClusterLabel,
|
||||||
// label the node with the role ID
|
// label the node with the role ID
|
||||||
"--label", fmt.Sprintf("%s=%s", NodeRoleKey, p.Role),
|
"--label", fmt.Sprintf("%s=%s", oci.NodeRoleKey, p.Role),
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, val := range p.Envs {
|
for key, val := range p.Envs {
|
||||||
|
|
|
@ -410,10 +410,10 @@ func HostPortBinding(ociBinary string, ociID string, contPort int) (int, error)
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListContainers lists all the containres that kic driver created on user's machine using a label
|
// listContainersByLabel lists all the containres that kic driver created on user's machine using a label
|
||||||
// io.x-k8s.kic.cluster
|
// io.x-k8s.kic.cluster
|
||||||
func ListContainersByLabel(ociBinary string, label string) (error, []string) {
|
func listContainersByLabel(ociBinary string, label string) ([]string, error) {
|
||||||
cmd := exec.Command(ociBinary, "ps", "--filter", fmt.Sprintf("label=%s", label), "--format", "{{.Names}")
|
cmd := exec.Command(ociBinary, "ps", "-a", "--filter", fmt.Sprintf("label=%s", label), "--format", "{{.Names}}")
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
cmd.Stdout = &b
|
cmd.Stdout = &b
|
||||||
cmd.Stderr = &b
|
cmd.Stderr = &b
|
||||||
|
@ -423,7 +423,7 @@ func ListContainersByLabel(ociBinary string, label string) (error, []string) {
|
||||||
for sc.Scan() {
|
for sc.Scan() {
|
||||||
lines = append(lines, sc.Text())
|
lines = append(lines, sc.Text())
|
||||||
}
|
}
|
||||||
return err, lines
|
return lines, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerID returns a container ID from its name
|
// ContainerID returns a container ID from its name
|
||||||
|
@ -452,15 +452,5 @@ func ContainerIPs(ociBinary string, name string) (string, string, error) {
|
||||||
|
|
||||||
// ListOwnedContainers lists all the containres that kic driver created on user's machine using a label
|
// ListOwnedContainers lists all the containres that kic driver created on user's machine using a label
|
||||||
func ListOwnedContainers(ociBinary string) ([]string, error) {
|
func ListOwnedContainers(ociBinary string) ([]string, error) {
|
||||||
cmd := exec.Command(ociBinary, "ps", "-a", "--filter", "label=io.x-k8s.kic.cluster", "--format", "{{.Names}}")
|
return listContainersByLabel(ociBinary, ClusterLabelKey)
|
||||||
var b bytes.Buffer
|
|
||||||
cmd.Stdout = &b
|
|
||||||
cmd.Stderr = &b
|
|
||||||
err := cmd.Run()
|
|
||||||
var lines []string
|
|
||||||
sc := bufio.NewScanner(&b)
|
|
||||||
for sc.Scan() {
|
|
||||||
lines = append(lines, sc.Text())
|
|
||||||
}
|
|
||||||
return lines, err
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ package oci
|
||||||
const (
|
const (
|
||||||
Docker = "docker"
|
Docker = "docker"
|
||||||
Podman = "podman"
|
Podman = "podman"
|
||||||
|
// ClusterLabelKey is applied to each node docker container for identification
|
||||||
|
ClusterLabelKey = "io.x-k8s.kic.cluster"
|
||||||
|
// NodeRoleKey is used to identify if it is control plane or worker
|
||||||
|
NodeRoleKey = "io.k8s.sigs.kic.role"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -21,10 +21,6 @@ import "k8s.io/minikube/pkg/drivers/kic/oci"
|
||||||
const (
|
const (
|
||||||
// Docker default bridge network is named "bridge" (https://docs.docker.com/network/bridge/#use-the-default-bridge-network)
|
// Docker default bridge network is named "bridge" (https://docs.docker.com/network/bridge/#use-the-default-bridge-network)
|
||||||
DefaultNetwork = "bridge"
|
DefaultNetwork = "bridge"
|
||||||
// ClusterLabelKey is applied to each node docker container for identification
|
|
||||||
ClusterLabelKey = "io.x-k8s.kic.cluster"
|
|
||||||
// NodeRoleKey is used to identify if it is control plane or worker
|
|
||||||
NodeRoleKey = "io.k8s.sigs.kic.role"
|
|
||||||
// DefaultPodCIDR is The CIDR to be used for pods inside the node.
|
// DefaultPodCIDR is The CIDR to be used for pods inside the node.
|
||||||
DefaultPodCIDR = "10.244.0.0/16"
|
DefaultPodCIDR = "10.244.0.0/16"
|
||||||
// DefaultBindIPV4 is The default IP the container will bind to.
|
// DefaultBindIPV4 is The default IP the container will bind to.
|
||||||
|
|
|
@ -154,7 +154,7 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile,
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
// try to get profiles list based on all contrainers created by docker driver
|
// try to get profiles list based on all contrainers created by docker driver
|
||||||
cs, err := oci.ListOwnedContainers("docker")
|
cs, err := oci.ListOwnedContainers(oci.Docker)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
pDirs = append(pDirs, cs...)
|
pDirs = append(pDirs, cs...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue