fullnode

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildConfigMaps

func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers, nodeKeys NodeKeys) ([]diff.Resource[*corev1.ConfigMap], error)

BuildConfigMaps creates a ConfigMap with configuration to be mounted as files into containers. Currently, the config.toml (for Comet), app.toml (for the Cosmos SDK) and node_key.json.

func BuildPVCs

func BuildPVCs(
	crd *cosmosv1.CosmosFullNode,
	dataSources map[int32]*dataSource,
	currentPVCs []*corev1.PersistentVolumeClaim,
) []diff.Resource[*corev1.PersistentVolumeClaim]

BuildPVCs outputs desired PVCs given the crd.

func BuildPods

func BuildPods(crd *cosmosv1.CosmosFullNode, cksums ConfigChecksums) ([]diff.Resource[*corev1.Pod], error)

BuildPods creates the final state of pods given the crd.

func BuildRoleBindings added in v0.20.0

func BuildRoleBindings(crd *cosmosv1.CosmosFullNode) []diff.Resource[*rbacv1.RoleBinding]

BuildRoleBindings returns a list of role binding bindings given the crd.

Creates a single role binding binding for the version check.

func BuildRoles added in v0.20.0

func BuildRoles(crd *cosmosv1.CosmosFullNode) []diff.Resource[*rbacv1.Role]

BuildRoles returns a list of role bindings given the crd.

Creates a single role binding for the version check.

func BuildServiceAccounts added in v0.20.0

func BuildServiceAccounts(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.ServiceAccount]

BuildServiceAccounts returns a list of service accounts given the crd.

Creates a single service account for the version check.

func BuildServices

func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service]

BuildServices returns a list of services given the crd.

Creates services based on the node type: - For regular nodes: Creates 1 RPC service and 1 p2p service per pod (replicas + 1 total) - For sentry nodes: Creates 1 RPC service and 2 p2p services per pod (replicas * 2 + 1 total)

P2P services diverge from traditional web and kubernetes architecture which typically uses a single service backed by multiple pods. This is necessary because:

  1. Pods may be in various states even with proper readiness probes
  2. We need to prevent confusion or disruption in peer exchange (PEX) within CometBFT
  3. Using a single p2p service could lead to misinterpreted byzantine behavior if an outside peer discovers a pod out of sync after previously connecting to a synced pod through the same address

Services are created with either LoadBalancer (for external access) or ClusterIP type, controlled by MaxP2PExternalAddresses setting.

func ChainHomeDir added in v0.9.1

func ChainHomeDir(crd *cosmosv1.CosmosFullNode) string

ChainHomeDir is the abs filepath for the chain's home directory.

func DownloadAddrbookCommand added in v0.18.0

func DownloadAddrbookCommand(cfg cosmosv1.ChainSpec) (string, []string)

DownloadAddrbookCommand returns a proper address book command for use in an init container.

func DownloadGenesisCommand

func DownloadGenesisCommand(cfg cosmosv1.ChainSpec) (string, []string)

DownloadGenesisCommand returns a proper genesis command for use in an init container.

The general strategy is if the user does not configure an external genesis file, use the genesis from the <chain-binary> init command. If the user supplies a custom script, we use that. Otherwise, we use attempt to download and extract the file.

func DownloadSnapshotCommand

func DownloadSnapshotCommand(cfg cosmosv1.ChainSpec) (string, []string)

DownloadSnapshotCommand returns a command and args for downloading and restoring from a snapshot.

func PVCName

func PVCName(pod *corev1.Pod) string

PVCName returns the primary PVC holding the chain data associated with the pod.

func ResetStatus

func ResetStatus(crd *cosmosv1.CosmosFullNode)

ResetStatus is used at the beginning of the reconcile loop. It resets the crd's status to a fresh state.

func SyncInfoStatus added in v0.15.0

func SyncInfoStatus(
	ctx context.Context,
	crd *cosmosv1.CosmosFullNode,
	collector StatusCollector,
) map[string]*cosmosv1.SyncInfoPodStatus

SyncInfoStatus returns the status of the full node's sync info.

Types

type CacheInvalidator added in v0.20.0

type CacheInvalidator interface {
	Invalidate(controller client.ObjectKey, pods []string)
}

type Client

type Client interface {
	client.Reader
	client.Writer

	Scheme() *runtime.Scheme
}

Client is a controller client. It is a subset of client.Client.

type ConfigChecksums added in v0.12.0

type ConfigChecksums map[client.ObjectKey]string

type ConfigMapControl

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

ConfigMapControl creates or updates configmaps.

func NewConfigMapControl

func NewConfigMapControl(client Client) ConfigMapControl

NewConfigMapControl returns a valid ConfigMapControl.

func (ConfigMapControl) Reconcile

Reconcile creates or updates configmaps containing items that are mounted into pods as files. The ConfigMap is never deleted unless the CRD itself is deleted.

type DiskUsageCollector added in v0.10.0

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

func NewDiskUsageCollector added in v0.10.0

func NewDiskUsageCollector(diskClient DiskUsager, lister Reader) *DiskUsageCollector

func (DiskUsageCollector) CollectDiskUsage added in v0.10.0

func (c DiskUsageCollector) CollectDiskUsage(ctx context.Context, crd *cosmosv1.CosmosFullNode) ([]PVCDiskUsage, error)

CollectDiskUsage retrieves the disk usage information for all pods belonging to the specified CosmosFullNode.

It returns a slice of PVCDiskUsage objects representing the disk usage information for each PVC or an error if fetching disk usage via all pods was unsuccessful.

type DiskUsager added in v0.10.0

type DiskUsager interface {
	DiskUsage(ctx context.Context, host, homeDir string) (healthcheck.DiskUsageResponse, error)
}

DiskUsager fetches disk usage statistics

type DriftDetection added in v0.15.0

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

DriftDetection detects pods that are lagging behind the latest block height.

func NewDriftDetection added in v0.15.0

func NewDriftDetection(collector StatusCollector) DriftDetection

func (DriftDetection) LaggingPods added in v0.15.0

func (d DriftDetection) LaggingPods(ctx context.Context, crd *cosmosv1.CosmosFullNode) []*corev1.Pod

LaggingPods returns pods that are lagging behind the latest block height.

type Getter added in v0.13.0

type Getter interface {
	Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
}

type Lister

type Lister interface {
	List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}

Lister can list resources, subset of client.Client.

type NodeKey added in v0.21.0

type NodeKey struct {
	PrivKey NodeKeyPrivKey `json:"priv_key"`
}

func (NodeKey) ID added in v0.21.0

func (nk NodeKey) ID() string

type NodeKeyCollector added in v0.24.1

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

NodeKeyCollector finds and collects node key information.

func NewNodeKeyCollector added in v0.24.1

func NewNodeKeyCollector(client Client) *NodeKeyCollector

func (NodeKeyCollector) Collect added in v0.24.1

Collect node key information given the crd.

type NodeKeyPrivKey added in v0.21.0

type NodeKeyPrivKey struct {
	Type  string             `json:"type"`
	Value ed25519.PrivateKey `json:"value"`
}

type NodeKeyRepresenter added in v0.24.1

type NodeKeyRepresenter struct {
	NodeKey          NodeKey
	MarshaledNodeKey []byte
}

NodeKeyRepresenter represents a NodeKey and its marshaled form. Since NodeKeys can be pulled from ConfigMaps, we store the marshaled form to avoid re-marshaling during ConfigMap creation.

type NodeKeys added in v0.24.1

type NodeKeys map[client.ObjectKey]NodeKeyRepresenter

Namespace maps an ObjectKey using the instance name to NodeKey.

type PVCAutoScaler added in v0.10.0

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

func NewPVCAutoScaler added in v0.10.0

func NewPVCAutoScaler(client StatusSyncer) *PVCAutoScaler

func (PVCAutoScaler) SignalPVCResize added in v0.10.0

func (scaler PVCAutoScaler) SignalPVCResize(ctx context.Context, crd *cosmosv1.CosmosFullNode, results []PVCDiskUsage) (bool, error)

SignalPVCResize patches the CosmosFullNode.status.selfHealing with the new calculated PVC size as a resource quantity. Assumes CosmosfullNode.spec.selfHealing.pvcAutoScaling is set or else this method may panic. The CosmosFullNode controller is responsible for increasing the PVC disk size.

Returns true if the status was patched.

Returns false and does not patch if: 1. The PVCs do not need resizing 2. The status already has >= calculated size. 3. The maximum size has been reached. It will patch up to the maximum size.

Returns an error if patching unsuccessful.

type PVCControl

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

PVCControl reconciles volumes for a CosmosFullNode. Unlike StatefulSet, PVCControl will update volumes by deleting and recreating volumes.

func NewPVCControl

func NewPVCControl(client Client) PVCControl

NewPVCControl returns a valid PVCControl

func (PVCControl) Reconcile

func (control PVCControl) Reconcile(ctx context.Context, reporter kube.Reporter, crd *cosmosv1.CosmosFullNode, pvcStatusChanges *PVCStatusChanges) (bool, kube.ReconcileError)

Reconcile is the control loop for PVCs. The bool return value, if true, indicates the controller should requeue the request.

type PVCDiskUsage added in v0.10.0

type PVCDiskUsage struct {
	Name        string // pvc name
	PercentUsed int
	Capacity    resource.Quantity
}

type PVCStatusChanges added in v0.20.0

type PVCStatusChanges struct {
	Deleted []string
}

type Peer added in v0.13.0

type Peer struct {
	P2PPort         int32
	NodeID          string
	PrivateAddress  string // Only the private address my-service.namespace.svc.cluster.local:<port>
	ExternalAddress string // Only the address <external-ip-or-hostname>:<port>. Not all peers will be external.
	// contains filtered or unexported fields
}

Peer contains information about a peer.

func (Peer) ExternalPeer added in v0.13.0

func (peer Peer) ExternalPeer() string

ExternalPeer returns the full external address of the peer in the format <node_id>@<external_address>:<port>.

func (Peer) PrivatePeer added in v0.13.0

func (peer Peer) PrivatePeer() string

PrivatePeer returns the full private identifier of the peer in the format <node_id>@<private_address>:<port>.

type PeerCollector added in v0.12.0

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

PeerCollector finds and collects peer information.

func NewPeerCollector added in v0.12.0

func NewPeerCollector(client Getter) *PeerCollector

func (PeerCollector) Collect added in v0.13.0

Collect peer information given the crd.

type Peers added in v0.13.0

type Peers map[client.ObjectKey]Peer

Peers maps an ObjectKey using the instance name to Peer.

func (Peers) AllExternal added in v0.13.0

func (peers Peers) AllExternal() []string

AllExternal returns a sorted list of all external peers in the format <node_id>@<external_address>:<port>.

func (Peers) AllPrivate added in v0.13.0

func (peers Peers) AllPrivate() []string

AllPrivate returns a sorted list of all private peers in the format <node_id>@<private_address>:<port>.

func (Peers) Default added in v0.13.0

func (peers Peers) Default() Peers

func (Peers) Except added in v0.13.0

func (peers Peers) Except(name, namespace string) Peers

Except returns a copy of the peers without the Peer for the given name and namespace.

func (Peers) Get added in v0.13.0

func (peers Peers) Get(name, namespace string) Peer

Get is a convenience getter.

func (Peers) HasIncompleteExternalAddress added in v0.13.0

func (peers Peers) HasIncompleteExternalAddress() bool

HasIncompleteExternalAddress returns true if any peer has an external address but it is not assigned yet.

func (Peers) NodeIDs added in v0.13.0

func (peers Peers) NodeIDs() []string

NodeIDs returns a sorted list of all node IDs.

type PodBuilder

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

PodBuilder builds corev1.Pods

func NewPodBuilder

func NewPodBuilder(crd *cosmosv1.CosmosFullNode) PodBuilder

NewPodBuilder returns a valid PodBuilder.

Panics if any argument is nil.

func (PodBuilder) Build

func (b PodBuilder) Build() (*corev1.Pod, error)

Build assigns the CosmosFullNode crd as the owner and returns a fully constructed pod.

func (PodBuilder) WithOrdinal

func (b PodBuilder) WithOrdinal(ordinal int32) PodBuilder

WithOrdinal updates adds name and other metadata to the pod using "ordinal" which is the pod's ordered sequence. Pods have deterministic, consistent names similar to a StatefulSet instead of generated names.

type PodControl

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

PodControl reconciles pods for a CosmosFullNode.

func NewPodControl

func NewPodControl(client Client, cacheInvalidator CacheInvalidator) PodControl

NewPodControl returns a valid PodControl.

func (PodControl) Reconcile

func (pc PodControl) Reconcile(
	ctx context.Context,
	reporter kube.Reporter,
	crd *cosmosv1.CosmosFullNode,
	cksums ConfigChecksums,
	syncInfo map[string]*cosmosv1.SyncInfoPodStatus,
) (bool, kube.ReconcileError)

Reconcile is the control loop for pods. The bool return value, if true, indicates the controller should requeue the request.

type Reader added in v0.10.0

type Reader = client.Reader

Reader lists and gets objects.

type RoleBindingControl added in v0.20.0

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

RoleBindingControl creates or updates RoleBindings.

func NewRoleBindingControl added in v0.20.0

func NewRoleBindingControl(client Client) RoleBindingControl

func (RoleBindingControl) Reconcile added in v0.20.0

Reconcile creates or updates role bindings.

type RoleControl added in v0.20.0

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

RoleControl creates or updates Roles.

func NewRoleControl added in v0.20.0

func NewRoleControl(client Client) RoleControl

func (RoleControl) Reconcile added in v0.20.0

Reconcile creates or updates roles.

type ServiceAccountControl added in v0.20.0

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

ServiceControl creates or updates Services.

func NewServiceAccountControl added in v0.20.0

func NewServiceAccountControl(client Client) ServiceAccountControl

func (ServiceAccountControl) Reconcile added in v0.20.0

Reconcile creates or updates service accounts.

type ServiceControl

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

ServiceControl creates or updates Services.

func NewServiceControl

func NewServiceControl(client Client) ServiceControl

func (ServiceControl) Reconcile

Reconcile creates or updates services. Some services, like P2P, reserve public addresses of which should not change. Therefore, services are never deleted unless the CRD itself is deleted.

type StatusClient added in v0.10.0

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

func NewStatusClient added in v0.10.0

func NewStatusClient(c client.Client) *StatusClient

func (*StatusClient) SyncUpdate added in v0.10.0

func (client *StatusClient) SyncUpdate(ctx context.Context, key client.ObjectKey, update func(status *cosmosv1.FullNodeStatus)) error

SyncUpdate synchronizes updates to a CosmosFullNode's status subresource per client.ObjectKey. There are several controllers that update a fullnode's status to signal the fullnode controller to take action and update the cluster state.

This method minimizes accidentally overwriting status fields by several actors.

Server-side-apply, in theory, would be a solution. During testing, however, it resulted in many conflict errors and would require non-trivial migration to clear existing deployment's metadata.managedFields.

type StatusCollector added in v0.15.0

type StatusCollector interface {
	Collect(ctx context.Context, controller client.ObjectKey) cosmos.StatusCollection
}

type StatusPatcher added in v0.10.0

type StatusPatcher interface {
	Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
}

StatusPatcher patches the status subresource of a resource.

type StatusSyncer added in v0.10.0

type StatusSyncer interface {
	SyncUpdate(ctx context.Context, key client.ObjectKey, update func(status *cosmosv1.FullNodeStatus)) error
}

Jump to

Keyboard shortcuts

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