Skip to content

Commit

Permalink
Completed all the unit test and got max coverage for the file
Browse files Browse the repository at this point in the history
  • Loading branch information
komer3 committed Mar 18, 2024
1 parent 2821ea9 commit 9454411
Show file tree
Hide file tree
Showing 5 changed files with 869 additions and 76 deletions.
14 changes: 13 additions & 1 deletion cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// LinodeClient defines functions suitable for provisioning object storage buckets and keys.
// LinodeClient defines around the LinodeGo Client. It defines all the functions that are required to create, delete, and get resources
// from Linode such as object storage buckets, node balancers, linodes, VPCs, etc.
type LinodeClient interface {
GetObjectStorageBucket(ctx context.Context, cluster, label string) (*linodego.ObjectStorageBucket, error)
CreateObjectStorageBucket(ctx context.Context, opts linodego.ObjectStorageBucketCreateOptions) (*linodego.ObjectStorageBucket, error)
Expand All @@ -19,6 +20,17 @@ type LinodeClient interface {
GetInstanceIPAddresses(ctx context.Context, linodeID int) (*linodego.InstanceIPAddressResponse, error)
DeleteNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, nodeID int) error
DeleteNodeBalancer(ctx context.Context, nodebalancerID int) error
CreateNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, opts linodego.NodeBalancerNodeCreateOptions) (*linodego.NodeBalancerNode, error)
ListInstances(ctx context.Context, opts *linodego.ListOptions) ([]linodego.Instance, error)
CreateInstance(ctx context.Context, opts linodego.InstanceCreateOptions) (*linodego.Instance, error)
BootInstance(ctx context.Context, linodeID int, configID int) error
ListInstanceConfigs(ctx context.Context, linodeID int, opts *linodego.ListOptions) ([]linodego.InstanceConfig, error)
GetInstanceDisk(ctx context.Context, linodeID int, diskID int) (*linodego.InstanceDisk, error)
ResizeInstanceDisk(ctx context.Context, linodeID int, diskID int, size int) error
CreateInstanceDisk(ctx context.Context, linodeID int, opts linodego.InstanceDiskCreateOptions) (*linodego.InstanceDisk, error)
GetInstance(ctx context.Context, linodeID int) (*linodego.Instance, error)
DeleteInstance(ctx context.Context, linodeID int) error
GetVPC(ctx context.Context, vpcID int) (*linodego.VPC, error)
}

// LinodeClientBuilder is a function that returns a LinodeClient.
Expand Down
3 changes: 1 addition & 2 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"

"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -29,7 +28,7 @@ type MachineScope struct {
PatchHelper *patch.Helper
Cluster *clusterv1.Cluster
Machine *clusterv1.Machine
LinodeClient *linodego.Client
LinodeClient LinodeClient
LinodeCluster *infrav1alpha1.LinodeCluster
LinodeMachine *infrav1alpha1.LinodeMachine
}
Expand Down
16 changes: 15 additions & 1 deletion cloud/services/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func AddNodeToNB(
if !kutil.IsControlPlaneMachine(machineScope.Machine) {
return nil
}

if machineScope.LinodeMachine.Spec.InstanceID == nil {
return errors.New("no InstanceID set for LinodeMachine.Spec")
}

// Get the private IP that was assigned
addresses, err := machineScope.LinodeClient.GetInstanceIPAddresses(ctx, *machineScope.LinodeMachine.Spec.InstanceID)
if err != nil {
Expand All @@ -132,12 +137,21 @@ func AddNodeToNB(
if machineScope.LinodeCluster.Spec.Network.LoadBalancerPort != 0 {
lbPort = machineScope.LinodeCluster.Spec.Network.LoadBalancerPort
}

if machineScope.LinodeCluster.Spec.Network.NodeBalancerConfigID == nil {
err := errors.New("nil NodeBalancer Config ID")
logger.Error(err, "config ID for NodeBalancer is nil")

return err
}

if machineScope.LinodeCluster.Spec.Network.NodeBalancerID == nil {
err := errors.New("nil NodeBalancer ID")
logger.Error(err, "NodeBalancer ID is nil")

return err
}

_, err = machineScope.LinodeClient.CreateNodeBalancerNode(
ctx,
*machineScope.LinodeCluster.Spec.Network.NodeBalancerID,
Expand Down Expand Up @@ -169,7 +183,7 @@ func DeleteNodeFromNB(
}

if machineScope.LinodeMachine.Spec.InstanceID == nil {
return errors.New("no InstanceID")
return errors.New("no InstanceID set for LinodeMachine.Spec")
}

if machineScope.LinodeCluster.Spec.ControlPlaneEndpoint.Host == "" {
Expand Down
Loading

0 comments on commit 9454411

Please sign in to comment.