Skip to content

Commit

Permalink
add unittests for vpc_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Apr 24, 2024
1 parent 02ed313 commit 346a4e6
Show file tree
Hide file tree
Showing 6 changed files with 474 additions and 9 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
2 changes: 1 addition & 1 deletion cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewClusterScope(ctx context.Context, apiKey string, params ClusterScopePara
type ClusterScope struct {
client k8sClient
PatchHelper *patch.Helper
LinodeClient LinodeNodeBalancerClient
LinodeClient LinodeMachineClient
Cluster *clusterv1.Cluster
LinodeCluster *infrav1alpha1.LinodeCluster
}
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)

Check warning on line 103 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L103

Added line #L103 was not covered by tests
}

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)

Check warning on line 170 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L170

Added line #L170 was not covered by tests

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 346a4e6

Please sign in to comment.