@@ -89,12 +89,16 @@ func defaultClientOptions(ctx context.Context, credentialsRef *infrav1.ObjectRef
8989 return opts , nil
9090}
9191
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 ) {
9393 opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
9494 if err != nil {
9595 return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
9696 }
9797
98+ if endpoints != nil && endpoints .ComputeServiceEndpoint != "" {
99+ opts = append (opts , option .WithEndpoint (endpoints .ComputeServiceEndpoint ))
100+ }
101+
98102 computeSvc , err := compute .NewService (ctx , opts ... )
99103 if err != nil {
100104 return nil , fmt .Errorf ("creating new compute service instance: %w" , err )
@@ -103,12 +107,16 @@ func newComputeService(ctx context.Context, credentialsRef *infrav1.ObjectRefere
103107 return computeSvc , nil
104108}
105109
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 ) {
107111 opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
108112 if err != nil {
109113 return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
110114 }
111115
116+ if endpoints != nil && endpoints .ContainerServiceEndpoint != "" {
117+ opts = append (opts , option .WithEndpoint (endpoints .ContainerServiceEndpoint ))
118+ }
119+
112120 managedClusterClient , err := container .NewClusterManagerClient (ctx , opts ... )
113121 if err != nil {
114122 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
117125 return managedClusterClient , nil
118126}
119127
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 ) {
121129 opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
122130 if err != nil {
123131 return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
124132 }
125133
134+ if endpoints != nil && endpoints .IAMServiceEndpoint != "" {
135+ opts = append (opts , option .WithEndpoint (endpoints .IAMServiceEndpoint ))
136+ }
137+
126138 credentialsClient , err := credentials .NewIamCredentialsClient (ctx , opts ... )
127139 if err != nil {
128140 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
131143 return credentialsClient , nil
132144}
133145
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 ) {
135147 opts , err := defaultClientOptions (ctx , credentialsRef , crClient )
136148 if err != nil {
137149 return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
138150 }
139151
152+ if endpoints != nil && endpoints .ComputeServiceEndpoint != "" {
153+ opts = append (opts , option .WithEndpoint (endpoints .ComputeServiceEndpoint ))
154+ }
155+
140156 instanceGroupManagersClient , err := computerest .NewInstanceGroupManagersRESTClient (ctx , opts ... )
141157 if err != nil {
142158 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.
145161 return instanceGroupManagersClient , nil
146162}
147163
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 ) {
149165 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+
152174 if err != nil {
153175 return nil , fmt .Errorf ("getting default gcp client options: %w" , err )
154176 }
0 commit comments