Skip to content

Commit

Permalink
feat(upgrade): enable bulk upgrade for volumes and spc (#1655)
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <shubham.bajpai@mayadata.io>
  • Loading branch information
shubham14bajpai authored Apr 8, 2020
1 parent a7b0b0f commit 65bde19
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 37 deletions.
53 changes: 41 additions & 12 deletions cmd/upgrade/executor/cstor_spc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ type CStorSPCOptions struct {

var (
cstorSPCUpgradeCmdHelpText = `
This command upgrades the cStor SPC
Usage: upgrade cstor-spc --spc-name <spc-name> --options...
This command upgrades one or many cStor SPC
`
cstorSPCUpgradeCmdExampleText = ` # Upgrade one spc at a time
upgrade cstor-spc --spc-name <spc-name> --options...
# Upgrade multiple spc at a time
upgrade cstor-spc <spc-name>... --options...`
)

// NewUpgradeCStorSPCJob upgrades all the cStor Pools associated with
Expand All @@ -48,13 +51,16 @@ func NewUpgradeCStorSPCJob() *cobra.Command {
Use: "cstor-spc",
Short: "Upgrade cStor SPC",
Long: cstorSPCUpgradeCmdHelpText,
Example: `upgrade cstor-spc --spc-name <spc-name>`,
Example: cstorSPCUpgradeCmdExampleText,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(options.RunCStorSPCUpgradeChecks(args), util.Fatal)
options.resourceKind = "storagePoolClaim"
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.RunCStorSPCUpgradeChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunCStorSPCUpgrade(cmd), util.Fatal)
if options.cstorSPC.spcName != "" {
singleCStorSPCUpgrade(cmd)
}
if len(args) != 0 {
bulkCStorSPCUpgrade(cmd, args)
}
},
}

Expand All @@ -66,20 +72,38 @@ func NewUpgradeCStorSPCJob() *cobra.Command {
return cmd
}

func singleCStorSPCUpgrade(cmd *cobra.Command) {
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunCStorSPCUpgrade(cmd), util.Fatal)
}

func bulkCStorSPCUpgrade(cmd *cobra.Command, args []string) {
for _, name := range args {
options.cstorSPC.spcName = name
singleCStorSPCUpgrade(cmd)
}
}

// RunCStorSPCUpgradeChecks will ensure the sanity of the cstor SPC upgrade options
func (u *UpgradeOptions) RunCStorSPCUpgradeChecks(cmd *cobra.Command) error {
if len(strings.TrimSpace(u.cstorSPC.spcName)) == 0 {
return errors.Errorf("Cannot execute upgrade job: cstor spc name is missing")
func (u *UpgradeOptions) RunCStorSPCUpgradeChecks(args []string) error {
if len(strings.TrimSpace(u.cstorSPC.spcName)) == 0 && len(args) == 0 {
return errors.Errorf("Cannot execute upgrade job:" +
" neither spc-name flag is set nor spc name list is provided")
}

return nil
}

// RunCStorSPCUpgrade upgrades the given Jiva Volume.
func (u *UpgradeOptions) RunCStorSPCUpgrade(cmd *cobra.Command) error {
klog.V(4).Infof("Started upgrading %s{%s} from %s to %s",
u.resourceKind,
u.cstorSPC.spcName,
u.fromVersion,
u.toVersion)

if apis.IsCurrentVersionValid(u.fromVersion) && apis.IsDesiredVersionValid(u.toVersion) {
klog.Infof("Upgrading to %s", u.toVersion)
err := upgrader.Exec(u.fromVersion, u.toVersion,
u.resourceKind,
u.cstorSPC.spcName,
Expand All @@ -93,5 +117,10 @@ func (u *UpgradeOptions) RunCStorSPCUpgrade(cmd *cobra.Command) error {
} else {
return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion)
}
klog.V(4).Infof("Successfully upgraded %s{%s} from %s to %s",
u.resourceKind,
u.cstorSPC.spcName,
u.fromVersion,
u.toVersion)
return nil
}
54 changes: 41 additions & 13 deletions cmd/upgrade/executor/cstor_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ type CStorVolumeOptions struct {

var (
cstorVolumeUpgradeCmdHelpText = `
This command upgrades the CStor Persistent Volume
Usage: upgrade cstor-volume --volname <pv-name> --options...
This command upgrades one or many CStor Persistent Volume
`
cstorVolumeUpgradeCmdExampleText = ` # Upgrade one volume at a time
upgrade cstor-volume --pv-name <pv-name> --options...
# Upgrade multiple volumes at a time
upgrade cstor-volume <pv-name>... --options...`
)

// NewUpgradeCStorVolumeJob upgrade a CStor Volume
Expand All @@ -47,13 +50,16 @@ func NewUpgradeCStorVolumeJob() *cobra.Command {
Use: "cstor-volume",
Short: "Upgrade CStor Volume",
Long: cstorVolumeUpgradeCmdHelpText,
Example: `upgrade cstor-volume --pv-name <pv-name>`,
Example: cstorVolumeUpgradeCmdExampleText,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(options.RunCStorVolumeUpgradeChecks(args), util.Fatal)
options.resourceKind = "cstorVolume"
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.RunCStorVolumeUpgradeChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunCStorVolumeUpgrade(cmd), util.Fatal)
if options.cstorVolume.pvName != "" {
singleCStorVolumeUpgrade(cmd)
}
if len(args) != 0 {
bulkCStorVolumeUpgrade(cmd, args)
}
},
}

Expand All @@ -65,21 +71,38 @@ func NewUpgradeCStorVolumeJob() *cobra.Command {
return cmd
}

func singleCStorVolumeUpgrade(cmd *cobra.Command) {
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunCStorVolumeUpgrade(cmd), util.Fatal)
}

func bulkCStorVolumeUpgrade(cmd *cobra.Command, args []string) {
for _, name := range args {
options.cstorVolume.pvName = name
singleCStorVolumeUpgrade(cmd)
}
}

// RunCStorVolumeUpgradeChecks will ensure the sanity of the cstor upgrade options
func (u *UpgradeOptions) RunCStorVolumeUpgradeChecks(cmd *cobra.Command) error {
if len(strings.TrimSpace(u.cstorVolume.pvName)) == 0 {
return errors.Errorf("Cannot execute upgrade job: cstor pv name is missing")
func (u *UpgradeOptions) RunCStorVolumeUpgradeChecks(args []string) error {
if len(strings.TrimSpace(u.cstorVolume.pvName)) == 0 && len(args) == 0 {
return errors.Errorf("Cannot execute upgrade job:" +
" neither pv-name flag is set nor pv name list is provided")
}

return nil
}

// RunCStorVolumeUpgrade upgrades the given CStor Volume.
func (u *UpgradeOptions) RunCStorVolumeUpgrade(cmd *cobra.Command) error {
klog.V(4).Infof("Started upgrading %s{%s} from %s to %s",
u.resourceKind,
u.cstorVolume.pvName,
u.fromVersion,
u.toVersion)

if apis.IsCurrentVersionValid(u.fromVersion) && apis.IsDesiredVersionValid(u.toVersion) {

klog.Infof("Upgrading to %s", u.toVersion)
err := upgrader.Exec(u.fromVersion, u.toVersion,
u.resourceKind,
u.cstorVolume.pvName,
Expand All @@ -93,5 +116,10 @@ func (u *UpgradeOptions) RunCStorVolumeUpgrade(cmd *cobra.Command) error {
} else {
return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion)
}
klog.V(4).Infof("Successfully upgraded %s{%s} from %s to %s",
u.resourceKind,
u.cstorVolume.pvName,
u.fromVersion,
u.toVersion)
return nil
}
48 changes: 36 additions & 12 deletions cmd/upgrade/executor/jiva_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ type JivaVolumeOptions struct {

var (
jivaVolumeUpgradeCmdHelpText = `
This command upgrades the Jiva Persistent Volume
Usage: upgrade jiva-volume --volname <pv-name> --options...
This command upgrades one or many Jiva Persistent Volume
`
jivaVolumeUpgradeCmdExampleText = ` # Upgrade one volume at a time
upgrade jiva-volume --pv-name <pv-name> --options...
# Upgrade multiple volumes at a time
upgrade jiva-volume <pv-name>... --options...`
)

// NewUpgradeJivaVolumeJob upgrade a Jiva Volume
Expand All @@ -47,13 +50,16 @@ func NewUpgradeJivaVolumeJob() *cobra.Command {
Use: "jiva-volume",
Short: "Upgrade Jiva Volume",
Long: jivaVolumeUpgradeCmdHelpText,
Example: `upgrade jiva-volume --pv-name <pv-name>`,
Example: jivaVolumeUpgradeCmdExampleText,
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(options.RunJivaVolumeUpgradeChecks(args), util.Fatal)
options.resourceKind = "jivaVolume"
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.RunJivaVolumeUpgradeChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunJivaVolumeUpgrade(cmd), util.Fatal)
if options.jivaVolume.pvName != "" {
singleJivaUpgrade(cmd)
}
if len(args) != 0 {
bulkJivaUpgrade(cmd, args)
}
},
}

Expand All @@ -65,10 +71,24 @@ func NewUpgradeJivaVolumeJob() *cobra.Command {
return cmd
}

func singleJivaUpgrade(cmd *cobra.Command) {
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunJivaVolumeUpgrade(cmd), util.Fatal)
}

func bulkJivaUpgrade(cmd *cobra.Command, args []string) {
for _, name := range args {
options.jivaVolume.pvName = name
singleJivaUpgrade(cmd)
}
}

// RunJivaVolumeUpgradeChecks will ensure the sanity of the jiva upgrade options
func (u *UpgradeOptions) RunJivaVolumeUpgradeChecks(cmd *cobra.Command) error {
if len(strings.TrimSpace(u.jivaVolume.pvName)) == 0 {
return errors.Errorf("Cannot execute upgrade job: jiva pv name is missing")
func (u *UpgradeOptions) RunJivaVolumeUpgradeChecks(args []string) error {
if len(strings.TrimSpace(u.jivaVolume.pvName)) == 0 && len(args) == 0 {
return errors.Errorf("Cannot execute upgrade job:" +
" neither pv-name flag is set nor pv name list is provided")
}

return nil
Expand Down Expand Up @@ -100,6 +120,10 @@ func (u *UpgradeOptions) RunJivaVolumeUpgrade(cmd *cobra.Command) error {
} else {
return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion)
}
klog.Infof("Upgraded successfully")
klog.V(4).Infof("Successfully upgraded %s{%s} from %s to %s",
u.resourceKind,
u.jivaVolume.pvName,
u.fromVersion,
u.toVersion)
return nil
}

0 comments on commit 65bde19

Please sign in to comment.