Skip to content

Commit

Permalink
config verification in deployment and upgrade with skip
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Sharma <jsharma@progress.com>
  • Loading branch information
jayvikramsharma1 committed Aug 17, 2023
1 parent 871a563 commit 972a40e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 44 deletions.
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
53 changes: 10 additions & 43 deletions components/automate-cli/cmd/chef-automate/deployHa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,27 @@ package main
import (
"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/logger"
"github.com/chef/automate/lib/platform/command"
"github.com/chef/automate/lib/sshutils"
"github.com/pkg/errors"
)

func executeDeployment(args []string) error {
var indexOfConfig = 0
var configFile = ""
for i, a := range args {
if strings.Contains(a, ".toml") {
configFile = a
indexOfConfig = i
break
}
}
err := executeConfigVerify(configFile)
if err != nil {
return status.New(status.ConfigVerifyError, err.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 executeConfigVerify(configFile string) error {
if len(configFile) > 1 {
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,
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
}
c := NewVerifyCmdFlow(httputils.NewClient(log), createSystemdServiceWithBinary, verifysystemdcreate.NewSystemdCreateUtilsImpl(), config.NewHaDeployConfig(), sshutils.NewSSHUtilWithCommandExecutor(sshutils.NewSshClient(), log, command.NewExecExecutor()), writer, deps)
return c.RunVerify(configFile)
}
return status.New(status.ConfigError, "Config file not found")
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

0 comments on commit 972a40e

Please sign in to comment.