Skip to content

Commit 1cb204d

Browse files
authored
Merge pull request #1594 from salasberryfin/backport_to_1.11
[release-1.11] bump google client and update gcp client auth
2 parents e5dc6cb + 7bd6d3f commit 1cb204d

7 files changed

Lines changed: 103 additions & 74 deletions

File tree

api/v1beta1/gcpcluster_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type GCPClusterSpec struct {
6262

6363
// CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
6464
// supplied then the credentials of the controller will be used.
65+
// When creating a new GCP client, the controller will try to extract the type
66+
// of credential from the JSON data, and it will request a client for the specific credential type.
6567
// +optional
6668
CredentialsRef *ObjectReference `json:"credentialsRef,omitempty"`
6769

cloud/scope/clients.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scope
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"time"
2324

@@ -43,6 +44,12 @@ type GCPServices struct {
4344
// GCPRateLimiter implements cloud.RateLimiter.
4445
type GCPRateLimiter struct{}
4546

47+
// credentialHeader is a helper struct used for determining the type of
48+
// GCP credentials from JSON data.
49+
type credentialHeader struct {
50+
Type string `json:"type"`
51+
}
52+
4653
// Accept blocks until the operation can be performed.
4754
func (rl *GCPRateLimiter) Accept(ctx context.Context, key *cloud.RateLimitKey) error {
4855
if key.Operation == "Get" && key.Service == "Operations" {
@@ -83,7 +90,22 @@ func defaultClientOptions(ctx context.Context, credentialsRef *infrav1.ObjectRef
8390
if err != nil {
8491
return nil, fmt.Errorf("getting gcp credentials from reference %s: %w", credentialsRef, err)
8592
}
86-
opts = append(opts, option.WithCredentialsJSON(rawData))
93+
94+
header := &credentialHeader{}
95+
if err := json.Unmarshal(rawData, header); err != nil {
96+
return nil, fmt.Errorf("parsing gcp credential type from reference %s: %w", credentialsRef, err)
97+
}
98+
99+
switch header.Type {
100+
case "service_account":
101+
opts = append(opts, option.WithAuthCredentialsJSON(option.ServiceAccount, rawData))
102+
case "external_account":
103+
opts = append(opts, option.WithAuthCredentialsJSON(option.ExternalAccount, rawData))
104+
case "impersonated_service_account":
105+
opts = append(opts, option.WithAuthCredentialsJSON(option.ImpersonatedServiceAccount, rawData))
106+
default:
107+
opts = append(opts, option.WithAuthCredentialsJSON(option.ServiceAccount, rawData))
108+
}
87109
}
88110

89111
return opts, nil

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ spec:
8686
description: |-
8787
CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
8888
supplied then the credentials of the controller will be used.
89+
When creating a new GCP client, the controller will try to extract the type
90+
of credential from the JSON data, and it will request a client for the specific credential type.
8991
properties:
9092
name:
9193
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpclustertemplates.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ spec:
103103
description: |-
104104
CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
105105
supplied then the credentials of the controller will be used.
106+
When creating a new GCP client, the controller will try to extract the type
107+
of credential from the JSON data, and it will request a client for the specific credential type.
106108
properties:
107109
name:
108110
description: |-

controllers/gcpcluster_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"context"
21+
2022
. "github.com/onsi/ginkgo/v2"
2123
. "github.com/onsi/gomega"
22-
"golang.org/x/net/context"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
2526
ctrl "sigs.k8s.io/controller-runtime"

go.mod

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ require (
1818
github.com/pkg/errors v0.9.1
1919
github.com/spf13/pflag v1.0.10
2020
github.com/stretchr/testify v1.11.1
21-
golang.org/x/crypto v0.43.0
22-
golang.org/x/mod v0.29.0
23-
golang.org/x/net v0.45.0
24-
google.golang.org/api v0.252.0
25-
google.golang.org/grpc v1.76.0
21+
golang.org/x/crypto v0.46.0
22+
golang.org/x/mod v0.30.0
23+
google.golang.org/api v0.258.0
24+
google.golang.org/grpc v1.77.0
2625
k8s.io/api v0.33.3
2726
k8s.io/apimachinery v0.33.3
2827
k8s.io/client-go v0.33.3
@@ -41,6 +40,7 @@ require (
4140
go.uber.org/automaxprocs v1.6.0 // indirect
4241
go.yaml.in/yaml/v2 v2.4.2 // indirect
4342
go.yaml.in/yaml/v3 v3.0.4 // indirect
43+
golang.org/x/net v0.48.0 // indirect
4444
sigs.k8s.io/randfill v1.0.0 // indirect
4545
)
4646

@@ -94,7 +94,7 @@ require (
9494
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
9595
github.com/google/s2a-go v0.1.9 // indirect
9696
github.com/google/uuid v1.6.0 // indirect
97-
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
97+
github.com/googleapis/enterprise-certificate-proxy v0.3.7 // indirect
9898
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
9999
github.com/inconshreveable/mousetrap v1.1.0 // indirect
100100
github.com/josharian/intern v1.0.0 // indirect
@@ -128,31 +128,31 @@ require (
128128
github.com/stoewer/go-strcase v1.3.0 // indirect
129129
github.com/subosito/gotenv v1.6.0 // indirect
130130
github.com/x448/float16 v0.8.4 // indirect
131-
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
131+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
132132
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
133133
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
134-
go.opentelemetry.io/otel v1.37.0 // indirect
134+
go.opentelemetry.io/otel v1.38.0 // indirect
135135
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
136136
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect
137-
go.opentelemetry.io/otel/metric v1.37.0 // indirect
138-
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
139-
go.opentelemetry.io/otel/trace v1.37.0 // indirect
137+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
138+
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
139+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
140140
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
141141
go.uber.org/multierr v1.11.0 // indirect
142142
go.uber.org/zap v1.27.0 // indirect; indirect// indirect
143143
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
144-
golang.org/x/oauth2 v0.31.0 // indirect
145-
golang.org/x/sync v0.17.0 // indirect
146-
golang.org/x/sys v0.37.0 // indirect
147-
golang.org/x/term v0.36.0 // indirect
148-
golang.org/x/text v0.30.0 // indirect
149-
golang.org/x/time v0.13.0 // indirect
150-
golang.org/x/tools v0.37.0 // indirect
144+
golang.org/x/oauth2 v0.34.0 // indirect
145+
golang.org/x/sync v0.19.0 // indirect
146+
golang.org/x/sys v0.39.0 // indirect
147+
golang.org/x/term v0.38.0 // indirect
148+
golang.org/x/text v0.32.0 // indirect
149+
golang.org/x/time v0.14.0 // indirect
150+
golang.org/x/tools v0.39.0 // indirect
151151
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
152152
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
153-
google.golang.org/genproto/googleapis/api v0.0.0-20250818200422-3122310a409c // indirect
154-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251002232023-7c0ddcbb5797 // indirect
155-
google.golang.org/protobuf v1.36.10 // indirect
153+
google.golang.org/genproto/googleapis/api v0.0.0-20251022142026-3a174f9686a8 // indirect
154+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251213004720-97cd9d5aeac2 // indirect
155+
google.golang.org/protobuf v1.36.11 // indirect
156156
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
157157
gopkg.in/inf.v0 v0.9.1 // indirect
158158
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)