Skip to content

Commit fcd3f5e

Browse files
committed
Revert "CORS-3906: Update MAPI GCP Provider to use custom GCP endpoints"
This reverts commit 17d99d9.
1 parent 3223f4c commit fcd3f5e

File tree

12 files changed

+17
-127
lines changed

12 files changed

+17
-127
lines changed

cmd/manager/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func main() {
9090

9191
// Sets up feature gates
9292
defaultMutableGate := feature.DefaultMutableFeatureGate
93-
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateMachineAPIMigration, apifeatures.FeatureGateGCPCustomAPIEndpoints)
93+
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateMachineAPIMigration)
9494
if err != nil {
9595
klog.Fatalf("Error setting up feature gates: %v", err)
9696
}
@@ -181,9 +181,8 @@ func main() {
181181
ctrl.SetLogger(klogr.New())
182182
setupLog := ctrl.Log.WithName("setup")
183183
if err = (&machinesetcontroller.Reconciler{
184-
Client: mgr.GetClient(),
185-
Log: ctrl.Log.WithName("controllers").WithName("MachineSet"),
186-
FeatureGates: defaultMutableGate,
184+
Client: mgr.GetClient(),
185+
Log: ctrl.Log.WithName("controllers").WithName("MachineSet"),
187186
}).SetupWithManager(mgr, controller.Options{}); err != nil {
188187
setupLog.Error(err, "unable to create controller", "controller", "MachineSet")
189188
os.Exit(1)

pkg/cloud/gcp/actuators/machine/actuator.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
machinev1 "github.com/openshift/api/machine/v1beta1"
1111
computeservice "github.com/openshift/machine-api-provider-gcp/pkg/cloud/gcp/actuators/services/compute"
1212
tagservice "github.com/openshift/machine-api-provider-gcp/pkg/cloud/gcp/actuators/services/tags"
13-
"github.com/openshift/machine-api-provider-gcp/pkg/cloud/gcp/actuators/util"
1413
corev1 "k8s.io/api/core/v1"
1514
"k8s.io/client-go/tools/record"
1615
"k8s.io/component-base/featuregate"
@@ -35,7 +34,6 @@ type Actuator struct {
3534
computeClientBuilder computeservice.BuilderFuncType
3635
tagsClientBuilder tagservice.BuilderFuncType
3736
featureGates featuregate.FeatureGate
38-
endpointLookup util.EndpointLookupFuncType
3937
}
4038

4139
// ActuatorParams holds parameter information for Actuator.
@@ -45,7 +43,6 @@ type ActuatorParams struct {
4543
ComputeClientBuilder computeservice.BuilderFuncType
4644
TagsClientBuilder tagservice.BuilderFuncType
4745
FeatureGates featuregate.FeatureGate
48-
EndpointLookup util.EndpointLookupFuncType
4946
}
5047

5148
// NewActuator returns an actuator.
@@ -56,7 +53,6 @@ func NewActuator(params ActuatorParams) *Actuator {
5653
computeClientBuilder: params.ComputeClientBuilder,
5754
tagsClientBuilder: params.TagsClientBuilder,
5855
featureGates: params.FeatureGates,
59-
endpointLookup: params.EndpointLookup,
6056
}
6157
}
6258

@@ -80,7 +76,6 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error
8076
computeClientBuilder: a.computeClientBuilder,
8177
tagsClientBuilder: a.tagsClientBuilder,
8278
featureGates: a.featureGates,
83-
endpointLookup: a.endpointLookup,
8479
})
8580
if err != nil {
8681
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
@@ -105,7 +100,6 @@ func (a *Actuator) Exists(ctx context.Context, machine *machinev1.Machine) (bool
105100
computeClientBuilder: a.computeClientBuilder,
106101
tagsClientBuilder: a.tagsClientBuilder,
107102
featureGates: a.featureGates,
108-
endpointLookup: a.endpointLookup,
109103
})
110104
if err != nil {
111105
return false, fmt.Errorf(scopeFailFmt, machine.Name, err)
@@ -147,7 +141,6 @@ func (a *Actuator) Update(ctx context.Context, machine *machinev1.Machine) error
147141
computeClientBuilder: a.computeClientBuilder,
148142
tagsClientBuilder: a.tagsClientBuilder,
149143
featureGates: a.featureGates,
150-
endpointLookup: a.endpointLookup,
151144
})
152145
if err != nil {
153146
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
@@ -185,7 +178,6 @@ func (a *Actuator) Delete(ctx context.Context, machine *machinev1.Machine) error
185178
computeClientBuilder: a.computeClientBuilder,
186179
tagsClientBuilder: a.tagsClientBuilder,
187180
featureGates: a.featureGates,
188-
endpointLookup: a.endpointLookup,
189181
})
190182
if err != nil {
191183
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)

pkg/cloud/gcp/actuators/machine/actuator_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ func TestActuatorEvents(t *testing.T) {
320320
ComputeClientBuilder: computeservice.MockBuilderFuncType,
321321
TagsClientBuilder: tagservice.NewMockTagServiceBuilder,
322322
FeatureGates: gate,
323-
EndpointLookup: util.MockGCPEndpointLookup,
324323
}
325324

326325
actuator := NewActuator(params)
@@ -425,7 +424,6 @@ func TestActuatorExists(t *testing.T) {
425424
ComputeClientBuilder: computeservice.MockBuilderFuncType,
426425
TagsClientBuilder: tagservice.NewMockTagServiceBuilder,
427426
FeatureGates: gate,
428-
EndpointLookup: util.MockGCPEndpointLookup,
429427
}
430428

431429
actuator := NewActuator(params)
@@ -448,7 +446,7 @@ func TestActuatorExists(t *testing.T) {
448446

449447
func NewDefaultMutableFeatureGate(gateConfig map[string]bool) (featuregate.MutableFeatureGate, error) {
450448
defaultMutableGate := feature.DefaultMutableFeatureGate
451-
_, err := features.NewFeatureGateOptions(defaultMutableGate, openshiftfeatures.SelfManaged, openshiftfeatures.FeatureGateMachineAPIMigration, openshiftfeatures.FeatureGateGCPCustomAPIEndpoints)
449+
_, err := features.NewFeatureGateOptions(defaultMutableGate, openshiftfeatures.SelfManaged, openshiftfeatures.FeatureGateMachineAPIMigration)
452450
if err != nil {
453451
return nil, fmt.Errorf("failed to set up default feature gate: %w", err)
454452
}

pkg/cloud/gcp/actuators/machine/machine_scope.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
configv1 "github.com/openshift/api/config/v1"
8-
apifeatures "github.com/openshift/api/features"
97
machinev1 "github.com/openshift/api/machine/v1beta1"
108
machineapierros "github.com/openshift/machine-api-operator/pkg/controller/machine"
119
computeservice "github.com/openshift/machine-api-provider-gcp/pkg/cloud/gcp/actuators/services/compute"
@@ -28,7 +26,6 @@ type machineScopeParams struct {
2826
computeClientBuilder computeservice.BuilderFuncType
2927
tagsClientBuilder tagservice.BuilderFuncType
3028
featureGates featuregate.FeatureGate
31-
endpointLookup util.EndpointLookupFuncType
3229
}
3330

3431
// machineScope defines a scope defined around a machine and its cluster.
@@ -88,31 +85,12 @@ func newMachineScope(params machineScopeParams) (*machineScope, error) {
8885
}
8986
}
9087

91-
var computeEndpoint *configv1.GCPServiceEndpoint = nil
92-
var tagsEndpoint *configv1.GCPServiceEndpoint = nil
93-
if params.featureGates.Enabled(featuregate.Feature(apifeatures.FeatureGateGCPCustomAPIEndpoints)) {
94-
lookupFunc := params.endpointLookup
95-
if lookupFunc == nil {
96-
lookupFunc = util.GetGCPServiceEndpoint
97-
}
98-
99-
computeEndpoint, err = lookupFunc(params.coreClient, configv1.GCPServiceEndpointNameCompute)
100-
if err != nil {
101-
return nil, machineapierros.InvalidMachineConfiguration("error getting compute service endpoint: %v", err)
102-
}
103-
104-
tagsEndpoint, err = lookupFunc(params.coreClient, "TagManager")
105-
if err != nil {
106-
return nil, machineapierros.InvalidMachineConfiguration("error getting tag manager service endpoint: %v", err)
107-
}
108-
}
109-
110-
computeService, err := params.computeClientBuilder(serviceAccountJSON, computeEndpoint)
88+
computeService, err := params.computeClientBuilder(serviceAccountJSON)
11189
if err != nil {
11290
return nil, machineapierros.InvalidMachineConfiguration("error creating compute service: %v", err)
11391
}
11492

115-
tagService, err := params.tagsClientBuilder(params.Context, serviceAccountJSON, tagsEndpoint)
93+
tagService, err := params.tagsClientBuilder(params.Context, serviceAccountJSON)
11694
if err != nil {
11795
return nil, machineapierros.InvalidMachineConfiguration("error creating tag service: %v", err)
11896
}

pkg/cloud/gcp/actuators/machine/machine_scope_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestNewMachineScope(t *testing.T) {
192192
name: "fail to create compute service",
193193
params: machineScopeParams{
194194
coreClient: fakeClient,
195-
computeClientBuilder: func(serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (computeservice.GCPComputeService, error) {
195+
computeClientBuilder: func(serviceAccountJSON string) (computeservice.GCPComputeService, error) {
196196
return nil, errors.New("test error")
197197
},
198198
machine: &machinev1.Machine{
@@ -221,7 +221,6 @@ func TestNewMachineScope(t *testing.T) {
221221
gate, err := NewDefaultMutableFeatureGate(nil)
222222
gs.Expect(err).To(Not(HaveOccurred()))
223223
tc.params.featureGates = gate
224-
tc.params.endpointLookup = util.MockGCPEndpointLookup
225224

226225
scope, err := newMachineScope(tc.params)
227226

@@ -427,7 +426,6 @@ func TestPatchMachine(t *testing.T) {
427426
computeClientBuilder: computeservice.MockBuilderFuncType,
428427
tagsClientBuilder: tagservice.NewMockTagServiceBuilder,
429428
featureGates: gate,
430-
endpointLookup: util.MockGCPEndpointLookup,
431429
})
432430

433431
gs.Expect(err).ToNot(HaveOccurred())

pkg/cloud/gcp/actuators/machineset/controller.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"github.com/openshift/machine-api-provider-gcp/pkg/cloud/gcp/actuators/util"
2222

2323
"github.com/go-logr/logr"
24-
configv1 "github.com/openshift/api/config/v1"
25-
apifeatures "github.com/openshift/api/features"
2624
machinev1 "github.com/openshift/api/machine/v1beta1"
2725
mapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine"
2826
mapiutil "github.com/openshift/machine-api-operator/pkg/util"
@@ -31,7 +29,6 @@ import (
3129
apierrors "k8s.io/apimachinery/pkg/api/errors"
3230
"k8s.io/apimachinery/pkg/runtime"
3331
"k8s.io/client-go/tools/record"
34-
"k8s.io/component-base/featuregate"
3532
ctrl "sigs.k8s.io/controller-runtime"
3633
"sigs.k8s.io/controller-runtime/pkg/client"
3734
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -56,8 +53,6 @@ type Reconciler struct {
5653
scheme *runtime.Scheme
5754
cache *machineTypesCache
5855

59-
FeatureGates featuregate.FeatureGate
60-
6156
// Allow a mock GCPComputeService to be injected during testing
6257
getGCPService func(namespace string, providerConfig machinev1.GCPMachineProviderSpec) (computeservice.GCPComputeService, error)
6358
}
@@ -220,15 +215,7 @@ func (r *Reconciler) getRealGCPService(namespace string, providerConfig machinev
220215
return nil, err
221216
}
222217

223-
var endpoint *configv1.GCPServiceEndpoint = nil
224-
if r.FeatureGates.Enabled(featuregate.Feature(apifeatures.FeatureGateGCPCustomAPIEndpoints)) {
225-
endpoint, err = util.GetGCPServiceEndpoint(r.Client, configv1.GCPServiceEndpointNameCompute)
226-
if err != nil {
227-
return nil, fmt.Errorf("failed to get GCP compute service endpoint: %v", err)
228-
}
229-
}
230-
231-
computeService, err := computeservice.NewComputeService(serviceAccountJSON, endpoint)
218+
computeService, err := computeservice.NewComputeService(serviceAccountJSON)
232219
if err != nil {
233220
return nil, mapierrors.InvalidMachineConfiguration("error creating compute service: %v", err)
234221
}

pkg/cloud/gcp/actuators/services/compute/computeservice.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"golang.org/x/oauth2/google"
99
"google.golang.org/api/option"
1010

11-
configv1 "github.com/openshift/api/config/v1"
1211
"github.com/openshift/machine-api-provider-gcp/pkg/version"
1312
"google.golang.org/api/compute/v1"
1413
)
@@ -45,25 +44,18 @@ type computeService struct {
4544
}
4645

4746
// BuilderFuncType is function type for building gcp client
48-
type BuilderFuncType func(serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (GCPComputeService, error)
47+
type BuilderFuncType func(serviceAccountJSON string) (GCPComputeService, error)
4948

5049
// NewComputeService return a new computeService
51-
func NewComputeService(serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (GCPComputeService, error) {
50+
func NewComputeService(serviceAccountJSON string) (GCPComputeService, error) {
5251
ctx := context.TODO()
5352

5453
creds, err := google.CredentialsFromJSON(ctx, []byte(serviceAccountJSON), compute.CloudPlatformScope)
5554
if err != nil {
5655
return nil, err
5756
}
5857

59-
options := []option.ClientOption{
60-
option.WithCredentials(creds),
61-
}
62-
if endpoint != nil && endpoint.URL != "" {
63-
options = append(options, option.WithEndpoint(endpoint.URL))
64-
}
65-
66-
service, err := compute.NewService(ctx, options...)
58+
service, err := compute.NewService(ctx, option.WithCredentials(creds))
6759
if err != nil {
6860
return nil, err
6961
}

pkg/cloud/gcp/actuators/services/compute/computeservice_mock.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77

88
compute "google.golang.org/api/compute/v1"
99
"google.golang.org/api/googleapi"
10-
11-
configv1 "github.com/openshift/api/config/v1"
1210
)
1311

1412
const (
@@ -136,12 +134,12 @@ func NewComputeServiceMock() (*compute.Instance, *GCPComputeServiceMock) {
136134
return &receivedInstance, &computeServiceMock
137135
}
138136

139-
func MockBuilderFuncType(serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (GCPComputeService, error) {
137+
func MockBuilderFuncType(serviceAccountJSON string) (GCPComputeService, error) {
140138
_, computeSvc := NewComputeServiceMock()
141139
return computeSvc, nil
142140
}
143141

144-
func MockBuilderFuncTypeNotFound(serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (GCPComputeService, error) {
142+
func MockBuilderFuncTypeNotFound(serviceAccountJSON string) (GCPComputeService, error) {
145143
_, computeSvc := NewComputeServiceMock()
146144
computeSvc.mockInstancesGet = func(project string, zone string, instance string) (*compute.Instance, error) {
147145
return nil, &googleapi.Error{

pkg/cloud/gcp/actuators/services/tags/tagservice.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
configv1 "github.com/openshift/api/config/v1"
8-
97
tags "google.golang.org/api/cloudresourcemanager/v3"
108
"google.golang.org/api/option"
119
)
@@ -22,18 +20,11 @@ type tagService struct {
2220
}
2321

2422
// BuilderFuncType is function type for building GCP tag client.
25-
type BuilderFuncType func(ctx context.Context, serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (TagService, error)
23+
type BuilderFuncType func(ctx context.Context, serviceAccountJSON string) (TagService, error)
2624

2725
// NewTagService return a new tagService.
28-
func NewTagService(ctx context.Context, serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (TagService, error) {
29-
options := []option.ClientOption{
30-
option.WithCredentialsJSON([]byte(serviceAccountJSON)),
31-
}
32-
if endpoint != nil && endpoint.URL != "" {
33-
options = append(options, option.WithEndpoint(endpoint.URL))
34-
}
35-
36-
service, err := tags.NewService(ctx, options...)
26+
func NewTagService(ctx context.Context, serviceAccountJSON string) (TagService, error) {
27+
service, err := tags.NewService(ctx, option.WithCredentialsJSON([]byte(serviceAccountJSON)))
3728
if err != nil {
3829
return nil, fmt.Errorf("could not create new tag service: %w", err)
3930
}

pkg/cloud/gcp/actuators/services/tags/tagservice_mock.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55

66
tags "google.golang.org/api/cloudresourcemanager/v3"
7-
8-
configv1 "github.com/openshift/api/config/v1"
97
)
108

119
// MockTagService mocks TagService interface for tests.
@@ -19,7 +17,7 @@ func NewMockTagService() *MockTagService {
1917
}
2018

2119
// NewMockTagServiceBuilder returns new mock for creating GCP tag client.
22-
func NewMockTagServiceBuilder(ctx context.Context, serviceAccountJSON string, endpoint *configv1.GCPServiceEndpoint) (TagService, error) {
20+
func NewMockTagServiceBuilder(ctx context.Context, serviceAccountJSON string) (TagService, error) {
2321
return NewMockTagService(), nil
2422
}
2523

0 commit comments

Comments
 (0)