From b3cf5a018067f92efa852e6acb97d913144b36a0 Mon Sep 17 00:00:00 2001 From: Manjunath A Kumatagi Date: Fri, 8 Apr 2022 10:47:01 +0530 Subject: [PATCH] Handle the scope properly --- cloud/scope/powervs_image.go | 36 ++++++++++++++++++++---------------- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cloud/scope/powervs_image.go b/cloud/scope/powervs_image.go index 56396f990..27d0dab74 100644 --- a/cloud/scope/powervs_image.go +++ b/cloud/scope/powervs_image.go @@ -63,12 +63,14 @@ func NewPowerVSImageScope(params PowerVSImageScopeParams) (scope *PowerVSImageSc scope = &PowerVSImageScope{} if params.Client == nil { - return nil, errors.New("failed to generate new scope from nil Client") + err = errors.New("failed to generate new scope from nil Client") + return } scope.client = params.Client if params.IBMPowerVSImage == nil { - return nil, errors.New("failed to generate new scope from nil IBMPowerVSImage") + err = errors.New("failed to generate new scope from nil IBMPowerVSImage") + return } scope.IBMPowerVSImage = params.IBMPowerVSImage @@ -79,24 +81,28 @@ func NewPowerVSImageScope(params PowerVSImageScopeParams) (scope *PowerVSImageSc helper, err := patch.NewHelper(params.IBMPowerVSImage, params.Client) if err != nil { - return nil, errors.Wrap(err, "failed to init patch helper") + err = errors.Wrap(err, "failed to init patch helper") + return } + scope.patchHelper = helper spec := params.IBMPowerVSImage.Spec auth, err := authenticator.GetAuthenticator() if err != nil { - return nil, errors.Wrap(err, "failed to get authenticator") + err = errors.Wrap(err, "failed to get authenticator") + return } account, err := servicesutils.GetAccount(auth) if err != nil { - return nil, errors.Wrap(err, "failed to get account") + err = errors.Wrap(err, "failed to get account") + return } rc, err := resourcecontroller.NewService(resourcecontroller.ServiceOptions{}) if err != nil { - return nil, err + return } res, _, err := rc.GetResourceInstance( @@ -104,12 +110,14 @@ func NewPowerVSImageScope(params PowerVSImageScopeParams) (scope *PowerVSImageSc ID: core.StringPtr(spec.ServiceInstanceID), }) if err != nil { - return nil, errors.Wrap(err, "failed to get resource instance") + err = errors.Wrap(err, "failed to get resource instance") + return } region, err := utils.GetRegion(*res.RegionID) if err != nil { - return nil, errors.Wrap(err, "failed to get region") + err = errors.Wrap(err, "failed to get region") + return } options := powervs.ServiceOptions{ @@ -124,16 +132,12 @@ func NewPowerVSImageScope(params PowerVSImageScopeParams) (scope *PowerVSImageSc c, err := powervs.NewService(options) if err != nil { - return nil, fmt.Errorf("failed to create NewIBMPowerVSClient") + err = fmt.Errorf("failed to create NewIBMPowerVSClient") + return } + scope.IBMPowerVSClient = c - return &PowerVSImageScope{ - Logger: params.Logger, - client: params.Client, - IBMPowerVSClient: c, - IBMPowerVSImage: params.IBMPowerVSImage, - patchHelper: helper, - }, nil + return scope, nil } func (i *PowerVSImageScope) ensureImageUnique(imageName string) (*models.ImageReference, error) { diff --git a/go.mod b/go.mod index 3b183ca67..b5ef9991f 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.19.0 github.com/pkg/errors v0.9.1 - github.com/ppc64le-cloud/powervs-utils v0.0.0-20210106101518-5d3f965b0344 + github.com/ppc64le-cloud/powervs-utils v0.0.0-20210415051532-4cdd6a79c8fa github.com/spf13/pflag v1.0.5 k8s.io/api v0.23.5 k8s.io/apimachinery v0.23.5 diff --git a/go.sum b/go.sum index 390707ca4..158ac7832 100644 --- a/go.sum +++ b/go.sum @@ -967,8 +967,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/ppc64le-cloud/powervs-utils v0.0.0-20210106101518-5d3f965b0344 h1:GDCICxOMTqRacDpbpNM79dUM3IZ0PwaayPt19Srq21k= -github.com/ppc64le-cloud/powervs-utils v0.0.0-20210106101518-5d3f965b0344/go.mod h1:KImYgHmvBVtAczNhyDBDSN54PGIdz0+QiPVQMmObEQY= +github.com/ppc64le-cloud/powervs-utils v0.0.0-20210415051532-4cdd6a79c8fa h1:jsCOe5d4zR/QQczn7uHAxrj6tTnEFVFA8gqNu2CFu0c= +github.com/ppc64le-cloud/powervs-utils v0.0.0-20210415051532-4cdd6a79c8fa/go.mod h1:KImYgHmvBVtAczNhyDBDSN54PGIdz0+QiPVQMmObEQY= github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=