Skip to content

Commit

Permalink
fix(ci): fix manager integration test (#1730)
Browse files Browse the repository at this point in the history
fix(ci): fix manager integration tests
  • Loading branch information
emosbaugh authored Jan 23, 2025
1 parent c936a95 commit e329813
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
9 changes: 4 additions & 5 deletions cmd/manager/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

func StartCmd(ctx context.Context, name string) *cobra.Command {
var (
dataDir string

disableWebsocket bool
)

Expand All @@ -24,7 +22,10 @@ func StartCmd(ctx context.Context, name string) *cobra.Command {
Short: fmt.Sprintf("Start the %s cluster manager", name),
PreRun: func(cmd *cobra.Command, args []string) {
// init runtime config and relevant env vars
runtimeconfig.ApplyFlags(cmd.Flags())
if dataDir := os.Getenv("DATA_DIR"); dataDir != "" {
runtimeconfig.SetDataDir(dataDir)
}

os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeConfig())
os.Setenv("TMPDIR", runtimeconfig.EmbeddedClusterTmpSubDir())
},
Expand Down Expand Up @@ -52,8 +53,6 @@ func StartCmd(ctx context.Context, name string) *cobra.Command {
},
}

cmd.Flags().StringVar(&dataDir, "data-dir", "", "Path to the data directory")

// flags to enable running in test mode
cmd.Flags().BoolVar(&disableWebsocket, "disable-websocket", false, "When set, don't connect to the KOTS webscoket")
cmd.Flags().MarkHidden("disable-websocket")
Expand Down
3 changes: 3 additions & 0 deletions pkg/manager/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var (
_systemdUnitFileContents []byte

managerDropInFileContents = `[Service]
Environment="DATA_DIR=%s"
# Empty ExecStart= will clear out the previous ExecStart value
ExecStart=
ExecStart=%s start
Expand Down Expand Up @@ -138,6 +140,7 @@ func writeSystemdUnitFile() error {
func writeDropInFile() error {
contents := fmt.Sprintf(
managerDropInFileContents,
runtimeconfig.EmbeddedClusterHomeDirectory(),
runtimeconfig.PathToEmbeddedClusterBinary("manager"),
)
err := systemd.WriteDropInFile(UnitName(), "embedded-cluster.conf", []byte(contents))
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/manager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test:

.PHONY: clean
clean:
rm -f manager.test
rm -f manager.test ../../../pkg/goods/bins/manager
-docker rm -f $(CONTAINER_NAME) 2>/dev/null ; true

.PHONY: build
Expand Down
47 changes: 40 additions & 7 deletions tests/integration/manager/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"

Expand All @@ -13,13 +15,42 @@ import (
"github.com/stretchr/testify/require"
)

const (
kubeconfigContents = `apiVersion: v1
kind: Config
clusters:
- name: dummy
cluster:
api-version: v1
server: http://example.com
contexts:
- name: dummy
context:
cluster: dummy
namespace: dummy
user: dummy
users:
- name: dummy
user:
token: dummy
current-context: dummy
`
)

func TestManagerInstall(t *testing.T) {
ctx := context.Background()

runtimeconfig.SetDataDir(getDataDir(t))
dataDir := getDataDir(t)
runtimeconfig.SetDataDir(dataDir)

// Write a dummy kubeconfig to the data dir
err := os.MkdirAll(filepath.Dir(runtimeconfig.PathToKubeConfig()), 0755)
require.NoError(t, err, "failed to create kubeconfig directory")
err = os.WriteFile(runtimeconfig.PathToKubeConfig(), []byte(kubeconfigContents), 0644)
require.NoError(t, err, "failed to write kubeconfig")

manager.SetServiceName("ec")
err := manager.Install(ctx, t.Logf)
err = manager.Install(ctx, t.Logf)
require.NoError(t, err, "failed to install manager")

// Verify service files exists
Expand All @@ -28,14 +59,16 @@ func TestManagerInstall(t *testing.T) {
dropInDirExists := checkFileExists(t, "/etc/systemd/system/ec-manager.service.d")
assert.True(t, dropInDirExists, "ec-manager.service.d drop-in directory should exist")

// Wait for service to start and become ready
// TODO: this should be added to the manager package
time.Sleep(5 * time.Second)

// Verify service is enabled and running
status := getServiceStatus(t, "ec-manager.service")
assert.Contains(t, status, "enabled", "service should be enabled")
assert.Contains(t, status, "active (running)", "service should be running")

// Wait for service to start and become ready
// TODO: this should be added to the manager package
assert.Eventually(t, func() bool {
status := getServiceStatus(t, "ec-manager.service")
return strings.Contains(status, "active (running)")
}, 10*time.Second, 1*time.Second, "service should be running")

err = manager.Uninstall(ctx, t.Logf)
require.NoError(t, err, "failed to uninstall manager")
Expand Down

0 comments on commit e329813

Please sign in to comment.