Skip to content

Commit

Permalink
Merge branch 'main' into doc-obj-buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
bcm820 authored Mar 25, 2024
2 parents 1266eda + dbf9b2c commit 6fe56a7
Show file tree
Hide file tree
Showing 7 changed files with 1,637 additions and 12 deletions.
42 changes: 39 additions & 3 deletions cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,45 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// LinodeObjectStorageClient defines functions suitable for provisioning object storage buckets and keys.
// LinodeClient is an interface that defines the methods that a Linode client must have to interact with Linode.
// It defines all the functions that are required to create, delete, and get resources
// from Linode such as object storage buckets, node balancers, linodes, and VPCs.
type LinodeMachineClient interface {
LinodeNodeBalancerClient
LinodeInstanceClient
LinodeVPCClient
}

// LinodeInstanceClient defines the methods that a Linode client must have to interact with Linode's Instance service.
type LinodeInstanceClient interface {
GetInstanceIPAddresses(ctx context.Context, linodeID int) (*linodego.InstanceIPAddressResponse, 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
}

// 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)
}

// LinodeNodeBalancerClient defines the methods that a Linode client must have to interact with Linode's Node Balancer service.
type LinodeNodeBalancerClient interface {
ListNodeBalancers(ctx context.Context, opts *linodego.ListOptions) ([]linodego.NodeBalancer, error)
CreateNodeBalancer(ctx context.Context, opts linodego.NodeBalancerCreateOptions) (*linodego.NodeBalancer, error)
CreateNodeBalancerConfig(ctx context.Context, nodebalancerID int, opts linodego.NodeBalancerConfigCreateOptions) (*linodego.NodeBalancerConfig, 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)
}

// LinodeObjectStorageClient defines the methods that a Linode client must have to interact with Linode's Object Storage service.
type LinodeObjectStorageClient interface {
GetObjectStorageBucket(ctx context.Context, cluster, label string) (*linodego.ObjectStorageBucket, error)
CreateObjectStorageBucket(ctx context.Context, opts linodego.ObjectStorageBucketCreateOptions) (*linodego.ObjectStorageBucket, error)
Expand All @@ -16,10 +54,8 @@ type LinodeObjectStorageClient interface {
DeleteObjectStorageKey(ctx context.Context, keyID int) error
}

// LinodeObjectStorageClientBuilder is a function that returns a LinodeObjectStorageClient.
type LinodeObjectStorageClientBuilder func(apiKey string) (LinodeObjectStorageClient, error)

// CreateLinodeObjectStorageClient is the main implementation of LinodeObjectStorageClientBuilder.
func CreateLinodeObjectStorageClient(apiKey string) (LinodeObjectStorageClient, error) {
return CreateLinodeClient(apiKey)
}
Expand Down
3 changes: 1 addition & 2 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"

"github.com/linode/linodego"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -85,7 +84,7 @@ func NewClusterScope(ctx context.Context, apiKey string, params ClusterScopePara
type ClusterScope struct {
client k8sClient
PatchHelper *patch.Helper
LinodeClient *linodego.Client
LinodeClient LinodeNodeBalancerClient
Cluster *clusterv1.Cluster
LinodeCluster *infrav1alpha1.LinodeCluster
}
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 LinodeMachineClient
LinodeCluster *infrav1alpha1.LinodeCluster
LinodeMachine *infrav1alpha1.LinodeMachine
}
Expand Down
7 changes: 3 additions & 4 deletions cloud/services/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func AddNodeToNB(
if !kutil.IsControlPlaneMachine(machineScope.Machine) {
return nil
}

// Get the private IP that was assigned
addresses, err := machineScope.LinodeClient.GetInstanceIPAddresses(ctx, *machineScope.LinodeMachine.Spec.InstanceID)
if err != nil {
Expand All @@ -132,12 +133,14 @@ 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
}

_, err = machineScope.LinodeClient.CreateNodeBalancerNode(
ctx,
*machineScope.LinodeCluster.Spec.Network.NodeBalancerID,
Expand Down Expand Up @@ -168,10 +171,6 @@ func DeleteNodeFromNB(
return nil
}

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

if machineScope.LinodeCluster.Spec.ControlPlaneEndpoint.Host == "" {
logger.Info("NodeBalancer already deleted, no NodeBalancer backend Node to remove")

Expand Down
Loading

0 comments on commit 6fe56a7

Please sign in to comment.