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

milestone release for v5 #8689

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions components/automate-cli/cmd/chef-automate/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PostChecklistManager struct {
version string
ci ChecklistManager
isExternalDB bool
isExternalOS bool
}

type PostCheckListItem struct {
Expand All @@ -30,25 +31,29 @@ 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)
if err != nil {
return &PostChecklistManager{
version: majorVersion,
isExternalDB: externalDB,
isExternalOS: externalOS,
}, err
}
return &PostChecklistManager{
version: majorVersion,
isExternalDB: externalDB,
isExternalOS: externalOS,
ci: ci,
}, nil
}
Expand Down Expand Up @@ -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++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions components/automate-deployment/pkg/majorupgradechecklist/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 =====
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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,
}, {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
121 changes: 121 additions & 0 deletions components/automate-deployment/pkg/majorupgradechecklist/v5.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading