Use constants instead of the KIC prefix strings
parent
d96d9d34ed
commit
28106fa2d7
|
@ -90,17 +90,17 @@ func init() {
|
|||
|
||||
func deleteContainersAndVolumes() {
|
||||
delLabel := fmt.Sprintf("%s=%s", oci.CreatedByLabelKey, "true")
|
||||
errs := oci.DeleteContainersByLabel("env", oci.Docker, delLabel)
|
||||
errs := oci.DeleteContainersByLabel(oci.Env, oci.Docker, delLabel)
|
||||
if len(errs) > 0 { // it will error if there is no container to delete
|
||||
glog.Infof("error delete containers by label %q (might be okay): %+v", delLabel, errs)
|
||||
}
|
||||
|
||||
errs = oci.DeleteAllVolumesByLabel("env", oci.Docker, delLabel)
|
||||
errs = oci.DeleteAllVolumesByLabel(oci.Env, oci.Docker, delLabel)
|
||||
if len(errs) > 0 { // it will not error if there is nothing to delete
|
||||
glog.Warningf("error delete volumes by label %q (might be okay): %+v", delLabel, errs)
|
||||
}
|
||||
|
||||
errs = oci.PruneAllVolumesByLabel("env", oci.Docker, delLabel)
|
||||
errs = oci.PruneAllVolumesByLabel(oci.Env, oci.Docker, delLabel)
|
||||
if len(errs) > 0 { // it will not error if there is nothing to delete
|
||||
glog.Warningf("error pruning volumes by label %q (might be okay): %+v", delLabel, errs)
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ func DeleteProfiles(profiles []*config.Profile) []error {
|
|||
|
||||
func deletePossibleKicLeftOver(name string) {
|
||||
delLabel := fmt.Sprintf("%s=%s", oci.ProfileLabelKey, name)
|
||||
prefixes := []string{"env", "sudo"}
|
||||
prefixes := []string{oci.Env, oci.Sudo}
|
||||
for i, bin := range []string{oci.Docker, oci.Podman} {
|
||||
prefix := prefixes[i]
|
||||
cs, err := oci.ListContainersByLabel(prefix, bin, delLabel)
|
||||
|
|
|
@ -41,7 +41,7 @@ func generateTarball(kubernetesVersion, containerRuntime, tarballFilename string
|
|||
driver := kic.NewDriver(kic.Config{
|
||||
KubernetesVersion: kubernetesVersion,
|
||||
ContainerRuntime: containerRuntime,
|
||||
OCIPrefix: "env",
|
||||
OCIPrefix: oci.Env,
|
||||
OCIBinary: oci.Docker,
|
||||
MachineName: profile,
|
||||
ImageDigest: kic.BaseImage,
|
||||
|
|
|
@ -231,7 +231,7 @@ func dockerSystemInfo() (dockerSysInfo, error) {
|
|||
// podmanSysInfo returns podman system info --format '{{json .}}'
|
||||
func podmanSystemInfo() (podmanSysInfo, error) {
|
||||
var ps podmanSysInfo
|
||||
rr, err := runCmd(exec.Command("sudo", Podman, "system", "info", "--format", "{{json .}}"))
|
||||
rr, err := runCmd(exec.Command(Sudo, Podman, "system", "info", "--format", "{{json .}}"))
|
||||
if err != nil {
|
||||
return ps, errors.Wrap(err, "get podman system info")
|
||||
}
|
||||
|
|
|
@ -56,13 +56,13 @@ func digDNS(ociBin, containerName, dns string) (net.IP, error) {
|
|||
// dockerGatewayIP gets the default gateway ip for the docker bridge on the user's host machine
|
||||
// gets the ip from user's host docker
|
||||
func dockerGatewayIP() (net.IP, error) {
|
||||
rr, err := runCmd(exec.Command(Docker, "network", "ls", "--filter", "name=bridge", "--format", "{{.ID}}"))
|
||||
rr, err := runCmd(exec.Command(Env, Docker, "network", "ls", "--filter", "name=bridge", "--format", "{{.ID}}"))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get network bridge")
|
||||
}
|
||||
|
||||
bridgeID := strings.TrimSpace(rr.Stdout.String())
|
||||
rr, err = runCmd(exec.Command("env", Docker, "inspect",
|
||||
rr, err = runCmd(exec.Command(Env, Docker, "inspect",
|
||||
"--format", "{{(index .IPAM.Config 0).Gateway}}", bridgeID))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "inspect IP bridge network %q.", bridgeID)
|
||||
|
@ -84,12 +84,12 @@ func ForwardedPort(ociBin string, ociID string, contPort int) (int, error) {
|
|||
|
||||
if ociBin == Podman {
|
||||
//podman inspect -f "{{range .NetworkSettings.Ports}}{{if eq .ContainerPort "80"}}{{.HostPort}}{{end}}{{end}}"
|
||||
rr, err = runCmd(exec.Command("sudo", ociBin, "inspect", "-f", fmt.Sprintf("{{range .NetworkSettings.Ports}}{{if eq .ContainerPort %s}}{{.HostPort}}{{end}}{{end}}", fmt.Sprint(contPort)), ociID))
|
||||
rr, err = runCmd(exec.Command(Sudo, ociBin, "inspect", "-f", fmt.Sprintf("{{range .NetworkSettings.Ports}}{{if eq .ContainerPort %s}}{{.HostPort}}{{end}}{{end}}", fmt.Sprint(contPort)), ociID))
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "get port %d for %q", contPort, ociID)
|
||||
}
|
||||
} else {
|
||||
rr, err = runCmd(exec.Command("env", ociBin, "inspect", "-f", fmt.Sprintf("'{{(index (index .NetworkSettings.Ports \"%d/tcp\") 0).HostPort}}'", contPort), ociID))
|
||||
rr, err = runCmd(exec.Command(Env, ociBin, "inspect", "-f", fmt.Sprintf("'{{(index (index .NetworkSettings.Ports \"%d/tcp\") 0).HostPort}}'", contPort), ociID))
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "get port %d for %q", contPort, ociID)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func ContainerIPs(ociBin string, name string) (string, string, error) {
|
|||
|
||||
// podmanConttainerIP returns ipv4, ipv6 of container or error
|
||||
func podmanConttainerIP(name string) (string, string, error) {
|
||||
rr, err := runCmd(exec.Command("sudo", Podman, "inspect",
|
||||
rr, err := runCmd(exec.Command(Sudo, Podman, "inspect",
|
||||
"-f", "{{.NetworkSettings.IPAddress}}",
|
||||
name))
|
||||
if err != nil {
|
||||
|
@ -132,7 +132,7 @@ func podmanConttainerIP(name string) (string, string, error) {
|
|||
// dockerContainerIP returns ipv4, ipv6 of container or error
|
||||
func dockerContainerIP(name string) (string, string, error) {
|
||||
// retrieve the IP address of the node using docker inspect
|
||||
lines, err := inspect("env", Docker, name, "{{range .NetworkSettings.Networks}}{{.IPAddress}},{{.GlobalIPv6Address}}{{end}}")
|
||||
lines, err := inspect(Env, Docker, name, "{{range .NetworkSettings.Networks}}{{.IPAddress}},{{.GlobalIPv6Address}}{{end}}")
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "inspecting NetworkSettings.Networks")
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@ package oci
|
|||
const (
|
||||
// DefaultBindIPV4 is The default IP the container will listen on.
|
||||
DefaultBindIPV4 = "127.0.0.1"
|
||||
// Env is env
|
||||
Env = "env"
|
||||
// Sudo is sudo
|
||||
Sudo = "sudo"
|
||||
// Docker is docker
|
||||
Docker = "docker"
|
||||
// Podman is podman
|
||||
|
|
|
@ -202,7 +202,7 @@ func (k *kicRunner) chmod(dst string, perm string) error {
|
|||
|
||||
// Podman cp command doesn't match docker and doesn't have -a
|
||||
func copyToPodman(src string, dest string) error {
|
||||
if out, err := exec.Command("sudo", oci.Podman, "cp", src, dest).CombinedOutput(); err != nil {
|
||||
if out, err := exec.Command(oci.Sudo, oci.Podman, "cp", src, dest).CombinedOutput(); err != nil {
|
||||
return errors.Wrapf(err, "podman copy %s into %s, output: %s", src, dest, string(out))
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -203,7 +203,7 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile,
|
|||
return nil, nil, err
|
||||
}
|
||||
// try to get profiles list based on all contrainers created by docker driver
|
||||
cs, err := oci.ListOwnedContainers("env", oci.Docker)
|
||||
cs, err := oci.ListOwnedContainers(oci.Env, oci.Docker)
|
||||
if err == nil {
|
||||
pDirs = append(pDirs, cs...)
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ func deleteOrphanedKIC(prefix string, ociBin string, name string) {
|
|||
func DeleteHost(api libmachine.API, machineName string) error {
|
||||
host, err := api.Load(machineName)
|
||||
if err != nil && host == nil {
|
||||
deleteOrphanedKIC("env", oci.Docker, machineName)
|
||||
deleteOrphanedKIC("sudo", oci.Podman, machineName)
|
||||
deleteOrphanedKIC(oci.Env, oci.Docker, machineName)
|
||||
deleteOrphanedKIC(oci.Sudo, oci.Podman, machineName)
|
||||
// Keep going even if minikube does not know about the host
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ func init() {
|
|||
if err := registry.Register(registry.DriverDef{
|
||||
Name: driver.Docker,
|
||||
Config: configure,
|
||||
Init: func() drivers.Driver { return kic.NewDriver(kic.Config{OCIPrefix: "env", OCIBinary: oci.Docker}) },
|
||||
Init: func() drivers.Driver { return kic.NewDriver(kic.Config{OCIPrefix: oci.Env, OCIBinary: oci.Docker}) },
|
||||
Status: status,
|
||||
Priority: priority,
|
||||
}); err != nil {
|
||||
|
@ -63,7 +63,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
|
|||
ImageDigest: viper.GetString("base-image"),
|
||||
CPU: cc.CPUs,
|
||||
Memory: cc.Memory,
|
||||
OCIPrefix: "env",
|
||||
OCIPrefix: oci.Env,
|
||||
OCIBinary: oci.Docker,
|
||||
APIServerPort: cc.Nodes[0].Port,
|
||||
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
|
||||
|
|
|
@ -45,7 +45,7 @@ func init() {
|
|||
if err := registry.Register(registry.DriverDef{
|
||||
Name: driver.Podman,
|
||||
Config: configure,
|
||||
Init: func() drivers.Driver { return kic.NewDriver(kic.Config{OCIPrefix: "sudo", OCIBinary: oci.Podman}) },
|
||||
Init: func() drivers.Driver { return kic.NewDriver(kic.Config{OCIPrefix: oci.Sudo, OCIBinary: oci.Podman}) },
|
||||
Status: status,
|
||||
Priority: registry.Experimental,
|
||||
}); err != nil {
|
||||
|
@ -61,7 +61,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
|
|||
ImageDigest: strings.Split(baseImage, "@")[0], // for podman does not support docker images references with both a tag and digest.
|
||||
CPU: cc.CPUs,
|
||||
Memory: cc.Memory,
|
||||
OCIPrefix: "sudo",
|
||||
OCIPrefix: oci.Sudo,
|
||||
OCIBinary: oci.Podman,
|
||||
APIServerPort: cc.Nodes[0].Port,
|
||||
}), nil
|
||||
|
@ -101,7 +101,7 @@ func status() registry.State {
|
|||
|
||||
// Run with sudo on linux (local), otherwise podman-remote (as podman)
|
||||
if runtime.GOOS == "linux" {
|
||||
cmd = exec.CommandContext(ctx, "sudo", "-n", oci.Podman, "info")
|
||||
cmd = exec.CommandContext(ctx, oci.Sudo, "-n", oci.Podman, "info")
|
||||
cmd.Env = append(os.Environ(), "LANG=C", "LC_ALL=C") // sudo is localized
|
||||
} else {
|
||||
cmd = exec.CommandContext(ctx, oci.Podman, "info")
|
||||
|
|
Loading…
Reference in New Issue