Skip to content

Commit

Permalink
add unittests for linodevpc_controller (#284)
Browse files Browse the repository at this point in the history
* add unittests for vpc_controller

* rebase and fix lint errors

---------

Co-authored-by: Rahul Sharma <[email protected]>
  • Loading branch information
rahulait and rahulait authored Apr 30, 2024
1 parent 182c7f9 commit 8a3977d
Show file tree
Hide file tree
Showing 5 changed files with 475 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type LinodeInstanceClient interface {
// LinodeVPCClient defines the methods that a Linode client must have to interact with Linode's VPC service.
type LinodeVPCClient interface {
GetVPC(ctx context.Context, vpcID int) (*linodego.VPC, error)
ListVPCs(ctx context.Context, opts *linodego.ListOptions) ([]linodego.VPC, error)
CreateVPC(ctx context.Context, opts linodego.VPCCreateOptions) (*linodego.VPC, error)
DeleteVPC(ctx context.Context, vpcID int) error
}

// LinodeNodeBalancerClient defines the methods that a Linode client must have to interact with Linode's Node Balancer service.
Expand Down
7 changes: 3 additions & 4 deletions cloud/scope/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"

"github.com/linode/linodego"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand All @@ -30,10 +29,10 @@ import (

// VPCScope defines the basic context for an actuator to operate upon.
type VPCScope struct {
client K8sClient
Client K8sClient

PatchHelper *patch.Helper
LinodeClient *linodego.Client
LinodeClient LinodeVPCClient
LinodeVPC *infrav1alpha1.LinodeVPC
}

Expand Down Expand Up @@ -77,7 +76,7 @@ func NewVPCScope(ctx context.Context, apiKey string, params VPCScopeParams) (*VP
}

return &VPCScope{
client: params.Client,
Client: params.Client,
LinodeClient: linodeClient,
LinodeVPC: params.LinodeVPC,
PatchHelper: helper,
Expand Down
8 changes: 4 additions & 4 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func (r *LinodeVPCReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, fmt.Errorf("failed to create VPC scope: %w", err)
}

return r.reconcile(ctx, vpcScope, log)
return r.reconcile(ctx, log, vpcScope)
}

func (r *LinodeVPCReconciler) reconcile(
ctx context.Context,
vpcScope *scope.VPCScope,
logger logr.Logger,
vpcScope *scope.VPCScope,
) (res ctrl.Result, err error) {
res = ctrl.Result{}

Expand Down Expand Up @@ -167,12 +167,12 @@ func (r *LinodeVPCReconciler) reconcile(
// Create
failureReason = infrav1alpha1.CreateVPCError

err = r.reconcileCreate(ctx, vpcScope, logger)
err = r.reconcileCreate(ctx, logger, vpcScope)

return
}

func (r *LinodeVPCReconciler) reconcileCreate(ctx context.Context, vpcScope *scope.VPCScope, logger logr.Logger) error {
func (r *LinodeVPCReconciler) reconcileCreate(ctx context.Context, logger logr.Logger, vpcScope *scope.VPCScope) error {
logger.Info("creating vpc")

if err := r.reconcileVPC(ctx, vpcScope, logger); err != nil {
Expand Down
Loading

0 comments on commit 8a3977d

Please sign in to comment.