Skip to content

Commit 562aff1

Browse files
feat: materialize host support bundle (#405)
* feat: materializes host support bundle we want to have the host suppport bundle definition stored locally in the node in case of the cluster being offline. * chore: disable puppeteer chrome download * chore: attempt to disable chrome download during puppeteer install * chore: use already installed chromium
1 parent d10ab5d commit 562aff1

File tree

11 files changed

+206
-8
lines changed

11 files changed

+206
-8
lines changed

.github/workflows/pull-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ jobs:
124124
- TestCommandsRequireSudo
125125
- TestInstallWithoutEmbed
126126
- TestResetAndReinstall
127+
- TestCollectSupportBundle
127128
steps:
128129
- name: Checkout
129130
uses: actions/checkout@v4

.github/workflows/release-dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
- TestInstallWithoutEmbed
106106
- TestInstallFromReplicatedApp
107107
- TestResetAndReinstall
108+
- TestCollectSupportBundle
108109
steps:
109110
- name: Checkout
110111
uses: actions/checkout@v4

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ADMIN_CONSOLE_IMAGE_OVERRIDE =
99
ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE =
1010
EMBEDDED_OPERATOR_CHART_URL = oci://registry.replicated.com/library
1111
EMBEDDED_OPERATOR_CHART_NAME = embedded-cluster-operator
12-
EMBEDDED_OPERATOR_CHART_VERSION = 0.23.1
12+
EMBEDDED_OPERATOR_CHART_VERSION = 0.24.1
1313
OPENEBS_CHART_URL = https://openebs.github.io/charts
1414
OPENEBS_CHART_NAME = openebs/openebs
1515
OPENEBS_CHART_VERSION = 3.10.0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
if ! kubectl support-bundle --output host.tar.gz --interactive=false /var/lib/embedded-cluster/support/host-support-bundle.yaml; then
6+
echo "Failed to collect local host support bundle"
7+
return 1
8+
fi
9+
10+
if ! kubectl support-bundle --output cluster.tar.gz --interactive=false --load-cluster-specs; then
11+
echo "Failed to collect cluster support bundle"
12+
return 1
13+
fi
14+
}
15+
16+
export KUBECONFIG=/var/lib/k0s/pki/admin.conf
17+
export PATH=$PATH:/var/lib/embedded-cluster/bin
18+
main "$@"

e2e/scripts/install-puppeteer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dea
4444
NODE_MAJOR=20
4545
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
4646
apt-get update && apt-get install nodejs -y
47-
npm install -g [email protected]
47+
PUPPETEER_SKIP_DOWNLOAD=1 npm install -g [email protected]

e2e/scripts/puppeteer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
NODE_PATH="$(npm root -g)" "$@"
3+
PUPPETEER_EXECUTABLE_PATH=/snap/bin/chromium NODE_PATH="$(npm root -g)" "$@"

e2e/support-bundle_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package e2e
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/replicatedhq/embedded-cluster/e2e/cluster"
8+
)
9+
10+
func TestCollectSupportBundle(t *testing.T) {
11+
t.Parallel()
12+
tc := cluster.NewTestCluster(&cluster.Input{
13+
T: t,
14+
Nodes: 1,
15+
Image: "ubuntu/jammy",
16+
LicensePath: "license.yaml",
17+
EmbeddedClusterPath: "../output/bin/embedded-cluster",
18+
})
19+
defer tc.Destroy()
20+
t.Logf("%s: installing embedded-cluster on node 0", time.Now().Format(time.RFC3339))
21+
line := []string{"single-node-install.sh"}
22+
stdout, stderr, err := RunCommandOnNode(t, tc, 0, line)
23+
if err != nil {
24+
t.Log("stdout:", stdout)
25+
t.Log("stderr:", stderr)
26+
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
27+
}
28+
29+
line = []string{"collect-support-bundle.sh"}
30+
stdout, stderr, err = RunCommandOnNode(t, tc, 0, line)
31+
if err != nil {
32+
t.Log("stdout:", stdout)
33+
t.Log("stderr:", stderr)
34+
t.Fatalf("fail to install collect support bundle on node %s: %v", tc.Nodes[0], err)
35+
}
36+
37+
t.Log("stdout:", stdout)
38+
t.Log("stderr:", stderr)
39+
t.Logf("%s: test complete", time.Now().Format(time.RFC3339))
40+
}

pkg/defaults/defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ func PathToK0sStatusSocket() string {
8585
func EmbeddedClusterHomeDirectory() string {
8686
return def().EmbeddedClusterHomeDirectory()
8787
}
88+
89+
// PathToEmbeddedClusterSupportFile calls PathToEmbeddedClusterSupportFile on the default provider.
90+
func PathToEmbeddedClusterSupportFile(name string) string {
91+
return def().PathToEmbeddedClusterSupportFile(name)
92+
}

pkg/defaults/provider.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,20 @@ func (d *Provider) PathToK0sStatusSocket() string {
160160
func (d *Provider) PathToK0sConfig() string {
161161
return "/etc/k0s/k0s.yaml"
162162
}
163+
164+
// EmbeddedClusterSupportSubDir returns the path to the directory where embedded-cluster
165+
// support files are stored. Things that are useful when providing end user support in
166+
// a running cluster should be stored into this directory.
167+
func (d *Provider) EmbeddedClusterSupportSubDir() string {
168+
path := filepath.Join(d.EmbeddedClusterHomeDirectory(), "support")
169+
if err := os.MkdirAll(path, 0700); err != nil {
170+
logrus.Fatalf("unable to create embedded-cluster support dir: %s", err)
171+
}
172+
return path
173+
}
174+
175+
// PathToEmbeddedClusterSupportFile is an utility function that returns the full path to
176+
// a materialized support file. This function does not check if the file exists.
177+
func (d *Provider) PathToEmbeddedClusterSupportFile(name string) string {
178+
return filepath.Join(d.EmbeddedClusterSupportSubDir(), name)
179+
}

pkg/goods/goods.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import (
1313
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
1414
)
1515

16-
//go:embed bins/*
17-
var binfs embed.FS
18-
1916
// K0sBinarySHA256 returns the SHA256 checksum of the embedded k0s binary.
2017
func K0sBinarySHA256() (string, error) {
2118
fp, err := binfs.Open("bins/k0s")
@@ -30,8 +27,11 @@ func K0sBinarySHA256() (string, error) {
3027
return hex.EncodeToString(hasher.Sum(nil)), nil
3128
}
3229

33-
// Materialize writes to disk all embedded assets.
34-
func Materialize() error {
30+
//go:embed bins/*
31+
var binfs embed.FS
32+
33+
// materializeBinaries materializes all binary files from inside bins directory.
34+
func materializeBinaries() error {
3535
entries, err := binfs.ReadDir("bins")
3636
if err != nil {
3737
return fmt.Errorf("unable to read embedded-cluster bins dir: %w", err)
@@ -49,3 +49,37 @@ func Materialize() error {
4949
}
5050
return nil
5151
}
52+
53+
//go:embed support/*
54+
var supportfs embed.FS
55+
56+
// materializeSupportFiles materializes all support files from inside support directory.
57+
func materializeSupportFiles() error {
58+
entries, err := supportfs.ReadDir("support")
59+
if err != nil {
60+
return fmt.Errorf("unable to read embedded-cluster support dir: %w", err)
61+
}
62+
for _, entry := range entries {
63+
srcpath := fmt.Sprintf("support/%s", entry.Name())
64+
srcfile, err := supportfs.ReadFile(srcpath)
65+
if err != nil {
66+
return fmt.Errorf("unable to read asset: %w", err)
67+
}
68+
dstpath := defaults.PathToEmbeddedClusterSupportFile(entry.Name())
69+
if err := os.WriteFile(dstpath, srcfile, 0700); err != nil {
70+
return fmt.Errorf("unable to write file: %w", err)
71+
}
72+
}
73+
return nil
74+
}
75+
76+
// Materialize writes to disk all embedded assets.
77+
func Materialize() error {
78+
if err := materializeBinaries(); err != nil {
79+
return fmt.Errorf("unable to materialize embedded binaries: %w", err)
80+
}
81+
if err := materializeSupportFiles(); err != nil {
82+
return fmt.Errorf("unable to materialize embedded support files: %w", err)
83+
}
84+
return nil
85+
}

0 commit comments

Comments
 (0)