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 PodMonitors to configure Prometheus how to monitor Redis and Sentinel pods #624

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
kubernetes-version: ${{ matrix.kubernetes }}
minikube-version: 1.28.0
driver: none
- name: Add PodMonitor CRD
run: curl 'https://raw.githubusercontent.com/prometheus-community/helm-charts/prometheus-operator-crds-4.0.2/charts/kube-prometheus-stack/crds/crd-podmonitors.yaml' | kubectl create -f -
- name: Add redisfailover CRD
run: kubectl create -f manifests/databases.spotahome.com_redisfailovers.yaml
- run: make ci-integration-test
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,4 @@ generate-crd:
-e CRD_OUT_PATH=/go/src/$(PROJECT_PACKAGE)/manifests \
$(CODEGEN_IMAGE) update-crd.sh
cp -f manifests/databases.spotahome.com_redisfailovers.yaml manifests/kustomize/base
cp -f manifests/databases.spotahome.com_redisfailovers.yaml charts/redisoperator/crds/
9 changes: 9 additions & 0 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

import (
prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -126,6 +127,14 @@ type Exporter struct {
Args []string `json:"args,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
PodMonitor PodMonitor `json:"podMonitor,omitempty"`
}

type PodMonitor struct {
Labels map[string]string `json:"labels,omitempty"`

// +optional
Interval prometheusv1.Duration `json:"interval,omitempty"`
}

// SentinelConfigCopy defines the specification for the sentinel exporter
Expand Down
24 changes: 24 additions & 0 deletions api/redisfailover/v1/zz_generated.deepcopy.go

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

1,828 changes: 1,647 additions & 181 deletions charts/redisoperator/crds/databases.spotahome.com_redisfailovers.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cmd/redisoperator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func (m *Main) Run() error {
}()

// Kubernetes clients.
k8sClient, customClient, aeClientset, err := utils.CreateKubernetesClients(m.flags)
k8sClient, customClient, aeClientset, monitoringV1Client, err := utils.CreateKubernetesClients(m.flags)
if err != nil {
return err
}

// Create kubernetes service.
k8sservice := k8s.New(k8sClient, customClient, aeClientset, m.logger, metricsRecorder)
k8sservice := k8s.New(k8sClient, customClient, aeClientset, monitoringV1Client, m.logger, metricsRecorder)

// Create the redis clients
redisClient := redis.New(metricsRecorder)
Expand Down
18 changes: 12 additions & 6 deletions cmd/utils/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"fmt"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -36,25 +37,30 @@ func LoadKubernetesConfig(flags *CMDFlags) (*rest.Config, error) {
}

// CreateKubernetesClients create the clients to connect to kubernetes
func CreateKubernetesClients(flags *CMDFlags) (kubernetes.Interface, redisfailoverclientset.Interface, apiextensionsclientset.Interface, error) {
func CreateKubernetesClients(flags *CMDFlags) (kubernetes.Interface, redisfailoverclientset.Interface, apiextensionsclientset.Interface, monitoringv1.MonitoringV1Interface, error) {
config, err := LoadKubernetesConfig(flags)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
customClientset, err := redisfailoverclientset.NewForConfig(config)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}

aeClientset, err := apiextensionsclientset.NewForConfig(config)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}

return clientset, customClientset, aeClientset, nil
monitoringV1Client, err := monitoringv1.NewForConfig(config)
if err != nil {
return nil, nil, nil, nil, err
}

return clientset, customClientset, aeClientset, monitoringV1Client, nil
}
15 changes: 15 additions & 0 deletions example/redisfailover/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
name: redisfailover
spec:
sentinel:
replicas: 1
exporter:
enabled: true
podMonitor:
labels:
hello: world
interval: 1m
redis:
replicas: 1
52 changes: 27 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,67 @@ go 1.19

require (
github.com/go-redis/redis/v8 v8.11.5
github.com/prometheus/client_golang v1.15.0
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.66.0
github.com/prometheus-operator/prometheus-operator/pkg/client v0.66.0
github.com/prometheus/client_golang v1.15.1
github.com/sirupsen/logrus v1.9.0
github.com/spotahome/kooper/v2 v2.3.0
github.com/stretchr/testify v1.8.2
k8s.io/api v0.25.3
k8s.io/apiextensions-apiserver v0.24.4
k8s.io/apimachinery v0.25.3
k8s.io/client-go v0.25.3
k8s.io/api v0.27.2
k8s.io/apiextensions-apiserver v0.27.2
k8s.io/apimachinery v0.27.2
k8s.io/client-go v0.27.2
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/controller-runtime v0.15.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading