From 768d69a423a6eace1a39679e9fb7171fa8bb696c Mon Sep 17 00:00:00 2001 From: Paco Xu Date: Fri, 6 Aug 2021 11:25:50 +0800 Subject: [PATCH] add 'projects/' suffix if this library is used with an older version of the google api library Signed-off-by: Paco Xu --- staging/src/k8s.io/legacy-cloud-providers/gce/gce.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go index 67e8ddca74e9..e5a73ddaed6a 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go @@ -435,9 +435,15 @@ func CreateGCECloud(config *CloudConfig) (*Cloud, error) { serviceAlpha.UserAgent = userAgent if config.APIEndpoint != "" { - service.BasePath = config.APIEndpoint - serviceBeta.BasePath = strings.Replace(config.APIEndpoint, "v1", "beta", -1) - serviceAlpha.BasePath = strings.Replace(config.APIEndpoint, "v1", "alpha", -1) + if strings.HasSuffix(service.BasePath, "/projects/") { + service.BasePath = getProjectsBasePath(config.APIEndpoint) + serviceBeta.BasePath = getProjectsBasePath(strings.Replace(config.APIEndpoint, "v1", "beta", -1)) + serviceAlpha.BasePath = getProjectsBasePath(strings.Replace(config.APIEndpoint, "v1", "alpha", -1)) + } else { + service.BasePath = config.APIEndpoint + serviceBeta.BasePath = strings.Replace(config.APIEndpoint, "v1", "beta", -1) + serviceAlpha.BasePath = strings.Replace(config.APIEndpoint, "v1", "alpha", -1) + } } containerService, err := container.NewService(context.Background(), option.WithTokenSource(config.TokenSource))