diff --git a/.gitignore b/.gitignore index 8a1fcf354..d9a8650b7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ bin images/kubeadm/run images/alpine/alpine.* docs/_build +ignitew diff --git a/Dockerfile.ignitew b/Dockerfile.ignitew new file mode 100644 index 000000000..ceaa8f7a9 --- /dev/null +++ b/Dockerfile.ignitew @@ -0,0 +1,23 @@ +FROM ubuntu:bionic + +RUN apt-get update && apt-get install -y curl + +ENV CNI_VERSION v0.8.2 +ENV ARCH amd64 + +# Install wrap packer +ADD https://github.com/dgiagio/warp/releases/download/v0.3.0/linux-x64.warp-packer /usr/bin/linux-x64.warp-packer +RUN chmod +x /usr/bin/linux-x64.warp-packer + +RUN mkdir /bundle +WORKDIR /bundle + +COPY bin/amd64/ignite /bundle/ignite + +RUN mkdir -p opt/cni/bin +RUN curl -sSL https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz | tar -xz -C opt/cni/bin + +# Create wrapper +RUN mkdir /output +WORKDIR /output +RUN linux-x64.warp-packer --arch linux-x64 --input_dir /bundle --exec ignite --output ignitew diff --git a/Makefile b/Makefile index bf39c5a59..ab7da02ec 100644 --- a/Makefile +++ b/Makefile @@ -265,6 +265,12 @@ serve-docs: build-docs @echo Stating docs website on http://localhost:${DOCS_PORT}/_build/html/index.html @$(DOCKER) run -i --rm -p ${DOCS_PORT}:8000 -e USER_ID=$$UID ignite-docs +build-ignitew: build-all + $(DOCKER) build --no-cache -t ignitew-builder -f Dockerfile.ignitew . + $(DOCKER) create --name=ignitew-builder ignitew-builder + $(DOCKER) cp ignitew-builder:/output/ignitew . + $(DOCKER) rm -f ignitew-builder + e2e: build-all e2e-nobuild e2e-nobuild: diff --git a/pkg/network/cni/cni.go b/pkg/network/cni/cni.go index 5f255c7d5..4c4f63ccb 100644 --- a/pkg/network/cni/cni.go +++ b/pkg/network/cni/cni.go @@ -7,6 +7,7 @@ import ( "net" "os" "path" + "path/filepath" "strings" "sync" @@ -97,7 +98,18 @@ func GetCNINetworkPlugin(runtime runtime.Interface) (network.Plugin, error) { } } - binDirs := []string{CNIBinDir} + var binDirs []string + + // Check if we have an embedded CNI along side the ignite binary + exeDir := filepath.Dir(os.Args[0]) + embeddedCNIBinDir := path.Join(exeDir, "opt", "cni", "bin") + // If we found the local CNI binary dir, we use it + if _, err := os.Stat(embeddedCNIBinDir); err == nil { + binDirs = append(binDirs, embeddedCNIBinDir) + } + + // and we always have the default value from CNIBinDir + binDirs = append(binDirs, CNIBinDir) cniInstance, err := gocni.New(gocni.WithMinNetworkCount(2), gocni.WithPluginConfDir(CNIConfDir), gocni.WithPluginDir(binDirs)) diff --git a/pkg/preflight/checkers/checks.go b/pkg/preflight/checkers/checks.go index b01e654f6..888e03908 100644 --- a/pkg/preflight/checkers/checks.go +++ b/pkg/preflight/checkers/checks.go @@ -6,6 +6,7 @@ import ( "net" "os" "os/exec" + "path/filepath" "strings" api "github.com/weaveworks/ignite/pkg/apis/ignite" @@ -99,9 +100,20 @@ func StartCmdChecks(vm *api.VM, ignoredPreflightErrors sets.String) error { for _, dependency := range constants.PathDependencies { checks = append(checks, ExistingFileChecker{filePath: dependency}) } + // This should be warning only, in case users prefer other network plugins if providers.NetworkPluginName == network.PluginCNI { - for _, dependency := range constants.CNIDependencies { - checks = append(checks, ExistingFileChecker{filePath: dependency}) + // In case of using ignitew, we put CNI plugin binaries relatively to the executable + exeDir := filepath.Dir(os.Args[0]) + if _, err := os.Stat(exeDir); err == nil { + for _, dependency := range constants.CNIDependencies { + releativeCNIPath := filepath.Join(exeDir, dependency) + checks = append(checks, ExistingFileChecker{filePath: releativeCNIPath}) + } + } else { + // Otherwise in the normal case, we check usually path + for _, dependency := range constants.CNIDependencies { + checks = append(checks, ExistingFileChecker{filePath: dependency}) + } } } checks = append(checks, providers.Runtime.PreflightChecker())