From 78999c9ed83a8fe96dc3c3ffcc0ae8863664182d Mon Sep 17 00:00:00 2001 From: lgtm <1gtm@users.noreply.github.com> Date: Mon, 6 Jun 2022 03:47:22 -0700 Subject: [PATCH] Make sure to fail the backup/restore sessions if license check fails. (#1554) (#1567) /cherry-pick * Make sure to fail the backup/restore sessions if license check fails. Signed-off-by: piyush1146115 * Refactor implementation. Signed-off-by: piyush1146115 Co-authored-by: Piyush Kanti Das --- pkg/backup.go | 9 +++++---- pkg/restore.go | 11 +++++++---- pkg/utils.go | 2 ++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/backup.go b/pkg/backup.go index 9696abb13..ad5de5d7f 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -121,10 +121,6 @@ func NewCmdBackup() *cobra.Command { if err != nil { return err } - err = license.CheckLicenseEndpoint(config, licenseApiService, SupportedProducts) - if err != nil { - return err - } opt.kubeClient, err = kubernetes.NewForConfig(config) if err != nil { return err @@ -211,6 +207,11 @@ func NewCmdBackup() *cobra.Command { func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic.BackupOutput, error) { var err error + err = license.CheckLicenseEndpoint(opt.config, licenseApiService, SupportedProducts) + if err != nil { + return nil, err + } + opt.setupOptions.StorageSecret, err = opt.kubeClient.CoreV1().Secrets(opt.storageSecret.Namespace).Get(context.TODO(), opt.storageSecret.Name, metav1.GetOptions{}) if err != nil { return nil, err diff --git a/pkg/restore.go b/pkg/restore.go index d872b4c89..361279828 100644 --- a/pkg/restore.go +++ b/pkg/restore.go @@ -81,10 +81,8 @@ func NewCmdRestore() *cobra.Command { if err != nil { return err } - err = license.CheckLicenseEndpoint(config, licenseApiService, SupportedProducts) - if err != nil { - return err - } + opt.config = config + opt.stashClient, err = stash_cs.NewForConfig(config) if err != nil { return err @@ -164,6 +162,11 @@ func NewCmdRestore() *cobra.Command { func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*restic.RestoreOutput, error) { var err error + err = license.CheckLicenseEndpoint(opt.config, licenseApiService, SupportedProducts) + if err != nil { + return nil, err + } + opt.setupOptions.StorageSecret, err = opt.kubeClient.CoreV1().Secrets(opt.storageSecret.Namespace).Get(context.TODO(), opt.storageSecret.Name, metav1.GetOptions{}) if err != nil { return nil, err diff --git a/pkg/utils.go b/pkg/utils.go index a8ffb547a..d2a9fd237 100644 --- a/pkg/utils.go +++ b/pkg/utils.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/kubernetes" + restclient "k8s.io/client-go/rest" "k8s.io/klog/v2" kmapi "kmodules.xyz/client-go/api/v1" appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned" @@ -66,6 +67,7 @@ type mongoOptions struct { defaultBackupOptions restic.BackupOptions dumpOptions []restic.DumpOptions defaultDumpOptions restic.DumpOptions + config *restclient.Config } func waitForDBReady(host string, port, waitTimeout int32) {