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

Jay/chef 4487 #8123

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func newAwsDeployemnt(configPath string) *awsDeployment {

func (a *awsDeployment) doDeployWork(args []string) error {
if isA2HARBFileExist() {
if !deployCmdFlags.skipVerify {
_, configFile := getConfigFileFromArgs(args)
err := executeConfigVerifyAndPromptConfirmationOnError(configFile)
if err != nil {
return err
}
}
err := a.generateConfig(DEPLOY)
if err != nil {
return status.Annotate(err, status.DeployError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ func newExistingInfa(configPath string) *existingInfra {
}

func (e *existingInfra) doDeployWork(args []string) error {
var err = bootstrapEnv(e, deployCmdFlags.airgap, false, DEPLOY)
if !deployCmdFlags.skipVerify {
_, configFile := getConfigFileFromArgs(args)
err := executeConfigVerifyAndPromptConfirmationOnError(configFile)
if err != nil {
return err
}
}
err := bootstrapEnv(e, deployCmdFlags.airgap, false, DEPLOY)
if err != nil {
return err
}
Expand Down
51 changes: 51 additions & 0 deletions components/automate-cli/cmd/chef-automate/cliUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ package main

import (
"fmt"
"os"
"strings"

"github.com/chef/automate/components/automate-cli/pkg/status"
"github.com/chef/automate/components/automate-cli/pkg/verifysystemdcreate"
"github.com/chef/automate/lib/config"
"github.com/chef/automate/lib/httputils"
"github.com/chef/automate/lib/io/fileutils"
"github.com/chef/automate/lib/logger"
"github.com/chef/automate/lib/platform/command"
"github.com/chef/automate/lib/pmt"
"github.com/chef/automate/lib/sshutils"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -108,3 +118,44 @@ func GetEnabledFlags(cmd *cobra.Command, flagsToIgnore map[string]int) string {
})
return flags
}

func executeConfigVerify(configFile string) error {

log, err := logger.NewLogger("text", "info")
if err != nil {
return err
}

createSystemdServiceWithBinary, err := verifysystemdcreate.NewCreateSystemdService(
verifysystemdcreate.NewSystemdCreateUtilsImpl(),
BINARY_DESTINATION_FOLDER,
SYSTEMD_PATH,
false,
writer,
)
if err != nil {
return err
}
deps := &verifyCmdDeps{
getAutomateHAInfraDetails: getAutomateHAInfraDetails,
PopulateHaCommonConfig: PopulateHaCommonConfig,
}
c := NewVerifyCmdFlow(httputils.NewClient(log), createSystemdServiceWithBinary, verifysystemdcreate.NewSystemdCreateUtilsImpl(), config.NewHaDeployConfig(), sshutils.NewSSHUtilWithCommandExecutor(sshutils.NewSshClient(), log, command.NewExecExecutor()), writer, deps)
return c.RunVerify(configFile)
}
func executeConfigVerifyAndPromptConfirmationOnError(configFile string) error {
err := executeConfigVerify(configFile)
if err != nil {
fsu := fileutils.NewFileSystemUtils()
p := pmt.PromptFactory(os.Stdin, os.Stdout, fsu)
ok, err := p.Confirm("Config verification failed. Do you still wan to continue?", "yes", "no")
if err != nil {
return status.Wrap(err, status.PromptFailed, err.Error())
}
if !ok {
err = errors.New("failed to confirm overwrite")
return status.Annotate(err, status.ConfigVerifyError)
}
}
return nil
}
7 changes: 7 additions & 0 deletions components/automate-cli/cmd/chef-automate/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var deployCmdFlags = struct {
bootstrapBundlePath string
userAuth bool
saas bool
skipVerify bool
}{}

// deployCmd represents the new command
Expand Down Expand Up @@ -184,6 +185,12 @@ func newDeployCmd() *cobra.Command {
"y",
false,
"Do not prompt for confirmation; accept defaults and continue")
cmd.PersistentFlags().BoolVarP(
&deployCmdFlags.skipVerify,
"skip-verify",
"",
false,
"Flag for skipping config verification check")

if !isDevMode() {
for _, flagName := range []string{
Expand Down
18 changes: 12 additions & 6 deletions components/automate-cli/cmd/chef-automate/deployHa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import (
)

func executeDeployment(args []string) error {
indexOfConfig, _ := getConfigFileFromArgs(args)
args = append(args[:indexOfConfig], args[indexOfConfig+1:]...)
args = append(args, "-y")
if isA2HARBFileExist() {
return executeAutomateClusterCtlCommandAsync("deploy", args, automateHADeployHelpDocs, true)
}
return errors.New(AUTOMATE_HA_INVALID_BASTION)
}
func getConfigFileFromArgs(args []string) (int, string) {
var indexOfConfig = 0
var configFile = ""
for i, a := range args {
if strings.Contains(a, ".toml") {
configFile = a
indexOfConfig = i
break
}
}
args = append(args[:indexOfConfig], args[indexOfConfig+1:]...)
args = append(args, "-y")
if isA2HARBFileExist() {
return executeAutomateClusterCtlCommandAsync("deploy", args, automateHADeployHelpDocs, true)
}
return errors.New(AUTOMATE_HA_INVALID_BASTION)
return indexOfConfig, configFile
}
15 changes: 15 additions & 0 deletions components/automate-cli/cmd/chef-automate/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var upgradeRunCmdFlags = struct {
acceptMLSA bool
upgradeHAWorkspace string
saas bool
skipVerify bool
}{}

var upgradeRunCmd = &cobra.Command{
Expand Down Expand Up @@ -385,6 +386,12 @@ func restartDeploymentService() error {
}

func runAutomateHAFlow(args []string, offlineMode bool) error {
if !upgradeRunCmdFlags.skipVerify {
err := executeConfigVerifyAndPromptConfirmationOnError("")
if err != nil {
return err
}
}
isManagedServices := isManagedServicesOn()
if isManagedServices && !upgradeRunCmdFlags.upgradefrontends {
return status.Annotate(
Expand Down Expand Up @@ -966,6 +973,14 @@ func init() {
command.Parent().HelpFunc()(command, strings)
})

upgradeRunCmd.PersistentFlags().BoolVarP(
&upgradeRunCmdFlags.skipVerify,
"skip-verify",
"",
false,
"Flag for skipping config verification check")
upgradeRunCmd.PersistentFlags().SetAnnotation("skip-storage-check", docs.Compatibility, []string{docs.CompatiblewithStandalone})

if !isDevMode() {
err := upgradeStatusCmd.PersistentFlags().MarkHidden("versions-file")
if err != nil {
Expand Down