2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-08-29 10:49:44 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-08-16 03:59:32 -04:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2022-08-29 10:49:44 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewUpgradeCmd returns a new cobra.Command for the upgrade command.
|
|
|
|
func NewUpgradeCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "upgrade",
|
2023-02-09 09:54:12 -05:00
|
|
|
Short: "Find and apply upgrades to your Constellation cluster",
|
|
|
|
Long: "Find and apply upgrades to your Constellation cluster.",
|
2022-08-29 10:49:44 -04:00
|
|
|
Args: cobra.ExactArgs(0),
|
|
|
|
}
|
|
|
|
|
2023-01-31 06:12:19 -05:00
|
|
|
cmd.AddCommand(newUpgradeCheckCmd())
|
2023-02-01 04:56:47 -05:00
|
|
|
cmd.AddCommand(newUpgradeApplyCmd())
|
2022-08-29 10:49:44 -04:00
|
|
|
return cmd
|
|
|
|
}
|
2023-08-16 03:59:32 -04:00
|
|
|
|
|
|
|
// upgradeCmdKind is the kind of the upgrade command (check, apply).
|
|
|
|
type upgradeCmdKind int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// upgradeCmdKindCheck corresponds to the upgrade check command.
|
|
|
|
upgradeCmdKindCheck upgradeCmdKind = iota
|
|
|
|
// upgradeCmdKindApply corresponds to the upgrade apply command.
|
|
|
|
upgradeCmdKindApply
|
|
|
|
// upgradeCmdKindIAM corresponds to the IAM upgrade command.
|
|
|
|
upgradeCmdKindIAM
|
|
|
|
)
|
|
|
|
|
|
|
|
func generateUpgradeID(kind upgradeCmdKind) string {
|
|
|
|
upgradeID := time.Now().Format("20060102150405") + "-" + strings.Split(uuid.New().String(), "-")[0]
|
|
|
|
switch kind {
|
|
|
|
case upgradeCmdKindCheck:
|
|
|
|
// When performing an upgrade check, the upgrade directory will only be used temporarily to store the
|
|
|
|
// Terraform state. The directory is deleted after the check is finished.
|
|
|
|
// Therefore, add a tmp-suffix to the upgrade ID to indicate that the directory will be cleared after the check.
|
|
|
|
upgradeID = "upgrade-" + upgradeID + "-tmp"
|
|
|
|
case upgradeCmdKindApply:
|
|
|
|
upgradeID = "upgrade-" + upgradeID
|
|
|
|
case upgradeCmdKindIAM:
|
|
|
|
upgradeID = "iam-" + upgradeID
|
|
|
|
}
|
|
|
|
return upgradeID
|
|
|
|
}
|