From b94d23a3e8a32d0215368f2a870a73a1ff1c2ace Mon Sep 17 00:00:00 2001 From: Otto Bittner Date: Fri, 3 Mar 2023 12:43:48 +0100 Subject: [PATCH] cli: create backups before upgrading microservices --- cli/internal/helm/client.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/internal/helm/client.go b/cli/internal/helm/client.go index ca40ed0d4..a585a3aa7 100644 --- a/cli/internal/helm/client.go +++ b/cli/internal/helm/client.go @@ -73,9 +73,17 @@ func NewClient(client crdClient, kubeConfigPath, helmNamespace string, log debug // If the CLI receives an interrupt signal it will cancel the context. // Canceling the context will prompt helm to abort and roll back the ongoing upgrade. func (c *Client) Upgrade(ctx context.Context, config *config.Config, timeout time.Duration, allowDestructive bool) error { + crds, err := c.backupCRDs(ctx) + if err != nil { + return fmt.Errorf("creating CRD backup: %w", err) + } + if err := c.backupCRs(ctx, crds); err != nil { + return fmt.Errorf("creating CR backup: %w", err) + } + upgradeErrs := []error{} invalidUpgrade := &compatibility.InvalidUpgradeError{} - err := c.upgradeRelease(ctx, timeout, config, ciliumPath, ciliumReleaseName, false, allowDestructive) + err = c.upgradeRelease(ctx, timeout, config, ciliumPath, ciliumReleaseName, false, allowDestructive) switch { case errors.As(err, &invalidUpgrade): upgradeErrs = append(upgradeErrs, fmt.Errorf("skipping Cilium upgrade: %w", err))