Skip to content

Commit

Permalink
Implement EC install CLI command integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Oct 30, 2024
1 parent 0cbc569 commit 4235ad1
Show file tree
Hide file tree
Showing 81 changed files with 1,403 additions and 197 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pkg/goods/images
.pre-commit-config.yaml
vendor
e2e/kots-release-install/license.yaml
tests/*/ec-dryrun.yaml
/bin/
/build/
/output/
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ e2e-tests: embedded-release
e2e-test:
go test -timeout 60m -ldflags="$(LD_FLAGS)" -v ./e2e -run ^$(TEST_NAME)$$

.PHONY: dryrun-tests
dryrun-tests:
@./scripts/dryrun-tests.sh

.PHONY: build-ttl.sh
build-ttl.sh:
$(MAKE) -C local-artifact-mirror build-ttl.sh \
Expand Down
3 changes: 3 additions & 0 deletions e2e/cluster/docker/cluster.go → cluster/docker/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (c *Cluster) WaitForReady() {
func (c *Cluster) Cleanup(envs ...map[string]string) {
c.generateSupportBundle(envs...)
c.copyPlaywrightReport()
c.Destroy()
}

func (c *Cluster) Destroy() {
for _, node := range c.Nodes {
node.Destroy()
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions e2e/cluster/interface.go → cluster/interface.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cluster

import (
"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/lxd"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 3 additions & 20 deletions cmd/embedded-cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package main

import (
"context"
"fmt"
"os"
"os/signal"
"path"
"syscall"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"github.com/replicatedhq/embedded-cluster/pkg/cmd"
"github.com/replicatedhq/embedded-cluster/pkg/logging"
)

Expand All @@ -22,25 +21,9 @@ func main() {
)
defer cancel()
logging.SetupLogging()

name := path.Base(os.Args[0])
var app = &cli.App{
Name: name,
Usage: fmt.Sprintf("Install and manage %s", name),
Suggest: true,
Commands: []*cli.Command{
installCommand(),
shellCommand(),
nodeCommands,
versionCommand,
joinCommand,
resetCommand(),
materializeCommand(),
updateCommand(),
restoreCommand(),
adminConsoleCommand(),
supportBundleCommand(),
},
}
app := cmd.NewApp(name)
if err := app.RunContext(ctx, os.Args); err != nil {
logrus.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/host-support-bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
)

func TestHostCollectSupportBundleInCluster(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/pkg/certs"
)

Expand Down
2 changes: 1 addition & 1 deletion e2e/local-artifact-mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
)

func TestLocalArtifactMirror(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/materialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
)

func TestMaterialize(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/preflights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"testing"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
)

Expand Down
2 changes: 1 addition & 1 deletion e2e/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/Masterminds/semver/v3"
"github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/pkg/versions"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion e2e/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
)

// This test creates 4 nodes, installs on the first one and then generate 2 join tokens
Expand Down
4 changes: 2 additions & 2 deletions e2e/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/lxd"
)

func TestSingleNodeDisasterRecovery(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/sudo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/cluster/lxd"
)

func TestCommandsRequireSudo(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/support-bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion e2e/unsupported-overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/docker"
"github.com/replicatedhq/embedded-cluster/cluster/docker"
)

func TestUnsupportedOverrides(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/cluster/lxd"
"github.com/replicatedhq/embedded-cluster/kinds/types"
"github.com/stretchr/testify/require"
)
Expand Down
28 changes: 20 additions & 8 deletions pkg/addons/embeddedclusteroperator/embeddedclusteroperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/replicatedhq/embedded-cluster/kinds/types"
"github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole"
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
"github.com/replicatedhq/embedded-cluster/pkg/release"
Expand Down Expand Up @@ -167,6 +168,10 @@ func (e *EmbeddedClusterOperator) createVersionMetadataConfigmap(ctx context.Con
// the result as a suffix for the config map name.
slugver := slug.Make(strings.TrimPrefix(versions.Version, "v"))
configmap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("version-metadata-%s", slugver),
Namespace: e.namespace,
Expand Down Expand Up @@ -256,6 +261,10 @@ func (e *EmbeddedClusterOperator) Outro(ctx context.Context, provider *defaults.
}

installation := ecv1beta1.Installation{
TypeMeta: metav1.TypeMeta{
APIVersion: ecv1beta1.GroupVersion.String(),
Kind: "Installation",
},
ObjectMeta: metav1.ObjectMeta{
Name: time.Now().Format("20060102150405"),
Labels: map[string]string{
Expand All @@ -281,14 +290,17 @@ func (e *EmbeddedClusterOperator) Outro(ctx context.Context, provider *defaults.
return fmt.Errorf("unable to create installation: %w", err)
}

// we wait for the installation to exist here because items do not show up in the apiserver instantaneously after being created
gotInstallation, err := waitForInstallationToExist(ctx, cli, installation.Name)
if err != nil {
return fmt.Errorf("unable to wait for installation to exist: %w", err)
}
gotInstallation.Status.State = ecv1beta1.InstallationStateKubernetesInstalled
if err := cli.Status().Update(ctx, gotInstallation); err != nil {
return fmt.Errorf("unable to update installation status: %w", err)
// TODO: figure out why fake client doesn't work here
if !dryrun.Enabled() {
// we wait for the installation to exist here because items do not show up in the apiserver instantaneously after being created
gotInstallation, err := waitForInstallationToExist(ctx, cli, installation.Name)
if err != nil {
return fmt.Errorf("unable to wait for installation to exist: %w", err)
}
gotInstallation.Status.State = ecv1beta1.InstallationStateKubernetesInstalled
if err := cli.Status().Update(ctx, gotInstallation); err != nil {
return fmt.Errorf("unable to update installation status: %w", err)
}
}

return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"fmt"
Expand Down
28 changes: 28 additions & 0 deletions pkg/cmd/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"fmt"

"github.com/urfave/cli/v2"
)

func NewApp(name string) *cli.App {
return &cli.App{
Name: name,
Usage: fmt.Sprintf("Install and manage %s", name),
Suggest: true,
Commands: []*cli.Command{
installCommand(),
shellCommand(),
nodeCommands,
versionCommand,
joinCommand,
resetCommand(),
materializeCommand(),
updateCommand(),
restoreCommand(),
adminConsoleCommand(),
supportBundleCommand(),
},
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/flags.go → pkg/cmd/flags.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"fmt"
Expand Down
Loading

0 comments on commit 4235ad1

Please sign in to comment.