diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-08-01 12:38:30 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-08-05 09:20:08 +0000 |
| commit | 3d0f98e5c7c80888e1e8878002dc9d491bed4ef2 (patch) | |
| tree | 97053d812a8be5af1b9cff5bb6d53a8d62ad8f38 /pkg/gce | |
| parent | f5bcc8dc6eb21df90aeb443032779df3e73c53a1 (diff) | |
pkg/gce.go: replace deprecated method
Bonus: add error processing.
Diffstat (limited to 'pkg/gce')
| -rw-r--r-- | pkg/gce/gce.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/pkg/gce/gce.go b/pkg/gce/gce.go index 792a3fb49..c89c474a7 100644 --- a/pkg/gce/gce.go +++ b/pkg/gce/gce.go @@ -26,6 +26,7 @@ import ( "golang.org/x/oauth2/google" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" + "google.golang.org/api/option" ) type Context struct { @@ -61,12 +62,10 @@ func NewContext(customZoneID string) (*Context, error) { return nil, fmt.Errorf("failed to get a token source: %w", err) } httpClient := oauth2.NewClient(background, tokenSource) - // nolint - // compute.New is deprecated: please use NewService instead. - // To provide a custom HTTP client, use option.WithHTTPClient. - // If you are using google.golang.org/api/googleapis/transport.APIKey, - // use option.WithAPIKey with NewService instead. - ctx.computeService, _ = compute.New(httpClient) + ctx.computeService, err = compute.NewService(background, option.WithHTTPClient(httpClient)) + if err != nil { + return nil, fmt.Errorf("failed to create compute service: %w", err) + } // Obtain project name, zone and current instance IP address. ctx.ProjectID, err = ctx.getMeta("project/project-id") if err != nil { |
