Documentation ¶
Index ¶
- Constants
- func IntersectPods(coll *StatusCollection, pods []corev1.Pod)
- func UpsertPod(coll *StatusCollection, pod *corev1.Pod)
- type CacheController
- func (c *CacheController) Close() error
- func (c *CacheController) Collect(ctx context.Context, controller client.ObjectKey) StatusCollection
- func (c *CacheController) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
- func (c *CacheController) SetupWithManager(_ context.Context, mgr ctrl.Manager) error
- func (c *CacheController) SyncedPods(ctx context.Context, controller client.ObjectKey) []*corev1.Pod
- type Collector
- type CometClient
- type CometStatus
- type StatusCollection
- type StatusCollector
- type StatusItem
- type Statuser
Constants ¶
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) SetupWithManager ¶ added in v0.15.0
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 `json:"jsonrpc"` ID int `json:"id"` Result struct { 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"` } `json:"node_info"` 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"` } `json:"sync_info"` ValidatorInfo struct { Address string `json:"address"` PubKey struct { Type string `json:"type"` Value string `json:"value"` } `json:"pub_key"` VotingPower string `json:"voting_power"` } `json:"validator_info"` } `json:"result"` }
CometStatus is the 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 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
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.