tsclient

package
v1.98.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package tsclient provides a mockable wrapper around the tailscale-client-go-v2 package for use by the Kubernetes operator. It also contains the Provider type used to manage multiple instances of tailscale clients for different tailnets.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClientNotFound is the error given when calling Provider.For with a tailnet that has not yet been registered
	// with the provider.
	ErrClientNotFound = errors.New("client not found")
	// ErrNotReady is the error given when calling Provider.For with a tailnet that has not yet been declared as
	// ready to use by the operator.
	ErrNotReady = errors.New("tailnet not ready")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// LoginURL should return the url of the Tailscale control plane.
	LoginURL() string
	// Devices should return a DeviceResource implementation used to interact with the devices API.
	Devices() DeviceResource
	// Keys should return a KeyResource implementation used to interact with the keys API.
	Keys() KeyResource
	// VIPServices should return a VIPServiceResource implementation used to interact with the VIP services API.
	VIPServices() VIPServiceResource
}

The Client interface describes types that interact with the Tailscale API.

func Wrap

func Wrap(client *tailscale.Client) Client

Wrap converts a given tailscale.Client into a Client.

type DeviceResource

type DeviceResource interface {
	// Delete should delete a device with a matching id.
	Delete(ctx context.Context, id string) error
	// List should return all devices based on the specified options.
	List(ctx context.Context, opts ...tailscale.ListDevicesOptions) ([]tailscale.Device, error)
	// Get should return the device with the matching identifier.
	Get(ctx context.Context, id string) (*tailscale.Device, error)
}

The DeviceResource interface describes types that expose device related API endpoints.

type KeyResource

type KeyResource interface {
	// CreateAuthKey should create and return a new auth key used to authenticate a device.
	CreateAuthKey(ctx context.Context, ckr tailscale.CreateKeyRequest) (*tailscale.Key, error)
	// List should return keys created by the caller or all keys if the provided boolean is set to true.
	List(ctx context.Context, all bool) ([]tailscale.Key, error)
}

The KeyResource interface describes types that expose key related API endpoints.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

The Provider type is used to manage multiple Client implementations for different tailnets.

func NewProvider

func NewProvider(defaultClient Client) *Provider

NewProvider returns a new instance of the Provider type that uses the given Client implementation as the default client. This client will be given when calling Provider.For with a blank tailnet name.

func (*Provider) Add

func (p *Provider) Add(tailnet string, client Client, ready bool)

Add a Client implementation for a given tailnet.

func (*Provider) For

func (p *Provider) For(tailnet string) (Client, error)

For returns a Client implementation associated with the given tailnet. Returns ErrClientNotFound if the given tailnet does not exist. Use a blank tailnet name to obtain the default Client.

func (*Provider) Remove

func (p *Provider) Remove(tailnet string)

Remove the Client implementation associated with the given tailnet.

type VIPServiceResource

type VIPServiceResource interface {
	// List should return all existing vip services within the tailnet.
	List(ctx context.Context) ([]tailscale.VIPService, error)
	// Delete should remove a named service from the tailnet.
	Delete(ctx context.Context, name string) error
	// Get should return the vip service associated with the given name.
	Get(ctx context.Context, name string) (*tailscale.VIPService, error)
	// CreateOrUpdate should update the provided vip service, creating it if it does not exist.
	CreateOrUpdate(ctx context.Context, svc tailscale.VIPService) error
}

The VIPServiceResource interface describes types that expose vip service related API endpoints.

Jump to

Keyboard shortcuts

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