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 deploy logic for Thanos receive ingest component #13

Merged
merged 13 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ go.work
*.swp
*.swo
*~

manager
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN go mod download
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/pkg/ internal/pkg/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
19 changes: 9 additions & 10 deletions api/v1alpha1/thanosreceive_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ type RouterSpec struct {
// Replicas is the number of router replicas.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
// +kubebuilder:validation:Optional
Replicas *int32 `json:"replicas,omitempty"`
// +kubebuilder:validation:Required
Copy link
Member

Choose a reason for hiding this comment

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

Do we need both default and required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think it works in terms of the openapi spec tbh

Replicas int32 `json:"replicas,omitempty"`
// ReplicationFactor is the replication factor for the router.
// +kubebuilder:default=1
// +kubebuilder:validation:Enum=1;3;5
// +kubebuilder:validation:Optional
ReplicationFactor *int32 `json:"replicationFactor,omitempty"`
// +kubebuilder:validation:Required
ReplicationFactor int32 `json:"replicationFactor,omitempty"`
}

// IngesterSpec represents the configuration for the ingestor
Expand All @@ -46,7 +46,7 @@ type IngesterSpec struct {
DefaultObjectStorageConfig ObjectStorageConfig `json:"defaultObjectStorageConfig,omitempty"`
// Hashrings is a list of hashrings to route to.
// +kubebuilder:validation:MaxItems=100
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Required
// +listType=map
// +listMapKey=name
Hashrings []IngestorHashringSpec `json:"hashrings,omitempty"`
Expand All @@ -59,12 +59,10 @@ type IngestorHashringSpec struct {
// By default, Name will be used as a prefix with the ThanosReceive name as a suffix separated by a hyphen.
// In cases where that name does not match the pattern below, i.e. the name is not a valid DNS-1123 subdomain,
// the Name will be used as is and must be unique within the namespace.
// This field is immutable.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
// +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"`
// 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.
Expand All @@ -73,8 +71,8 @@ type IngestorHashringSpec struct {
// Replicas is the number of replicas/members of the hashring to add to the Thanos Receive StatefulSet.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
// +kubebuilder:validation:Optional
Replicas *int32 `json:"replicas,omitempty"`
// +kubebuilder:validation:Required
Replicas int32 `json:"replicas,omitempty"`
// Retention is the duration for which the Thanos Receive StatefulSet will retain data.
// +kubebuilder:default="2h"
// +kubebuilder:validation:Optional
Expand All @@ -97,14 +95,15 @@ type IngestorHashringSpec struct {
}

// 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"
// +kubebuilder:validation:XValidation:rule="self.ingestor.hashrings.all(h, h.replicas >= self.router.replicationFactor )", 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"`
// Ingester is the configuration for the ingestor.
// +kubebuilder:validation:Required
Ingester IngesterSpec `json:"ingestor,omitempty"`
}

Expand Down
9 changes: 9 additions & 0 deletions api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
)

// Duration is a valid time duration that can be parsed by Prometheus model.ParseDuration() function.
Expand Down Expand Up @@ -50,3 +51,11 @@ type CommonThanosFields struct {
// +kubebuilder:default:=logfmt
LogFormat string `json:"logFormat,omitempty" opt:"log.format"`
}

func (osc *ObjectStorageConfig) ToSecretKeySelector() corev1.SecretKeySelector {
return corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: osc.Name},
Key: osc.Key,
Optional: ptr.To(false),
}
}
15 changes: 0 additions & 15 deletions api/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ func main() {
os.Exit(1)
}
if err = (&controller.ThanosReceiveReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("thanos-receive-ingest-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ThanosReceive")
os.Exit(1)
Expand Down
10 changes: 3 additions & 7 deletions config/crd/bases/monitoring.thanos.io_thanosreceives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ spec:
By default, Name will be used as a prefix with the ThanosReceive name as a suffix separated by a hyphen.
In cases where that name does not match the pattern below, i.e. the name is not a valid DNS-1123 subdomain,
the Name will be used as is and must be unique within the namespace.
This field is immutable.
maxLength: 253
minLength: 1
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
objectStorageConfig:
description: ObjectStorageConfig is the secret that contains
the object storage configuration for the hashring.
Expand Down Expand Up @@ -246,9 +242,9 @@ spec:
type: string
type: object
x-kubernetes-validations:
- message: Ingester replicas must be greater than or equal to the Router
replicas
rule: self.ingestor.hashrings.all(h, h.replicas >= self.router.replicas
- message: ' Ingester replicas must be greater than or equal to the Router
replicas'
rule: self.ingestor.hashrings.all(h, h.replicas >= self.router.replicationFactor
)
status:
description: Status defines the observed state of ThanosReceive
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ module github.com/thanos-community/thanos-operator
go 1.21

require (
github.com/go-logr/logr v1.4.1
github.com/imdario/mergo v0.3.16
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/prometheus/prometheus v0.52.1
github.com/stretchr/testify v1.9.0
k8s.io/api v0.29.3
k8s.io/apimachinery v0.29.3
k8s.io/client-go v0.29.3
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.17.0
)

Expand All @@ -19,7 +24,6 @@ require (
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
Expand All @@ -33,7 +37,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240416155748-26353dc0451f // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -47,7 +51,6 @@ require (
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
Expand All @@ -67,7 +70,6 @@ require (
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/google/pprof v0.0.0-20240416155748-26353dc0451f h1:WpZiq8iqvGjJ3m3wzA
github.com/google/pprof v0.0.0-20240416155748-26353dc0451f/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd h1:PpuIBO5P3e9hpqBD0O/HjhShYuM6XE0i/lbE6J94kww=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down Expand Up @@ -82,6 +84,8 @@ github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+a
github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/prometheus/prometheus v0.52.1 h1:BrQ29YG+mzdGh8DgHPirHbeMGNqtL+INe0rqg7ttBJ4=
github.com/prometheus/prometheus v0.52.1/go.mod h1:3z74cVsmVH0iXOR5QBjB7Pa6A0KJeEAK5A6UsmAFb1g=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
Loading
Loading