Skip to content

Commit

Permalink
merge in #581 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-mccoy committed Jul 1, 2022
1 parent de873d4 commit 702b780
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 122 deletions.
2 changes: 1 addition & 1 deletion packages/gitea/gitea-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gitea:
config:
APP_NAME: "Zarf Gitops Service"
server:
ROOT_URL: "http://127.0.0.1:45003"
# ROOT_URL: "http://127.0.0.1:45003"
DISABLE_SSH: true
OFFLINE_MODE: true
database:
Expand Down
1 change: 1 addition & 0 deletions packages/gitea/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ components:
valuesFiles:
- gitea-values.yaml
scripts:
timeoutSeconds: 60
after:
- "./zarf tools create-read-only-gitea-user"
3 changes: 1 addition & 2 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ var rootCmd = &cobra.Command{
// Disable progress bars for CI envs
if os.Getenv("CI") == "true" {
message.Debug("CI environment detected, disabling progress bars")
// message.NoProgress = true
message.SetLogLevel(message.TraceLevel)
message.NoProgress = true
}
},
Short: "Small tool to bundle dependencies with K3s for air-gapped deployments",
Expand Down
16 changes: 10 additions & 6 deletions src/internal/helm/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ func Destroy(purgeAllZarfInstallations bool) {
// Filter on zarf releases
if zarfPrefix.MatchString(release.Name) {
spinner.Updatef("Uninstalling helm chart %s/%s", release.Namespace, release.Name)
// Establish a new actionConfig for the namespace
actionConfig, _ = createActionConfig(release.Namespace, spinner)
// Perform the uninstall
response, err := uninstallChart(actionConfig, release.Name)
message.Debug(response)
if err != nil {
if err = RemoveChart(release.Namespace, release.Name, spinner); err != nil {
// Don't fatal since this is a removal action
spinner.Errorf(err, "Unable to uninstall the chart")
}
Expand All @@ -59,3 +54,12 @@ func Destroy(purgeAllZarfInstallations bool) {

spinner.Success()
}

func RemoveChart(namespace string, name string, spinner *message.Spinner) error {
// Establish a new actionConfig for the namespace
actionConfig, _ := createActionConfig(namespace, spinner)
// Perform the uninstall
response, err := uninstallChart(actionConfig, name)
message.Debug(response)
return err
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"io/ioutil"
"os"
"os/exec"
"testing"
Expand All @@ -9,8 +10,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestGeneralCLI(t *testing.T) {
t.Log("E2E: Testing general CLI")
func TestUseCLI(t *testing.T) {
t.Log("E2E: Use CLI")
e2e.setup(t)
defer e2e.teardown(t)

Expand All @@ -21,7 +22,10 @@ func TestGeneralCLI(t *testing.T) {
// output, err = exec.Command("bash", "-c", "\"echo 'random test data 🦄' > shasum-test-file\"").Output()
shasumTestFilePath := "shasum-test-file"

e2e.cleanFiles(shasumTestFilePath)
// run `zarf create` with a specified image cache location
imageCachePath := "/tmp/.image_cache-location"

e2e.cleanFiles(shasumTestFilePath, imageCachePath)

testfile, _ := os.Create(shasumTestFilePath)
cmd := exec.Command("echo", "random test data 🦄")
Expand Down Expand Up @@ -58,5 +62,12 @@ func TestGeneralCLI(t *testing.T) {
stdOut, stdErr, err = e2e.execZarfCommand("package", "deploy", "https://zarf-examples.s3.amazonaws.com/zarf-package-appliance-demo-doom-20210125.tar.zst", "--confirm")
assert.Error(t, err, stdOut, stdErr)

e2e.cleanFiles(shasumTestFilePath)
stdOut, stdErr, err = e2e.execZarfCommand("package", "create", "examples/game", "--confirm", "--zarf-cache", imageCachePath)
require.NoError(t, err, stdOut, stdErr)

files, err := ioutil.ReadDir(imageCachePath)
require.NoError(t, err, "Error when reading image cache path")
assert.Greater(t, len(files), 1)

e2e.cleanFiles(shasumTestFilePath, imageCachePath)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eComponentChoice(t *testing.T) {
t.Log("E2E: Testing component choice")
func TestComponentChoice(t *testing.T) {
t.Log("E2E: Component choice")
e2e.setup(t)
defer e2e.teardown(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eComponentScripts(t *testing.T) {
func TestComponentScripts(t *testing.T) {
t.Log("E2E: Testing component scripts")
e2e.setup(t)
defer e2e.teardown(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eInitCluster(t *testing.T) {
func TestZarfInit(t *testing.T) {
t.Log("E2E: Zarf init (limit to 10 minutes)")
e2e.setup(t)
defer e2e.teardown(t)

Expand All @@ -19,7 +20,6 @@ func TestE2eInitCluster(t *testing.T) {
initComponents = "k3s,logging,git-server"
}

t.Log("Running `zarf init`, limit to 10 minutes")
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Minute)
defer cancel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eComponentVariables(t *testing.T) {
t.Log("E2E: Testing component variables")
func TestComponentVariables(t *testing.T) {
t.Log("E2E: Component variables")
e2e.setup(t)
defer e2e.teardown(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestDataInjection(t *testing.T) {
t.Log("E2E: Testing data injection")
t.Log("E2E: Data injection")
e2e.setup(t)
defer e2e.teardown(t)

Expand All @@ -39,4 +39,9 @@ func TestDataInjection(t *testing.T) {

kubectlOut, _ = exec.Command("kubectl", "-n", pod.Namespace, "exec", pod.Name, "--", "ls", "/test/subdirectory-test").Output()
assert.Contains(t, string(kubectlOut), "this-is-an-example-file.txt")

e2e.chartsToRemove = append(e2e.chartsToRemove, ChartTarget{
namespace: "demo",
name: "zarf-raw-example-data-injection-pod",
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eExampleGame(t *testing.T) {
t.Log("E2E: Testing example game")
func TestDosGames(t *testing.T) {
t.Log("E2E: Dos games")
e2e.setup(t)
defer e2e.teardown(t)

Expand All @@ -33,4 +33,9 @@ func TestE2eExampleGame(t *testing.T) {
resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d?doom", localPort))
assert.NoError(t, err, resp)
assert.Equal(t, 200, resp.StatusCode)

e2e.chartsToRemove = append(e2e.chartsToRemove, ChartTarget{
namespace: "zarf",
name: "zarf-raw-multi-games",
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eExampleHelm(t *testing.T) {
t.Log("E2E: Testing example helm chart")
func TestHelm(t *testing.T) {
t.Log("E2E: Helm chart")
e2e.setup(t)
defer e2e.teardown(t)

Expand All @@ -23,4 +23,9 @@ func TestE2eExampleHelm(t *testing.T) {
// Verify multiple helm installs of different release names were deployed
kubectlOut, _ := exec.Command("kubectl", "get", "pods", "-n=helm-releasename", "--no-headers").Output()
assert.Contains(t, string(kubectlOut), "zarf-cool-name-podinfo")

e2e.chartsToRemove = append(e2e.chartsToRemove, ChartTarget{
namespace: "demo",
name: "zarf-raw-example-data-injection-pod",
})
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package test

import (
"encoding/json"
"fmt"
"net/http"
"os"
"os/exec"
"strings"
"testing"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/internal/git"
"github.com/defenseunicorns/zarf/src/internal/k8s"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGitopsExample(t *testing.T) {
t.Log("E2E: Testing gitops example")
func TestGitServer(t *testing.T) {
t.Log("E2E: Git server")
e2e.setup(t)
defer e2e.teardown(t)

Expand Down Expand Up @@ -66,6 +71,34 @@ func TestGitopsExample(t *testing.T) {
err = os.Chdir("..")
assert.NoError(t, err, "unable to change directories back to blah blah blah")

// Make sure Gitea comes up cleanly
resp, err := http.Get("http://127.0.0.1:45003/explore/repos")
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)

// Init the state variable
state := k8s.LoadZarfState()
config.InitState(state)

// Get the repo as the readonly user
repoName := "mirror__repo1.dso.mil__platform-one__big-bang__apps__security-tools__twistlock"
getRepoRequest, _ := http.NewRequest("GET", fmt.Sprintf("http://%s:%d/api/v1/repos/%v/%v", config.IPV4Localhost, k8s.PortGit, config.ZarfGitPushUser, repoName), nil)
getRepoResponseBody, err := git.DoHttpThings(getRepoRequest, config.ZarfGitReadUser, config.GetSecret(config.StateGitPull))
assert.NoError(t, err)

// Make sure the only permissions are pull (read)
var bodyMap map[string]interface{}
json.Unmarshal(getRepoResponseBody, &bodyMap)
permissionsMap := bodyMap["permissions"].(map[string]interface{})
assert.False(t, permissionsMap["admin"].(bool))
assert.False(t, permissionsMap["push"].(bool))
assert.True(t, permissionsMap["pull"].(bool))

e2e.cleanFiles("mirror__github.com__stefanprodan__podinfo")
e2e.cleanFiles("mirror__github.com__defenseunicorns__zarf")

e2e.chartsToRemove = append(e2e.chartsToRemove, ChartTarget{
namespace: "zarf",
name: "zarf-gitea",
})
}
28 changes: 28 additions & 0 deletions src/test/e2e/26_logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package test

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLogginga(t *testing.T) {
t.Log("E2E: Logging")
e2e.setup(t)
defer e2e.teardown(t)

// Establish the port-forward into the logging service
err := e2e.execZarfBackgroundCommand("connect", "logging", "--cli-only")
assert.NoError(t, err, "unable to establish tunnel to logging")

// Make sure Grafana comes up cleanly
resp, err := http.Get("http://127.0.0.1:45002/monitor/login")
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)

e2e.chartsToRemove = append(e2e.chartsToRemove, ChartTarget{
namespace: "zarf",
name: "zarf-loki-stack",
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestE2eRemoteSgete(t *testing.T) {
t.Log("E2E: Testing remote sget")
func TestCosignDeploy(t *testing.T) {
t.Log("E2E: Cosign deploy")
e2e.setup(t)
defer e2e.teardown(t)

Expand All @@ -17,4 +17,9 @@ func TestE2eRemoteSgete(t *testing.T) {
// Deploy the game
stdOut, stdErr, err := e2e.execZarfCommand("package", "deploy", path, "--confirm")
require.NoError(t, err, stdOut, stdErr)

e2e.chartsToRemove = append(e2e.chartsToRemove, ChartTarget{
namespace: "zarf",
name: "zarf-raw-multi-games",
})
}
26 changes: 22 additions & 4 deletions src/test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ import (
"testing"
"time"

"github.com/defenseunicorns/zarf/src/internal/helm"
"github.com/defenseunicorns/zarf/src/internal/message"
"github.com/defenseunicorns/zarf/src/internal/utils"
)

// ZarfE2ETest Struct holding common fields most of the tests will utilize
type ZarfE2ETest struct {
zarfBinPath string
arch string
applianceMode bool
cmdsToKill []*exec.Cmd
zarfBinPath string
arch string
applianceMode bool
cmdsToKill []*exec.Cmd
chartsToRemove []ChartTarget
}

type ChartTarget struct {
name string
namespace string
}

// getCLIName looks at the OS and CPU architecture to determine which Zarf binary needs to be run
Expand All @@ -37,6 +45,8 @@ func getCLIName() string {
// setup actions for each test
func (e2e *ZarfE2ETest) setup(t *testing.T) {
t.Log("Test setup")

// utils.ExecCommandWithContext(context.TODO(), true, "kubectl")
}

// teardown actions for each test
Expand All @@ -50,7 +60,15 @@ func (e2e *ZarfE2ETest) teardown(t *testing.T) {
}
}
}

spinner := message.NewProgressSpinner("Remove test helm charts")
for _, chart := range e2e.chartsToRemove {
helm.RemoveChart(chart.namespace, chart.name, spinner)
}
spinner.Success()

e2e.cmdsToKill = []*exec.Cmd{}
e2e.chartsToRemove = []ChartTarget{}
}

// execZarfCommand executes a Zarf command
Expand Down
Loading

0 comments on commit 702b780

Please sign in to comment.