Skip to content

Commit

Permalink
Check in code
Browse files Browse the repository at this point in the history
  • Loading branch information
Starttoaster committed Jan 2, 2025
1 parent 83fb23f commit 1c5a0b5
Show file tree
Hide file tree
Showing 36 changed files with 1,138 additions and 57 deletions.
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
99 changes: 99 additions & 0 deletions api/v1/chiadatalayer_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
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
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 {
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
// +kubebuilder:default=true
// +optional
Enabled bool `json:"enabled,omitempty"`

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

// 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{})
}
89 changes: 89 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"flag"
"github.com/chia-network/chia-operator/internal/controller/chiadatalayer"
"os"

_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand All @@ -19,6 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

k8schianetv1 "github.com/chia-network/chia-operator/api/v1"
k8sv1 "github.com/chia-network/chia-operator/api/v1"
"github.com/chia-network/chia-operator/internal/controller/chiaca"
"github.com/chia-network/chia-operator/internal/controller/chiacrawler"
"github.com/chia-network/chia-operator/internal/controller/chiafarmer"
Expand All @@ -41,6 +43,7 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(k8schianetv1.AddToScheme(scheme))
utilruntime.Must(k8sv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down Expand Up @@ -164,6 +167,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ChiaNetwork")
os.Exit(1)
}
if err = (&chiadatalayer.ChiaDataLayerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("chiadatalayer-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ChiaDataLayer")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resources:
- bases/k8s.chia.net_chiaintroducers.yaml
- bases/k8s.chia.net_chiacrawlers.yaml
- bases/k8s.chia.net_chianetworks.yaml
- bases/k8s.chia.net_chiadatalayers.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -36,6 +37,7 @@ patchesStrategicMerge:
#- path: patches/cainjection_in_chiaintroducers.yaml
#- path: patches/cainjection_in_chiacrawlers.yaml
#- path: patches/cainjection_in_chianetworks.yaml
#- path: patches/cainjection_in_chiadatalayers.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
2 changes: 1 addition & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namePrefix: chia-operator-
# someName: someValue

resources:
#- ../crd # Commented to avoid `make release` building the CRDs into the manager manifests
- ../crd # Commented to avoid `make release` building the CRDs into the manager manifests
- ../rbac
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
Expand Down
27 changes: 27 additions & 0 deletions config/rbac/chiadatalayer_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit chiadatalayers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: chia-operator
app.kubernetes.io/managed-by: kustomize
name: chiadatalayer-editor-role
rules:
- apiGroups:
- k8s.chia.net
resources:
- chiadatalayers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- k8s.chia.net
resources:
- chiadatalayers/status
verbs:
- get
Loading

0 comments on commit 1c5a0b5

Please sign in to comment.