diff --git a/pkg/backup.go b/pkg/backup.go index 8946de919..a66932392 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -69,10 +69,8 @@ func NewCmdBackup() *cobra.Command { if err != nil { return err } - err = license.CheckLicenseEndpoint(config, licenseApiService, SupportedProducts) - if err != nil { - return err - } + opt.config = config + opt.kubeClient, err = kubernetes.NewForConfig(config) if err != nil { return err @@ -155,6 +153,11 @@ func NewCmdBackup() *cobra.Command { func (opt *mysqlOptions) backupMySQL(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 63e226f58..94ea291a8 100644 --- a/pkg/restore.go +++ b/pkg/restore.go @@ -60,10 +60,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.kubeClient, err = kubernetes.NewForConfig(config) if err != nil { return err @@ -137,6 +135,12 @@ func NewCmdRestore() *cobra.Command { func (opt *mysqlOptions) restoreMySQL(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 04fb73c2a..fcef54558 100644 --- a/pkg/utils.go +++ b/pkg/utils.go @@ -32,6 +32,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" + restclient "k8s.io/client-go/rest" "k8s.io/klog/v2" kmapi "kmodules.xyz/client-go/api/v1" appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1" @@ -64,6 +65,7 @@ type mysqlOptions struct { setupOptions restic.SetupOptions backupOptions restic.BackupOptions dumpOptions restic.DumpOptions + config *restclient.Config } type sessionWrapper struct {