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 (
|
|
|
|
"context"
|
2022-12-19 10:52:15 -05:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2022-08-29 10:49:44 -04:00
|
|
|
|
2023-06-09 09:41:02 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
2023-08-08 07:03:23 -04:00
|
|
|
"github.com/rogpeppe/go-internal/diff"
|
2022-08-29 10:49:44 -04:00
|
|
|
"github.com/spf13/cobra"
|
2023-08-08 07:03:23 -04:00
|
|
|
"gopkg.in/yaml.v3"
|
2023-08-24 10:40:47 -04:00
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
2022-08-29 10:49:44 -04:00
|
|
|
)
|
|
|
|
|
2023-02-01 04:56:47 -05:00
|
|
|
func newUpgradeApplyCmd() *cobra.Command {
|
2022-08-29 10:49:44 -04:00
|
|
|
cmd := &cobra.Command{
|
2023-02-09 09:54:12 -05:00
|
|
|
Use: "apply",
|
2023-02-01 04:56:47 -05:00
|
|
|
Short: "Apply an upgrade to a Constellation cluster",
|
|
|
|
Long: "Apply an upgrade to a Constellation cluster by applying the chosen configuration.",
|
2022-08-29 10:49:44 -04:00
|
|
|
Args: cobra.NoArgs,
|
2023-10-24 09:39:18 -04:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
// Define flags for apply backend that are not set by upgrade-apply
|
|
|
|
cmd.Flags().Bool("merge-kubeconfig", false, "")
|
|
|
|
return runApply(cmd, args)
|
|
|
|
},
|
2023-10-26 09:59:13 -04:00
|
|
|
Deprecated: "use 'constellation apply' instead.",
|
2022-08-29 10:49:44 -04:00
|
|
|
}
|
|
|
|
|
2023-01-17 08:01:56 -05:00
|
|
|
cmd.Flags().BoolP("yes", "y", false, "run upgrades without further confirmation\n"+
|
2023-03-14 13:34:58 -04:00
|
|
|
"WARNING: might delete your resources in case you are using cert-manager in your cluster. Please read the docs.\n"+
|
|
|
|
"WARNING: might unintentionally overwrite measurements in the running cluster.")
|
2023-06-06 09:22:06 -04:00
|
|
|
cmd.Flags().Duration("timeout", 5*time.Minute, "change helm upgrade timeout\n"+
|
2023-02-01 05:23:57 -05:00
|
|
|
"Might be useful for slow connections or big clusters.")
|
2023-08-11 09:18:59 -04:00
|
|
|
cmd.Flags().Bool("conformance", false, "enable conformance mode")
|
|
|
|
cmd.Flags().Bool("skip-helm-wait", false, "install helm charts without waiting for deployments to be ready")
|
2023-09-08 08:55:07 -04:00
|
|
|
cmd.Flags().StringSlice("skip-phases", nil, "comma-separated list of upgrade phases to skip\n"+
|
|
|
|
"one or multiple of { infrastructure | helm | image | k8s }")
|
2023-10-24 09:39:18 -04:00
|
|
|
must(cmd.Flags().MarkHidden("timeout"))
|
2022-12-19 10:52:15 -05:00
|
|
|
|
2022-08-29 10:49:44 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-08-08 07:03:23 -04:00
|
|
|
func diffAttestationCfg(currentAttestationCfg config.AttestationCfg, newAttestationCfg config.AttestationCfg) (string, error) {
|
|
|
|
// cannot compare structs directly with go-cmp because of unexported fields in the attestation config
|
|
|
|
currentYml, err := yaml.Marshal(currentAttestationCfg)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("marshalling remote attestation config: %w", err)
|
|
|
|
}
|
|
|
|
newYml, err := yaml.Marshal(newAttestationCfg)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("marshalling local attestation config: %w", err)
|
|
|
|
}
|
|
|
|
diff := string(diff.Diff("current", currentYml, "new", newYml))
|
|
|
|
return diff, nil
|
|
|
|
}
|
|
|
|
|
2023-08-16 03:59:32 -04:00
|
|
|
type kubernetesUpgrader interface {
|
2023-09-08 08:55:07 -04:00
|
|
|
UpgradeNodeVersion(ctx context.Context, conf *config.Config, force, skipImage, skipK8s bool) error
|
2023-07-21 10:43:51 -04:00
|
|
|
ExtendClusterConfigCertSANs(ctx context.Context, alternativeNames []string) error
|
2023-08-11 09:18:59 -04:00
|
|
|
GetClusterAttestationConfig(ctx context.Context, variant variant.Variant) (config.AttestationCfg, error)
|
2023-08-23 02:14:39 -04:00
|
|
|
ApplyJoinConfig(ctx context.Context, newAttestConfig config.AttestationCfg, measurementSalt []byte) error
|
2023-08-24 10:40:47 -04:00
|
|
|
BackupCRs(ctx context.Context, crds []apiextensionsv1.CustomResourceDefinition, upgradeDir string) error
|
|
|
|
BackupCRDs(ctx context.Context, upgradeDir string) ([]apiextensionsv1.CustomResourceDefinition, error)
|
2023-08-16 03:59:32 -04:00
|
|
|
}
|