Skip to content

Commit

Permalink
changed interface
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Apr 22, 2024
1 parent 6d0c50e commit 28734e5
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 43 deletions.
1 change: 1 addition & 0 deletions cloud/services/compute/firewalls/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"

"sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down
10 changes: 6 additions & 4 deletions cloud/services/compute/firewalls/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ package firewalls
import (
"context"

k8scloud "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud"
)

type firewallsInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.Firewall, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Firewall) error
Update(ctx context.Context, key *meta.Key, obj *compute.Firewall) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.Firewall, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Firewall, options ...k8scloud.Option) error
Update(ctx context.Context, key *meta.Key, obj *compute.Firewall, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

// Scope is an interfaces that hold used methods.
Expand Down
5 changes: 4 additions & 1 deletion cloud/services/compute/instances/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ import (
"context"
"fmt"

"github.com/pkg/errors"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"github.com/pkg/errors"
"google.golang.org/api/compute/v1"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down
4 changes: 3 additions & 1 deletion cloud/services/compute/instances/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"

infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -211,7 +213,7 @@ func TestService_createOrGetInstance(t *testing.T) {
mockInstance: &cloud.MockInstances{
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
Objects: map[meta.Key]*cloud.MockInstancesObj{},
GetHook: func(_ context.Context, _ *meta.Key, _ *cloud.MockInstances) (bool, *compute.Instance, error) {
GetHook: func(_ context.Context, _ *meta.Key, _ *cloud.MockInstances, _ ...cloud.Option) (bool, *compute.Instance, error) {
return true, &compute.Instance{}, &googleapi.Error{Code: http.StatusBadRequest}
},
},
Expand Down
14 changes: 8 additions & 6 deletions cloud/services/compute/instances/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ import (

"github.com/go-logr/logr"

k8scloud "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud"
)

type instancesInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.Instance, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Instance) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.Instance, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Instance, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type instancegroupsInterface interface {
AddInstances(ctx context.Context, key *meta.Key, req *compute.InstanceGroupsAddInstancesRequest) error
ListInstances(ctx context.Context, key *meta.Key, req *compute.InstanceGroupsListInstancesRequest, fl *filter.F) ([]*compute.InstanceWithNamedPorts, error)
RemoveInstances(ctx context.Context, key *meta.Key, req *compute.InstanceGroupsRemoveInstancesRequest) error
AddInstances(ctx context.Context, key *meta.Key, req *compute.InstanceGroupsAddInstancesRequest, options ...k8scloud.Option) error
ListInstances(ctx context.Context, key *meta.Key, req *compute.InstanceGroupsListInstancesRequest, fl *filter.F, options ...k8scloud.Option) ([]*compute.InstanceWithNamedPorts, error)
RemoveInstances(ctx context.Context, key *meta.Key, req *compute.InstanceGroupsRemoveInstancesRequest, options ...k8scloud.Option) error
}

// Scope is an interfaces that hold used methods.
Expand Down
1 change: 1 addition & 0 deletions cloud/services/compute/loadbalancers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"k8s.io/utils/ptr"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down
2 changes: 1 addition & 1 deletion cloud/services/compute/loadbalancers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestService_createOrGetInstanceGroup(t *testing.T) {
mockInstanceGroup: &cloud.MockInstanceGroups{
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
Objects: map[meta.Key]*cloud.MockInstanceGroupsObj{},
GetHook: func(_ context.Context, _ *meta.Key, _ *cloud.MockInstanceGroups) (bool, *compute.InstanceGroup, error) {
GetHook: func(_ context.Context, _ *meta.Key, _ *cloud.MockInstanceGroups, _ ...cloud.Option) (bool, *compute.InstanceGroup, error) {
return true, &compute.InstanceGroup{}, &googleapi.Error{Code: http.StatusBadRequest}
},
},
Expand Down
42 changes: 22 additions & 20 deletions cloud/services/compute/loadbalancers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,50 @@ package loadbalancers
import (
"context"

k8scloud "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud"
)

type addressesInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.Address, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Address) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.Address, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Address, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type backendservicesInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.BackendService, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.BackendService) error
Update(context.Context, *meta.Key, *compute.BackendService) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.BackendService, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.BackendService, options ...k8scloud.Option) error
Update(ctx context.Context, key *meta.Key, obj *compute.BackendService, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type forwardingrulesInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.ForwardingRule, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.ForwardingRule) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.ForwardingRule, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.ForwardingRule, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type healthchecksInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.HealthCheck, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.HealthCheck) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.HealthCheck, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.HealthCheck, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type instancegroupsInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.InstanceGroup, error)
List(ctx context.Context, zone string, fl *filter.F) ([]*compute.InstanceGroup, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.InstanceGroup) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.InstanceGroup, error)
List(ctx context.Context, zone string, fl *filter.F, options ...k8scloud.Option) ([]*compute.InstanceGroup, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.InstanceGroup, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type targettcpproxiesInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.TargetTcpProxy, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.TargetTcpProxy) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.TargetTcpProxy, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.TargetTcpProxy, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

// Scope is an interfaces that hold used methods.
Expand Down
2 changes: 2 additions & 0 deletions cloud/services/compute/networks/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"k8s.io/utils/ptr"

infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down
14 changes: 8 additions & 6 deletions cloud/services/compute/networks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ package networks
import (
"context"

k8scloud "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud"
)

type networksInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.Network, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Network) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.Network, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Network, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

type routersInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.Router, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Router) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.Router, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Router, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

// Scope is an interfaces that hold used methods.
Expand Down
1 change: 1 addition & 0 deletions cloud/services/compute/subnets/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down
4 changes: 3 additions & 1 deletion cloud/services/compute/subnets/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"

infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -111,7 +113,7 @@ func TestService_Reconcile(t *testing.T) {
mockSubnetworks: &cloud.MockSubnetworks{
ProjectRouter: &cloud.SingleProjectRouter{ID: "my-proj"},
Objects: map[meta.Key]*cloud.MockSubnetworksObj{},
GetHook: func(_ context.Context, _ *meta.Key, _ *cloud.MockSubnetworks) (bool, *compute.Subnetwork, error) {
GetHook: func(_ context.Context, _ *meta.Key, _ *cloud.MockSubnetworks, _ ...cloud.Option) (bool, *compute.Subnetwork, error) {
return true, &compute.Subnetwork{}, &googleapi.Error{Code: http.StatusBadRequest}
},
},
Expand Down
8 changes: 5 additions & 3 deletions cloud/services/compute/subnets/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ package subnets
import (
"context"

k8scloud "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
"google.golang.org/api/compute/v1"

"sigs.k8s.io/cluster-api-provider-gcp/cloud"
)

type subnetsInterface interface {
Get(ctx context.Context, key *meta.Key) (*compute.Subnetwork, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Subnetwork) error
Delete(ctx context.Context, key *meta.Key) error
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.Subnetwork, error)
Insert(ctx context.Context, key *meta.Key, obj *compute.Subnetwork, options ...k8scloud.Option) error
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
}

// Scope is an interfaces that hold used methods.
Expand Down

0 comments on commit 28734e5

Please sign in to comment.