constellation/cli/internal/cmd/upgrade.go
Daniel Weiße ed0bfd9d41
cli: move helm and terraform out of kubernetes package (#2222)
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
2023-08-16 09:59:32 +02:00

58 lines
1.6 KiB
Go

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package cmd
import (
"strings"
"time"
"github.com/google/uuid"
"github.com/spf13/cobra"
)
// NewUpgradeCmd returns a new cobra.Command for the upgrade command.
func NewUpgradeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "upgrade",
Short: "Find and apply upgrades to your Constellation cluster",
Long: "Find and apply upgrades to your Constellation cluster.",
Args: cobra.ExactArgs(0),
}
cmd.AddCommand(newUpgradeCheckCmd())
cmd.AddCommand(newUpgradeApplyCmd())
return cmd
}
// 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
}