mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-16 01:06:27 +00:00
* Introduce PrometheusAgent CRD Operator is able to run with PrometheusAgent resources in the cluster, but doesn't do anything with them yet. This is the first step to implement the Prometheus Agent Operator. Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> * Re-enable configmap and secret informers Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 1a71db03db6b41cd0cee9d0193b6ea3884bb5bae) * Implement Resolve for Agent operator Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 49558165b9178b6c1bda833a48f7bfe1468c942a) * Operator is able to create Agent Statefulset Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 7a3826683c92f917312c866a2bb6401dc54b95f2) * Agent Operator creates secret from ServiceMonitors Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 11232669befb4de9d0765dfadfe5fae00b575f11) * Agent Operator creates secret from PodMonitors Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 5ae551734bac2babc056c86443d15729d43d12b0) * Agent Operator creates secret from Probes Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 9637612fbbe9617335fd6188271ebf2cc74a3693) * Agent Operator configures remote-write Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit c4bdf230d527e19f8b77ca5f938b9254ed344f7d) * Agent Operator configures additionalScrapeConfigs Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit d9f28db764641e682bf4fe8963310f791979c387) * Implement UpdateStatus Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit c546ecaf3e8b73916df44a8f48b279c6988e32f5) * Add resource handlers Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 5b83359445e20f88ea5fff80302fce62d58058b9) * make format Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> (cherry picked from commit 6507964ba28f4ebf32ce3203db752444e288c45d) * Only start agent operator if there is enough permission Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> * Remove node endpoint syncronization from agent operator The server operator already handles it Signed-off-by: ArthurSens <arthursens2005@gmail.com> * Move PrometheusAgent API from v1 to v1alpha1 Signed-off-by: ArthurSens <arthursens2005@gmail.com> * pkg/prometheus/agent/statefulset.go: Fix image concatenation Signed-off-by: ArthurSens <arthursens2005@gmail.com> * Avoid name colisions between Prometheus Agents and Servers Signed-off-by: ArthurSens <arthursens2005@gmail.com> * agent/createOrUpdateConfigurationSecret: Do not handle case where servicemonitor and podmonitor selectors are empty Signed-off-by: ArthurSens <arthursens2005@gmail.com> * make format Signed-off-by: ArthurSens <arthursens2005@gmail.com> * make --always-make format generate Signed-off-by: ArthurSens <arthursens2005@gmail.com> * Remove unused fields from Operator struct Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> * Add deployment mode as new selector label for agent/server ssts Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> * WIP: Fix OperatorUpgrade e2e test Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> * Panic if type casting PrometheusInterface doesn't return Prometheus/Agent Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> * Detect whether PrometheusAgent CRD is installed or not If the operator's service account has all permissions on the cluster and the CRD isn't installed then the PrometheusAgent controller will run but fail because of the absence of the CRD. Signed-off-by: Simon Pasquier <spasquie@redhat.com> * Create dedicated governing service for Prometheus agent Signed-off-by: Simon Pasquier <spasquie@redhat.com> --------- Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com> Signed-off-by: ArthurSens <arthursens2005@gmail.com> Signed-off-by: Simon Pasquier <spasquie@redhat.com> Co-authored-by: Simon Pasquier <spasquie@redhat.com>
151 lines
3.8 KiB
Go
151 lines
3.8 KiB
Go
// Copyright 2023 The prometheus-operator Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package prometheus
|
|
|
|
import (
|
|
"testing"
|
|
|
|
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
|
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
|
)
|
|
|
|
func TestStatefulSetKeyToPrometheusKey(t *testing.T) {
|
|
cases := []struct {
|
|
input string
|
|
expectedKey string
|
|
expectedMatch bool
|
|
}{
|
|
{
|
|
input: "namespace/prometheus-test",
|
|
expectedKey: "namespace/test",
|
|
expectedMatch: true,
|
|
},
|
|
{
|
|
input: "namespace/prometheus-test-shard-1",
|
|
expectedKey: "namespace/test",
|
|
expectedMatch: true,
|
|
},
|
|
{
|
|
input: "allns-z-thanosrulercreatedeletecluster-qcwdmj-0/thanos-ruler-test",
|
|
expectedKey: "",
|
|
expectedMatch: false,
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
match, key := StatefulSetKeyToPrometheusKey(c.input)
|
|
if c.expectedKey != key {
|
|
t.Fatalf("Expected prometheus key %q got %q", c.expectedKey, key)
|
|
}
|
|
if c.expectedMatch != match {
|
|
notExp := ""
|
|
if !c.expectedMatch {
|
|
notExp = "not "
|
|
}
|
|
t.Fatalf("Expected input %sto be matching a prometheus key, but did not", notExp)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestKeyToStatefulSetKey(t *testing.T) {
|
|
cases := []struct {
|
|
p monitoringv1.PrometheusInterface
|
|
name string
|
|
shard int
|
|
expected string
|
|
}{
|
|
{
|
|
p: &monitoringv1.Prometheus{},
|
|
name: "namespace/test",
|
|
shard: 0,
|
|
expected: "namespace/prometheus-test",
|
|
},
|
|
{
|
|
p: &monitoringv1alpha1.PrometheusAgent{},
|
|
name: "namespace/test",
|
|
shard: 1,
|
|
expected: "namespace/prom-agent-test-shard-1",
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
got := KeyToStatefulSetKey(c.p, c.name, c.shard)
|
|
if c.expected != got {
|
|
t.Fatalf("Expected key %q got %q", c.expected, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidateRemoteWriteConfig(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
spec monitoringv1.RemoteWriteSpec
|
|
expectErr bool
|
|
}{
|
|
{
|
|
name: "with_OAuth2",
|
|
spec: monitoringv1.RemoteWriteSpec{
|
|
OAuth2: &monitoringv1.OAuth2{},
|
|
},
|
|
}, {
|
|
name: "with_SigV4",
|
|
spec: monitoringv1.RemoteWriteSpec{
|
|
Sigv4: &monitoringv1.Sigv4{},
|
|
},
|
|
},
|
|
{
|
|
name: "with_OAuth2_and_SigV4",
|
|
spec: monitoringv1.RemoteWriteSpec{
|
|
OAuth2: &monitoringv1.OAuth2{},
|
|
Sigv4: &monitoringv1.Sigv4{},
|
|
},
|
|
expectErr: true,
|
|
}, {
|
|
name: "with_OAuth2_and_BasicAuth",
|
|
spec: monitoringv1.RemoteWriteSpec{
|
|
OAuth2: &monitoringv1.OAuth2{},
|
|
BasicAuth: &monitoringv1.BasicAuth{},
|
|
},
|
|
expectErr: true,
|
|
}, {
|
|
name: "with_BasicAuth_and_SigV4",
|
|
spec: monitoringv1.RemoteWriteSpec{
|
|
BasicAuth: &monitoringv1.BasicAuth{},
|
|
Sigv4: &monitoringv1.Sigv4{},
|
|
},
|
|
expectErr: true,
|
|
}, {
|
|
name: "with_BasicAuth_and_SigV4_and_OAuth2",
|
|
spec: monitoringv1.RemoteWriteSpec{
|
|
BasicAuth: &monitoringv1.BasicAuth{},
|
|
Sigv4: &monitoringv1.Sigv4{},
|
|
OAuth2: &monitoringv1.OAuth2{},
|
|
},
|
|
expectErr: true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
test := c
|
|
t.Run(test.name, func(t *testing.T) {
|
|
err := ValidateRemoteWriteSpec(test.spec)
|
|
if err != nil && !test.expectErr {
|
|
t.Fatalf("unexpected error occurred: %v", err)
|
|
}
|
|
if err == nil && test.expectErr {
|
|
t.Fatalf("expected an error, got nil")
|
|
}
|
|
})
|
|
}
|
|
}
|