Skip to content

Commit

Permalink
spec: Update spec for receive/compact (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgough authored Jun 17, 2024
1 parent 1cfd505 commit 786a4f7
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 134 deletions.
22 changes: 6 additions & 16 deletions api/v1alpha1/thanoscompact_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

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

Expand All @@ -38,10 +37,9 @@ const (
type ThanosCompactSpec struct {
// CommonThanosFields are the options available to all Thanos components.
CommonThanosFields `json:",inline"`
// ObjectStorageConfig is the secret's key that contains the object storage configuration.
// The secret needs to be in the same namespace as the ThanosCompact object.
// ObjectStorageConfig is the object storage configuration for the compact component.
// +kubebuilder:validation:Required
ObjectStorageConfig corev1.SecretKeySelector `json:"objectStorageConfig"`
ObjectStorageConfig *ObjectStorageConfig `json:"objectStorageConfig,omitempty"`
// RetentionConfig is the retention configuration for the compact component.
// +kubebuilder:validation:Required
RetentionConfig RetentionResolutionConfig `json:"retentionConfig,omitempty"`
Expand All @@ -53,7 +51,7 @@ type ThanosCompactSpec struct {
GroupConfig GroupConfig `json:"groupConfig,omitempty"`
// ShardingConfig is the sharding configuration for the compact component.
// +kubebuilder:validation:Optional
ShardingConfig ShardingConfig `json:"shardingConfig,omitempty"`
ShardingConfig *ShardingConfig `json:"shardingConfig,omitempty"`
}

// ThanosCompactStatus defines the observed state of ThanosCompact
Expand Down Expand Up @@ -164,17 +162,9 @@ type ShardingConfig struct {
}

// ExternalLabelShardingConfig defines the sharding configuration based on explicit external labels and their values.
type ExternalLabelShardingConfig struct {
// ExternalLabel is the external label to shard on.
// This label must be present in the block's metadata.
// +kubebuilder:validation:Required
ExternalLabel string `json:"externalLabel,omitempty"`
// Values is the list of values (as a regular expression) to shard on.
// Each value will be a configured and deployed as a separate compact component.
// +kubebuilder:default=".*"
// +kubebuilder:validation:Optional
Values []string `json:"values,omitempty"`
}
// The keys are the external labels to shard on and the values are the values (as regular expressions) to shard on.
// Each value will be a configured and deployed as a separate compact component.
type ExternalLabelShardingConfig map[string]string

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
Expand Down
71 changes: 30 additions & 41 deletions api/v1alpha1/thanosreceive_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,9 @@ limitations under the License.
package v1alpha1

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

// TenantMatcher represents the type of tenant matching to use.
type TenantMatcher string

const (
// TenantMatcherTypeExact matches tenants exactly. This is also the default one.
TenantMatcherTypeExact TenantMatcher = "exact"
// TenantMatcherGlob matches tenants using glob patterns.
TenantMatcherGlob TenantMatcher = "glob"
)

// HashringAlgorithm represents the hashing algorithm to use.
type HashringAlgorithm string

const (
// AlgorithmKetama is the ketama hashing algorithm.
AlgorithmKetama HashringAlgorithm = "ketama"
)

// RouterSpec represents the configuration for the router
type RouterSpec struct {
// Labels are additional labels to add to the router components.
Expand All @@ -47,23 +28,27 @@ type RouterSpec struct {
Labels map[string]string `json:"labels,omitempty"`
// Replicas is the number of router replicas.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Required
// +kubebuilder:default=1
// +kubebuilder:validation:Optional
Replicas *int32 `json:"replicas,omitempty"`
// ReplicationFactor is the replication factor for the router.
// +kubebuilder:validation:Default=1
// +kubebuilder:default=1
// +kubebuilder:validation:Enum=1;3;5
// +kubebuilder:validation:Required
// +kubebuilder:validation:Optional
ReplicationFactor *int32 `json:"replicationFactor,omitempty"`
}

// IngestorSpec represents the configuration for the ingestor
type IngestorSpec struct {
// ObjectStorageConfig is the secret's key that contains the object storage configuration.
// The secret needs to be in the same namespace as the ReceiveHashring object.
// Can be overridden by the ObjectStorageConfig in the IngestorHashringSpec.
// +kubebuilder:validation:Optional
ObjectStorageConfig corev1.SecretKeySelector `json:"objectStorageConfig"`
// IngesterSpec represents the configuration for the ingestor
type IngesterSpec struct {
// DefaultObjectStorageConfig is the secret that contains the object storage configuration for the ingest components.
// Can be overridden by the ObjectStorageConfig in the IngestorHashringSpec per hashring.
// +kubebuilder:validation:Required
DefaultObjectStorageConfig ObjectStorageConfig `json:"defaultObjectStorageConfig,omitempty"`
// Hashrings is a list of hashrings to route to.
// +kubebuilder:validation:MaxItems=100
// +kubebuilder:validation:Optional
// +listType=map
// +listMapKey=name
Hashrings []IngestorHashringSpec `json:"hashrings,omitempty"`
}

Expand All @@ -80,45 +65,47 @@ type IngestorHashringSpec struct {
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="Value is immutable"
Name string `json:"name,omitempty"`
Name string `json:"name"`
// Labels are additional labels to add to the hashring components.
// Labels set here will overwrite the labels inherited from the ThanosReceive object if they have the same key.
// +kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`
// Replicas is the number of replicas/members of the hashring to add to the Thanos Receive StatefulSet.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Required
// +kubebuilder:default=1
// +kubebuilder:validation:Optional
Replicas *int32 `json:"replicas,omitempty"`
// Retention is the duration for which the Thanos Receive StatefulSet will retain data.
// +kubebuilder:default="2h"
// +kubebuilder:validation:Required
Retention Duration `json:"retention,omitempty"`
// ObjectStorageConfig is the secret's key that contains the object storage configuration.
// The secret needs to be in the same namespace as the ReceiveHashring object.
// +kubebuilder:validation:Optional
ObjectStorageConfig corev1.SecretKeySelector `json:"objectStorageConfig"`
Retention *Duration `json:"retention,omitempty"`
// ObjectStorageConfig is the secret that contains the object storage configuration for the hashring.
// +kubebuilder:validation:Optional
ObjectStorageConfig *ObjectStorageConfig `json:"objectStorageConfig,omitempty"`
// StorageSize is the size of the storage to be used by the Thanos Receive StatefulSet.
// +kubebuilder:validation:Required
StorageSize *string `json:"storageSize,omitempty"`
// +kubebuilder:validation:Pattern=`^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$`
StorageSize string `json:"storageSize"`
// Tenants is a list of tenants that should be matched by the hashring.
// An empty list matches all tenants.
// +kubebuilder:validation:Optional
Tenants []string `json:"tenants,omitempty"`
// TenantMatcherType is the type of tenant matching to use.
// +kubebuilder:default:="exact"
// +kubebuilder:validation:Enum=exact;glob
TenantMatcherType TenantMatcher `json:"tenantMatcherType,omitempty"`
TenantMatcherType string `json:"tenantMatcherType,omitempty"`
}

// ThanosReceiveSpec defines the desired state of ThanosReceive
// +kubebuilder:validation:XValidation:rule="self.ingestor.hashrings.all(h, h.replicas >= self.router.replicas )", message="Ingester replicas must be greater than or equal to the Router replicas"
type ThanosReceiveSpec struct {
// CommonThanosFields are the options available to all Thanos components.
CommonThanosFields `json:",inline"`
// Router is the configuration for the router.
// +kubebuilder:validation:Required
Router RouterSpec `json:"router,omitempty"`
// Ingestor is the configuration for the ingestor.
Ingestor IngestorSpec `json:"ingestor,omitempty"`
// Ingester is the configuration for the ingestor.
Ingester IngesterSpec `json:"ingestor,omitempty"`
}

// ThanosReceiveStatus defines the observed state of ThanosReceive
Expand All @@ -135,7 +122,9 @@ type ThanosReceive struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ThanosReceiveSpec `json:"spec,omitempty"`
// Spec defines the desired state of ThanosReceive
Spec ThanosReceiveSpec `json:"spec,omitempty"`
// Status defines the observed state of ThanosReceive
Status ThanosReceiveStatus `json:"status,omitempty"`
}

Expand Down
13 changes: 9 additions & 4 deletions api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import (
// +kubebuilder:validation:Pattern:="^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$"
type Duration string

// ObjectStorageConfig is the secret that contains the object storage configuration.
// The secret needs to be in the same namespace as the ReceiveHashring object.
// See https://thanos.io/tip/thanos/storage.md/#supported-clients for relevant documentation.
type ObjectStorageConfig corev1.SecretKeySelector

// CommonThanosFields are the options available to all Thanos components.
// +k8s:deepcopy-gen=true
type CommonThanosFields struct {
// Version of Thanos to be deployed.
// If not specified, the operator assumes the latest upstream version of
// Thanos available at the time when the version of the operator was
// released.
Version string `json:"version,omitempty"`
// Thanos available at the time when the version of the operator was released.
// +kubebuilder:validation:Optional
Version *string `json:"version,omitempty"`
// Container image to use for the Thanos components.
// +optional
// +kubebuilder:validation:Optional
Image *string `json:"image,omitempty"`

// Image pull policy for the Thanos containers.
Expand Down
Loading

0 comments on commit 786a4f7

Please sign in to comment.