util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExportedLogsPath is the path where test logs will be exported.
	ExportedLogsPath = "/tmp/clusterlink-k8s-tests"
)

Variables

View Source
var PolicyAllowAll = &v1alpha1.AccessPolicy{
	ObjectMeta: metav1.ObjectMeta{
		Name: "allow-all",
	},
	Spec: v1alpha1.AccessPolicySpec{
		Action: v1alpha1.AccessPolicyActionAllow,
		From: v1alpha1.WorkloadSetOrSelectorList{{
			WorkloadSelector: &metav1.LabelSelector{},
		}},
		To: v1alpha1.WorkloadSetOrSelectorList{{
			WorkloadSelector: &metav1.LabelSelector{},
		}},
	},
}

Functions

This section is empty.

Types

type AsyncRunner

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

AsyncRunner allows asynchronous running of functions with error tracking.

func (*AsyncRunner) Error

func (r *AsyncRunner) Error() error

Error returns the (combined) errors collected.

func (*AsyncRunner) Run

func (r *AsyncRunner) Run(f func() error)

Error returns the (combined) errors collected.

func (*AsyncRunner) SetError

func (r *AsyncRunner) SetError(err error)

SetError collects a new error.

func (*AsyncRunner) Wait

func (r *AsyncRunner) Wait() error

Wait for async operations to finish.

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

ClusterLink represents a clusterlink instance.

func (*ClusterLink) AccessService

func (c *ClusterLink) AccessService(
	clientFn func(*KindCluster, *Service) (string, error),
	service *Service, allowRetry bool, expectedError error,
) (string, error)

Access a cluster service.

func (*ClusterLink) Client

func (c *ClusterLink) Client() *client.Client

Client returns a controlplane API client for this cluster.

func (*ClusterLink) Cluster

func (c *ClusterLink) Cluster() *KindCluster

Cluster returns the backing kind cluster.

func (*ClusterLink) CreateExport

func (c *ClusterLink) CreateExport(service *Service) error

func (*ClusterLink) CreateImport

func (c *ClusterLink) CreateImport(service *Service, peer *ClusterLink, exportName string) error

func (*ClusterLink) CreatePeer

func (c *ClusterLink) CreatePeer(peer *ClusterLink) error

func (*ClusterLink) CreatePolicy

func (c *ClusterLink) CreatePolicy(policy *v1alpha1.AccessPolicy) error

func (*ClusterLink) CreateService

func (c *ClusterLink) CreateService(service *Service) error

func (*ClusterLink) DeleteExport

func (c *ClusterLink) DeleteExport(name string) error

func (*ClusterLink) DeleteImport

func (c *ClusterLink) DeleteImport(name string) error

func (*ClusterLink) DeletePeer

func (c *ClusterLink) DeletePeer(peer *ClusterLink) error

func (*ClusterLink) DeletePolicy

func (c *ClusterLink) DeletePolicy(name string) error

func (*ClusterLink) DeleteService added in v0.1.0

func (c *ClusterLink) DeleteService(name string) error

func (*ClusterLink) GetAllExports

func (c *ClusterLink) GetAllExports() (*[]v1alpha1.Export, error)

func (*ClusterLink) GetAllImports

func (c *ClusterLink) GetAllImports() (*[]v1alpha1.Import, error)

func (*ClusterLink) GetAllPeers

func (c *ClusterLink) GetAllPeers() (*[]v1alpha1.Peer, error)

func (*ClusterLink) GetAllPolicies

func (c *ClusterLink) GetAllPolicies() (*[]v1alpha1.AccessPolicy, error)

func (*ClusterLink) GetExport

func (c *ClusterLink) GetExport(name string) (*v1alpha1.Export, error)

func (*ClusterLink) GetImport

func (c *ClusterLink) GetImport(name string) (*v1alpha1.Import, error)

func (*ClusterLink) GetPeer

func (c *ClusterLink) GetPeer(peer *ClusterLink) (*v1alpha1.Peer, error)

func (*ClusterLink) GetPolicy

func (c *ClusterLink) GetPolicy(name string) (*v1alpha1.AccessPolicy, error)

func (*ClusterLink) IP

func (c *ClusterLink) IP() string

IP returns the peer IP.

func (*ClusterLink) Name

func (c *ClusterLink) Name() string

Name returns the peer name.

func (*ClusterLink) Namespace

func (c *ClusterLink) Namespace() string

Namespace returns the clusterlink kubernetes namespace.

func (*ClusterLink) Port

func (c *ClusterLink) Port() uint16

Port returns the peer port.

func (*ClusterLink) RestartControlplane

func (c *ClusterLink) RestartControlplane() error

RestartControlplane restarts the controlplane.

func (*ClusterLink) RestartDataplane

func (c *ClusterLink) RestartDataplane() error

RestartDataplane restarts the dataplane.

func (*ClusterLink) ScaleControlplane

func (c *ClusterLink) ScaleControlplane(replicas int32) error

ScaleControlplane scales the controlplane deployment.

func (*ClusterLink) ScaleDataplane

func (c *ClusterLink) ScaleDataplane(replicas int32) error

ScaleDataplane scales the dataplane deployment.

func (*ClusterLink) UpdateExport

func (c *ClusterLink) UpdateExport(name string, service *Service) error

func (*ClusterLink) UpdateImport

func (c *ClusterLink) UpdateImport(service *Service, peer *ClusterLink, exportName string) error

func (*ClusterLink) UpdatePeer

func (c *ClusterLink) UpdatePeer(peer *ClusterLink) error

func (*ClusterLink) UpdatePolicy

func (c *ClusterLink) UpdatePolicy(policy *v1alpha1.AccessPolicy) error

func (*ClusterLink) WaitForControlplaneAPI

func (c *ClusterLink) WaitForControlplaneAPI() error

WaitForControlplaneAPI waits until the controlplane API server is up.

func (*ClusterLink) WaitForExportCondition added in v0.1.0

func (c *ClusterLink) WaitForExportCondition(
	export *v1alpha1.Export,
	conditionType string,
	expectedConditionStatus bool,
) error

func (*ClusterLink) WaitForImportCondition added in v0.1.0

func (c *ClusterLink) WaitForImportCondition(
	imp *v1alpha1.Import,
	conditionType string,
	expectedConditionStatus bool,
) error

func (*ClusterLink) WaitForPeerCondition added in v0.1.0

func (c *ClusterLink) WaitForPeerCondition(
	peer *v1alpha1.Peer,
	conditionType string,
	expectedConditionStatus bool,
) error

type Fabric

type Fabric struct {
	AsyncRunner
	// contains filtered or unexported fields
}

Fabric represents a collection of clusterlinks.

func NewFabric

func NewFabric() (*Fabric, error)

NewFabric returns a new empty fabric.

func (*Fabric) CreatePeer

func (f *Fabric) CreatePeer(cluster *KindCluster)

CreatePeer creates certificates for a new peer on a given kind cluster.

func (f *Fabric) DeployClusterlinks(peerCount uint8, cfg *PeerConfig) ([]*ClusterLink, error)

DeployClusterlinks deploys clusterlink to <peerCount> clusters.

func (*Fabric) Namespace

func (f *Fabric) Namespace() string

Namespace returns fabric namespace.

func (*Fabric) PeerKindCluster

func (f *Fabric) PeerKindCluster(num int) *KindCluster

PeerKindCluster returns the peer kind cluster.

func (*Fabric) SwitchToNewNamespace

func (f *Fabric) SwitchToNewNamespace(name string, appendName bool) error

SwitchToNewNamespace creates a new namespace to be used for deploying clusterlink. It also updates the current nodeport value.

type KindCluster

type KindCluster struct {
	AsyncRunner
	// contains filtered or unexported fields
}

KindCluster represents a kind kubernetes cluster.

func NewKindCluster

func NewKindCluster(name string) *KindCluster

NewKindCluster returns a new yet to be running kind cluster.

func (*KindCluster) CreateFromPath

func (c *KindCluster) CreateFromPath(folder string) error

CreateFromPath creates k8s objects from a yaml in a folder.

func (*KindCluster) CreateFromYAML

func (c *KindCluster) CreateFromYAML(yaml, namespace string) error

CreateFromYAML creates k8s objects from a yaml string, in a given namespace.

func (*KindCluster) CreateNamespace

func (c *KindCluster) CreateNamespace(name string) error

CreateNamespace creates a namespace.

func (*KindCluster) CreatePodAndService

func (c *KindCluster) CreatePodAndService(podAndService *PodAndService) error

CreatePodAndService creates a pod exposed by a service.

func (*KindCluster) DeleteNamespace

func (c *KindCluster) DeleteNamespace(name string) error

DeleteNamespace deletes a namespace.

func (*KindCluster) Destroy

func (c *KindCluster) Destroy() error

Destroy cluster.

func (*KindCluster) ExportLogs

func (c *KindCluster) ExportLogs() error

ExportLogs exports cluster logs to files.

func (*KindCluster) ExposeNodeport

func (c *KindCluster) ExposeNodeport(service *Service) (uint16, error)

ExposeNodeport returns a nodeport (uint16) for accessing a given k8s service. The returned nodeport service is cached across subsequent calls.

func (*KindCluster) IP

func (c *KindCluster) IP() string

IP returns the cluster IP.

func (*KindCluster) LoadImage

func (c *KindCluster) LoadImage(name string)

LoadImage loads a docker image to the cluster. Assumes Start was already called.

func (*KindCluster) Name

func (c *KindCluster) Name() string

Name returns the cluster name.

func (*KindCluster) Resources

func (c *KindCluster) Resources() *resources.Resources

Resources returns the cluster resources.

func (*KindCluster) RunPod

func (c *KindCluster) RunPod(podSpec *Pod) (string, error)

RunPod runs a pod, wait for its completion, and return its standard output.

func (*KindCluster) ScaleDeployment

func (c *KindCluster) ScaleDeployment(name, namespace string, replicas int32) error

ScaleDeployment updates the number of deployment replicas, and waits for this update to complete.

func (*KindCluster) Start

func (c *KindCluster) Start()

Start the kind cluster. Should be called only once.

func (*KindCluster) WaitFor added in v0.1.0

func (c *KindCluster) WaitFor(
	obj k8s.Object,
	statusConditions *[]metav1.Condition,
	conditionType string,
	expectedConditionStatus bool,
) error

WaitFor waits for a condition to be set on an object.

func (*KindCluster) WaitForDeletion added in v0.1.0

func (c *KindCluster) WaitForDeletion(obj k8s.Object) error

WaitFor waits for a condition to be set on an object.

type PeerConfig

type PeerConfig struct {
	// CRUDMode indicates a CRUD-based controlplane (i.e. not CRD mode).
	CRUDMode bool
	// DataplaneType is the dataplane type (envoy / go).
	DataplaneType string
	// Dataplanes is the number of dataplane instances.
	Dataplanes uint16
	// ControlplanePersistency should be true if controlplane should use persistent storage.
	ControlplanePersistency bool
	// ExpectLargeDataplaneTraffic hints that a large amount of dataplane traffic is expected.
	ExpectLargeDataplaneTraffic bool
	// DeployWithOperator deploys clusterlink using an operator.
	DeployWithOperator bool
}

PeerConfig is a peer configuration.

type Pod

type Pod struct {
	// Name is the pod name.
	Name string
	// Namespace is the pod namespace.
	Namespace string
	// Image is the container image.
	Image string
	// Args are the container command line arguments.
	Args []string
}

Pod represents a kubernetes pod.

type PodAndService

type PodAndService struct {
	Service

	// Image is the container image.
	Image string
	// Args are the container command line arguments.
	Args []string
}

PodAndService represents a kubernetes service and a backing pod.

type Service

type Service struct {
	// Name is the service name.
	Name string
	// Namespace is the service namespace.
	Namespace string
	// Port is the service external listening port.
	Port uint16
}

Service represents a kubernetes service.

type StatusObject added in v0.1.0

type StatusObject interface {
	k8s.Object
	GetStatusConditions() []metav1.Condition
}

StatusObject represents a k8s object with status conditions.

Jump to

Keyboard shortcuts

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