Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always respect the --confirm flag #297

Merged
merged 4 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ package-example-single-big-bang-package: ## Create the Zarf package for single-b
package-example-gitops-data:
cd examples/gitops-data && ../../$(ZARF_BIN) package create --confirm && mv zarf-package-* ../../build/

.PHONY: package-example-tiny-kafka
package-example-tiny-kafka:
cd examples/tiny-kafka && ../../$(ZARF_BIN) package create --confirm && mv zarf-package-* ../../build/

.PHONY: test-cloud-e2e-example-game
test-cloud-e2e-example-game: ## Runs the Doom game as an E2E test in the cloud. Requires access to an AWS account. Costs money. Make sure you ran the `build-cli`, `init-package`, and `package-example-game` targets first
cd test/e2e && go test ./... -run TestE2eExampleGame -v -timeout 1200s
Expand All @@ -97,7 +101,7 @@ test-cloud-e2e-git-based-helm-chart:
################ END Pending removal post-merge

.PHONY: test-cloud-e2e-general-cli
test-cloud-e2e-general-cli: ## Runs tests of the CLI that don't need a cluster
test-cloud-e2e-general-cli: package-example-tiny-kafka ## Runs tests of the CLI that don't need a cluster
cd test/e2e && go test ./... -run TestGeneralCli -v -timeout 1200s

.PHONY: test-e2e
Expand Down
11 changes: 7 additions & 4 deletions cli/internal/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/defenseunicorns/zarf/cli/types"
"io"
"io/ioutil"
"net/http"
Expand All @@ -13,6 +12,8 @@ import (
"strings"
"time"

"github.com/defenseunicorns/zarf/cli/types"

"github.com/goccy/go-yaml"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -78,16 +79,18 @@ func confirmAction(configPath string, userMessage string) bool {
utils.ColorPrintYAML(text)

// Display prompt if not auto-confirmed
var confirmFlag bool
if config.DeployOptions.Confirm {
message.Infof("%s Zarf package confirmed", userMessage)
return config.DeployOptions.Confirm
} else {
prompt := &survey.Confirm{
Message: userMessage + " this Zarf package?",
}
_ = survey.AskOne(prompt, &config.DeployOptions.Confirm)
_ = survey.AskOne(prompt, &confirmFlag)
}

return config.DeployOptions.Confirm
return confirmFlag
}

func getValidComponents(allComponents []types.ZarfComponent, requestedComponentNames []string) []types.ZarfComponent {
Expand All @@ -99,7 +102,7 @@ func getValidComponents(allComponents []types.ZarfComponent, requestedComponentN
// If the component is not required check if the user wants it deployed
if !confirmComponent {
// Check if this is one of the components that has been requested
if len(requestedComponentNames) > 0 {
if len(requestedComponentNames) > 0 || config.DeployOptions.Confirm {
for index, requestedComponent := range requestedComponentNames {
if strings.ToLower(requestedComponent) == component.Name {
confirmComponent = true
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/e2e_general_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func TestGeneralCli(t *testing.T) {
// Upload the Zarf artifacts
teststructure.RunTestStage(e2e.testing, "UPLOAD", func() {
e2e.syncFileToRemoteServer("../../build/zarf", fmt.Sprintf("/home/%s/build/zarf", e2e.username), "0700")
e2e.syncFileToRemoteServer("../../build/zarf-init.tar.zst", fmt.Sprintf("/home/%s/build/zarf-init.tar.zst", e2e.username), "0700")
e2e.syncFileToRemoteServer("../../build/zarf-package-kafka-strimzi-demo.tar.zst", fmt.Sprintf("/home/%s/build/zarf-package-kafka-strimzi-demo.tar.zst", e2e.username), "0700")
})

teststructure.RunTestStage(e2e.testing, "TEST", func() {
Expand Down Expand Up @@ -57,6 +59,14 @@ func TestGeneralCli(t *testing.T) {
output, err = e2e.runSSHCommand("cd /home/%s/build && ./zarf pki regenerate --host some_unique_server", e2e.username)
require.Error(e2e.testing, err, output)

// Initialize Zarf for the next set of tests
output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf init --confirm --components k3s'", e2e.username)
require.NoError(e2e.testing, err, output)

// Verify that we do not timeout when passing the `--confirm` flag without specifying the `--components` flag
output, err = e2e.runSSHCommand("sudo timeout 120 sudo bash -c 'cd /home/%s/build && ./zarf package deploy zarf-package-kafka-strimzi-demo.tar.zst --confirm' || false", e2e.username)
require.NoError(e2e.testing, err, output)

// Test that `zarf package deploy` doesn't die when given a URL
// NOTE: Temporarily commenting this out because this seems out of scope for a general cli test. Having this included also means we would have to fully standup a `zarf init` command.
// TODO: Move this to it's own e2e test.
Expand Down