cosmos

package
v0.21.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const CacheControllerName = "CosmosCache"

Variables

This section is empty.

Functions

func IntersectPods added in v0.15.0

func IntersectPods(coll *StatusCollection, pods []corev1.Pod)

IntersectPods removes all pods from the collection that are not in the given list.

func UpsertPod added in v0.15.0

func UpsertPod(coll *StatusCollection, pod *corev1.Pod)

UpsertPod updates the pod in the collection or adds an item to the collection if it does not exist. All operations are performed in-place.

Types

type CacheController added in v0.15.0

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

CacheController periodically polls pods for their CometBFT status and caches the result. The cache is a controller so it can watch CosmosFullNode objects to warm or invalidate the cache.

func NewCacheController added in v0.15.0

func NewCacheController(collector Collector, reader client.Reader, recorder record.EventRecorder) *CacheController

func (*CacheController) Close added in v0.15.0

func (c *CacheController) Close() error

Close stops all cache collecting and waits for all goroutines to exit.

func (*CacheController) Collect added in v0.15.0

func (c *CacheController) Collect(ctx context.Context, controller client.ObjectKey) StatusCollection

Collect returns a StatusCollection for the given controller. Only returns cached CometStatus.

func (*CacheController) Invalidate added in v0.20.0

func (c *CacheController) Invalidate(controller client.ObjectKey, pods []string)

Invalidate removes the given pods status from the cache.

func (*CacheController) Reconcile added in v0.15.0

func (*CacheController) SetupWithManager added in v0.15.0

func (c *CacheController) SetupWithManager(_ context.Context, mgr ctrl.Manager) error

SetupWithManager watches CosmosFullNode objects and starts cache collecting.

func (*CacheController) SyncedPods added in v0.15.0

func (c *CacheController) SyncedPods(ctx context.Context, controller client.ObjectKey) []*corev1.Pod

SyncedPods returns only the pods that are ready and in sync (i.e. caught up with chain tip).

type Collector added in v0.15.0

type Collector interface {
	Collect(ctx context.Context, pods []corev1.Pod) StatusCollection
}

type CometClient added in v0.15.0

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

CometClient knows how to make requests to the CometBFT (formerly Comet) RPC endpoints. This package uses a custom client because 1) parsing JSON is simple and 2) we prevent any dependency on CometBFT packages.

func NewCometClient added in v0.15.0

func NewCometClient(client *http.Client) *CometClient

func (*CometClient) Status added in v0.15.0

func (client *CometClient) Status(ctx context.Context, rpcHost string) (CometStatus, error)

Status finds the latest status.

type CometStatus added in v0.15.0

type CometStatus struct {
	JSONRPC string
	ID      int
	Result  struct {
		NodeInfo      NodeInfo
		SyncInfo      SyncInfo
		ValidatorInfo ValidatorInfo
	}
}

CometStatus is the common response from the /status RPC endpoint.

func (CometStatus) LatestBlockHeight added in v0.15.0

func (status CometStatus) LatestBlockHeight() uint64

LatestBlockHeight parses the latest block height string. If the string is malformed, returns 0.

type NodeInfo added in v0.21.2

type NodeInfo struct {
	ProtocolVersion struct {
		P2P   string `json:"p2p"`
		Block string `json:"block"`
		App   string `json:"app"`
	} `json:"protocol_version"`
	ID         string `json:"id"`
	ListenAddr string `json:"listen_addr"`
	Network    string `json:"network"`
	Version    string `json:"version"`
	Channels   string `json:"channels"`
	Moniker    string `json:"moniker"`
	Other      struct {
		TxIndex    string `json:"tx_index"`
		RPCAddress string `json:"rpc_address"`
	} `json:"other"`
}

type StatusCollection added in v0.15.0

type StatusCollection []StatusItem

StatusCollection is a list of pods and CometBFT status associated with the pod.

func (StatusCollection) Len added in v0.15.0

func (coll StatusCollection) Len() int

Len returns the number of items in the collection. Part of the sort.Interface implementation.

func (StatusCollection) Less added in v0.15.0

func (coll StatusCollection) Less(i, j int) bool

Less implements sort.Interface.

func (StatusCollection) Pods added in v0.15.0

func (coll StatusCollection) Pods() []*corev1.Pod

Pods returns all pods.

func (StatusCollection) Swap added in v0.15.0

func (coll StatusCollection) Swap(i, j int)

Swap implements sort.Interface.

func (StatusCollection) Synced added in v0.15.0

func (coll StatusCollection) Synced() StatusCollection

Synced returns all items that are caught up with the chain tip.

func (StatusCollection) SyncedPods added in v0.15.0

func (coll StatusCollection) SyncedPods() []*corev1.Pod

SyncedPods returns the pods that are caught up with the chain tip.

type StatusCollector added in v0.15.0

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

StatusCollector collects the CometBFT status of all pods owned by a controller.

func NewStatusCollector added in v0.15.0

func NewStatusCollector(comet Statuser, timeout time.Duration) *StatusCollector

NewStatusCollector returns a valid StatusCollector. Timeout is exposed here because it is important for good performance in reconcile loops, and reminds callers to set it.

func (StatusCollector) Collect added in v0.15.0

func (coll StatusCollector) Collect(ctx context.Context, pods []corev1.Pod) StatusCollection

Collect returns a StatusCollection for the given pods. Any non-nil error can be treated as transient and retried.

type StatusItem added in v0.15.0

type StatusItem struct {
	Pod    *corev1.Pod
	Status CometStatus
	TS     time.Time
	Err    error
}

StatusItem is a pod paired with its CometBFT status.

func (StatusItem) GetPod added in v0.15.0

func (status StatusItem) GetPod() *corev1.Pod

GetPod returns the pod.

func (StatusItem) GetStatus added in v0.15.0

func (status StatusItem) GetStatus() (CometStatus, error)

GetStatus returns the CometBFT status or an error if the status could not be fetched.

func (StatusItem) Timestamp added in v0.15.0

func (status StatusItem) Timestamp() time.Time

Timestamp returns the time when the CometBFT status was fetched.

type Statuser added in v0.15.0

type Statuser interface {
	Status(ctx context.Context, rpcHost string) (CometStatus, error)
}

Statuser calls the RPC status endpoint.

type SyncInfo added in v0.21.2

type SyncInfo struct {
	LatestBlockHash     string    `json:"latest_block_hash"`
	LatestAppHash       string    `json:"latest_app_hash"`
	LatestBlockHeight   string    `json:"latest_block_height"`
	LatestBlockTime     time.Time `json:"latest_block_time"`
	EarliestBlockHash   string    `json:"earliest_block_hash"`
	EarliestAppHash     string    `json:"earliest_app_hash"`
	EarliestBlockHeight string    `json:"earliest_block_height"`
	EarliestBlockTime   time.Time `json:"earliest_block_time"`
	CatchingUp          bool      `json:"catching_up"`
}

type ValidatorInfo added in v0.21.2

type ValidatorInfo struct {
	Address string `json:"address"`
	PubKey  struct {
		Type  string `json:"type"`
		Value string `json:"value"`
	} `json:"pub_key"`
	VotingPower string `json:"voting_power"`
}

Jump to

Keyboard shortcuts

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