Skip to content

Commit 90af048

Browse files
committed
fix: Adjust impersonateServiceAccount structure to match other providers
1 parent 344811c commit 90af048

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

package/crds/kubernetes.crossplane.io_providerconfigs.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ spec:
141141
description: |-
142142
ImpersonateServiceAccount is the email address of the Google Service Account to impersonate.
143143
This is only valid when the identity type is GoogleApplicationCredentials.
144-
type: string
144+
properties:
145+
name:
146+
description: Name of the service account to impersonate.
147+
type: string
148+
required:
149+
- name
150+
type: object
145151
secretRef:
146152
description: |-
147153
A SecretRef is a reference to a secret key that contains the credentials

pkg/kube/client/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,13 @@ func (b *IdentityAwareBuilder) restForProviderConfig(ctx context.Context, pc kco
114114
if id := pc.Identity; id != nil {
115115
switch id.Type {
116116
case kconfig.IdentityTypeGoogleApplicationCredentials:
117+
impersonateSA := ""
118+
if id.ImpersonateServiceAccount != nil {
119+
impersonateSA = id.ImpersonateServiceAccount.Name
120+
}
117121
switch id.Source { //nolint:exhaustive
118122
case xpv1.CredentialsSourceInjectedIdentity:
119-
if err := gke.WrapRESTConfig(ctx, rc, nil, id.ImpersonateServiceAccount, gke.DefaultScopes...); err != nil {
123+
if err := gke.WrapRESTConfig(ctx, rc, nil, impersonateSA, gke.DefaultScopes...); err != nil {
120124
return nil, errors.Wrap(err, errInjectGoogleCredentials)
121125
}
122126
default:
@@ -125,7 +129,7 @@ func (b *IdentityAwareBuilder) restForProviderConfig(ctx context.Context, pc kco
125129
return nil, errors.Wrap(err, errExtractGoogleCredentials)
126130
}
127131

128-
if err := gke.WrapRESTConfig(ctx, rc, creds, id.ImpersonateServiceAccount, gke.DefaultScopes...); err != nil {
132+
if err := gke.WrapRESTConfig(ctx, rc, creds, impersonateSA, gke.DefaultScopes...); err != nil {
129133
return nil, errors.Wrap(err, errInjectGoogleCredentials)
130134
}
131135
}

pkg/kube/config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ type Identity struct {
5353
// ImpersonateServiceAccount is the email address of the Google Service Account to impersonate.
5454
// This is only valid when the identity type is GoogleApplicationCredentials.
5555
// +optional
56-
ImpersonateServiceAccount string `json:"impersonateServiceAccount,omitempty"`
56+
ImpersonateServiceAccount *ImpersonateServiceAccountConfig `json:"impersonateServiceAccount,omitempty"`
5757

5858
ProviderCredentials `json:",inline"`
5959
}
6060

61+
// ImpersonateServiceAccountConfig contains the configuration for impersonating a service account.
62+
type ImpersonateServiceAccountConfig struct {
63+
// Name of the service account to impersonate.
64+
Name string `json:"name"`
65+
}
66+
6167
// A ProviderConfigSpec defines the desired state of a ProviderConfig.
6268
type ProviderConfigSpec struct {
6369
// Credentials used to connect to the Kubernetes API. Typically a

0 commit comments

Comments
 (0)