@@ -89,12 +89,16 @@ func defaultClientOptions(ctx context.Context, credentialsRef *infrav1.ObjectRef
89
89
return opts , nil
90
90
}
91
91
92
- func newComputeService (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client ) (* compute.Service , error ) {
92
+ func newComputeService (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client , endpoints * infrav1. ServiceEndpoints ) (* compute.Service , error ) {
93
93
opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
94
94
if err != nil {
95
95
return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
96
96
}
97
97
98
+ if endpoints != nil && endpoints .ComputeServiceEndpoint != "" {
99
+ opts = append (opts , option .WithEndpoint (endpoints .ComputeServiceEndpoint ))
100
+ }
101
+
98
102
computeSvc , err := compute .NewService (ctx , opts ... )
99
103
if err != nil {
100
104
return nil , fmt .Errorf ("creating new compute service instance: %w" , err )
@@ -103,12 +107,16 @@ func newComputeService(ctx context.Context, credentialsRef *infrav1.ObjectRefere
103
107
return computeSvc , nil
104
108
}
105
109
106
- func newClusterManagerClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client ) (* container.ClusterManagerClient , error ) {
110
+ func newClusterManagerClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client , endpoints * infrav1. ServiceEndpoints ) (* container.ClusterManagerClient , error ) {
107
111
opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
108
112
if err != nil {
109
113
return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
110
114
}
111
115
116
+ if endpoints != nil && endpoints .ContainerServiceEndpoint != "" {
117
+ opts = append (opts , option .WithEndpoint (endpoints .ContainerServiceEndpoint ))
118
+ }
119
+
112
120
managedClusterClient , err := container .NewClusterManagerClient (ctx , opts ... )
113
121
if err != nil {
114
122
return nil , errors .Errorf ("failed to create gcp cluster manager client: %v" , err )
@@ -117,12 +125,16 @@ func newClusterManagerClient(ctx context.Context, credentialsRef *infrav1.Object
117
125
return managedClusterClient , nil
118
126
}
119
127
120
- func newIamCredentialsClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client ) (* credentials.IamCredentialsClient , error ) {
128
+ func newIamCredentialsClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client , endpoints * infrav1. ServiceEndpoints ) (* credentials.IamCredentialsClient , error ) {
121
129
opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
122
130
if err != nil {
123
131
return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
124
132
}
125
133
134
+ if endpoints != nil && endpoints .IAMServiceEndpoint != "" {
135
+ opts = append (opts , option .WithEndpoint (endpoints .IAMServiceEndpoint ))
136
+ }
137
+
126
138
credentialsClient , err := credentials .NewIamCredentialsClient (ctx , opts ... )
127
139
if err != nil {
128
140
return nil , errors .Errorf ("failed to create gcp ciam credentials client: %v" , err )
@@ -131,12 +143,16 @@ func newIamCredentialsClient(ctx context.Context, credentialsRef *infrav1.Object
131
143
return credentialsClient , nil
132
144
}
133
145
134
- func newInstanceGroupManagerClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client ) (* computerest.InstanceGroupManagersClient , error ) {
146
+ func newInstanceGroupManagerClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client , endpoints * infrav1. ServiceEndpoints ) (* computerest.InstanceGroupManagersClient , error ) {
135
147
opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
136
148
if err != nil {
137
149
return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
138
150
}
139
151
152
+ if endpoints != nil && endpoints .ComputeServiceEndpoint != "" {
153
+ opts = append (opts , option .WithEndpoint (endpoints .ComputeServiceEndpoint ))
154
+ }
155
+
140
156
instanceGroupManagersClient , err := computerest .NewInstanceGroupManagersRESTClient (ctx , opts ... )
141
157
if err != nil {
142
158
return nil , errors .Errorf ("failed to create gcp instance group managers rest client: %v" , err )
@@ -145,10 +161,16 @@ func newInstanceGroupManagerClient(ctx context.Context, credentialsRef *infrav1.
145
161
return instanceGroupManagersClient , nil
146
162
}
147
163
148
- func newTagBindingsClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client , location string ) (* resourcemanager.TagBindingsClient , error ) {
164
+ func newTagBindingsClient (ctx context.Context , credentialsRef * infrav1.ObjectReference , crClient client.Client , location string , endpoints * infrav1. ServiceEndpoints ) (* resourcemanager.TagBindingsClient , error ) {
149
165
opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
150
- endpoint := location + "-cloudresourcemanager.googleapis.com:443"
151
- opts = append (opts , option .WithEndpoint (endpoint ))
166
+
167
+ if endpoints != nil && endpoints .ResourceManagerServiceEndpoint != "" {
168
+ opts = append (opts , option .WithEndpoint (endpoints .ResourceManagerServiceEndpoint ))
169
+ } else {
170
+ endpoint := location + "-cloudresourcemanager.googleapis.com:443"
171
+ opts = append (opts , option .WithEndpoint (endpoint ))
172
+ }
173
+
152
174
if err != nil {
153
175
return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
154
176
}
0 commit comments