Skip to content

Commit

Permalink
feat: including support-bundle binary (#81)
Browse files Browse the repository at this point in the history
we are including support-bundle binary from now on. this commit also
renames the `preflight` binary to `kubectl-preflight` so it properly
behaves as a kubectl plugin (same for support-bundle binary).
  • Loading branch information
ricardomaraschini authored Sep 15, 2023
1 parent 11f0392 commit 0d792a9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
37 changes: 29 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ K0SCTL_VERSION = v0.15.5
TERRAFORM_VERSION = 1.5.4
OPENEBS_VERSION = 3.7.0
K0S_VERSION = v1.27.5+k0s.0
PREFLIGHT_VERSION = v0.71.1
TROUBLESHOOT_VERSION = v0.72.0
LD_FLAGS = -X github.com/replicatedhq/helmvm/pkg/defaults.K0sVersion=$(K0S_VERSION) -X main.Version=$(VERSION)

default: helmvm-linux-amd64
Expand Down Expand Up @@ -95,28 +95,49 @@ pkg/goods/bins/helmvm/k0sctl-darwin-arm64:
curl -L -o pkg/goods/bins/helmvm/k0sctl-darwin-arm64 "https://github.com/k0sproject/k0sctl/releases/download/$(K0SCTL_VERSION)/k0sctl-darwin-arm64"
chmod +x pkg/goods/bins/helmvm/k0sctl-darwin-arm64

pkg/goods/bins/helmvm/preflight:
pkg/goods/bins/helmvm/kubectl-support_bundle-linux-amd64:
mkdir -p pkg/goods/bins/helmvm
mkdir -p output/tmp/support-bundle
curl -L -o output/tmp/support-bundle/support-bundle.tar.gz https://github.com/replicatedhq/troubleshoot/releases/download/$(TROUBLESHOOT_VERSION)/support-bundle_linux_amd64.tar.gz
tar -xzf output/tmp/support-bundle/support-bundle.tar.gz -C output/tmp/support-bundle
mv output/tmp/support-bundle/support-bundle pkg/goods/bins/helmvm/kubectl-support_bundle-linux-amd64

pkg/goods/bins/helmvm/kubectl-support_bundle-darwin-amd64:
mkdir -p pkg/goods/bins/helmvm
mkdir -p output/tmp/support-bundle
curl -L -o output/tmp/support-bundle/support-bundle.tar.gz https://github.com/replicatedhq/troubleshoot/releases/download/$(TROUBLESHOOT_VERSION)/support-bundle_darwin_amd64.tar.gz
tar -xzf output/tmp/support-bundle/support-bundle.tar.gz -C output/tmp/support-bundle
mv output/tmp/support-bundle/support-bundle pkg/goods/bins/helmvm/kubectl-support_bundle-darwin-amd64

pkg/goods/bins/helmvm/kubectl-support_bundle-darwin-arm64:
mkdir -p pkg/goods/bins/helmvm
mkdir -p output/tmp/support-bundle
curl -L -o output/tmp/support-bundle/support-bundle.tar.gz https://github.com/replicatedhq/troubleshoot/releases/download/$(TROUBLESHOOT_VERSION)/support-bundle_darwin_arm64.tar.gz
tar -xzf output/tmp/support-bundle/support-bundle.tar.gz -C output/tmp/support-bundle
mv output/tmp/support-bundle/support-bundle pkg/goods/bins/helmvm/kubectl-support_bundle-darwin-arm64

pkg/goods/bins/helmvm/kubectl-preflight:
mkdir -p pkg/goods/bins/helmvm
mkdir -p output/tmp/preflight
curl -L -o output/tmp/preflight/preflight.tar.gz https://github.com/replicatedhq/troubleshoot/releases/download/$(PREFLIGHT_VERSION)/preflight_linux_amd64.tar.gz
curl -L -o output/tmp/preflight/preflight.tar.gz https://github.com/replicatedhq/troubleshoot/releases/download/$(TROUBLESHOOT_VERSION)/preflight_linux_amd64.tar.gz
tar -xzf output/tmp/preflight/preflight.tar.gz -C output/tmp/preflight
mv output/tmp/preflight/preflight pkg/goods/bins/helmvm/preflight
mv output/tmp/preflight/preflight pkg/goods/bins/helmvm/kubectl-preflight

.PHONY: static
static: pkg/addons/adminconsole/charts/adminconsole-$(ADMIN_CONSOLE_CHART_VERSION).tgz \
output/bin/yq \
pkg/goods/bins/helmvm/preflight \
pkg/goods/bins/helmvm/kubectl-preflight \
pkg/goods/bins/k0sctl/k0s-$(K0S_VERSION) \
pkg/goods/images/list.txt

.PHONY: static-darwin-arm64
static-darwin-arm64: pkg/goods/bins/helmvm/kubectl-darwin-arm64 pkg/goods/bins/helmvm/k0sctl-darwin-arm64 pkg/goods/bins/helmvm/terraform-darwin-arm64
static-darwin-arm64: pkg/goods/bins/helmvm/kubectl-darwin-arm64 pkg/goods/bins/helmvm/k0sctl-darwin-arm64 pkg/goods/bins/helmvm/terraform-darwin-arm64 pkg/goods/bins/helmvm/kubectl-support_bundle-darwin-arm64

.PHONY: static-darwin-amd64
static-darwin-amd64: pkg/goods/bins/helmvm/kubectl-darwin-amd64 pkg/goods/bins/helmvm/k0sctl-darwin-amd64 pkg/goods/bins/helmvm/terraform-darwin-amd64
static-darwin-amd64: pkg/goods/bins/helmvm/kubectl-darwin-amd64 pkg/goods/bins/helmvm/k0sctl-darwin-amd64 pkg/goods/bins/helmvm/terraform-darwin-amd64 pkg/goods/bins/helmvm/kubectl-support_bundle-darwin-amd64

.PHONY: static-linux-amd64
static-linux-amd64: pkg/goods/bins/helmvm/kubectl-linux-amd64 pkg/goods/bins/helmvm/k0sctl-linux-amd64 pkg/goods/bins/helmvm/terraform-linux-amd64
static-linux-amd64: pkg/goods/bins/helmvm/kubectl-linux-amd64 pkg/goods/bins/helmvm/k0sctl-linux-amd64 pkg/goods/bins/helmvm/terraform-linux-amd64 pkg/goods/bins/helmvm/kubectl-support_bundle-linux-amd64

.PHONY: helmvm-linux-amd64
helmvm-linux-amd64: static static-linux-amd64
Expand Down
4 changes: 2 additions & 2 deletions pkg/goods/goods.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func Materialize() error {
suffix := fmt.Sprintf("-%s-%s", runtime.GOOS, runtime.GOARCH)
for _, entry := range entries {
if entry.IsDir() || !strings.HasSuffix(entry.Name(), suffix) {
// we always materialize 'preflight' binary because
// we always materialize 'kubectl-preflight' binary because
// we run it remotely in the configured cluster nodes.
if entry.Name() != "preflight" {
if entry.Name() != "kubectl-preflight" {
continue
}
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/preflights/preflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"

"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
Expand Down Expand Up @@ -68,7 +70,7 @@ func RunLocal(ctx context.Context, spec *v1beta2.HostPreflightSpec) (*Output, er
return nil, fmt.Errorf("unable to save preflight locally: %w", err)
}
defer os.Remove(fpath)
binpath := defaults.PathToHelmVMBinary("preflight")
binpath := defaults.PathToHelmVMBinary("kubectl-preflight")
stdout := bytes.NewBuffer(nil)
cmd := exec.Command(binpath, "--interactive=false", "--format=json", fpath)
cmd.Stdout, cmd.Stderr = stdout, io.Discard
Expand Down Expand Up @@ -97,8 +99,9 @@ func Run(ctx context.Context, host *cluster.Host, spec *v1beta2.HostPreflightSpe
if err := uploadFile(host, fpath, "/tmp/helmvm-preflight.yaml", 0600); err != nil {
return nil, err
}
binpath := defaults.PathToHelmVMBinary("preflight")
if err := uploadFile(host, binpath, "/tmp/preflight", 0755); err != nil {
src := defaults.PathToHelmVMBinary("kubectl-preflight")
dst := path.Join("/tmp", filepath.Base(src))
if err := uploadFile(host, src, dst, 0755); err != nil {
return nil, err
}
return execute(host)
Expand Down Expand Up @@ -134,7 +137,7 @@ func execute(host *cluster.Host) (*Output, error) {
}
defer host.Disconnect()
arg := "--interactive=false --format=json"
cmd := fmt.Sprintf("/tmp/preflight %s /tmp/helmvm-preflight.yaml 2>/dev/null", arg)
cmd := fmt.Sprintf("/tmp/kubectl-preflight %s /tmp/helmvm-preflight.yaml 2>/dev/null", arg)
var err error
out := bytes.NewBuffer(nil)
opts := []rexec.Option{rexec.Sudo(host), rexec.Writer(out)}
Expand Down

0 comments on commit 0d792a9

Please sign in to comment.