Skip to content

Commit

Permalink
Update APIs to use common reuse structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Starttoaster committed Dec 17, 2023
1 parent 9aa34f7 commit dbb3dc1
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 553 deletions.
31 changes: 31 additions & 0 deletions api/v1/chiacommon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ package v1

import corev1 "k8s.io/api/core/v1"

// CommonSpec represents the common configuration options for controller APIs at the top-spec level
type CommonSpec struct {
AdditionalMetadata `json:",inline"`

// ChiaExporterConfig defines the configuration options available to Chia component containers
// +optional
ChiaExporterConfig ChiaExporterConfigSpec `json:"chiaExporter,omitempty"`

//StorageConfig defines the Chia container's CHIA_ROOT storage config
// +optional
Storage *StorageConfig `json:"storage,omitempty"`

// ServiceType is the type of the service that governs this ChiaNode StatefulSet.
// +optional
// +kubebuilder:default="ClusterIP"
ServiceType string `json:"serviceType,omitempty"`

// ImagePullPolicy is the pull policy for containers in the pod
// +optional
// +kubebuilder:default="Always"
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// NodeSelector selects a node by key value pairs
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// PodSecurityContext defines the security context for the pod
// +optional
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
}

// CommonChiaConfigSpec represents the common configuration options for a chia spec
type CommonChiaConfigSpec struct {
// Image defines the image to use for the chia component containers
Expand Down
29 changes: 1 addition & 28 deletions api/v1/chiafarmer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,15 @@ Copyright 2023 Chia Network Inc.
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ChiaFarmerSpec defines the desired state of ChiaFarmer
type ChiaFarmerSpec struct {
AdditionalMetadata `json:",inline"`
CommonSpec `json:",inline"`

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

// ChiaExporterConfig defines the configuration options available to Chia component containers
// +optional
ChiaExporterConfig ChiaExporterConfigSpec `json:"chiaExporter,omitempty"`

//StorageConfig defines the Chia container's CHIA_ROOT storage config
// +optional
Storage *StorageConfig `json:"storage,omitempty"`

// ServiceType is the type of the service for the farmer instance
// +optional
// +kubebuilder:default="ClusterIP"
ServiceType string `json:"serviceType"`

// ImagePullPolicy is the pull policy for containers in the pod
// +optional
// +kubebuilder:default="Always"
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// NodeSelector selects a node by key value pairs
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// PodSecurityContext defines the security context for the pod
// +optional
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
}

// ChiaFarmerConfigSpec defines the desired state of Chia component configuration
Expand Down
69 changes: 2 additions & 67 deletions api/v1/chiaharvester_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,24 @@ Copyright 2023 Chia Network Inc.
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ChiaHarvesterSpec defines the desired state of ChiaHarvester
type ChiaHarvesterSpec struct {
AdditionalMetadata `json:",inline"`
CommonSpec `json:",inline"`

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

// ChiaExporterConfig defines the configuration options available to Chia component containers
// +optional
ChiaExporterConfig ChiaExporterConfigSpec `json:"chiaExporter,omitempty"`

//StorageConfig defines the Chia container's CHIA_ROOT storage config
// +optional
Storage *StorageConfig `json:"storage,omitempty"`

// ServiceType is the type of the service for the harvester instance
// +optional
// +kubebuilder:default="ClusterIP"
ServiceType string `json:"serviceType"`

// ImagePullPolicy is the pull policy for containers in the pod
// +optional
// +kubebuilder:default="Always"
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// NodeSelector selects a node by key value pairs
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// PodSecurityContext defines the security context for the pod
// +optional
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
}

// ChiaHarvesterConfigSpec defines the desired state of Chia component configuration
type ChiaHarvesterConfigSpec struct {
// CASecretName is the name of the secret that contains the CA crt and key.
CASecretName string `json:"caSecretName"`
CommonChiaConfigSpec `json:",inline"`

// FarmerAddress defines the harvester's farmer peer's hostname. The farmer's port is inferred.
// In Kubernetes this is likely to be <farmer service name>.<namespace>.svc.cluster.local
FarmerAddress string `json:"farmerAddress"`

// Testnet is set to true if the Chia container should switch to the latest default testnet's settings
// +optional
Testnet *bool `json:"testnet,omitempty"`

// LogLevel is set to the desired chia config log_level
// +optional
LogLevel *string `json:"logLevel,omitempty"`

// Timezone can be set to your local timezone for accurate timestamps. Defaults to UTC
// +optional
Timezone *string `json:"timezone,omitempty"`

// Image defines the image to use for the chia component containers
// +kubebuilder:default="ghcr.io/chia-network/chia:latest"
// +optional
Image string `json:"image"`

// Periodic probe of container liveness.
// +optional
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`

// Periodic probe of container service readiness.
// +optional
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`

// StartupProbe indicates that the Pod has successfully initialized.
// +optional
StartupProbe *corev1.Probe `json:"startupProbe,omitempty"`

// Resources defines the compute resources for the Chia container
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`

// SecurityContext defines the security context for the chia container
// +optional
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}

// ChiaHarvesterStatus defines the observed state of ChiaHarvester
Expand Down
29 changes: 1 addition & 28 deletions api/v1/chianode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,20 @@ Copyright 2023 Chia Network Inc.
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ChiaNodeSpec defines the desired state of ChiaNode
type ChiaNodeSpec struct {
AdditionalMetadata `json:",inline"`
CommonSpec `json:",inline"`

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

// ChiaExporterConfig defines the configuration options available to Chia component containers
// +optional
ChiaExporterConfig ChiaExporterConfigSpec `json:"chiaExporter,omitempty"`

//StorageConfig defines the Chia container's CHIA_ROOT storage config
// +optional
Storage *StorageConfig `json:"storage,omitempty"`

// ServiceType is the type of the service that governs this ChiaNode StatefulSet.
// +optional
// +kubebuilder:default="ClusterIP"
ServiceType string `json:"serviceType"`

// ImagePullPolicy is the pull policy for containers in the pod
// +optional
// +kubebuilder:default="Always"
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// Replicas is the desired number of replicas of the given Statefulset. defaults to 1.
// +optional
// +kubebuilder:default=1
Replicas int32 `json:"replicas,omitempty"`

// NodeSelector selects a node by key value pairs
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// PodSecurityContext defines the security context for the pod
// +optional
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
}

// ChiaConfigSpec defines the desired state of Chia component configuration
Expand Down
69 changes: 2 additions & 67 deletions api/v1/chiatimelord_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,24 @@ Copyright 2023 Chia Network Inc.
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ChiaTimelordSpec defines the desired state of ChiaTimelord
type ChiaTimelordSpec struct {
AdditionalMetadata `json:",inline"`
CommonSpec `json:",inline"`

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

// ChiaExporterConfig defines the configuration options available to Chia component containers
// +optional
ChiaExporterConfig ChiaExporterConfigSpec `json:"chiaExporter"`

//StorageConfig defines the Chia container's CHIA_ROOT storage config
// +optional
Storage *StorageConfig `json:"storage,omitempty"`

// ServiceType is the type of the service for the timelord instance
// +optional
// +kubebuilder:default="ClusterIP"
ServiceType string `json:"serviceType"`

// ImagePullPolicy is the pull policy for containers in the pod
// +optional
// +kubebuilder:default="Always"
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// NodeSelector selects a node by key value pairs
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// PodSecurityContext defines the security context for the pod
// +optional
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
}

// ChiaTimelordConfigSpec defines the desired state of Chia component configuration
type ChiaTimelordConfigSpec struct {
// CASecretName is the name of the secret that contains the CA crt and key.
CASecretName string `json:"caSecretName"`
CommonChiaConfigSpec `json:",inline"`

// FullNodePeer defines the timelord's full_node peer in host:port format.
// In Kubernetes this is likely to be <node service name>.<namespace>.svc.cluster.local:8555
FullNodePeer string `json:"fullNodePeer"`

// Testnet is set to true if the Chia container should switch to the latest default testnet's settings
// +optional
Testnet *bool `json:"testnet,omitempty"`

// LogLevel is set to the desired chia config log_level
// +optional
LogLevel *string `json:"logLevel,omitempty"`

// Timezone can be set to your local timezone for accurate timestamps. Defaults to UTC
// +optional
Timezone *string `json:"timezone,omitempty"`

// Image defines the image to use for the chia component containers
// +kubebuilder:default="ghcr.io/chia-network/chia:latest"
// +optional
Image string `json:"image"`

// Periodic probe of container liveness.
// +optional
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`

// Periodic probe of container service readiness.
// +optional
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`

// StartupProbe indicates that the Pod has successfully initialized.
// +optional
StartupProbe *corev1.Probe `json:"startupProbe,omitempty"`

// Resources defines the compute resources for the Chia container
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`

// SecurityContext defines the security context for the chia container
// +optional
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}

// ChiaTimelordStatus defines the observed state of ChiaTimelord
Expand Down
Loading

0 comments on commit dbb3dc1

Please sign in to comment.