From 5d3fd0b2e7f8de3cc53ea728bd3cebfbc8255457 Mon Sep 17 00:00:00 2001 From: Sahiba Goyal <108404805+Sahiba3108@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:06:14 +0530 Subject: [PATCH] add checklist for v5 for postgres (#8672) * add checklist for v5 for postgres Signed-off-by: Sahiba3108 * add checklist for v5 for postgres Signed-off-by: Sahiba3108 * add checklist for v5 for postgres Signed-off-by: Sahiba3108 * add checklist for v5 for postgres Signed-off-by: Sahiba3108 * add checklist for v5 for postgres Signed-off-by: Sahiba3108 --------- Signed-off-by: Sahiba3108 --- .../automate-cli/cmd/chef-automate/upgrade.go | 38 ++++++ .../checklist_manager.go | 2 + .../post_checklist_manager.go | 11 +- .../majorupgradechecklist/upgrade_utils.go | 2 + .../pkg/majorupgradechecklist/v3.go | 18 +-- .../pkg/majorupgradechecklist/v5.go | 121 ++++++++++++++++++ 6 files changed, 180 insertions(+), 12 deletions(-) create mode 100644 components/automate-deployment/pkg/majorupgradechecklist/v5.go diff --git a/components/automate-cli/cmd/chef-automate/upgrade.go b/components/automate-cli/cmd/chef-automate/upgrade.go index fa10b61efe5..f758033ce5c 100644 --- a/components/automate-cli/cmd/chef-automate/upgrade.go +++ b/components/automate-cli/cmd/chef-automate/upgrade.go @@ -224,6 +224,29 @@ func runUpgradeCmd(cmd *cobra.Command, args []string) error { if isError { return nil } + case "5": + ci, err := majorupgradechecklist.NewChecklistManager(writer, validatedResp.TargetVersion) + if err != nil { + return status.Wrap( + err, + status.DeploymentServiceCallError, + "Request to start upgrade failed", + ) + } + + flags := majorupgradechecklist.ChecklistUpgradeFlags{ + SkipStorageCheck: upgradeRunCmdFlags.skipStorageCheck, + OsDestDataDir: upgradeRunCmdFlags.osDestDataDir, + } + err = ci.RunChecklist(configCmdFlags.timeout, flags) + if err != nil { + exec.Command("/bin/sh", "-c", disableMaintenanceModeCmd).Output() + return status.Wrap( + err, + status.DeploymentServiceCallError, + "Request to start upgrade failed", + ) + } default: return status.Errorf(status.UpgradeError, "invalid major version") } @@ -730,6 +753,21 @@ func postUpgradeStatus(resp *api.UpgradeStatusResponse) error { if err != nil { return err } + case "5": + pendingPostChecklist, err := GetPendingPostChecklist(resp.CurrentVersion) + if err != nil { + return err + } + if len(pendingPostChecklist) > 0 { + writer.Println(majorupgradechecklist.POST_UPGRADE_HEADER) + for index, msg := range pendingPostChecklist { + writer.Body("\n" + strconv.Itoa(index+1) + ") " + msg) + } + } + err = majorupgradechecklist.SetSeenTrueForExternal() + if err != nil { + return err + } } return nil } diff --git a/components/automate-deployment/pkg/majorupgradechecklist/checklist_manager.go b/components/automate-deployment/pkg/majorupgradechecklist/checklist_manager.go index 55412e4bd7b..d92bd32f654 100644 --- a/components/automate-deployment/pkg/majorupgradechecklist/checklist_manager.go +++ b/components/automate-deployment/pkg/majorupgradechecklist/checklist_manager.go @@ -24,6 +24,8 @@ func NewChecklistManager(writer cli.FormatWriter, version string) (ChecklistMana return NewV3ChecklistManager(writer, version), nil case "4": return NewV4ChecklistManager(writer, version), nil + case "5": + return NewV5ChecklistManager(writer, version), nil default: return nil, status.Errorf(status.UpgradeError, "invalid major version") } diff --git a/components/automate-deployment/pkg/majorupgradechecklist/post_checklist_manager.go b/components/automate-deployment/pkg/majorupgradechecklist/post_checklist_manager.go index 17a8eac3010..630a87d139f 100644 --- a/components/automate-deployment/pkg/majorupgradechecklist/post_checklist_manager.go +++ b/components/automate-deployment/pkg/majorupgradechecklist/post_checklist_manager.go @@ -12,6 +12,7 @@ type PostChecklistManager struct { version string ci ChecklistManager isExternalDB bool + isExternalOS bool } type PostCheckListItem struct { @@ -30,13 +31,15 @@ type PostChecklist struct { func NewPostChecklistManager(version string) (*PostChecklistManager, error) { externalDB := false - + externalOS := false majorVersion, _ := GetMajorVersion(version) switch majorVersion { case "3": externalDB = IsExternalPG() case "4": - externalDB = IsExternalElasticSearch() + externalOS = IsExternalElasticSearch() + case "5": + externalDB = IsExternalPG() } ci, err := NewChecklistManager(nil, version) @@ -44,11 +47,13 @@ func NewPostChecklistManager(version string) (*PostChecklistManager, error) { return &PostChecklistManager{ version: majorVersion, isExternalDB: externalDB, + isExternalOS: externalOS, }, err } return &PostChecklistManager{ version: majorVersion, isExternalDB: externalDB, + isExternalOS: externalOS, ci: ci, }, nil } @@ -119,7 +124,7 @@ func (pcm *PostChecklistManager) ReadPendingPostChecklistFile(path string) ([]st } if showPostChecklist { - if pcm.isExternalDB && pcm.version != "3" { + if pcm.isExternalOS { postCmdList = []string{"External OpenSearch Patch"} } else { for i := 0; i < len(res.PostChecklist); i++ { diff --git a/components/automate-deployment/pkg/majorupgradechecklist/upgrade_utils.go b/components/automate-deployment/pkg/majorupgradechecklist/upgrade_utils.go index 316a2e7549a..9e438cf3c6e 100644 --- a/components/automate-deployment/pkg/majorupgradechecklist/upgrade_utils.go +++ b/components/automate-deployment/pkg/majorupgradechecklist/upgrade_utils.go @@ -98,6 +98,8 @@ func CheckSpaceAvailable(isMigration bool, dbDataPath string, version string, sk dbDataPath = habRootPath + "svc/automate-postgresql/data/pgdata" case "4": dbDataPath = habRootPath + "svc/automate-elasticsearch/data" + case "5": + dbDataPath = habRootPath + "svc/automate-postgresql/data/pgdata13" } } habFreeSpace, err := cm.GetFreeSpaceinGB(habRootPath) diff --git a/components/automate-deployment/pkg/majorupgradechecklist/v3.go b/components/automate-deployment/pkg/majorupgradechecklist/v3.go index c4fe6f2dcc7..057e5a5e953 100644 --- a/components/automate-deployment/pkg/majorupgradechecklist/v3.go +++ b/components/automate-deployment/pkg/majorupgradechecklist/v3.go @@ -13,7 +13,7 @@ const ( initMsg = `This is a Major upgrade. ======================== - 1) In this release Embedded PostgreSQL is upgraded to version 13.5 + 1) In this release Embedded PostgreSQL is upgraded to version %v 2) This will need special care if you use Embedded PostgreSQL. ===== Your installation is using %s PostgreSQL ===== @@ -35,7 +35,7 @@ const ( $ ` + run_chef_automate_upgrade_status_cmd + ` This should return: Automate is up-to-date` - run_pg_data_migrate = `Migrate Data from PG 9.6 to PG 13.5 using this command: + run_pg_data_migrate = `Migrate Data from PG %v to PG %v using this command: $ ` + run_pg_data_migrate_cmd run_pg_data_migrate_cmd = `chef-automate post-major-upgrade migrate --data=pg` @@ -44,7 +44,7 @@ const ( run_chef_automate_status = `Check all services are running using: $ chef-automate status` - run_pg_data_cleanup = `If you are sure all data is available in Upgraded Automate, then we can free up old PostgreSQL 9.6 Data by running: + run_pg_data_cleanup = `If you are sure all data is available in Upgraded Automate, then we can free up old PostgreSQL %v Data by running: $ ` + run_pg_data_cleanup_cmd run_pg_data_cleanup_cmd = `chef-automate post-major-upgrade clear-data --data=PG` @@ -70,7 +70,7 @@ var postChecklistEmbedded = []PostCheckListItem{ IsExecuted: false, }, { Id: "migrate_pg", - Msg: run_pg_data_migrate, + Msg: fmt.Sprintf(run_pg_data_migrate, 9.6, 13.5), Cmd: run_pg_data_migrate_cmd, IsExecuted: false, }, { @@ -81,7 +81,7 @@ var postChecklistEmbedded = []PostCheckListItem{ IsExecuted: false, }, { Id: "clean_up", - Msg: run_pg_data_cleanup, + Msg: fmt.Sprintf(run_pg_data_cleanup, 9.6), Cmd: run_pg_data_cleanup_cmd, Optional: true, IsExecuted: false, @@ -158,7 +158,7 @@ func (ci *V3ChecklistManager) RunChecklist(timeout int64, flags ChecklistUpgrade if ci.isExternalPG { dbType = "External" postcheck = postChecklistExternal - checklists = append(checklists, []Checklist{downTimeCheck(), backupCheck(), replaceS3Url(), externalPGUpgradeCheck(), postChecklistIntimationCheck()}...) + checklists = append(checklists, []Checklist{downTimeCheck(), backupCheck(), replaceS3Url(), externalPGUpgradeCheck(9.6, 13.5), postChecklistIntimationCheck()}...) } else { dbType = "Embedded" postcheck = postChecklistEmbedded @@ -170,7 +170,7 @@ func (ci *V3ChecklistManager) RunChecklist(timeout int64, flags ChecklistUpgrade Writer: ci.writer, } - ci.writer.Println(fmt.Sprintf(initMsg, dbType, ci.version)) //display the init message + ci.writer.Println(fmt.Sprintf(initMsg, 13.5, dbType, ci.version)) //display the init message for _, item := range checklists { if item.TestFunc == nil { @@ -272,12 +272,12 @@ func postChecklistIntimationCheck() Checklist { } } -func externalPGUpgradeCheck() Checklist { +func externalPGUpgradeCheck(current_version, target_version float64) Checklist { return Checklist{ Name: "external_pg_upgrade_acceptance", Description: "confirmation check for external PG upgrade", TestFunc: func(h ChecklistHelper) error { - resp, err := h.Writer.Confirm("Upgrade your PostgreSQL 9.6 to 13.5 with the help of your Database Administrator") + resp, err := h.Writer.Confirm(fmt.Sprintf("Upgrade your PostgreSQL %v to %v with the help of your Database Administrator", current_version, target_version)) if err != nil { h.Writer.Error(err.Error()) return status.Errorf(status.InvalidCommandArgsError, err.Error()) diff --git a/components/automate-deployment/pkg/majorupgradechecklist/v5.go b/components/automate-deployment/pkg/majorupgradechecklist/v5.go new file mode 100644 index 00000000000..75422a71fda --- /dev/null +++ b/components/automate-deployment/pkg/majorupgradechecklist/v5.go @@ -0,0 +1,121 @@ +package majorupgradechecklist + +import ( + "fmt" + + "github.com/chef/automate/components/automate-deployment/pkg/cli" + "github.com/pkg/errors" +) + +var postChecklistEmbeddedV5 = []PostCheckListItem{ + { + Id: "upgrade_status", + Msg: run_chef_automate_upgrade_status, + Cmd: run_chef_automate_upgrade_status_cmd, + Optional: true, + IsExecuted: false, + }, { + Id: "migrate_pg", + Msg: fmt.Sprintf(run_pg_data_migrate, 13.5, 17.0), + Cmd: run_pg_data_migrate_cmd, + IsExecuted: false, + }, { + Id: "check_ui", + Msg: ui_check, + Cmd: "", + Optional: true, + IsExecuted: false, + }, { + Id: "clean_up", + Msg: fmt.Sprintf(run_pg_data_cleanup, 13.5), + Cmd: run_pg_data_cleanup_cmd, + Optional: true, + IsExecuted: false, + }, +} + +var postChecklistExternalV5 = []PostCheckListItem{ + { + Id: "patch_new_config", + Msg: patch_new_conf, + Cmd: patch_new_conf_cmd, + Optional: true, + IsExecuted: false, + }, { + Id: "upgrade_status", + Msg: run_chef_automate_upgrade_status, + Cmd: run_chef_automate_upgrade_status_cmd, + Optional: true, + IsExecuted: false, + }, { + Id: "status", + Msg: run_chef_automate_status, + Cmd: run_chef_automate_status_cmd, + Optional: true, + IsExecuted: false, + }, { + Id: "check_ui", + Msg: ui_check, + Cmd: "", + Optional: true, + IsExecuted: false, + }, +} + +type V5ChecklistManager struct { + writer cli.FormatWriter + version string + isExternalPG bool +} + +func NewV5ChecklistManager(writer cli.FormatWriter, version string) *V5ChecklistManager { + return &V5ChecklistManager{ + writer: writer, + version: version, + isExternalPG: IsExternalPG(), + } +} + +func (ci *V5ChecklistManager) GetPostChecklist() []PostCheckListItem { + var postChecklist []PostCheckListItem + if ci.isExternalPG { + postChecklist = postChecklistExternalV5 + } else { + postChecklist = postChecklistEmbeddedV5 + } + return postChecklist +} + +func (ci *V5ChecklistManager) RunChecklist(timeout int64, flags ChecklistUpgradeFlags) error { + + var dbType string + checklists := []Checklist{} + var postcheck []PostCheckListItem + + if ci.isExternalPG { + dbType = "External" + postcheck = postChecklistExternalV5 + checklists = append(checklists, []Checklist{downTimeCheck(), backupCheck(), externalPGUpgradeCheck(13.5, 17.0), postChecklistIntimationCheck()}...) + } else { + dbType = "Embedded" + postcheck = postChecklistEmbeddedV5 + checklists = append(checklists, []Checklist{diskSpaceCheck(ci.version, flags.SkipStorageCheck, flags.OsDestDataDir), downTimeCheck(), backupCheck(), postChecklistIntimationCheck()}...) + } + checklists = append(checklists, showPostChecklist(&postcheck), promptUpgradeContinue()) + + helper := ChecklistHelper{ + Writer: ci.writer, + } + + ci.writer.Println(fmt.Sprintf(initMsg, 17.0, dbType, ci.version)) //display the init message + + for _, item := range checklists { + if item.TestFunc == nil { + continue + } + if err := item.TestFunc(helper); err != nil { + return errors.Wrap(err, "one of the checklist was not accepted/satisfied for upgrade") + } + } + return nil +}