Skip to content

Commit fe92697

Browse files
authored
fix: use app slug for service and binary name (#2293)
* fix: use app slug for service and binary name * f * f * f
1 parent 0678def commit fe92697

File tree

11 files changed

+58
-23
lines changed

11 files changed

+58
-23
lines changed

e2e/install_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,17 @@ func TestSingleNodeUpgradePreviousStable(t *testing.T) {
420420

421421
initialVersion := fmt.Sprintf("appver-%s-previous-stable", os.Getenv("SHORT_SHA"))
422422

423+
withEnv := map[string]string{
424+
"EMBEDDED_CLUSTER_BIN": "embedded-cluster",
425+
}
426+
423427
downloadECReleaseWithOptions(t, tc, 0, downloadECReleaseOptions{
424428
version: initialVersion,
425429
})
426430

427431
installSingleNodeWithOptions(t, tc, installOptions{
428432
version: initialVersion,
433+
withEnv: withEnv,
429434
})
430435

431436
if stdout, stderr, err := tc.SetupPlaywrightAndRunTest("deploy-app"); err != nil {
@@ -435,6 +440,7 @@ func TestSingleNodeUpgradePreviousStable(t *testing.T) {
435440
checkInstallationStateWithOptions(t, tc, installationStateOptions{
436441
version: initialVersion,
437442
k8sVersion: k8sVersionPreviousStable(),
443+
withEnv: withEnv,
438444
})
439445

440446
appUpgradeVersion := fmt.Sprintf("appver-%s-noop", os.Getenv("SHORT_SHA"))
@@ -453,6 +459,7 @@ func TestSingleNodeUpgradePreviousStable(t *testing.T) {
453459

454460
checkInstallationStateWithOptions(t, tc, installationStateOptions{
455461
version: appUpgradeVersion,
462+
withEnv: withEnv,
456463
})
457464

458465
appUpgradeVersion = fmt.Sprintf("appver-%s-upgrade", os.Getenv("SHORT_SHA"))
@@ -463,7 +470,9 @@ func TestSingleNodeUpgradePreviousStable(t *testing.T) {
463470
t.Fatalf("fail to run playwright test deploy-upgrade: %v: %s: %s", err, stdout, stderr)
464471
}
465472

466-
checkPostUpgradeState(t, tc)
473+
checkPostUpgradeStateWithOptions(t, tc, postUpgradeStateOptions{
474+
withEnv: withEnv,
475+
})
467476

468477
t.Logf("%s: test complete", time.Now().Format(time.RFC3339))
469478
}
@@ -1150,6 +1159,7 @@ func TestMultiNodeAirgapUpgradePreviousStable(t *testing.T) {
11501159
// Use an alternate data directory
11511160
withEnv := map[string]string{
11521161
"EMBEDDED_CLUSTER_BASE_DIR": "/var/lib/ec",
1162+
"EMBEDDED_CLUSTER_BIN": "embedded-cluster",
11531163
}
11541164

11551165
tc := cmx.NewCluster(&cmx.ClusterInput{

e2e/scripts/collect-support-bundle-host.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@ set -euox pipefail
44
DIR=/usr/local/bin
55
. $DIR/common.sh
66

7+
function collect_support_bundle() {
8+
"${EMBEDDED_CLUSTER_BASE_DIR}/bin/kubectl-support_bundle" --output host.tar.gz --interactive=false "${EMBEDDED_CLUSTER_BASE_DIR}/support/host-support-bundle.yaml"
9+
}
10+
11+
function collect_installer_logs() {
12+
tar -czvf host.tar.gz /var/log/embedded-cluster
13+
}
14+
715
main() {
8-
if ! kubectl support-bundle --output host.tar.gz --interactive=false "${EMBEDDED_CLUSTER_BASE_DIR}/support/host-support-bundle.yaml" ; then
9-
echo "Failed to collect local host support bundle"
10-
return 1
16+
if ! collect_support_bundle; then
17+
echo "Failed to collect support bundle"
18+
if ! collect_installer_logs; then
19+
echo "Failed to collect installer logs"
20+
return 1
21+
fi
22+
echo "Installer logs collected successfully"
23+
return 0
1124
fi
25+
26+
echo "Support bundle collected successfully"
1227
}
1328

1429
main "$@"

e2e/scripts/common.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
export EMBEDDED_CLUSTER_BIN="${EMBEDDED_CLUSTER_BIN:-embedded-cluster}"
3+
export EMBEDDED_CLUSTER_BIN="${EMBEDDED_CLUSTER_BIN:-embedded-cluster-smoke-test-staging-app}"
44
export EMBEDDED_CLUSTER_BASE_DIR="${EMBEDDED_CLUSTER_BASE_DIR:-/var/lib/embedded-cluster}"
55
export PATH="$PATH:${EMBEDDED_CLUSTER_BASE_DIR}/bin"
66
export K0SCONFIG=/etc/k0s/k0s.yaml
@@ -300,12 +300,12 @@ ensure_version_metadata_present() {
300300
# ensure_binary_copy verifies that the installer is copying itself to the default location of
301301
# banaries in the node.
302302
ensure_binary_copy() {
303-
if ! ls "${EMBEDDED_CLUSTER_BASE_DIR}/bin/embedded-cluster" ; then
303+
if ! ls "${EMBEDDED_CLUSTER_BASE_DIR}/bin/${EMBEDDED_CLUSTER_BIN}" ; then
304304
echo "embedded-cluster binary not found on default location"
305305
ls -la "${EMBEDDED_CLUSTER_BASE_DIR}/bin"
306306
return 1
307307
fi
308-
if ! "${EMBEDDED_CLUSTER_BASE_DIR}/bin/embedded-cluster" version ; then
308+
if ! "${EMBEDDED_CLUSTER_BASE_DIR}/bin/${EMBEDDED_CLUSTER_BIN}" version ; then
309309
echo "embedded-cluster binary is not executable"
310310
return 1
311311
fi

e2e/scripts/embedded-preflight.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ main() {
6262
echo "Failed to wait for healthy node"
6363
exit 1
6464
fi
65-
if ! systemctl restart embedded-cluster; then
65+
if ! systemctl restart "${EMBEDDED_CLUSTER_BIN}"; then
6666
echo "Failed to restart embedded-cluster service"
6767
exit 1
6868
fi

e2e/scripts/reset-installation.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ DIR=/usr/local/bin
77
main() {
88
local additional_flags=("$@")
99

10-
if ! "${EMBEDDED_CLUSTER_BIN}" reset --yes "${additional_flags[@]}" | tee /tmp/log ; then
10+
if ! "${EMBEDDED_CLUSTER_BASE_DIR}/bin/${EMBEDDED_CLUSTER_BIN}" reset --yes "${additional_flags[@]}" | tee /tmp/log ; then
1111
echo "Failed to uninstall embedded-cluster"
1212
exit 1
1313
fi
1414

15-
if systemctl status embedded-cluster; then
15+
if systemctl status "${EMBEDDED_CLUSTER_BIN}"; then
1616
echo "Unexpectedly got status of embedded-cluster service"
1717
exit 1
1818
fi

e2e/scripts/single-node-airgap-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ main() {
8989
if ! check_airgap_pvc; then
9090
exit 1
9191
fi
92-
if ! systemctl status embedded-cluster; then
92+
if ! systemctl status "${EMBEDDED_CLUSTER_BIN}"; then
9393
echo "Failed to get status of embedded-cluster service"
9494
exit 1
9595
fi

e2e/scripts/single-node-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ main() {
147147
if ! ensure_release_builtin_overrides; then
148148
exit 1
149149
fi
150-
if ! systemctl status embedded-cluster; then
150+
if ! systemctl status "${EMBEDDED_CLUSTER_BIN}"; then
151151
echo "Failed to get status of embedded-cluster service"
152152
exit 1
153153
fi

pkg-new/k0s/k0s.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type K0s struct {
3434
// kubeconfig and similar.
3535
func (k *K0s) GetStatus(ctx context.Context) (*K0sStatus, error) {
3636
if _, err := os.Stat(k0sBinPath); err != nil {
37-
return nil, fmt.Errorf("%s does not seem to be installed on this node", runtimeconfig.BinaryName())
37+
return nil, err
3838
}
3939

4040
// get k0s status json
@@ -184,7 +184,7 @@ func PatchK0sConfig(path string, patch string) error {
184184
return nil
185185
}
186186
finalcfg := k0sv1beta1.ClusterConfig{
187-
ObjectMeta: metav1.ObjectMeta{Name: runtimeconfig.BinaryName()},
187+
ObjectMeta: metav1.ObjectMeta{Name: "k0s"},
188188
}
189189
if _, err := os.Stat(path); err == nil {
190190
data, err := os.ReadFile(path)

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var k0sConfigPathOverride string
3030
func RenderK0sConfig(proxyRegistryDomain string) *k0sconfig.ClusterConfig {
3131
cfg := k0sconfig.DefaultClusterConfig()
3232
// Customize the default k0s configuration to our taste.
33-
cfg.Name = runtimeconfig.BinaryName()
33+
cfg.Name = "k0s"
3434
cfg.Spec.Konnectivity = nil
3535
cfg.Spec.Network.KubeRouter = nil
3636
cfg.Spec.Network.Provider = "calico"

pkg/runtimeconfig/defaults.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ const (
3838
ECConfigPath = "/etc/embedded-cluster/ec.yaml"
3939
)
4040

41-
// BinaryName returns the binary name, this is useful for places where we
42-
// need to present the name of the binary to the user (the name may vary if
43-
// the binary is renamed). We make sure the name does not contain invalid
41+
// BinaryName returns the intended binary name. This is the app slug when a release is embedded,
42+
// otherwise it is the basename of the executable. This is useful for places where we need to
43+
// present the name of the binary to the user. We make sure the name does not contain invalid
4444
// characters for a filename.
4545
func BinaryName() string {
46-
exe, err := os.Executable()
47-
if err != nil {
48-
logrus.Fatalf("unable to get executable path: %s", err)
46+
var name string
47+
if release := release.GetChannelRelease(); release != nil {
48+
name = release.AppSlug
49+
} else {
50+
exe, err := os.Executable()
51+
if err != nil {
52+
logrus.Fatalf("unable to get executable path: %s", err)
53+
}
54+
name = filepath.Base(exe)
4955
}
50-
base := filepath.Base(exe)
51-
return slug.Make(base)
56+
return slug.Make(name)
5257
}
5358

5459
// EmbeddedClusterLogsSubDir returns the path to the directory where embedded-cluster logs

0 commit comments

Comments
 (0)