Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hcloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var providerVersion = "unknown"

type cloud struct {
client *hcloud.Client
robotClient robot.Client
robotClient hrobot.RobotClient
cfg config.HCCMConfiguration
recorder record.EventRecorder
networkID int64
Expand Down Expand Up @@ -95,7 +95,7 @@ func NewCloud(cidr string) (cloudprovider.Interface, error) {
client := hcloud.NewClient(opts...)
metadataClient := metadata.NewClient()

var robotClient robot.Client
var robotClient hrobot.RobotClient
if cfg.Robot.Enabled && cfg.Robot.User != "" && cfg.Robot.Password != "" {
c := hrobot.NewBasicAuthClientWithCustomHttpClient(
cfg.Robot.User,
Expand Down
8 changes: 4 additions & 4 deletions hcloud/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net"

hrobot "github.com/syself/hrobot-go"
hrobotmodels "github.com/syself/hrobot-go/models"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/legacydatacenter"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/metrics"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/providerid"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/robot"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand All @@ -43,7 +43,7 @@ const (

type instances struct {
client *hcloud.Client
robotClient robot.Client
robotClient hrobot.RobotClient
recorder record.EventRecorder
networkID int64
cfg config.HCCMConfiguration
Expand All @@ -56,7 +56,7 @@ var (

func newInstances(
client *hcloud.Client,
robotClient robot.Client,
robotClient hrobot.RobotClient,
recorder record.EventRecorder,
networkID int64,
cfg config.HCCMConfiguration,
Expand Down Expand Up @@ -359,7 +359,7 @@ func (s hcloudServer) Metadata(networkID int64, _ *corev1.Node, cfg config.HCCMC

type robotServer struct {
*hrobotmodels.Server
robotClient robot.Client
robotClient hrobot.RobotClient
recorder record.EventRecorder
}

Expand Down
4 changes: 2 additions & 2 deletions hcloud/instances_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"regexp"
"strings"

hrobot "github.com/syself/hrobot-go"
hrobotmodels "github.com/syself/hrobot-go/models"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/metrics"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/robot"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func getCloudServerByID(ctx context.Context, c *hcloud.Client, id int64) (*hclou
return server, nil
}

func getRobotServerByName(c robot.Client, node *corev1.Node) (server *hrobotmodels.Server, err error) {
func getRobotServerByName(c hrobot.RobotClient, node *corev1.Node) (server *hrobotmodels.Server, err error) {
const op = "hcloud/getRobotServerByName"

if c == nil {
Expand Down
11 changes: 0 additions & 11 deletions internal/hcops/action.go

This file was deleted.

14 changes: 2 additions & 12 deletions internal/hcops/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@ import (
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// HCloudCertificateClient defines the hcloud-go function related to
// certificate management.
type HCloudCertificateClient interface {
AllWithOpts(context.Context, hcloud.CertificateListOpts) ([]*hcloud.Certificate, error)
Get(ctx context.Context, idOrName string) (*hcloud.Certificate, *hcloud.Response, error)
CreateCertificate(
ctx context.Context, opts hcloud.CertificateCreateOpts,
) (hcloud.CertificateCreateResult, *hcloud.Response, error)
}

// CertificateOps implements all operations regarding Hetzner Cloud Certificates.
type CertificateOps struct {
ActionClient HCloudActionClient
CertClient HCloudCertificateClient
ActionClient hcloud.IActionClient
CertClient hcloud.ICertificateClient
}

// GetCertificateByNameOrID obtains a certificate from the Hetzner Cloud
Expand Down
55 changes: 5 additions & 50 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

hrobot "github.com/syself/hrobot-go"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
Expand All @@ -16,65 +17,19 @@ import (
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/config"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/metrics"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/providerid"
"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/robot"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// LabelServiceUID is a label added to the Hetzner Cloud backend to uniquely
// identify a load balancer managed by Hetzner Cloud Cloud Controller Manager.
const LabelServiceUID = "hcloud-ccm/service-uid"

// HCloudLoadBalancerClient defines the hcloud-go functions required by the
// Load Balancer operations type.
type HCloudLoadBalancerClient interface {
GetByID(ctx context.Context, id int64) (*hcloud.LoadBalancer, *hcloud.Response, error)
GetByName(ctx context.Context, name string) (*hcloud.LoadBalancer, *hcloud.Response, error)

Create(ctx context.Context, opts hcloud.LoadBalancerCreateOpts) (hcloud.LoadBalancerCreateResult, *hcloud.Response, error)
Update(
ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerUpdateOpts,
) (*hcloud.LoadBalancer, *hcloud.Response, error)
Delete(ctx context.Context, lb *hcloud.LoadBalancer) (*hcloud.Response, error)

AddService(
ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerAddServiceOpts,
) (*hcloud.Action, *hcloud.Response, error)
UpdateService(
ctx context.Context, lb *hcloud.LoadBalancer, listenPort int, opts hcloud.LoadBalancerUpdateServiceOpts,
) (*hcloud.Action, *hcloud.Response, error)
DeleteService(
ctx context.Context, lb *hcloud.LoadBalancer, listenPort int,
) (*hcloud.Action, *hcloud.Response, error)

ChangeAlgorithm(ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerChangeAlgorithmOpts) (*hcloud.Action, *hcloud.Response, error)
ChangeType(ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerChangeTypeOpts) (*hcloud.Action, *hcloud.Response, error)
ChangeDNSPtr(ctx context.Context, lb *hcloud.LoadBalancer, ip string, ptr *string) (*hcloud.Action, *hcloud.Response, error)

AddServerTarget(ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerAddServerTargetOpts) (*hcloud.Action, *hcloud.Response, error)
RemoveServerTarget(ctx context.Context, lb *hcloud.LoadBalancer, server *hcloud.Server) (*hcloud.Action, *hcloud.Response, error)

AddIPTarget(ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerAddIPTargetOpts) (*hcloud.Action, *hcloud.Response, error)
RemoveIPTarget(ctx context.Context, lb *hcloud.LoadBalancer, server net.IP) (*hcloud.Action, *hcloud.Response, error)

AttachToNetwork(ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerAttachToNetworkOpts) (*hcloud.Action, *hcloud.Response, error)
DetachFromNetwork(ctx context.Context, lb *hcloud.LoadBalancer, opts hcloud.LoadBalancerDetachFromNetworkOpts) (*hcloud.Action, *hcloud.Response, error)

EnablePublicInterface(
ctx context.Context, loadBalancer *hcloud.LoadBalancer,
) (*hcloud.Action, *hcloud.Response, error)
DisablePublicInterface(
ctx context.Context, loadBalancer *hcloud.LoadBalancer,
) (*hcloud.Action, *hcloud.Response, error)

AllWithOpts(ctx context.Context, opts hcloud.LoadBalancerListOpts) ([]*hcloud.LoadBalancer, error)
}

// LoadBalancerOps implements all operations regarding Hetzner Cloud Load Balancers.
type LoadBalancerOps struct {
LBClient HCloudLoadBalancerClient
ActionClient HCloudActionClient
NetworkClient HCloudNetworkClient
RobotClient robot.Client
LBClient hcloud.ILoadBalancerClient
ActionClient hcloud.IActionClient
NetworkClient hcloud.INetworkClient
RobotClient hrobot.RobotClient
CertOps *CertificateOps
RetryDelay time.Duration
NetworkID int64
Expand Down
11 changes: 0 additions & 11 deletions internal/hcops/network.go

This file was deleted.

1 change: 1 addition & 0 deletions internal/mocks/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type ActionClient struct {
mock.Mock
hcloud.IActionClient // embedded for compile-time interface satisfaction
}

func (m *ActionClient) WaitFor(ctx context.Context, actions ...*hcloud.Action) error {
Expand Down
8 changes: 8 additions & 0 deletions internal/mocks/casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func getRobotServers(args mock.Arguments, i int) []hrobotmodels.Server {
return v.([]hrobotmodels.Server)
}

func getReset(args mock.Arguments, i int) *hrobotmodels.Reset {
v := args.Get(i)
if v == nil {
return nil
}
return v.(*hrobotmodels.Reset)
}

func getNetworkPtr(args mock.Arguments, i int) *hcloud.Network {
v := args.Get(i)
if v == nil {
Expand Down
1 change: 1 addition & 0 deletions internal/mocks/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type CertificateClient struct {
mock.Mock
hcloud.ICertificateClient // embedded for compile-time interface satisfaction
}

func (m *CertificateClient) AllWithOpts(
Expand Down
1 change: 1 addition & 0 deletions internal/mocks/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type LoadBalancerClient struct {
mock.Mock
hcloud.ILoadBalancerClient // embedded for compile-time interface satisfaction
}

func (m *LoadBalancerClient) GetByID(ctx context.Context, id int64) (*hcloud.LoadBalancer, *hcloud.Response, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/mocks/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type NetworkClient struct {
mock.Mock
hcloud.INetworkClient // embedded for compile-time interface satisfaction
}

func (m *NetworkClient) GetByID(ctx context.Context, id int64) (*hcloud.Network, *hcloud.Response, error) {
Expand Down
65 changes: 4 additions & 61 deletions internal/mocks/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package mocks

import (
"github.com/stretchr/testify/mock"
hrobot "github.com/syself/hrobot-go"
hrobotmodels "github.com/syself/hrobot-go/models"
)

type RobotClient struct {
mock.Mock
hrobot.RobotClient // embedded for compile-time interface satisfaction; unmocked methods will panic
}

func (m *RobotClient) ServerGet(id int) (*hrobotmodels.Server, error) {
Expand All @@ -19,66 +21,7 @@ func (m *RobotClient) ServerGetList() ([]hrobotmodels.Server, error) {
return getRobotServers(args, 0), args.Error(1)
}

func (m *RobotClient) BootLinuxDelete(id int) (*hrobotmodels.Linux, error) {
panic("this method should not be called")
}
func (m *RobotClient) BootLinuxGet(id int) (*hrobotmodels.Linux, error) {
panic("this method should not be called")
}
func (m *RobotClient) BootLinuxSet(id int, input *hrobotmodels.LinuxSetInput) (*hrobotmodels.Linux, error) {
panic("this method should not be called")
}
func (m *RobotClient) BootRescueDelete(id int) (*hrobotmodels.Rescue, error) {
panic("this method should not be called")
}
func (m *RobotClient) BootRescueGet(id int) (*hrobotmodels.Rescue, error) {
panic("this method should not be called")
}
func (m *RobotClient) BootRescueSet(id int, input *hrobotmodels.RescueSetInput) (*hrobotmodels.Rescue, error) {
panic("this method should not be called")
}
func (m *RobotClient) FailoverGet(ip string) (*hrobotmodels.Failover, error) {
panic("this method should not be called")
}
func (m *RobotClient) FailoverGetList() ([]hrobotmodels.Failover, error) {
panic("this method should not be called")
}
func (m *RobotClient) GetVersion() string {
panic("this method should not be called")
}
func (m *RobotClient) IPGetList() ([]hrobotmodels.IP, error) {
panic("this method should not be called")
}
func (m *RobotClient) KeyGetList() ([]hrobotmodels.Key, error) {
panic("this method should not be called")
}
func (m *RobotClient) KeySet(input *hrobotmodels.KeySetInput) (*hrobotmodels.Key, error) {
panic("this method should not be called")
}
func (m *RobotClient) RDnsGet(ip string) (*hrobotmodels.Rdns, error) {
panic("this method should not be called")
}
func (m *RobotClient) RDnsGetList() ([]hrobotmodels.Rdns, error) {
panic("this method should not be called")
}
func (m *RobotClient) ResetGet(id int) (*hrobotmodels.Reset, error) {
panic("this method should not be called")
}
func (m *RobotClient) ResetSet(id int, input *hrobotmodels.ResetSetInput) (*hrobotmodels.ResetPost, error) {
panic("this method should not be called")
}
func (m *RobotClient) ServerReverse(id int) (*hrobotmodels.Cancellation, error) {
panic("this method should not be called")
}
func (m *RobotClient) ServerSetName(id int, input *hrobotmodels.ServerSetNameInput) (*hrobotmodels.Server, error) {
panic("this method should not be called")
}
func (m *RobotClient) SetBaseURL(baseURL string) {
panic("this method should not be called")
}
func (m *RobotClient) SetUserAgent(userAgent string) {
panic("this method should not be called")
}
func (m *RobotClient) ValidateCredentials() error {
panic("this method should not be called")
args := m.Called(id)
return getReset(args, 0), args.Error(1)
}
13 changes: 7 additions & 6 deletions internal/robot/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"sync"
"time"

hrobot "github.com/syself/hrobot-go"
hrobotmodels "github.com/syself/hrobot-go/models"
)

type cacheRobotClient struct {
robotClient Client
timeout time.Duration
hrobot.RobotClient // embed inner client to forward all unoverridden methods
timeout time.Duration

lastUpdate time.Time
// mutex is necessary to synchronize parallel access to the cache
Expand All @@ -20,10 +21,10 @@ type cacheRobotClient struct {
serversByID map[int]*hrobotmodels.Server
}

func NewCachedClient(cacheTimeout time.Duration, robotClient Client) Client {
func NewCachedClient(cacheTimeout time.Duration, robotClient hrobot.RobotClient) hrobot.RobotClient {
return &cacheRobotClient{
RobotClient: robotClient,
timeout: cacheTimeout,
robotClient: robotClient,

serversByID: make(map[int]*hrobotmodels.Server),
}
Expand Down Expand Up @@ -64,7 +65,7 @@ func (c *cacheRobotClient) updateCacheIfNecessary() error {
return nil
}

servers, err := c.robotClient.ServerGetList()
servers, err := c.RobotClient.ServerGetList()
if err != nil {
return err
}
Expand All @@ -85,5 +86,5 @@ func (c *cacheRobotClient) updateCacheIfNecessary() error {

// ResetGet does not use the cache, as we need up to date information for its function.
func (c *cacheRobotClient) ResetGet(id int) (*hrobotmodels.Reset, error) {
return c.robotClient.ResetGet(id)
return c.RobotClient.ResetGet(id)
}
11 changes: 0 additions & 11 deletions internal/robot/interface.go

This file was deleted.

Loading
Loading