Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the scope properly #621

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down