Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data_layer support #230

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@ resources:
kind: ChiaNetwork
path: github.com/chia-network/chia-operator/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: chia.net
group: k8s
kind: ChiaDataLayer
path: github.com/chia-network/chia-operator/api/v1
version: v1
version: "3"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Kubernetes operator for managing Chia components in kubernetes. Currently suppor
- introducers
- seeders
- crawlers
- data_layer

Easily run Chia components in Kubernetes by applying simple manifests. A whole farm can be ran with each component isolated in its own pod, with a chia-exporter sidecar to scrape Prometheus metrics.

Expand Down
60 changes: 28 additions & 32 deletions api/v1/chiacommon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,37 +237,6 @@ type AdditionalMetadata struct {
Annotations map[string]string `json:"annotations,omitempty"`
}

/*
Full storage config example:

storage:
chiaRoot:
// Only one of persistentVolumeClaim or hostPathVolume should be specified, persistentVolumeClaim will be preferred if both are specified
persistentVolumeClaim:
claimName: "chiaroot-data"
hostPathVolume:
path: "/home/user/storage/chiaroot"

plots:
persistentVolumeClaim:
- claimName: "plot1"
- claimName: "plot2"
hostPathVolume:
- path: "/home/user/storage/plots1"
- path: "/home/user/storage/plots2"
*/

// StorageConfig contains storage configuration settings
type StorageConfig struct {
// Storage configuration for CHIA_ROOT
// +optional
ChiaRoot *ChiaRootConfig `json:"chiaRoot,omitempty"`

// Storage configuration for harvester plots
// +optional
Plots *PlotsConfig `json:"plots,omitempty"`
}

// Service contains kubernetes Service related configuration options
type Service struct {
AdditionalMetadata `json:",inline"`
Expand Down Expand Up @@ -307,14 +276,29 @@ type Service struct {
RollIntoPeerService *bool `json:"rollIntoPeerService,omitempty"`
}

// StorageConfig contains storage configuration settings
type StorageConfig struct {
// Storage configuration for CHIA_ROOT
// +optional
ChiaRoot *ChiaRootConfig `json:"chiaRoot,omitempty"`

// Storage configuration for harvester plots
// +optional
Plots *PlotsConfig `json:"plots,omitempty"`

// Storage configuration for data_layer server files
// +optional
DataLayerServerFiles *DataLayerServerFilesConfig `json:"dataLayerServerFiles,omitempty"`
}

// ChiaRootConfig optional config for CHIA_ROOT persistent storage, likely only needed for Chia full_nodes, but may help in startup time for other components.
// Both options may be specified but only one can be used, therefore PersistentVolumeClaims will be respected over HostPath volumes if both are specified.
type ChiaRootConfig struct {
// PersistentVolumeClaim use an existing persistent volume claim to store CHIA_ROOT data
// +optional
PersistentVolumeClaim *PersistentVolumeClaimConfig `json:"persistentVolumeClaim,omitempty"`

// HostPathVolume use an existing persistent volume claim to store CHIA_ROOT data
// HostPathVolume use an existing directory on the host to store CHIA_ROOT data
// +optional
HostPathVolume *HostPathVolumeConfig `json:"hostPathVolume,omitempty"`
}
Expand All @@ -331,6 +315,18 @@ type PlotsConfig struct {
HostPathVolume []*HostPathVolumeConfig `json:"hostPathVolume,omitempty"`
}

// DataLayerServerFilesConfig optional config for data_layer server file persistent storage.
// Both options may be specified but only one can be used, therefore PersistentVolumeClaims will be respected over HostPath volumes if both are specified.
type DataLayerServerFilesConfig struct {
// PersistentVolumeClaim use an existing persistent volume claim to store server files
// +optional
PersistentVolumeClaim *PersistentVolumeClaimConfig `json:"persistentVolumeClaim,omitempty"`

// HostPathVolume use an existing directory on the host to store server files
// +optional
HostPathVolume *HostPathVolumeConfig `json:"hostPathVolume,omitempty"`
}

// PersistentVolumeClaimConfig config for PVC volumes in kubernetes
type PersistentVolumeClaimConfig struct {
// ClaimName is the name of an existing PersistentVolumeClaim in the target namespace
Expand Down
95 changes: 95 additions & 0 deletions api/v1/chiadatalayer_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2024 Chia Network Inc.
*/

package v1

import (
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ChiaDataLayerSpec defines the desired state of ChiaDataLayer
type ChiaDataLayerSpec struct {
CommonSpec `json:",inline"`

// ChiaConfig defines the configuration options available to Chia component containers
ChiaConfig ChiaDataLayerSpecChia `json:"chia"`

// DataLayerHTTPConfig defines the desired state of an optional data_layer_http sidecar
// +optional
DataLayerHTTPConfig ChiaDataLayerHTTPSpecChia `json:"dataLayerHTTP"`

// Strategy describes how to replace existing pods with new ones.
// +optional
Strategy *appsv1.DeploymentStrategy `json:"strategy,omitempty"`
}

// ChiaDataLayerSpecChia defines the desired state of Chia component configuration
type ChiaDataLayerSpecChia struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What settings would be valuable for this? Off the top of my head, it would be cool to be able to add or delete store IDs from the builtin wallet in the yaml config. But doing that I believe would likely require config sidecar be developed that runs alongside the data_layer container in the Pod and makes all the RPC requests for managing stores from the yaml config for a ChiaDatalayer resource.

Maybe there's another option? But I don't think using the chia-docker entrypoint script works as I believe the data_layer/wallet RPC needs to be up.

Copy link
Contributor Author

@Starttoaster Starttoaster Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go that far with developing the config sidecar, it may as well support all of the actions from https://docs.chia.net/guides/datalayer-user-guide/

Config sidecar will likely be developed after this PR. Just standing up the instance and managing the wallet manually by exec-ing into the chia container as a MVP.

CommonSpecChia `json:",inline"`

// CASecretName is the name of the secret that contains the CA crt and key.
// +optional
CASecretName *string `json:"caSecretName"`

// SecretKey defines the k8s Secret name and key for a Chia mnemonic
SecretKey ChiaSecretKey `json:"secretKey"`

// FullNodePeers is a list of hostnames/IPs and port numbers to full_node peers.
// Either fullNodePeer or fullNodePeers should be specified. fullNodePeers takes precedence.
// +optional
FullNodePeers *[]Peer `json:"fullNodePeers,omitempty"`

// TrustedCIDRs is a list of CIDRs that this chia component should trust peers from
// See: https://docs.chia.net/faq/?_highlight=trust#what-are-trusted-peers-and-how-do-i-add-them
// +optional
TrustedCIDRs *[]string `json:"trustedCIDRs,omitempty"`
}

// ChiaDataLayerHTTPSpecChia defines the desired state of an optional data_layer_http sidecar
// data_layer_http is a chia component, and therefore inherits most of the generic configuration options for any chia component
type ChiaDataLayerHTTPSpecChia struct {
CommonSpecChia `json:",inline"`

// Enabled defines whether a data_layer_http sidecar container should run as a sidecar to the chia container
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Service defines settings for the Service optionally installed with any data_layer_http resource.
// This Service will default to being enabled with a ClusterIP Service type if data_layer_http is enabled.
// +optional
Service Service `json:"service,omitempty"`
}

// ChiaDataLayerStatus defines the observed state of ChiaDataLayer
type ChiaDataLayerStatus struct {
// Ready says whether the chia component is ready, this should be true when the data_layer resource is in the target namespace
// +kubebuilder:default=false
Ready bool `json:"ready,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// ChiaDataLayer is the Schema for the chiadatalayers API
type ChiaDataLayer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ChiaDataLayerSpec `json:"spec,omitempty"`
Status ChiaDataLayerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ChiaDataLayerList contains a list of ChiaDataLayer
type ChiaDataLayerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ChiaDataLayer `json:"items"`
}

func init() {
SchemeBuilder.Register(&ChiaDataLayer{}, &ChiaDataLayerList{})
}
Loading
Loading