hcops

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func WatchAction

func WatchAction(ctx context.Context, ac HCloudActionClient, a *hcloud.Action) error

Types

type AllServersCache added in v1.8.1

type AllServersCache struct {
	LoadFunc    func(context.Context) ([]*hcloud.Server, error)
	LoadTimeout time.Duration
	MaxAge      time.Duration
	// contains filtered or unexported fields
}

AllServersCache caches the result of the LoadFunc and provides random access to servers using select hcloud.Server attributes.

To simplify things the allServersCache reloads all servers on every cache miss, or whenever a timeout expired.

func (*AllServersCache) ByName added in v1.8.1

func (c *AllServersCache) ByName(name string) (*hcloud.Server, error)

ByName obtains a server from the cache using the servers name.

Note that a pointer to the object stored in the cache is returned. Modifying this object affects the cache and all other code parts holding a reference. Furthermore modifying the returned server is not concurrency safe.

func (*AllServersCache) ByPrivateIP added in v1.8.1

func (c *AllServersCache) ByPrivateIP(ip net.IP) (*hcloud.Server, error)

ByPrivateIP obtains a server from the cache using the IP of one of its private networks.

Note that a pointer to the object stored in the cache is returned. Modifying this object affects the cache and all other code parts holding a reference. Furthermore modifying the returned server is not concurrency safe.

type HCloudActionClient

type HCloudActionClient interface {
	WatchProgress(ctx context.Context, a *hcloud.Action) (<-chan int, <-chan error)
}

type HCloudLoadBalancerClient

type HCloudLoadBalancerClient interface {
	GetByID(ctx context.Context, id int) (*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)
	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)

	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)

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

HCloudLoadBalancerClient defines the hcloud-go functions required by the Load Balancer operations type.

type HCloudNetworkClient

type HCloudNetworkClient interface {
	GetByID(ctx context.Context, id int) (*hcloud.Network, *hcloud.Response, error)
}

type LoadBalancerOps

type LoadBalancerOps struct {
	LBClient      HCloudLoadBalancerClient
	ActionClient  HCloudActionClient
	NetworkClient HCloudNetworkClient
	RetryDelay    time.Duration
	NetworkID     int
}

LoadBalancerOps implements all operations regarding Hetzner Cloud Load Balancers.

func (*LoadBalancerOps) Create

func (l *LoadBalancerOps) Create(
	ctx context.Context, lbName string, svc *v1.Service,
) (*hcloud.LoadBalancer, error)

Create creates a new Load Balancer using the Hetzner Cloud API.

It adds annotations identifying the HC Load Balancer to svc.

func (*LoadBalancerOps) GetByID

func (l *LoadBalancerOps) GetByID(ctx context.Context, id int) (*hcloud.LoadBalancer, error)

GetByID retrieves a Hetzner Cloud Load Balancer by id.

If no Load Balancer with id could be found, a wrapped ErrNotFound is returned.

func (*LoadBalancerOps) GetByName

func (l *LoadBalancerOps) GetByName(ctx context.Context, name string) (*hcloud.LoadBalancer, error)

GetByName retrieves a Hetzner Cloud Load Balancer by name.

If no Load Balancer with name could be found, a wrapped ErrNotFound is returned.

func (*LoadBalancerOps) ReconcileHCLB

func (l *LoadBalancerOps) ReconcileHCLB(ctx context.Context, lb *hcloud.LoadBalancer, svc *v1.Service) (bool, error)

ReconcileHCLB configures the Hetzner Cloud Load Balancer to match what is defined for the K8S Load Balancer svc.

func (*LoadBalancerOps) ReconcileHCLBServices

func (l *LoadBalancerOps) ReconcileHCLBServices(
	ctx context.Context, lb *hcloud.LoadBalancer, svc *v1.Service,
) (bool, error)

ReconcileHCLBServices synchronizes services exposed by the Hetzner Cloud Load Balancer with the kubernetes cluster.

func (*LoadBalancerOps) ReconcileHCLBTargets

func (l *LoadBalancerOps) ReconcileHCLBTargets(
	ctx context.Context, lb *hcloud.LoadBalancer, svc *v1.Service, nodes []*v1.Node,
) (bool, error)

ReconcileHCLBTargets adds or removes target nodes from the Hetzner Cloud Load Balancer when nodes are added or removed to the K8S cluster.

type LoadBalancerOpsFixture

type LoadBalancerOpsFixture struct {
	Name          string
	Ctx           context.Context
	LBClient      *mocks.LoadBalancerClient
	ActionClient  *mocks.ActionClient
	NetworkClient *mocks.NetworkClient

	LBOps *LoadBalancerOps

	T *testing.T
}

func NewLoadBalancerOpsFixture

func NewLoadBalancerOpsFixture(t *testing.T) *LoadBalancerOpsFixture

func (*LoadBalancerOpsFixture) AssertExpectations

func (fx *LoadBalancerOpsFixture) AssertExpectations()

func (*LoadBalancerOpsFixture) MockAddServerTarget

func (*LoadBalancerOpsFixture) MockAddService

func (*LoadBalancerOpsFixture) MockCreate

func (*LoadBalancerOpsFixture) MockDeleteService

func (fx *LoadBalancerOpsFixture) MockDeleteService(lb *hcloud.LoadBalancer, port int, err error) *hcloud.Action

func (*LoadBalancerOpsFixture) MockGetByID

func (fx *LoadBalancerOpsFixture) MockGetByID(lb *hcloud.LoadBalancer, err error)

func (*LoadBalancerOpsFixture) MockRemoveServerTarget

func (fx *LoadBalancerOpsFixture) MockRemoveServerTarget(
	lb *hcloud.LoadBalancer, s *hcloud.Server, err error,
) *hcloud.Action

func (*LoadBalancerOpsFixture) MockUpdateService

func (fx *LoadBalancerOpsFixture) MockUpdateService(
	opts hcloud.LoadBalancerUpdateServiceOpts, lb *hcloud.LoadBalancer, listenPort int, err error,
) *hcloud.Action

func (*LoadBalancerOpsFixture) MockWatchProgress

func (fx *LoadBalancerOpsFixture) MockWatchProgress(a *hcloud.Action, err error)

type MockLoadBalancerOps

type MockLoadBalancerOps struct {
	mock.Mock
}

func (*MockLoadBalancerOps) Create

func (m *MockLoadBalancerOps) Create(
	ctx context.Context, lbName string, service *v1.Service,
) (*hcloud.LoadBalancer, error)

func (*MockLoadBalancerOps) GetByID

func (*MockLoadBalancerOps) GetByName

func (m *MockLoadBalancerOps) GetByName(ctx context.Context, name string) (*hcloud.LoadBalancer, error)

func (*MockLoadBalancerOps) ReconcileHCLB

func (m *MockLoadBalancerOps) ReconcileHCLB(
	ctx context.Context, lb *hcloud.LoadBalancer, svc *v1.Service,
) (bool, error)

func (*MockLoadBalancerOps) ReconcileHCLBServices

func (m *MockLoadBalancerOps) ReconcileHCLBServices(
	ctx context.Context, lb *hcloud.LoadBalancer, svc *v1.Service,
) (bool, error)

func (*MockLoadBalancerOps) ReconcileHCLBTargets

func (m *MockLoadBalancerOps) ReconcileHCLBTargets(
	ctx context.Context, lb *hcloud.LoadBalancer, svc *v1.Service, nodes []*v1.Node,
) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL