Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podman as an option when using kind #415

Closed
wants to merge 17 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions pkg/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand All @@ -32,6 +33,7 @@ var kindVersion = 0.16
var container_reg_name = "kind-registry"
var container_reg_port = "5001"
var installKnative = true
var container_engine = ""

// SetUp creates a local Kind cluster and installs all the relevant Knative components
func SetUp(name, kVersion string, installServing, installEventing bool) error {
Expand All @@ -44,6 +46,14 @@ func SetUp(name, kVersion string, installServing, installEventing bool) error {
installEventing = true
}

cengine, err := getInstalledContainerEngine()
container_engine = cengine

if err != nil {
fmt.Println(err)
os.Exit(1)
}

// kubectl is required, fail if not found
if _, err := exec.LookPath("kubectl"); err != nil {
fmt.Println("ERROR: kubectl is required for quickstart")
Expand Down Expand Up @@ -90,7 +100,7 @@ func SetUp(name, kVersion string, installServing, installEventing bool) error {

func createKindCluster() error {

if err := checkDocker(); err != nil {
if err := checkContainerEngine(); err != nil {
return fmt.Errorf("%w", err)
}
if err := createLocalRegistry(); err != nil {
Expand All @@ -107,11 +117,28 @@ func createKindCluster() error {
return nil
}

// check if docker or podman are installed
func getInstalledContainerEngine() (string, error) {
if fname, err := exec.LookPath("docker"); err == nil {
if fpath, err := filepath.Abs(fname); err == nil {
return fpath, nil
}
}

if fname, err := exec.LookPath("podman"); err == nil {
if fpath, err := filepath.Abs(fname); err == nil {
return fpath, nil
}
}

return "", fmt.Errorf("ERROR: either podman or docker are required for quickstart")
}

// checkDocker checks that Docker is running on the users local system.
func checkDocker() error {
dockerCheck := exec.Command("docker", "stats", "--no-stream")
if err := dockerCheck.Run(); err != nil {
return fmt.Errorf("docker not running")
func checkContainerEngine() error {
containerEngineCheck := exec.Command(container_engine, "stats", "--no-stream")
if err := containerEngineCheck.Run(); err != nil {
return fmt.Errorf("%s not running", container_engine)
}
return nil
}
Expand All @@ -122,7 +149,7 @@ func createLocalRegistry() error {
return fmt.Errorf("failed to delete local registry: %w", err)
}
localRegCheck := exec.Command(
"docker", "run", "-d", "--restart=always", "-p", "0.0.0.0:"+container_reg_port+":5000",
container_engine, "run", "-d", "--restart=always", "-p", "0.0.0.0:"+container_reg_port+":5000",
"--name", container_reg_name, "registry:2",
)
if err := localRegCheck.Run(); err != nil {
Expand All @@ -132,9 +159,9 @@ func createLocalRegistry() error {
}

func connectLocalRegistry() error {
connectLocalRegistry := exec.Command("docker", "network", "connect", "kind", container_reg_name)
connectLocalRegistry := exec.Command(container_engine, "network", "connect", "kind", container_reg_name)
if err := connectLocalRegistry.Run(); err != nil {
return fmt.Errorf("failed to connect local registry to kind cluster")
return fmt.Errorf("failed to connect local registry to kind cluster: %w", err)
}
cm := fmt.Sprintf(`
apiVersion: v1
Expand Down Expand Up @@ -316,5 +343,5 @@ func parseKindVersion(v string) (float64, error) {
}

func deleteContainerRegistry() *exec.Cmd {
return exec.Command("docker", "rm", "-f", container_reg_name, "&&", "||", "true")
return exec.Command(container_engine, "rm", "-f", container_reg_name)
}