Skip to content

Commit

Permalink
[cherry-pick] Make sure to fail the backup/restore sessions if licens…
Browse files Browse the repository at this point in the history
…e check fails. (#1192) (#1196)

* Make sure to fail the backup/restore sessions if license check fails. (#1192)

/cherry-pick

* Make sure to fail the backup/restore sessions if license check fails.

Signed-off-by: piyush1146115 <piyush@appscode.com>

* Run linter.

Signed-off-by: piyush1146115 <piyush@appscode.com>

* Refactor implementation.

Signed-off-by: piyush1146115 <piyush@appscode.com>

* Update docker images

Signed-off-by: Emruz Hossain <emruz@appscode.com>

Co-authored-by: Piyush Kanti Das <piyush123kantidas@gmail.com>
Co-authored-by: Emruz Hossain <emruz@appscode.com>
  • Loading branch information
3 people committed Jun 6, 2022
1 parent 4d4072c commit c212700
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dbg
Expand Up @@ -36,7 +36,7 @@ RUN set -x \
&& apk add --update --no-cache bash ca-certificates curl git

RUN npm config set unsafe-perm true \
&& npm install -g https://github.com/stashed/elasticsearch-dump#88ffff07568743344dcfed9f51c45921e6712e2d
&& npm install -g https://github.com/stashed/elasticsearch-dump#2932ffdcae8e13e4c43f410bf410e2f83c8d8b6b

COPY --from=0 restic /bin/restic
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.in
Expand Up @@ -36,7 +36,7 @@ RUN set -x \
&& apk add --update --no-cache bash ca-certificates curl git

RUN npm config set unsafe-perm true \
&& npm install -g https://github.com/stashed/elasticsearch-dump#88ffff07568743344dcfed9f51c45921e6712e2d
&& npm install -g https://github.com/stashed/elasticsearch-dump#2932ffdcae8e13e4c43f410bf410e2f83c8d8b6b

COPY --from=0 /restic /bin/restic
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
Expand Down
11 changes: 7 additions & 4 deletions pkg/backup.go
Expand Up @@ -68,10 +68,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
Expand Down Expand Up @@ -156,6 +154,11 @@ func NewCmdBackup() *cobra.Command {

func (opt *esOptions) backupElasticsearch(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
Expand Down
11 changes: 7 additions & 4 deletions pkg/restore.go
Expand Up @@ -64,10 +64,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
Expand Down Expand Up @@ -139,6 +137,11 @@ func NewCmdRestore() *cobra.Command {

func (opt *esOptions) restoreElasticsearch(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
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils.go
Expand Up @@ -33,6 +33,7 @@ import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/klog/v2"
kmapi "kmodules.xyz/client-go/api/v1"
meta_util "kmodules.xyz/client-go/meta"
Expand Down Expand Up @@ -66,6 +67,7 @@ type esOptions struct {
setupOptions restic.SetupOptions
backupOptions restic.BackupOptions
restoreOptions restic.RestoreOptions
config *restclient.Config
}
type sessionWrapper struct {
sh *shell.Session
Expand Down

0 comments on commit c212700

Please sign in to comment.