ctok

package
v1.2.4 Latest Latest
Warning

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

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

Documentation

Overview

Package ctok implements a syncer from cloud to k8s.

Package ctok contains a reusable abstraction for efficiently watching for changes in resources in a Kubernetes cluster.

Index

Constants

View Source
const (
	// K8SQuietPeriod is the time to wait for no service changes before syncing.
	K8SQuietPeriod = 1 * time.Second

	// K8SMaxPeriod is the maximum time to wait before forcing a sync, even
	// if there are active changes going on.
	K8SMaxPeriod = 5 * time.Second

	True  = "true"
	False = "false"
)
View Source
const (
	// CloudSourcedServiceLabel defines cloud-sourced service label
	CloudSourcedServiceLabel = "cloud-sourced-service"
	// CloudServiceLabel defines cloud service label
	CloudServiceLabel = "cloud-service"
)

Variables

This section is empty.

Functions

func IsSyncCloudNamespace

func IsSyncCloudNamespace(ns *corev1.Namespace) bool

IsSyncCloudNamespace if sync namespace

Types

type Aggregator

type Aggregator interface {
	// Aggregate micro services
	Aggregate(context.Context, MicroSvcName) map[MicroSvcName]*MicroSvcMeta
}

Aggregator aggregates micro services

type CtoKSource added in v1.2.1

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

CtoKSource is the source for the sync that watches cloud services and updates a CtoKSyncer whenever the set of services to register changes.

func NewCtoKSource added in v1.2.1

func NewCtoKSource(controller connector.ConnectController,
	syncer *CtoKSyncer,
	discClient connector.ServiceDiscoveryClient,
	domain string) *CtoKSource

func (*CtoKSource) Aggregate added in v1.2.1

func (s *CtoKSource) Aggregate(ctx context.Context, svcName MicroSvcName) map[MicroSvcName]*MicroSvcMeta

Aggregate micro services

func (*CtoKSource) Run added in v1.2.1

func (s *CtoKSource) Run(ctx context.Context)

Run is the long-running loop for watching cloud services and updating the CtoKSyncer.

type CtoKSyncer added in v1.2.1

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

CtoKSyncer is the destination where services are registered.

While in practice we only have one syncer (K8S), the interface abstraction makes it easy and possible to test the CtoKSource in isolation.

func NewCtoKSyncer added in v1.2.1

func NewCtoKSyncer(
	controller connector.ConnectController,
	discClient connector.ServiceDiscoveryClient,
	kubeClient kubernetes.Interface,
	ctx context.Context,
	fsmNamespace string) *CtoKSyncer

NewCtoKSyncer creates a new mesh syncer

func (*CtoKSyncer) Delete added in v1.2.1

func (s *CtoKSyncer) Delete(key string, _ interface{}) error

Delete implements the controller.Resource interface.

func (*CtoKSyncer) Informer added in v1.2.1

func (s *CtoKSyncer) Informer() cache.SharedIndexInformer

Informer implements the controller.Resource interface. It tells Kubernetes that we want to watch for changes to Services.

func (*CtoKSyncer) Ready added in v1.2.1

func (s *CtoKSyncer) Ready()

Ready wait util ready

func (*CtoKSyncer) Run added in v1.2.1

func (s *CtoKSyncer) Run(ch <-chan struct{})

Run implements the controller.Backgrounder interface.

func (*CtoKSyncer) SetMicroAggregator added in v1.2.1

func (s *CtoKSyncer) SetMicroAggregator(microAggregator Aggregator)

func (*CtoKSyncer) SetServices added in v1.2.1

func (s *CtoKSyncer) SetServices(svcs map[MicroSvcName]MicroSvcDomainName)

SetServices is called with the services that should be created. The key is the service name and the destination is the external DNS entry to point to.

func (*CtoKSyncer) Upsert added in v1.2.1

func (s *CtoKSyncer) Upsert(key string, raw interface{}) error

Upsert implements the controller.Resource interface.

type MicroEndpointAddr

type MicroEndpointAddr string

MicroEndpointAddr defines string as micro endpoint addr

func (MicroEndpointAddr) To16

func (addr MicroEndpointAddr) To16() net.IP

To16 converts the IP address ip to a 16-byte representation. If ip is not an IP address (it is the wrong length), To16 returns nil.

func (MicroEndpointAddr) To4

func (addr MicroEndpointAddr) To4() net.IP

To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil.

type MicroSvcAppProtocol

type MicroSvcAppProtocol string

MicroSvcAppProtocol defines app protocol

type MicroSvcDomainName

type MicroSvcDomainName string

MicroSvcDomainName defines string as microservice domain name

type MicroSvcMeta

type MicroSvcMeta struct {
	Ports       map[MicroSvcPort]MicroSvcAppProtocol
	Addresses   map[MicroEndpointAddr]int
	ClusterSet  string
	ClusterId   string
	WithGateway bool
	ViaGateway  string
	HealthCheck bool
}

MicroSvcMeta defines micro service meta

type MicroSvcName

type MicroSvcName string

MicroSvcName defines string as microservice name

type MicroSvcPort

type MicroSvcPort int

MicroSvcPort defines int as micro service port

Jump to

Keyboard shortcuts

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