mirror of https://github.com/kubernetes/kops.git
Replace deprecated method calls to google cloud libraries
Required for static-check to pass.
This commit is contained in:
parent
bad8debd19
commit
5ebbfc96b9
|
@ -24,6 +24,7 @@ go_library(
|
|||
"//vendor/golang.org/x/oauth2/google:go_default_library",
|
||||
"//vendor/google.golang.org/api/compute/v1:go_default_library",
|
||||
"//vendor/google.golang.org/api/dns/v1:go_default_library",
|
||||
"//vendor/google.golang.org/api/option:go_default_library",
|
||||
"//vendor/gopkg.in/gcfg.v1:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
"//vendor/k8s.io/legacy-cloud-providers/gce:go_default_library",
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"golang.org/x/oauth2/google"
|
||||
compute "google.golang.org/api/compute/v1"
|
||||
dns "google.golang.org/api/dns/v1"
|
||||
"google.golang.org/api/option"
|
||||
gcfg "gopkg.in/gcfg.v1"
|
||||
"k8s.io/klog"
|
||||
|
||||
|
@ -78,10 +79,12 @@ func newCloudDns(config io.Reader) (*Interface, error) {
|
|||
// CreateInterface creates a clouddns.Interface object using the specified parameters.
|
||||
// If no tokenSource is specified, uses oauth2.DefaultTokenSource.
|
||||
func CreateInterface(projectID string, tokenSource oauth2.TokenSource) (*Interface, error) {
|
||||
ctx := context.TODO()
|
||||
|
||||
if tokenSource == nil {
|
||||
var err error
|
||||
tokenSource, err = google.DefaultTokenSource(
|
||||
context.TODO(),
|
||||
ctx,
|
||||
compute.CloudPlatformScope,
|
||||
compute.ComputeScope)
|
||||
klog.V(4).Infof("Using DefaultTokenSource %#v", tokenSource)
|
||||
|
@ -92,9 +95,7 @@ func CreateInterface(projectID string, tokenSource oauth2.TokenSource) (*Interfa
|
|||
klog.Infof("Using existing Token Source %#v", tokenSource)
|
||||
}
|
||||
|
||||
oauthClient := oauth2.NewClient(context.TODO(), tokenSource)
|
||||
|
||||
service, err := dns.New(oauthClient)
|
||||
service, err := dns.NewService(ctx, option.WithTokenSource(tokenSource))
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get Cloud DNS client: %v", err)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ go_library(
|
|||
deps = [
|
||||
"//pkg/nodeidentity:go_default_library",
|
||||
"//vendor/cloud.google.com/go/compute/metadata:go_default_library",
|
||||
"//vendor/golang.org/x/oauth2/google:go_default_library",
|
||||
"//vendor/google.golang.org/api/compute/v0.beta:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"cloud.google.com/go/compute/metadata"
|
||||
"golang.org/x/oauth2/google"
|
||||
compute "google.golang.org/api/compute/v0.beta"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/klog"
|
||||
|
@ -48,12 +47,7 @@ type nodeIdentifier struct {
|
|||
func New() (nodeidentity.Identifier, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
client, err := google.DefaultClient(ctx, compute.ComputeScope)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building google API client: %v", err)
|
||||
}
|
||||
|
||||
computeService, err := compute.New(client)
|
||||
computeService, err := compute.NewService(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building compute API client: %v", err)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ go_library(
|
|||
"//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach:go_default_library",
|
||||
"//vendor/golang.org/x/net/context:go_default_library",
|
||||
"//vendor/golang.org/x/oauth2/google:go_default_library",
|
||||
"//vendor/google.golang.org/api/compute/v0.beta:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/rbac/v1beta1:go_default_library",
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
"cloud.google.com/go/compute/metadata"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/oauth2/google"
|
||||
compute "google.golang.org/api/compute/v0.beta"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/protokube/pkg/etcd"
|
||||
|
@ -51,11 +50,7 @@ var _ Volumes = &GCEVolumes{}
|
|||
func NewGCEVolumes() (*GCEVolumes, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
client, err := google.DefaultClient(ctx, compute.ComputeScope)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building google API client: %v", err)
|
||||
}
|
||||
computeService, err := compute.New(client)
|
||||
computeService, err := compute.NewService(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building compute API client: %v", err)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package gce
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -124,24 +123,19 @@ func NewGCECloud(region string, project string, labels map[string]string) (GCECl
|
|||
klog.Infof("Will load GOOGLE_APPLICATION_CREDENTIALS from %s", os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
|
||||
}
|
||||
|
||||
// TODO: should we create different clients with per-service scopes?
|
||||
client, err := google.DefaultClient(ctx, compute.CloudPlatformScope)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building google API client: %v", err)
|
||||
}
|
||||
computeService, err := compute.New(client)
|
||||
computeService, err := compute.NewService(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building compute API client: %v", err)
|
||||
}
|
||||
c.compute = computeService
|
||||
|
||||
storageService, err := storage.New(client)
|
||||
storageService, err := storage.NewService(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building storage API client: %v", err)
|
||||
}
|
||||
c.storage = storageService
|
||||
|
||||
iamService, err := iam.New(client)
|
||||
iamService, err := iam.NewService(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building IAM API client: %v", err)
|
||||
}
|
||||
|
@ -152,7 +146,7 @@ func NewGCECloud(region string, project string, labels map[string]string) (GCECl
|
|||
{
|
||||
// Attempt to log the current GCE service account in user, for diagnostic purposes
|
||||
// At least until we get e2e running, we're doing this always
|
||||
tokenInfo, err := c.getTokenInfo(client)
|
||||
tokenInfo, err := c.getTokenInfo(ctx)
|
||||
if err != nil {
|
||||
klog.Infof("unable to get token info: %v", err)
|
||||
} else {
|
||||
|
@ -344,8 +338,8 @@ func FindInstanceTemplates(c GCECloud, clusterName string) ([]*compute.InstanceT
|
|||
}
|
||||
|
||||
// logTokenInfo returns information about the active credential
|
||||
func (c *gceCloudImplementation) getTokenInfo(client *http.Client) (*oauth2.Tokeninfo, error) {
|
||||
tokenSource, err := google.DefaultTokenSource(context.TODO(), compute.CloudPlatformScope)
|
||||
func (c *gceCloudImplementation) getTokenInfo(ctx context.Context) (*oauth2.Tokeninfo, error) {
|
||||
tokenSource, err := google.DefaultTokenSource(ctx, compute.CloudPlatformScope)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building token source: %v", err)
|
||||
}
|
||||
|
@ -357,9 +351,9 @@ func (c *gceCloudImplementation) getTokenInfo(client *http.Client) (*oauth2.Toke
|
|||
|
||||
// Note: do not log token or any portion of it
|
||||
|
||||
service, err := oauth2.New(client)
|
||||
service, err := oauth2.NewService(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating oauth2 service client: %v", err)
|
||||
return nil, fmt.Errorf("error creating oauth2 service: %v", err)
|
||||
}
|
||||
|
||||
tokenInfo, err := service.Tokeninfo().AccessToken(token.AccessToken).Do()
|
||||
|
|
|
@ -44,8 +44,8 @@ go_library(
|
|||
"//vendor/github.com/pkg/sftp:go_default_library",
|
||||
"//vendor/golang.org/x/crypto/ssh:go_default_library",
|
||||
"//vendor/golang.org/x/net/context:go_default_library",
|
||||
"//vendor/golang.org/x/oauth2/google:go_default_library",
|
||||
"//vendor/google.golang.org/api/googleapi:go_default_library",
|
||||
"//vendor/google.golang.org/api/option:go_default_library",
|
||||
"//vendor/google.golang.org/api/storage/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/homedir:go_default_library",
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"github.com/denverdino/aliyungo/oss"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/oauth2/google"
|
||||
"google.golang.org/api/option"
|
||||
storage "google.golang.org/api/storage/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/klog"
|
||||
|
@ -361,12 +361,8 @@ func (c *VFSContext) getGCSClient() (*storage.Service, error) {
|
|||
// TODO: Should we fall back to read-only?
|
||||
scope := storage.DevstorageReadWriteScope
|
||||
|
||||
httpClient, err := google.DefaultClient(context.Background(), scope)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building GCS HTTP client: %v", err)
|
||||
}
|
||||
|
||||
gcsClient, err := storage.New(httpClient)
|
||||
ctx := context.Background()
|
||||
gcsClient, err := storage.NewService(ctx, option.WithScopes(scope))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building GCS client: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue