Skip to content

Commit

Permalink
Handle the scope properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumatag committed Apr 8, 2022
1 parent 1e2ed3a commit 1441c52
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
36 changes: 20 additions & 16 deletions cloud/scope/powervs_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -79,37 +81,43 @@ 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(
&resourcecontrollerv2.GetResourceInstanceOptions{
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{
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr
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=
Expand Down

0 comments on commit 1441c52

Please sign in to comment.