mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-15 16:56:24 +00:00
Prometheus Agent support (#5385)
* 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>
This commit is contained in:
parent
32ebc58aea
commit
cc47b1e160
43 changed files with 36646 additions and 340 deletions
1968
Documentation/api.md
1968
Documentation/api.md
File diff suppressed because it is too large
Load diff
|
@ -39,6 +39,9 @@ rules:
|
|||
- prometheuses
|
||||
- prometheuses/finalizers
|
||||
- prometheuses/status
|
||||
- prometheusagents
|
||||
- prometheusagents/finalizers
|
||||
- prometheusagents/status
|
||||
- thanosrulers
|
||||
- thanosrulers/finalizers
|
||||
- servicemonitors
|
||||
|
|
7878
bundle.yaml
7878
bundle.yaml
File diff suppressed because it is too large
Load diff
|
@ -35,6 +35,7 @@ import (
|
|||
alertmanagercontroller "github.com/prometheus-operator/prometheus-operator/pkg/alertmanager"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
|
||||
prometheusagentcontroller "github.com/prometheus-operator/prometheus-operator/pkg/prometheus/agent"
|
||||
prometheuscontroller "github.com/prometheus-operator/prometheus-operator/pkg/prometheus/server"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/server"
|
||||
thanoscontroller "github.com/prometheus-operator/prometheus-operator/pkg/thanos"
|
||||
|
@ -264,6 +265,13 @@ func Main() int {
|
|||
return 1
|
||||
}
|
||||
|
||||
pao, err := prometheusagentcontroller.New(ctx, cfg, log.With(logger, "component", "prometheusagentoperator"), r)
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, "instantiating prometheus-agent controller failed: ", err)
|
||||
cancel()
|
||||
return 1
|
||||
}
|
||||
|
||||
ao, err := alertmanagercontroller.New(ctx, cfg, log.With(logger, "component", "alertmanageroperator"), r)
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, "instantiating alertmanager controller failed: ", err)
|
||||
|
@ -351,6 +359,7 @@ func Main() int {
|
|||
}))
|
||||
|
||||
wg.Go(func() error { return po.Run(ctx) })
|
||||
wg.Go(func() error { return pao.Run(ctx) })
|
||||
wg.Go(func() error { return ao.Run(ctx) })
|
||||
wg.Go(func() error { return to.Run(ctx) })
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -17,6 +17,9 @@ rules:
|
|||
- prometheuses
|
||||
- prometheuses/finalizers
|
||||
- prometheuses/status
|
||||
- prometheusagents
|
||||
- prometheusagents/finalizers
|
||||
- prometheusagents/status
|
||||
- thanosrulers
|
||||
- thanosrulers/finalizers
|
||||
- servicemonitors
|
||||
|
|
|
@ -33,6 +33,7 @@ function(params) {
|
|||
if po.config.enableAlertmanagerConfigV1beta1 then
|
||||
(import 'alertmanagerconfigs-v1beta1-crd.libsonnet')
|
||||
else {},
|
||||
'0prometheusagentCustomResourceDefinition': import 'prometheusagents-crd.json',
|
||||
'0prometheusCustomResourceDefinition': import 'prometheuses-crd.json',
|
||||
'0servicemonitorCustomResourceDefinition': import 'servicemonitors-crd.json',
|
||||
'0podmonitorCustomResourceDefinition': import 'podmonitors-crd.json',
|
||||
|
@ -77,6 +78,9 @@ function(params) {
|
|||
'prometheuses',
|
||||
'prometheuses/finalizers',
|
||||
'prometheuses/status',
|
||||
'prometheusagents',
|
||||
'prometheusagents/finalizers',
|
||||
'prometheusagents/status',
|
||||
'thanosrulers',
|
||||
'thanosrulers/finalizers',
|
||||
'servicemonitors',
|
||||
|
|
7065
jsonnet/prometheus-operator/prometheusagents-crd.json
Normal file
7065
jsonnet/prometheus-operator/prometheusagents-crd.json
Normal file
File diff suppressed because it is too large
Load diff
92
pkg/apis/monitoring/v1alpha1/prometheusagent_types.go
Normal file
92
pkg/apis/monitoring/v1alpha1/prometheusagent_types.go
Normal file
|
@ -0,0 +1,92 @@
|
|||
// 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 v1alpha1
|
||||
|
||||
import (
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
PrometheusAgentsKind = "PrometheusAgent"
|
||||
PrometheusAgentName = "prometheusagents"
|
||||
PrometheusAgentKindKey = "prometheusagent"
|
||||
)
|
||||
|
||||
func (l *PrometheusAgent) GetCommonPrometheusFields() monitoringv1.CommonPrometheusFields {
|
||||
return l.Spec.CommonPrometheusFields
|
||||
}
|
||||
|
||||
func (l *PrometheusAgent) SetCommonPrometheusFields(f monitoringv1.CommonPrometheusFields) {
|
||||
l.Spec.CommonPrometheusFields = f
|
||||
}
|
||||
|
||||
func (l *PrometheusAgent) GetTypeMeta() metav1.TypeMeta {
|
||||
return l.TypeMeta
|
||||
}
|
||||
|
||||
// +genclient
|
||||
// +k8s:openapi-gen=true
|
||||
// +kubebuilder:resource:categories="prometheus-operator",shortName="promagent"
|
||||
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version",description="The version of Prometheus agent"
|
||||
// +kubebuilder:printcolumn:name="Desired",type="integer",JSONPath=".spec.replicas",description="The number of desired replicas"
|
||||
// +kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.availableReplicas",description="The number of ready replicas"
|
||||
// +kubebuilder:printcolumn:name="Reconciled",type="string",JSONPath=".status.conditions[?(@.type == 'Reconciled')].status"
|
||||
// +kubebuilder:printcolumn:name="Available",type="string",JSONPath=".status.conditions[?(@.type == 'Available')].status"
|
||||
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
|
||||
// +kubebuilder:printcolumn:name="Paused",type="boolean",JSONPath=".status.paused",description="Whether the resource reconciliation is paused or not",priority=1
|
||||
// +kubebuilder:subresource:status
|
||||
|
||||
// PrometheusAgent defines a Prometheus agent deployment.
|
||||
type PrometheusAgent struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
// Specification of the desired behavior of the Prometheus agent. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
|
||||
Spec PrometheusAgentSpec `json:"spec"`
|
||||
// Most recent observed status of the Prometheus cluster. Read-only.
|
||||
// More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
|
||||
Status monitoringv1.PrometheusStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *PrometheusAgent) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// PrometheusAgentList is a list of Prometheus agents.
|
||||
// +k8s:openapi-gen=true
|
||||
type PrometheusAgentList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
// Standard list metadata
|
||||
// More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
metav1.ListMeta `json:"metadata,omitempty"`
|
||||
// List of Prometheus agents
|
||||
Items []*PrometheusAgent `json:"items"`
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *PrometheusAgentList) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// PrometheusAgentSpec is a specification of the desired behavior of the Prometheus agent. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
|
||||
// +k8s:openapi-gen=true
|
||||
type PrometheusAgentSpec struct {
|
||||
monitoringv1.CommonPrometheusFields `json:",inline"`
|
||||
}
|
|
@ -49,6 +49,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
|
|||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
&AlertmanagerConfig{},
|
||||
&AlertmanagerConfigList{},
|
||||
&PrometheusAgent{},
|
||||
&PrometheusAgentList{},
|
||||
)
|
||||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||
return nil
|
||||
|
|
|
@ -439,6 +439,69 @@ func (in *PagerDutyLinkConfig) DeepCopy() *PagerDutyLinkConfig {
|
|||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PrometheusAgent) DeepCopyInto(out *PrometheusAgent) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||
in.Spec.DeepCopyInto(&out.Spec)
|
||||
in.Status.DeepCopyInto(&out.Status)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusAgent.
|
||||
func (in *PrometheusAgent) DeepCopy() *PrometheusAgent {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PrometheusAgent)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PrometheusAgentList) DeepCopyInto(out *PrometheusAgentList) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]*PrometheusAgent, len(*in))
|
||||
for i := range *in {
|
||||
if (*in)[i] != nil {
|
||||
in, out := &(*in)[i], &(*out)[i]
|
||||
*out = new(PrometheusAgent)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusAgentList.
|
||||
func (in *PrometheusAgentList) DeepCopy() *PrometheusAgentList {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PrometheusAgentList)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PrometheusAgentSpec) DeepCopyInto(out *PrometheusAgentSpec) {
|
||||
*out = *in
|
||||
in.CommonPrometheusFields.DeepCopyInto(&out.CommonPrometheusFields)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusAgentSpec.
|
||||
func (in *PrometheusAgentSpec) DeepCopy() *PrometheusAgentSpec {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PrometheusAgentSpec)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PushoverConfig) DeepCopyInto(out *PushoverConfig) {
|
||||
*out = *in
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
// Copyright 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.
|
||||
|
||||
// Code generated by applyconfiguration-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
|
||||
)
|
||||
|
||||
// PrometheusAgentApplyConfiguration represents an declarative configuration of the PrometheusAgent type for use
|
||||
// with apply.
|
||||
type PrometheusAgentApplyConfiguration struct {
|
||||
v1.TypeMetaApplyConfiguration `json:",inline"`
|
||||
*v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"`
|
||||
Spec *PrometheusAgentSpecApplyConfiguration `json:"spec,omitempty"`
|
||||
Status *monitoringv1.PrometheusStatusApplyConfiguration `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// PrometheusAgent constructs an declarative configuration of the PrometheusAgent type for use with
|
||||
// apply.
|
||||
func PrometheusAgent(name, namespace string) *PrometheusAgentApplyConfiguration {
|
||||
b := &PrometheusAgentApplyConfiguration{}
|
||||
b.WithName(name)
|
||||
b.WithNamespace(namespace)
|
||||
b.WithKind("PrometheusAgent")
|
||||
b.WithAPIVersion("monitoring.coreos.com/v1alpha1")
|
||||
return b
|
||||
}
|
||||
|
||||
// WithKind sets the Kind field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Kind field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithKind(value string) *PrometheusAgentApplyConfiguration {
|
||||
b.Kind = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the APIVersion field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithAPIVersion(value string) *PrometheusAgentApplyConfiguration {
|
||||
b.APIVersion = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithName sets the Name field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Name field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithName(value string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.Name = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithGenerateName sets the GenerateName field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the GenerateName field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithGenerateName(value string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.GenerateName = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithNamespace sets the Namespace field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Namespace field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithNamespace(value string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.Namespace = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithUID sets the UID field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the UID field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithUID(value types.UID) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.UID = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ResourceVersion field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithResourceVersion(value string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.ResourceVersion = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithGeneration sets the Generation field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Generation field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithGeneration(value int64) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.Generation = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the CreationTimestamp field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithCreationTimestamp(value metav1.Time) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.CreationTimestamp = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the DeletionTimestamp field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.DeletionTimestamp = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
b.DeletionGracePeriodSeconds = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithLabels puts the entries into the Labels field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, the entries provided by each call will be put on the Labels field,
|
||||
// overwriting an existing map entries in Labels field with the same key.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithLabels(entries map[string]string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
if b.Labels == nil && len(entries) > 0 {
|
||||
b.Labels = make(map[string]string, len(entries))
|
||||
}
|
||||
for k, v := range entries {
|
||||
b.Labels[k] = v
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithAnnotations puts the entries into the Annotations field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, the entries provided by each call will be put on the Annotations field,
|
||||
// overwriting an existing map entries in Annotations field with the same key.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithAnnotations(entries map[string]string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
if b.Annotations == nil && len(entries) > 0 {
|
||||
b.Annotations = make(map[string]string, len(entries))
|
||||
}
|
||||
for k, v := range entries {
|
||||
b.Annotations[k] = v
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the OwnerReferences field.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
for i := range values {
|
||||
if values[i] == nil {
|
||||
panic("nil value passed to WithOwnerReferences")
|
||||
}
|
||||
b.OwnerReferences = append(b.OwnerReferences, *values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithFinalizers adds the given value to the Finalizers field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the Finalizers field.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithFinalizers(values ...string) *PrometheusAgentApplyConfiguration {
|
||||
b.ensureObjectMetaApplyConfigurationExists()
|
||||
for i := range values {
|
||||
b.Finalizers = append(b.Finalizers, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *PrometheusAgentApplyConfiguration) ensureObjectMetaApplyConfigurationExists() {
|
||||
if b.ObjectMetaApplyConfiguration == nil {
|
||||
b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{}
|
||||
}
|
||||
}
|
||||
|
||||
// WithSpec sets the Spec field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Spec field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithSpec(value *PrometheusAgentSpecApplyConfiguration) *PrometheusAgentApplyConfiguration {
|
||||
b.Spec = value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithStatus sets the Status field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Status field is set to the value of the last call.
|
||||
func (b *PrometheusAgentApplyConfiguration) WithStatus(value *monitoringv1.PrometheusStatusApplyConfiguration) *PrometheusAgentApplyConfiguration {
|
||||
b.Status = value
|
||||
return b
|
||||
}
|
|
@ -0,0 +1,602 @@
|
|||
// Copyright 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.
|
||||
|
||||
// Code generated by applyconfiguration-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
v1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// PrometheusAgentSpecApplyConfiguration represents an declarative configuration of the PrometheusAgentSpec type for use
|
||||
// with apply.
|
||||
type PrometheusAgentSpecApplyConfiguration struct {
|
||||
v1.CommonPrometheusFieldsApplyConfiguration `json:",inline"`
|
||||
}
|
||||
|
||||
// PrometheusAgentSpecApplyConfiguration constructs an declarative configuration of the PrometheusAgentSpec type for use with
|
||||
// apply.
|
||||
func PrometheusAgentSpec() *PrometheusAgentSpecApplyConfiguration {
|
||||
return &PrometheusAgentSpecApplyConfiguration{}
|
||||
}
|
||||
|
||||
// WithPodMetadata sets the PodMetadata field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the PodMetadata field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPodMetadata(value *v1.EmbeddedObjectMetadataApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.PodMetadata = value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithServiceMonitorSelector sets the ServiceMonitorSelector field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ServiceMonitorSelector field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithServiceMonitorSelector(value metav1.LabelSelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ServiceMonitorSelector = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithServiceMonitorNamespaceSelector sets the ServiceMonitorNamespaceSelector field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ServiceMonitorNamespaceSelector field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithServiceMonitorNamespaceSelector(value metav1.LabelSelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ServiceMonitorNamespaceSelector = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPodMonitorSelector sets the PodMonitorSelector field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the PodMonitorSelector field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPodMonitorSelector(value metav1.LabelSelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.PodMonitorSelector = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPodMonitorNamespaceSelector sets the PodMonitorNamespaceSelector field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the PodMonitorNamespaceSelector field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPodMonitorNamespaceSelector(value metav1.LabelSelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.PodMonitorNamespaceSelector = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithProbeSelector sets the ProbeSelector field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ProbeSelector field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithProbeSelector(value metav1.LabelSelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ProbeSelector = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithProbeNamespaceSelector sets the ProbeNamespaceSelector field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ProbeNamespaceSelector field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithProbeNamespaceSelector(value metav1.LabelSelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ProbeNamespaceSelector = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithVersion sets the Version field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Version field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithVersion(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Version = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPaused sets the Paused field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Paused field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPaused(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Paused = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithImage sets the Image field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Image field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithImage(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Image = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithImagePullPolicy sets the ImagePullPolicy field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ImagePullPolicy field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithImagePullPolicy(value corev1.PullPolicy) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ImagePullPolicy = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithImagePullSecrets adds the given value to the ImagePullSecrets field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the ImagePullSecrets field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithImagePullSecrets(values ...corev1.LocalObjectReference) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.ImagePullSecrets = append(b.ImagePullSecrets, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithReplicas sets the Replicas field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Replicas field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithReplicas(value int32) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Replicas = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithShards sets the Shards field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Shards field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithShards(value int32) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Shards = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithReplicaExternalLabelName sets the ReplicaExternalLabelName field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ReplicaExternalLabelName field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithReplicaExternalLabelName(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ReplicaExternalLabelName = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPrometheusExternalLabelName sets the PrometheusExternalLabelName field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the PrometheusExternalLabelName field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPrometheusExternalLabelName(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.PrometheusExternalLabelName = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithLogLevel sets the LogLevel field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the LogLevel field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithLogLevel(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.LogLevel = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithLogFormat sets the LogFormat field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the LogFormat field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithLogFormat(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.LogFormat = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithScrapeInterval sets the ScrapeInterval field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ScrapeInterval field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithScrapeInterval(value monitoringv1.Duration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ScrapeInterval = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithScrapeTimeout sets the ScrapeTimeout field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ScrapeTimeout field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithScrapeTimeout(value monitoringv1.Duration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ScrapeTimeout = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, the entries provided by each call will be put on the ExternalLabels field,
|
||||
// overwriting an existing map entries in ExternalLabels field with the same key.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithExternalLabels(entries map[string]string) *PrometheusAgentSpecApplyConfiguration {
|
||||
if b.ExternalLabels == nil && len(entries) > 0 {
|
||||
b.ExternalLabels = make(map[string]string, len(entries))
|
||||
}
|
||||
for k, v := range entries {
|
||||
b.ExternalLabels[k] = v
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnableRemoteWriteReceiver sets the EnableRemoteWriteReceiver field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnableRemoteWriteReceiver field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnableRemoteWriteReceiver(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnableRemoteWriteReceiver = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnableFeatures adds the given value to the EnableFeatures field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the EnableFeatures field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnableFeatures(values ...string) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.EnableFeatures = append(b.EnableFeatures, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithExternalURL sets the ExternalURL field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ExternalURL field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithExternalURL(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ExternalURL = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithRoutePrefix sets the RoutePrefix field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the RoutePrefix field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithRoutePrefix(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.RoutePrefix = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithStorage sets the Storage field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Storage field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithStorage(value *v1.StorageSpecApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Storage = value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithVolumes adds the given value to the Volumes field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the Volumes field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithVolumes(values ...corev1.Volume) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.Volumes = append(b.Volumes, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithVolumeMounts adds the given value to the VolumeMounts field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the VolumeMounts field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithVolumeMounts(values ...corev1.VolumeMount) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.VolumeMounts = append(b.VolumeMounts, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithWeb sets the Web field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Web field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithWeb(value *v1.PrometheusWebSpecApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Web = value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithResources sets the Resources field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Resources field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithResources(value corev1.ResourceRequirements) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Resources = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithNodeSelector puts the entries into the NodeSelector field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, the entries provided by each call will be put on the NodeSelector field,
|
||||
// overwriting an existing map entries in NodeSelector field with the same key.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithNodeSelector(entries map[string]string) *PrometheusAgentSpecApplyConfiguration {
|
||||
if b.NodeSelector == nil && len(entries) > 0 {
|
||||
b.NodeSelector = make(map[string]string, len(entries))
|
||||
}
|
||||
for k, v := range entries {
|
||||
b.NodeSelector[k] = v
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithServiceAccountName sets the ServiceAccountName field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ServiceAccountName field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithServiceAccountName(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ServiceAccountName = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithSecrets adds the given value to the Secrets field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the Secrets field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithSecrets(values ...string) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.Secrets = append(b.Secrets, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithConfigMaps adds the given value to the ConfigMaps field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the ConfigMaps field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithConfigMaps(values ...string) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.ConfigMaps = append(b.ConfigMaps, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithAffinity sets the Affinity field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the Affinity field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithAffinity(value corev1.Affinity) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.Affinity = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithTolerations adds the given value to the Tolerations field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the Tolerations field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithTolerations(values ...corev1.Toleration) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.Tolerations = append(b.Tolerations, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithTopologySpreadConstraints adds the given value to the TopologySpreadConstraints field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the TopologySpreadConstraints field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithTopologySpreadConstraints(values ...corev1.TopologySpreadConstraint) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.TopologySpreadConstraints = append(b.TopologySpreadConstraints, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithRemoteWrite adds the given value to the RemoteWrite field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the RemoteWrite field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithRemoteWrite(values ...*v1.RemoteWriteSpecApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
if values[i] == nil {
|
||||
panic("nil value passed to WithRemoteWrite")
|
||||
}
|
||||
b.RemoteWrite = append(b.RemoteWrite, *values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithSecurityContext sets the SecurityContext field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the SecurityContext field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithSecurityContext(value corev1.PodSecurityContext) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.SecurityContext = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithListenLocal sets the ListenLocal field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ListenLocal field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithListenLocal(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ListenLocal = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithContainers adds the given value to the Containers field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the Containers field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithContainers(values ...corev1.Container) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.Containers = append(b.Containers, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithInitContainers adds the given value to the InitContainers field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the InitContainers field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithInitContainers(values ...corev1.Container) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.InitContainers = append(b.InitContainers, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithAdditionalScrapeConfigs sets the AdditionalScrapeConfigs field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the AdditionalScrapeConfigs field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithAdditionalScrapeConfigs(value corev1.SecretKeySelector) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.AdditionalScrapeConfigs = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithAPIServerConfig sets the APIServerConfig field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the APIServerConfig field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithAPIServerConfig(value *v1.APIServerConfigApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.APIServerConfig = value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPriorityClassName sets the PriorityClassName field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the PriorityClassName field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPriorityClassName(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.PriorityClassName = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPortName sets the PortName field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the PortName field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPortName(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.PortName = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithArbitraryFSAccessThroughSMs sets the ArbitraryFSAccessThroughSMs field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the ArbitraryFSAccessThroughSMs field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithArbitraryFSAccessThroughSMs(value *v1.ArbitraryFSAccessThroughSMsConfigApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.ArbitraryFSAccessThroughSMs = value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithOverrideHonorLabels sets the OverrideHonorLabels field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the OverrideHonorLabels field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithOverrideHonorLabels(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.OverrideHonorLabels = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithOverrideHonorTimestamps sets the OverrideHonorTimestamps field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the OverrideHonorTimestamps field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithOverrideHonorTimestamps(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.OverrideHonorTimestamps = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithIgnoreNamespaceSelectors sets the IgnoreNamespaceSelectors field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the IgnoreNamespaceSelectors field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithIgnoreNamespaceSelectors(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.IgnoreNamespaceSelectors = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedNamespaceLabel sets the EnforcedNamespaceLabel field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedNamespaceLabel field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedNamespaceLabel(value string) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedNamespaceLabel = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedSampleLimit sets the EnforcedSampleLimit field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedSampleLimit field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedSampleLimit(value uint64) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedSampleLimit = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedTargetLimit sets the EnforcedTargetLimit field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedTargetLimit field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedTargetLimit(value uint64) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedTargetLimit = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedLabelLimit sets the EnforcedLabelLimit field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedLabelLimit field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedLabelLimit(value uint64) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedLabelLimit = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedLabelNameLengthLimit sets the EnforcedLabelNameLengthLimit field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedLabelNameLengthLimit field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedLabelNameLengthLimit(value uint64) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedLabelNameLengthLimit = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedLabelValueLengthLimit sets the EnforcedLabelValueLengthLimit field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedLabelValueLengthLimit field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedLabelValueLengthLimit(value uint64) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedLabelValueLengthLimit = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithEnforcedBodySizeLimit sets the EnforcedBodySizeLimit field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the EnforcedBodySizeLimit field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithEnforcedBodySizeLimit(value monitoringv1.ByteSize) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.EnforcedBodySizeLimit = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithMinReadySeconds sets the MinReadySeconds field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the MinReadySeconds field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithMinReadySeconds(value uint32) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.MinReadySeconds = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithHostAliases adds the given value to the HostAliases field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the HostAliases field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithHostAliases(values ...*v1.HostAliasApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
if values[i] == nil {
|
||||
panic("nil value passed to WithHostAliases")
|
||||
}
|
||||
b.HostAliases = append(b.HostAliases, *values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithAdditionalArgs adds the given value to the AdditionalArgs field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the AdditionalArgs field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithAdditionalArgs(values ...*v1.ArgumentApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
if values[i] == nil {
|
||||
panic("nil value passed to WithAdditionalArgs")
|
||||
}
|
||||
b.AdditionalArgs = append(b.AdditionalArgs, *values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithWALCompression sets the WALCompression field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the WALCompression field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithWALCompression(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.WALCompression = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithExcludedFromEnforcement adds the given value to the ExcludedFromEnforcement field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the ExcludedFromEnforcement field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithExcludedFromEnforcement(values ...*v1.ObjectReferenceApplyConfiguration) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
if values[i] == nil {
|
||||
panic("nil value passed to WithExcludedFromEnforcement")
|
||||
}
|
||||
b.ExcludedFromEnforcement = append(b.ExcludedFromEnforcement, *values[i])
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithHostNetwork sets the HostNetwork field in the declarative configuration to the given value
|
||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||
// If called multiple times, the HostNetwork field is set to the value of the last call.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithHostNetwork(value bool) *PrometheusAgentSpecApplyConfiguration {
|
||||
b.HostNetwork = &value
|
||||
return b
|
||||
}
|
||||
|
||||
// WithPodTargetLabels adds the given value to the PodTargetLabels field in the declarative configuration
|
||||
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
|
||||
// If called multiple times, values provided by each call will be appended to the PodTargetLabels field.
|
||||
func (b *PrometheusAgentSpecApplyConfiguration) WithPodTargetLabels(values ...string) *PrometheusAgentSpecApplyConfiguration {
|
||||
for i := range values {
|
||||
b.PodTargetLabels = append(b.PodTargetLabels, values[i])
|
||||
}
|
||||
return b
|
||||
}
|
|
@ -205,6 +205,10 @@ func ForKind(kind schema.GroupVersionKind) interface{} {
|
|||
return &monitoringv1alpha1.PagerDutyImageConfigApplyConfiguration{}
|
||||
case v1alpha1.SchemeGroupVersion.WithKind("PagerDutyLinkConfig"):
|
||||
return &monitoringv1alpha1.PagerDutyLinkConfigApplyConfiguration{}
|
||||
case v1alpha1.SchemeGroupVersion.WithKind("PrometheusAgent"):
|
||||
return &monitoringv1alpha1.PrometheusAgentApplyConfiguration{}
|
||||
case v1alpha1.SchemeGroupVersion.WithKind("PrometheusAgentSpec"):
|
||||
return &monitoringv1alpha1.PrometheusAgentSpecApplyConfiguration{}
|
||||
case v1alpha1.SchemeGroupVersion.WithKind("PushoverConfig"):
|
||||
return &monitoringv1alpha1.PushoverConfigApplyConfiguration{}
|
||||
case v1alpha1.SchemeGroupVersion.WithKind("Receiver"):
|
||||
|
|
|
@ -71,6 +71,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource
|
|||
// Group=monitoring.coreos.com, Version=v1alpha1
|
||||
case v1alpha1.SchemeGroupVersion.WithResource("alertmanagerconfigs"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Monitoring().V1alpha1().AlertmanagerConfigs().Informer()}, nil
|
||||
case v1alpha1.SchemeGroupVersion.WithResource("prometheusagents"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Monitoring().V1alpha1().PrometheusAgents().Informer()}, nil
|
||||
|
||||
// Group=monitoring.coreos.com, Version=v1beta1
|
||||
case v1beta1.SchemeGroupVersion.WithResource("alertmanagerconfigs"):
|
||||
|
|
|
@ -24,6 +24,8 @@ import (
|
|||
type Interface interface {
|
||||
// AlertmanagerConfigs returns a AlertmanagerConfigInformer.
|
||||
AlertmanagerConfigs() AlertmanagerConfigInformer
|
||||
// PrometheusAgents returns a PrometheusAgentInformer.
|
||||
PrometheusAgents() PrometheusAgentInformer
|
||||
}
|
||||
|
||||
type version struct {
|
||||
|
@ -41,3 +43,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList
|
|||
func (v *version) AlertmanagerConfigs() AlertmanagerConfigInformer {
|
||||
return &alertmanagerConfigInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
|
||||
// PrometheusAgents returns a PrometheusAgentInformer.
|
||||
func (v *version) PrometheusAgents() PrometheusAgentInformer {
|
||||
return &prometheusAgentInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
// Copyright 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.
|
||||
|
||||
// Code generated by informer-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"context"
|
||||
time "time"
|
||||
|
||||
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
||||
internalinterfaces "github.com/prometheus-operator/prometheus-operator/pkg/client/informers/externalversions/internalinterfaces"
|
||||
v1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/client/listers/monitoring/v1alpha1"
|
||||
versioned "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
cache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
// PrometheusAgentInformer provides access to a shared informer and lister for
|
||||
// PrometheusAgents.
|
||||
type PrometheusAgentInformer interface {
|
||||
Informer() cache.SharedIndexInformer
|
||||
Lister() v1alpha1.PrometheusAgentLister
|
||||
}
|
||||
|
||||
type prometheusAgentInformer struct {
|
||||
factory internalinterfaces.SharedInformerFactory
|
||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
||||
namespace string
|
||||
}
|
||||
|
||||
// NewPrometheusAgentInformer constructs a new informer for PrometheusAgent type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewPrometheusAgentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
|
||||
return NewFilteredPrometheusAgentInformer(client, namespace, resyncPeriod, indexers, nil)
|
||||
}
|
||||
|
||||
// NewFilteredPrometheusAgentInformer constructs a new informer for PrometheusAgent type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFilteredPrometheusAgentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
||||
return cache.NewSharedIndexInformer(
|
||||
&cache.ListWatch{
|
||||
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.MonitoringV1alpha1().PrometheusAgents(namespace).List(context.TODO(), options)
|
||||
},
|
||||
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.MonitoringV1alpha1().PrometheusAgents(namespace).Watch(context.TODO(), options)
|
||||
},
|
||||
},
|
||||
&monitoringv1alpha1.PrometheusAgent{},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
)
|
||||
}
|
||||
|
||||
func (f *prometheusAgentInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
||||
return NewFilteredPrometheusAgentInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
||||
}
|
||||
|
||||
func (f *prometheusAgentInformer) Informer() cache.SharedIndexInformer {
|
||||
return f.factory.InformerFor(&monitoringv1alpha1.PrometheusAgent{}, f.defaultInformer)
|
||||
}
|
||||
|
||||
func (f *prometheusAgentInformer) Lister() v1alpha1.PrometheusAgentLister {
|
||||
return v1alpha1.NewPrometheusAgentLister(f.Informer().GetIndexer())
|
||||
}
|
|
@ -23,3 +23,11 @@ type AlertmanagerConfigListerExpansion interface{}
|
|||
// AlertmanagerConfigNamespaceListerExpansion allows custom methods to be added to
|
||||
// AlertmanagerConfigNamespaceLister.
|
||||
type AlertmanagerConfigNamespaceListerExpansion interface{}
|
||||
|
||||
// PrometheusAgentListerExpansion allows custom methods to be added to
|
||||
// PrometheusAgentLister.
|
||||
type PrometheusAgentListerExpansion interface{}
|
||||
|
||||
// PrometheusAgentNamespaceListerExpansion allows custom methods to be added to
|
||||
// PrometheusAgentNamespaceLister.
|
||||
type PrometheusAgentNamespaceListerExpansion interface{}
|
||||
|
|
97
pkg/client/listers/monitoring/v1alpha1/prometheusagent.go
Normal file
97
pkg/client/listers/monitoring/v1alpha1/prometheusagent.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Copyright 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.
|
||||
|
||||
// Code generated by lister-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
v1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
// PrometheusAgentLister helps list PrometheusAgents.
|
||||
// All objects returned here must be treated as read-only.
|
||||
type PrometheusAgentLister interface {
|
||||
// List lists all PrometheusAgents in the indexer.
|
||||
// Objects returned here must be treated as read-only.
|
||||
List(selector labels.Selector) (ret []*v1alpha1.PrometheusAgent, err error)
|
||||
// PrometheusAgents returns an object that can list and get PrometheusAgents.
|
||||
PrometheusAgents(namespace string) PrometheusAgentNamespaceLister
|
||||
PrometheusAgentListerExpansion
|
||||
}
|
||||
|
||||
// prometheusAgentLister implements the PrometheusAgentLister interface.
|
||||
type prometheusAgentLister struct {
|
||||
indexer cache.Indexer
|
||||
}
|
||||
|
||||
// NewPrometheusAgentLister returns a new PrometheusAgentLister.
|
||||
func NewPrometheusAgentLister(indexer cache.Indexer) PrometheusAgentLister {
|
||||
return &prometheusAgentLister{indexer: indexer}
|
||||
}
|
||||
|
||||
// List lists all PrometheusAgents in the indexer.
|
||||
func (s *prometheusAgentLister) List(selector labels.Selector) (ret []*v1alpha1.PrometheusAgent, err error) {
|
||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*v1alpha1.PrometheusAgent))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// PrometheusAgents returns an object that can list and get PrometheusAgents.
|
||||
func (s *prometheusAgentLister) PrometheusAgents(namespace string) PrometheusAgentNamespaceLister {
|
||||
return prometheusAgentNamespaceLister{indexer: s.indexer, namespace: namespace}
|
||||
}
|
||||
|
||||
// PrometheusAgentNamespaceLister helps list and get PrometheusAgents.
|
||||
// All objects returned here must be treated as read-only.
|
||||
type PrometheusAgentNamespaceLister interface {
|
||||
// List lists all PrometheusAgents in the indexer for a given namespace.
|
||||
// Objects returned here must be treated as read-only.
|
||||
List(selector labels.Selector) (ret []*v1alpha1.PrometheusAgent, err error)
|
||||
// Get retrieves the PrometheusAgent from the indexer for a given namespace and name.
|
||||
// Objects returned here must be treated as read-only.
|
||||
Get(name string) (*v1alpha1.PrometheusAgent, error)
|
||||
PrometheusAgentNamespaceListerExpansion
|
||||
}
|
||||
|
||||
// prometheusAgentNamespaceLister implements the PrometheusAgentNamespaceLister
|
||||
// interface.
|
||||
type prometheusAgentNamespaceLister struct {
|
||||
indexer cache.Indexer
|
||||
namespace string
|
||||
}
|
||||
|
||||
// List lists all PrometheusAgents in the indexer for a given namespace.
|
||||
func (s prometheusAgentNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.PrometheusAgent, err error) {
|
||||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*v1alpha1.PrometheusAgent))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// Get retrieves the PrometheusAgent from the indexer for a given namespace and name.
|
||||
func (s prometheusAgentNamespaceLister) Get(name string) (*v1alpha1.PrometheusAgent, error) {
|
||||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.NewNotFound(v1alpha1.Resource("prometheusagent"), name)
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), nil
|
||||
}
|
|
@ -30,6 +30,10 @@ func (c *FakeMonitoringV1alpha1) AlertmanagerConfigs(namespace string) v1alpha1.
|
|||
return &FakeAlertmanagerConfigs{c, namespace}
|
||||
}
|
||||
|
||||
func (c *FakeMonitoringV1alpha1) PrometheusAgents(namespace string) v1alpha1.PrometheusAgentInterface {
|
||||
return &FakePrometheusAgents{c, namespace}
|
||||
}
|
||||
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *FakeMonitoringV1alpha1) RESTClient() rest.Interface {
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
// Copyright 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.
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
json "encoding/json"
|
||||
"fmt"
|
||||
|
||||
v1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
||||
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1alpha1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
labels "k8s.io/apimachinery/pkg/labels"
|
||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
testing "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
// FakePrometheusAgents implements PrometheusAgentInterface
|
||||
type FakePrometheusAgents struct {
|
||||
Fake *FakeMonitoringV1alpha1
|
||||
ns string
|
||||
}
|
||||
|
||||
var prometheusagentsResource = schema.GroupVersionResource{Group: "monitoring.coreos.com", Version: "v1alpha1", Resource: "prometheusagents"}
|
||||
|
||||
var prometheusagentsKind = schema.GroupVersionKind{Group: "monitoring.coreos.com", Version: "v1alpha1", Kind: "PrometheusAgent"}
|
||||
|
||||
// Get takes name of the prometheusAgent, and returns the corresponding prometheusAgent object, and an error if there is any.
|
||||
func (c *FakePrometheusAgents) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewGetAction(prometheusagentsResource, c.ns, name), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of PrometheusAgents that match those selectors.
|
||||
func (c *FakePrometheusAgents) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PrometheusAgentList, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewListAction(prometheusagentsResource, prometheusagentsKind, c.ns, opts), &v1alpha1.PrometheusAgentList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
||||
if label == nil {
|
||||
label = labels.Everything()
|
||||
}
|
||||
list := &v1alpha1.PrometheusAgentList{ListMeta: obj.(*v1alpha1.PrometheusAgentList).ListMeta}
|
||||
for _, item := range obj.(*v1alpha1.PrometheusAgentList).Items {
|
||||
if label.Matches(labels.Set(item.Labels)) {
|
||||
list.Items = append(list.Items, item)
|
||||
}
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested prometheusAgents.
|
||||
func (c *FakePrometheusAgents) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.
|
||||
InvokesWatch(testing.NewWatchAction(prometheusagentsResource, c.ns, opts))
|
||||
|
||||
}
|
||||
|
||||
// Create takes the representation of a prometheusAgent and creates it. Returns the server's representation of the prometheusAgent, and an error, if there is any.
|
||||
func (c *FakePrometheusAgents) Create(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.CreateOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewCreateAction(prometheusagentsResource, c.ns, prometheusAgent), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
||||
|
||||
// Update takes the representation of a prometheusAgent and updates it. Returns the server's representation of the prometheusAgent, and an error, if there is any.
|
||||
func (c *FakePrometheusAgents) Update(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.UpdateOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateAction(prometheusagentsResource, c.ns, prometheusAgent), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
||||
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
func (c *FakePrometheusAgents) UpdateStatus(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.UpdateOptions) (*v1alpha1.PrometheusAgent, error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateSubresourceAction(prometheusagentsResource, "status", c.ns, prometheusAgent), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
||||
|
||||
// Delete takes name of the prometheusAgent and deletes it. Returns an error if one occurs.
|
||||
func (c *FakePrometheusAgents) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
_, err := c.Fake.
|
||||
Invokes(testing.NewDeleteActionWithOptions(prometheusagentsResource, c.ns, name, opts), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *FakePrometheusAgents) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
action := testing.NewDeleteCollectionAction(prometheusagentsResource, c.ns, listOpts)
|
||||
|
||||
_, err := c.Fake.Invokes(action, &v1alpha1.PrometheusAgentList{})
|
||||
return err
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched prometheusAgent.
|
||||
func (c *FakePrometheusAgents) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(prometheusagentsResource, c.ns, name, pt, data, subresources...), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
||||
|
||||
// Apply takes the given apply declarative configuration, applies it and returns the applied prometheusAgent.
|
||||
func (c *FakePrometheusAgents) Apply(ctx context.Context, prometheusAgent *monitoringv1alpha1.PrometheusAgentApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
if prometheusAgent == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent provided to Apply must not be nil")
|
||||
}
|
||||
data, err := json.Marshal(prometheusAgent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name := prometheusAgent.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent.Name must be provided to Apply")
|
||||
}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(prometheusagentsResource, c.ns, *name, types.ApplyPatchType, data), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
||||
|
||||
// ApplyStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus().
|
||||
func (c *FakePrometheusAgents) ApplyStatus(ctx context.Context, prometheusAgent *monitoringv1alpha1.PrometheusAgentApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
if prometheusAgent == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent provided to Apply must not be nil")
|
||||
}
|
||||
data, err := json.Marshal(prometheusAgent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name := prometheusAgent.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent.Name must be provided to Apply")
|
||||
}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(prometheusagentsResource, c.ns, *name, types.ApplyPatchType, data, "status"), &v1alpha1.PrometheusAgent{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.PrometheusAgent), err
|
||||
}
|
|
@ -17,3 +17,5 @@
|
|||
package v1alpha1
|
||||
|
||||
type AlertmanagerConfigExpansion interface{}
|
||||
|
||||
type PrometheusAgentExpansion interface{}
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
type MonitoringV1alpha1Interface interface {
|
||||
RESTClient() rest.Interface
|
||||
AlertmanagerConfigsGetter
|
||||
PrometheusAgentsGetter
|
||||
}
|
||||
|
||||
// MonitoringV1alpha1Client is used to interact with features provided by the monitoring.coreos.com group.
|
||||
|
@ -38,6 +39,10 @@ func (c *MonitoringV1alpha1Client) AlertmanagerConfigs(namespace string) Alertma
|
|||
return newAlertmanagerConfigs(c, namespace)
|
||||
}
|
||||
|
||||
func (c *MonitoringV1alpha1Client) PrometheusAgents(namespace string) PrometheusAgentInterface {
|
||||
return newPrometheusAgents(c, namespace)
|
||||
}
|
||||
|
||||
// NewForConfig creates a new MonitoringV1alpha1Client for the given config.
|
||||
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
|
||||
// where httpClient was generated with rest.HTTPClientFor(c).
|
||||
|
|
|
@ -0,0 +1,254 @@
|
|||
// Copyright 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.
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"context"
|
||||
json "encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
v1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
||||
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1alpha1"
|
||||
scheme "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/scheme"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
rest "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// PrometheusAgentsGetter has a method to return a PrometheusAgentInterface.
|
||||
// A group's client should implement this interface.
|
||||
type PrometheusAgentsGetter interface {
|
||||
PrometheusAgents(namespace string) PrometheusAgentInterface
|
||||
}
|
||||
|
||||
// PrometheusAgentInterface has methods to work with PrometheusAgent resources.
|
||||
type PrometheusAgentInterface interface {
|
||||
Create(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.CreateOptions) (*v1alpha1.PrometheusAgent, error)
|
||||
Update(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.UpdateOptions) (*v1alpha1.PrometheusAgent, error)
|
||||
UpdateStatus(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.UpdateOptions) (*v1alpha1.PrometheusAgent, error)
|
||||
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
|
||||
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
|
||||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.PrometheusAgent, error)
|
||||
List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.PrometheusAgentList, error)
|
||||
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
|
||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PrometheusAgent, err error)
|
||||
Apply(ctx context.Context, prometheusAgent *monitoringv1alpha1.PrometheusAgentApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.PrometheusAgent, err error)
|
||||
ApplyStatus(ctx context.Context, prometheusAgent *monitoringv1alpha1.PrometheusAgentApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.PrometheusAgent, err error)
|
||||
PrometheusAgentExpansion
|
||||
}
|
||||
|
||||
// prometheusAgents implements PrometheusAgentInterface
|
||||
type prometheusAgents struct {
|
||||
client rest.Interface
|
||||
ns string
|
||||
}
|
||||
|
||||
// newPrometheusAgents returns a PrometheusAgents
|
||||
func newPrometheusAgents(c *MonitoringV1alpha1Client, namespace string) *prometheusAgents {
|
||||
return &prometheusAgents{
|
||||
client: c.RESTClient(),
|
||||
ns: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// Get takes name of the prometheusAgent, and returns the corresponding prometheusAgent object, and an error if there is any.
|
||||
func (c *prometheusAgents) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(name).
|
||||
VersionedParams(&options, scheme.ParameterCodec).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of PrometheusAgents that match those selectors.
|
||||
func (c *prometheusAgents) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PrometheusAgentList, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &v1alpha1.PrometheusAgentList{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested prometheusAgents.
|
||||
func (c *prometheusAgents) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
opts.Watch = true
|
||||
return c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Watch(ctx)
|
||||
}
|
||||
|
||||
// Create takes the representation of a prometheusAgent and creates it. Returns the server's representation of the prometheusAgent, and an error, if there is any.
|
||||
func (c *prometheusAgents) Create(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.CreateOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Post().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(prometheusAgent).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Update takes the representation of a prometheusAgent and updates it. Returns the server's representation of the prometheusAgent, and an error, if there is any.
|
||||
func (c *prometheusAgents) Update(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.UpdateOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(prometheusAgent.Name).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(prometheusAgent).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
func (c *prometheusAgents) UpdateStatus(ctx context.Context, prometheusAgent *v1alpha1.PrometheusAgent, opts v1.UpdateOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(prometheusAgent.Name).
|
||||
SubResource("status").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(prometheusAgent).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete takes name of the prometheusAgent and deletes it. Returns an error if one occurs.
|
||||
func (c *prometheusAgents) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
return c.client.Delete().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(name).
|
||||
Body(&opts).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *prometheusAgents) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
var timeout time.Duration
|
||||
if listOpts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
return c.client.Delete().
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
VersionedParams(&listOpts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Body(&opts).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched prometheusAgent.
|
||||
func (c *prometheusAgents) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Patch(pt).
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(name).
|
||||
SubResource(subresources...).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Apply takes the given apply declarative configuration, applies it and returns the applied prometheusAgent.
|
||||
func (c *prometheusAgents) Apply(ctx context.Context, prometheusAgent *monitoringv1alpha1.PrometheusAgentApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
if prometheusAgent == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent provided to Apply must not be nil")
|
||||
}
|
||||
patchOpts := opts.ToPatchOptions()
|
||||
data, err := json.Marshal(prometheusAgent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name := prometheusAgent.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent.Name must be provided to Apply")
|
||||
}
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Patch(types.ApplyPatchType).
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(*name).
|
||||
VersionedParams(&patchOpts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// ApplyStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus().
|
||||
func (c *prometheusAgents) ApplyStatus(ctx context.Context, prometheusAgent *monitoringv1alpha1.PrometheusAgentApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.PrometheusAgent, err error) {
|
||||
if prometheusAgent == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent provided to Apply must not be nil")
|
||||
}
|
||||
patchOpts := opts.ToPatchOptions()
|
||||
data, err := json.Marshal(prometheusAgent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
name := prometheusAgent.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("prometheusAgent.Name must be provided to Apply")
|
||||
}
|
||||
|
||||
result = &v1alpha1.PrometheusAgent{}
|
||||
err = c.client.Patch(types.ApplyPatchType).
|
||||
Namespace(c.ns).
|
||||
Resource("prometheusagents").
|
||||
Name(*name).
|
||||
SubResource("status").
|
||||
VersionedParams(&patchOpts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
1373
pkg/prometheus/agent/operator.go
Normal file
1373
pkg/prometheus/agent/operator.go
Normal file
File diff suppressed because it is too large
Load diff
483
pkg/prometheus/agent/statefulset.go
Normal file
483
pkg/prometheus/agent/statefulset.go
Normal file
|
@ -0,0 +1,483 @@
|
|||
// 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 prometheusagent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/pkg/errors"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
|
||||
prompkg "github.com/prometheus-operator/prometheus-operator/pkg/prometheus"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/webconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
prometheusMode = "agent"
|
||||
governingServiceName = "prometheus-agent-operated"
|
||||
)
|
||||
|
||||
func makeStatefulSet(
|
||||
logger log.Logger,
|
||||
name string,
|
||||
p monitoringv1.PrometheusInterface,
|
||||
config *operator.Config,
|
||||
cg *prompkg.ConfigGenerator,
|
||||
inputHash string,
|
||||
shard int32,
|
||||
tlsAssetSecrets []string,
|
||||
) (*appsv1.StatefulSet, error) {
|
||||
cpf := p.GetCommonPrometheusFields()
|
||||
objMeta := p.GetObjectMeta()
|
||||
typeMeta := p.GetTypeMeta()
|
||||
|
||||
if cpf.PortName == "" {
|
||||
cpf.PortName = prompkg.DefaultPortName
|
||||
}
|
||||
|
||||
if cpf.Replicas == nil {
|
||||
cpf.Replicas = &prompkg.MinReplicas
|
||||
}
|
||||
intZero := int32(0)
|
||||
if cpf.Replicas != nil && *cpf.Replicas < 0 {
|
||||
cpf.Replicas = &intZero
|
||||
}
|
||||
|
||||
// We need to re-set the common fields because cpf is only a copy of the original object.
|
||||
// We set some defaults if some fields are not present, and we want those fields set in the original Prometheus object before building the StatefulSetSpec.
|
||||
p.SetCommonPrometheusFields(cpf)
|
||||
spec, err := makeStatefulSetSpec(logger, p, config, cg, shard, tlsAssetSecrets)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "make StatefulSet spec")
|
||||
}
|
||||
|
||||
boolTrue := true
|
||||
// do not transfer kubectl annotations to the statefulset so it is not
|
||||
// pruned by kubectl
|
||||
annotations := make(map[string]string)
|
||||
for key, value := range objMeta.GetAnnotations() {
|
||||
if !strings.HasPrefix(key, "kubectl.kubernetes.io/") {
|
||||
annotations[key] = value
|
||||
}
|
||||
}
|
||||
labels := make(map[string]string)
|
||||
for key, value := range objMeta.GetLabels() {
|
||||
labels[key] = value
|
||||
}
|
||||
labels[prompkg.ShardLabelName] = fmt.Sprintf("%d", shard)
|
||||
labels[prompkg.PrometheusNameLabelName] = objMeta.GetName()
|
||||
labels[prompkg.PrometheusModeLabeLName] = prometheusMode
|
||||
|
||||
statefulset := &appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: config.Labels.Merge(labels),
|
||||
Annotations: annotations,
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
APIVersion: typeMeta.APIVersion,
|
||||
BlockOwnerDeletion: &boolTrue,
|
||||
Controller: &boolTrue,
|
||||
Kind: typeMeta.Kind,
|
||||
Name: objMeta.GetName(),
|
||||
UID: objMeta.GetUID(),
|
||||
},
|
||||
},
|
||||
},
|
||||
Spec: *spec,
|
||||
}
|
||||
|
||||
if statefulset.ObjectMeta.Annotations == nil {
|
||||
statefulset.ObjectMeta.Annotations = map[string]string{
|
||||
prompkg.SSetInputHashName: inputHash,
|
||||
}
|
||||
} else {
|
||||
statefulset.ObjectMeta.Annotations[prompkg.SSetInputHashName] = inputHash
|
||||
}
|
||||
|
||||
if cpf.ImagePullSecrets != nil && len(cpf.ImagePullSecrets) > 0 {
|
||||
statefulset.Spec.Template.Spec.ImagePullSecrets = cpf.ImagePullSecrets
|
||||
}
|
||||
storageSpec := cpf.Storage
|
||||
if storageSpec == nil {
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: prompkg.VolumeName(p),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
},
|
||||
})
|
||||
} else if storageSpec.EmptyDir != nil {
|
||||
emptyDir := storageSpec.EmptyDir
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: prompkg.VolumeName(p),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
EmptyDir: emptyDir,
|
||||
},
|
||||
})
|
||||
} else if storageSpec.Ephemeral != nil {
|
||||
ephemeral := storageSpec.Ephemeral
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: prompkg.VolumeName(p),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
Ephemeral: ephemeral,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
pvcTemplate := operator.MakeVolumeClaimTemplate(storageSpec.VolumeClaimTemplate)
|
||||
if pvcTemplate.Name == "" {
|
||||
pvcTemplate.Name = prompkg.VolumeName(p)
|
||||
}
|
||||
if storageSpec.VolumeClaimTemplate.Spec.AccessModes == nil {
|
||||
pvcTemplate.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}
|
||||
} else {
|
||||
pvcTemplate.Spec.AccessModes = storageSpec.VolumeClaimTemplate.Spec.AccessModes
|
||||
}
|
||||
pvcTemplate.Spec.Resources = storageSpec.VolumeClaimTemplate.Spec.Resources
|
||||
pvcTemplate.Spec.Selector = storageSpec.VolumeClaimTemplate.Spec.Selector
|
||||
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *pvcTemplate)
|
||||
}
|
||||
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, cpf.Volumes...)
|
||||
|
||||
if cpf.HostNetwork {
|
||||
statefulset.Spec.Template.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
|
||||
}
|
||||
|
||||
return statefulset, nil
|
||||
}
|
||||
|
||||
func makeStatefulSetSpec(
|
||||
logger log.Logger,
|
||||
p monitoringv1.PrometheusInterface,
|
||||
c *operator.Config,
|
||||
cg *prompkg.ConfigGenerator,
|
||||
shard int32,
|
||||
tlsAssetSecrets []string,
|
||||
) (*appsv1.StatefulSetSpec, error) {
|
||||
// Prometheus may take quite long to shut down to checkpoint existing data.
|
||||
// Allow up to 10 minutes for clean termination.
|
||||
terminationGracePeriod := int64(600)
|
||||
cpf := p.GetCommonPrometheusFields()
|
||||
promName := p.GetObjectMeta().GetName()
|
||||
|
||||
pImagePath, err := operator.BuildImagePath(
|
||||
operator.StringPtrValOrDefault(cpf.Image, ""),
|
||||
operator.StringValOrDefault("", c.PrometheusDefaultBaseImage),
|
||||
operator.StringValOrDefault(cpf.Version, operator.DefaultPrometheusVersion),
|
||||
"",
|
||||
"",
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webRoutePrefix := "/"
|
||||
if cpf.RoutePrefix != "" {
|
||||
webRoutePrefix = cpf.RoutePrefix
|
||||
}
|
||||
|
||||
cpf.EnableFeatures = append(cpf.EnableFeatures, "agent")
|
||||
promArgs := prompkg.BuildCommonPrometheusArgs(cpf, cg, webRoutePrefix)
|
||||
promArgs = appendAgentArgs(promArgs, cg)
|
||||
|
||||
var ports []v1.ContainerPort
|
||||
if !cpf.ListenLocal {
|
||||
ports = []v1.ContainerPort{
|
||||
{
|
||||
Name: cpf.PortName,
|
||||
ContainerPort: 9090,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
volumes, promVolumeMounts, err := prompkg.BuildCommonVolumes(p, tlsAssetSecrets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Mount web config and web TLS credentials as volumes.
|
||||
// We always mount the web config file for versions greater than 2.24.0.
|
||||
// With this we avoid redeploying prometheus when reconfiguring between
|
||||
// HTTP and HTTPS and vice-versa.
|
||||
webConfigGenerator := cg.WithMinimumVersion("2.24.0")
|
||||
if webConfigGenerator.IsCompatible() {
|
||||
var fields monitoringv1.WebConfigFileFields
|
||||
if cpf.Web != nil {
|
||||
fields = cpf.Web.WebConfigFileFields
|
||||
}
|
||||
|
||||
webConfig, err := webconfig.New(prompkg.WebConfigDir, prompkg.WebConfigSecretName(p), fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
confArg, configVol, configMount, err := webConfig.GetMountParameters()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
promArgs = append(promArgs, confArg)
|
||||
volumes = append(volumes, configVol...)
|
||||
promVolumeMounts = append(promVolumeMounts, configMount...)
|
||||
} else if cpf.Web != nil {
|
||||
webConfigGenerator.Warn("web.config.file")
|
||||
}
|
||||
|
||||
// The /-/ready handler returns OK only after the TSDB initialization has
|
||||
// completed. The WAL replay can take a significant time for large setups
|
||||
// hence we enable the startup probe with a generous failure threshold (15
|
||||
// minutes) to ensure that the readiness probe only comes into effect once
|
||||
// Prometheus is effectively ready.
|
||||
// We don't want to use the /-/healthy handler here because it returns OK as
|
||||
// soon as the web server is started (irrespective of the WAL replay).
|
||||
readyProbeHandler := prompkg.ProbeHandler("/-/ready", cpf, webConfigGenerator, webRoutePrefix)
|
||||
startupProbe := &v1.Probe{
|
||||
ProbeHandler: readyProbeHandler,
|
||||
TimeoutSeconds: prompkg.ProbeTimeoutSeconds,
|
||||
PeriodSeconds: 15,
|
||||
FailureThreshold: 60,
|
||||
}
|
||||
|
||||
readinessProbe := &v1.Probe{
|
||||
ProbeHandler: readyProbeHandler,
|
||||
TimeoutSeconds: prompkg.ProbeTimeoutSeconds,
|
||||
PeriodSeconds: 5,
|
||||
FailureThreshold: 3,
|
||||
}
|
||||
|
||||
livenessProbe := &v1.Probe{
|
||||
ProbeHandler: prompkg.ProbeHandler("/-/healthy", cpf, webConfigGenerator, webRoutePrefix),
|
||||
TimeoutSeconds: prompkg.ProbeTimeoutSeconds,
|
||||
PeriodSeconds: 5,
|
||||
FailureThreshold: 6,
|
||||
}
|
||||
|
||||
podAnnotations, podLabels := prompkg.BuildPodMetadata(cpf, cg)
|
||||
// In cases where an existing selector label is modified, or a new one is added, new sts cannot match existing pods.
|
||||
// We should try to avoid removing such immutable fields whenever possible since doing
|
||||
// so forces us to enter the 'recreate cycle' and can potentially lead to downtime.
|
||||
// The requirement to make a change here should be carefully evaluated.
|
||||
podSelectorLabels := map[string]string{
|
||||
"app.kubernetes.io/name": "prometheus-agent",
|
||||
"app.kubernetes.io/managed-by": "prometheus-operator",
|
||||
"app.kubernetes.io/instance": promName,
|
||||
prompkg.ShardLabelName: fmt.Sprintf("%d", shard),
|
||||
prompkg.PrometheusNameLabelName: promName,
|
||||
}
|
||||
|
||||
for k, v := range podSelectorLabels {
|
||||
podLabels[k] = v
|
||||
}
|
||||
|
||||
finalSelectorLabels := c.Labels.Merge(podSelectorLabels)
|
||||
finalLabels := c.Labels.Merge(podLabels)
|
||||
|
||||
var additionalContainers, operatorInitContainers []v1.Container
|
||||
|
||||
prometheusURIScheme := "http"
|
||||
if cpf.Web != nil && cpf.Web.TLSConfig != nil {
|
||||
prometheusURIScheme = "https"
|
||||
}
|
||||
|
||||
var watchedDirectories []string
|
||||
configReloaderVolumeMounts := []v1.VolumeMount{
|
||||
{
|
||||
Name: "config",
|
||||
MountPath: prompkg.ConfDir,
|
||||
},
|
||||
{
|
||||
Name: "config-out",
|
||||
MountPath: prompkg.ConfOutDir,
|
||||
},
|
||||
}
|
||||
|
||||
var minReadySeconds int32
|
||||
if cpf.MinReadySeconds != nil {
|
||||
minReadySeconds = int32(*cpf.MinReadySeconds)
|
||||
}
|
||||
|
||||
operatorInitContainers = append(operatorInitContainers,
|
||||
operator.CreateConfigReloader(
|
||||
"init-config-reloader",
|
||||
operator.ReloaderConfig(c.ReloaderConfig),
|
||||
operator.ReloaderRunOnce(),
|
||||
operator.LogFormat(cpf.LogFormat),
|
||||
operator.LogLevel(cpf.LogLevel),
|
||||
operator.VolumeMounts(configReloaderVolumeMounts),
|
||||
operator.ConfigFile(path.Join(prompkg.ConfDir, prompkg.ConfigFilename)),
|
||||
operator.ConfigEnvsubstFile(path.Join(prompkg.ConfOutDir, prompkg.ConfigEnvsubstFilename)),
|
||||
operator.WatchedDirectories(watchedDirectories),
|
||||
operator.Shard(shard),
|
||||
operator.ImagePullPolicy(cpf.ImagePullPolicy),
|
||||
),
|
||||
)
|
||||
|
||||
initContainers, err := k8sutil.MergePatchContainers(operatorInitContainers, cpf.InitContainers)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to merge init containers spec")
|
||||
}
|
||||
|
||||
containerArgs, err := operator.BuildArgs(promArgs, cpf.AdditionalArgs)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
boolFalse := false
|
||||
boolTrue := true
|
||||
operatorContainers := append([]v1.Container{
|
||||
{
|
||||
Name: "prometheus",
|
||||
Image: pImagePath,
|
||||
ImagePullPolicy: cpf.ImagePullPolicy,
|
||||
Ports: ports,
|
||||
Args: containerArgs,
|
||||
VolumeMounts: promVolumeMounts,
|
||||
StartupProbe: startupProbe,
|
||||
LivenessProbe: livenessProbe,
|
||||
ReadinessProbe: readinessProbe,
|
||||
Resources: cpf.Resources,
|
||||
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
|
||||
SecurityContext: &v1.SecurityContext{
|
||||
ReadOnlyRootFilesystem: &boolTrue,
|
||||
AllowPrivilegeEscalation: &boolFalse,
|
||||
Capabilities: &v1.Capabilities{
|
||||
Drop: []v1.Capability{"ALL"},
|
||||
},
|
||||
},
|
||||
},
|
||||
operator.CreateConfigReloader(
|
||||
"config-reloader",
|
||||
operator.ReloaderConfig(c.ReloaderConfig),
|
||||
operator.ReloaderURL(url.URL{
|
||||
Scheme: prometheusURIScheme,
|
||||
Host: c.LocalHost + ":9090",
|
||||
Path: path.Clean(webRoutePrefix + "/-/reload"),
|
||||
}),
|
||||
operator.ListenLocal(cpf.ListenLocal),
|
||||
operator.LocalHost(c.LocalHost),
|
||||
operator.LogFormat(cpf.LogFormat),
|
||||
operator.LogLevel(cpf.LogLevel),
|
||||
operator.ConfigFile(path.Join(prompkg.ConfDir, prompkg.ConfigFilename)),
|
||||
operator.ConfigEnvsubstFile(path.Join(prompkg.ConfOutDir, prompkg.ConfigEnvsubstFilename)),
|
||||
operator.WatchedDirectories(watchedDirectories), operator.VolumeMounts(configReloaderVolumeMounts),
|
||||
operator.Shard(shard),
|
||||
operator.ImagePullPolicy(cpf.ImagePullPolicy),
|
||||
),
|
||||
}, additionalContainers...)
|
||||
|
||||
containers, err := k8sutil.MergePatchContainers(operatorContainers, cpf.Containers)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to merge containers spec")
|
||||
}
|
||||
|
||||
// PodManagementPolicy is set to Parallel to mitigate issues in kubernetes: https://github.com/kubernetes/kubernetes/issues/60164
|
||||
// This is also mentioned as one of limitations of StatefulSets: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations
|
||||
return &appsv1.StatefulSetSpec{
|
||||
ServiceName: governingServiceName,
|
||||
Replicas: cpf.Replicas,
|
||||
PodManagementPolicy: appsv1.ParallelPodManagement,
|
||||
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
|
||||
Type: appsv1.RollingUpdateStatefulSetStrategyType,
|
||||
},
|
||||
MinReadySeconds: minReadySeconds,
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: finalSelectorLabels,
|
||||
},
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: finalLabels,
|
||||
Annotations: podAnnotations,
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: containers,
|
||||
InitContainers: initContainers,
|
||||
SecurityContext: cpf.SecurityContext,
|
||||
ServiceAccountName: cpf.ServiceAccountName,
|
||||
AutomountServiceAccountToken: &boolTrue,
|
||||
NodeSelector: cpf.NodeSelector,
|
||||
PriorityClassName: cpf.PriorityClassName,
|
||||
TerminationGracePeriodSeconds: &terminationGracePeriod,
|
||||
Volumes: volumes,
|
||||
Tolerations: cpf.Tolerations,
|
||||
Affinity: cpf.Affinity,
|
||||
TopologySpreadConstraints: cpf.TopologySpreadConstraints,
|
||||
HostAliases: operator.MakeHostAliases(cpf.HostAliases),
|
||||
HostNetwork: cpf.HostNetwork,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func makeStatefulSetService(p *monitoringv1alpha1.PrometheusAgent, config operator.Config) *v1.Service {
|
||||
p = p.DeepCopy()
|
||||
|
||||
if p.Spec.PortName == "" {
|
||||
p.Spec.PortName = prompkg.DefaultPortName
|
||||
}
|
||||
|
||||
svc := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: governingServiceName,
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
Name: p.GetName(),
|
||||
Kind: p.Kind,
|
||||
APIVersion: p.APIVersion,
|
||||
UID: p.GetUID(),
|
||||
},
|
||||
},
|
||||
Labels: config.Labels.Merge(map[string]string{
|
||||
"operated-prometheus": "true",
|
||||
}),
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
ClusterIP: "None",
|
||||
Ports: []v1.ServicePort{
|
||||
{
|
||||
Name: p.Spec.PortName,
|
||||
Port: 9090,
|
||||
TargetPort: intstr.FromString(p.Spec.PortName),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{
|
||||
"app.kubernetes.io/name": "prometheus-agent",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
// appendAgentArgs appends arguments that are only valid for the Prometheus agent.
|
||||
func appendAgentArgs(promArgs []monitoringv1.Argument, cg *prompkg.ConfigGenerator) []monitoringv1.Argument {
|
||||
|
||||
promArgs = append(promArgs,
|
||||
monitoringv1.Argument{Name: "storage.agent.path", Value: prompkg.StorageDir},
|
||||
)
|
||||
|
||||
return promArgs
|
||||
}
|
108
pkg/prometheus/operator.go
Normal file
108
pkg/prometheus/operator.go
Normal file
|
@ -0,0 +1,108 @@
|
|||
// Copyright 2016 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 (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
var prometheusKeyInShardStatefulSet = regexp.MustCompile("^(.+)/prometheus-(.+)-shard-[1-9][0-9]*$")
|
||||
var prometheusKeyInStatefulSet = regexp.MustCompile("^(.+)/prometheus-(.+)$")
|
||||
|
||||
func StatefulSetKeyToPrometheusKey(key string) (bool, string) {
|
||||
r := prometheusKeyInStatefulSet
|
||||
if prometheusKeyInShardStatefulSet.MatchString(key) {
|
||||
r = prometheusKeyInShardStatefulSet
|
||||
}
|
||||
|
||||
matches := r.FindAllStringSubmatch(key, 2)
|
||||
if len(matches) != 1 {
|
||||
return false, ""
|
||||
}
|
||||
if len(matches[0]) != 3 {
|
||||
return false, ""
|
||||
}
|
||||
return true, matches[0][1] + "/" + matches[0][2]
|
||||
}
|
||||
|
||||
func KeyToStatefulSetKey(p monitoringv1.PrometheusInterface, key string, shard int) string {
|
||||
keyParts := strings.Split(key, "/")
|
||||
return fmt.Sprintf("%s/%s", keyParts[0], statefulSetNameFromPrometheusName(p, keyParts[1], shard))
|
||||
}
|
||||
|
||||
func statefulSetNameFromPrometheusName(p monitoringv1.PrometheusInterface, name string, shard int) string {
|
||||
if shard == 0 {
|
||||
return fmt.Sprintf("%s-%s", prefix(p), name)
|
||||
}
|
||||
return fmt.Sprintf("%s-%s-shard-%d", prefix(p), name, shard)
|
||||
}
|
||||
|
||||
func NewTLSAssetSecret(p monitoringv1.PrometheusInterface, labels map[string]string) *v1.Secret {
|
||||
objMeta := p.GetObjectMeta()
|
||||
typeMeta := p.GetTypeMeta()
|
||||
|
||||
boolTrue := true
|
||||
return &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: TLSAssetsSecretName(p),
|
||||
Labels: labels,
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
APIVersion: typeMeta.APIVersion,
|
||||
BlockOwnerDeletion: &boolTrue,
|
||||
Controller: &boolTrue,
|
||||
Kind: typeMeta.Kind,
|
||||
Name: objMeta.GetName(),
|
||||
UID: objMeta.GetUID(),
|
||||
},
|
||||
},
|
||||
},
|
||||
Data: map[string][]byte{},
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateRemoteWriteSpec checks that mutually exclusive configurations are not
|
||||
// included in the Prometheus remoteWrite configuration section.
|
||||
// Reference:
|
||||
// https://github.com/prometheus/prometheus/blob/main/docs/configuration/configuration.md#remote_write
|
||||
func ValidateRemoteWriteSpec(spec monitoringv1.RemoteWriteSpec) error {
|
||||
var nonNilFields []string
|
||||
for k, v := range map[string]interface{}{
|
||||
"basicAuth": spec.BasicAuth,
|
||||
"oauth2": spec.OAuth2,
|
||||
"authorization": spec.Authorization,
|
||||
"sigv4": spec.Sigv4,
|
||||
} {
|
||||
if reflect.ValueOf(v).IsNil() {
|
||||
continue
|
||||
}
|
||||
nonNilFields = append(nonNilFields, fmt.Sprintf("%q", k))
|
||||
}
|
||||
|
||||
if len(nonNilFields) > 1 {
|
||||
return errors.Errorf("%s can't be set at the same time, at most one of them must be defined", strings.Join(nonNilFields, " and "))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
151
pkg/prometheus/operator_test.go
Normal file
151
pkg/prometheus/operator_test.go
Normal file
|
@ -0,0 +1,151 @@
|
|||
// 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")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -2025,3 +2025,56 @@ func (cg *ConfigGenerator) appendAdditionalScrapeConfigs(scrapeConfigs []yaml.Ma
|
|||
|
||||
return append(scrapeConfigs, addlScrapeConfigs...), nil
|
||||
}
|
||||
|
||||
// GenerateAgentConfiguration creates a serialized YAML representation of a Prometheus Agent configuration using the provided resources.
|
||||
func (cg *ConfigGenerator) GenerateAgentConfiguration(
|
||||
sMons map[string]*v1.ServiceMonitor,
|
||||
pMons map[string]*v1.PodMonitor,
|
||||
probes map[string]*v1.Probe,
|
||||
store *assets.Store,
|
||||
additionalScrapeConfigs []byte,
|
||||
) ([]byte, error) {
|
||||
cpf := cg.prom.GetCommonPrometheusFields()
|
||||
|
||||
// validates the value of scrapeTimeout based on scrapeInterval
|
||||
if cpf.ScrapeTimeout != "" {
|
||||
if err := CompareScrapeTimeoutToScrapeInterval(cpf.ScrapeTimeout, cpf.ScrapeInterval); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Global config
|
||||
cfg := yaml.MapSlice{}
|
||||
globalItems := yaml.MapSlice{}
|
||||
globalItems = cg.appendScrapeIntervals(globalItems)
|
||||
globalItems = cg.appendExternalLabels(globalItems)
|
||||
cfg = append(cfg, yaml.MapItem{Key: "global", Value: globalItems})
|
||||
|
||||
// Scrape config
|
||||
var (
|
||||
scrapeConfigs []yaml.MapSlice
|
||||
apiserverConfig = cpf.APIServerConfig
|
||||
shards = int32(1)
|
||||
)
|
||||
if cpf.Shards != nil && *cpf.Shards > 1 {
|
||||
shards = *cpf.Shards
|
||||
}
|
||||
scrapeConfigs = cg.appendServiceMonitorConfigs(scrapeConfigs, sMons, apiserverConfig, store, shards)
|
||||
scrapeConfigs = cg.appendPodMonitorConfigs(scrapeConfigs, pMons, apiserverConfig, store, shards)
|
||||
scrapeConfigs = cg.appendProbeConfigs(scrapeConfigs, probes, apiserverConfig, store, shards)
|
||||
scrapeConfigs, err := cg.appendAdditionalScrapeConfigs(scrapeConfigs, additionalScrapeConfigs, shards)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "generate additional scrape configs")
|
||||
}
|
||||
cfg = append(cfg, yaml.MapItem{
|
||||
Key: "scrape_configs",
|
||||
Value: scrapeConfigs,
|
||||
})
|
||||
|
||||
// Remote write config
|
||||
if len(cpf.RemoteWrite) > 0 {
|
||||
cfg = append(cfg, cg.generateRemoteWriteConfig(store))
|
||||
}
|
||||
|
||||
return yaml.Marshal(cfg)
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -266,7 +264,7 @@ func New(ctx context.Context, conf operator.Config, logger log.Logger, r prometh
|
|||
c.mdClient,
|
||||
resyncPeriod,
|
||||
func(options *metav1.ListOptions) {
|
||||
options.LabelSelector = labelPrometheusName
|
||||
options.LabelSelector = prompkg.LabelPrometheusName
|
||||
},
|
||||
),
|
||||
v1.SchemeGroupVersion.WithResource(string(v1.ResourceConfigMaps)),
|
||||
|
@ -1020,7 +1018,7 @@ func (c *Operator) Resolve(ss *appsv1.StatefulSet) metav1.Object {
|
|||
return nil
|
||||
}
|
||||
|
||||
match, promKey := statefulSetKeyToPrometheusKey(key)
|
||||
match, promKey := prompkg.StatefulSetKeyToPrometheusKey(key)
|
||||
if !match {
|
||||
level.Debug(c.logger).Log("msg", "StatefulSet key did not match a Prometheus key format", "key", key)
|
||||
return nil
|
||||
|
@ -1039,37 +1037,6 @@ func (c *Operator) Resolve(ss *appsv1.StatefulSet) metav1.Object {
|
|||
return p.(*monitoringv1.Prometheus)
|
||||
}
|
||||
|
||||
func statefulSetNameFromPrometheusName(name string, shard int) string {
|
||||
if shard == 0 {
|
||||
return fmt.Sprintf("prometheus-%s", name)
|
||||
}
|
||||
return fmt.Sprintf("prometheus-%s-shard-%d", name, shard)
|
||||
}
|
||||
|
||||
var prometheusKeyInShardStatefulSet = regexp.MustCompile("^(.+)/prometheus-(.+)-shard-[1-9][0-9]*$")
|
||||
var prometheusKeyInStatefulSet = regexp.MustCompile("^(.+)/prometheus-(.+)$")
|
||||
|
||||
func statefulSetKeyToPrometheusKey(key string) (bool, string) {
|
||||
r := prometheusKeyInStatefulSet
|
||||
if prometheusKeyInShardStatefulSet.MatchString(key) {
|
||||
r = prometheusKeyInShardStatefulSet
|
||||
}
|
||||
|
||||
matches := r.FindAllStringSubmatch(key, 2)
|
||||
if len(matches) != 1 {
|
||||
return false, ""
|
||||
}
|
||||
if len(matches[0]) != 3 {
|
||||
return false, ""
|
||||
}
|
||||
return true, matches[0][1] + "/" + matches[0][2]
|
||||
}
|
||||
|
||||
func prometheusKeyToStatefulSetKey(key string, shard int) string {
|
||||
keyParts := strings.Split(key, "/")
|
||||
return fmt.Sprintf("%s/%s", keyParts[0], statefulSetNameFromPrometheusName(keyParts[1], shard))
|
||||
}
|
||||
|
||||
func (c *Operator) handleMonitorNamespaceUpdate(oldo, curo interface{}) {
|
||||
old := oldo.(*v1.Namespace)
|
||||
cur := curo.(*v1.Namespace)
|
||||
|
@ -1183,7 +1150,7 @@ func (c *Operator) sync(ctx context.Context, key string) error {
|
|||
|
||||
// Create governing service if it doesn't exist.
|
||||
svcClient := c.kclient.CoreV1().Services(p.Namespace)
|
||||
if err := k8sutil.CreateOrUpdateService(ctx, svcClient, prompkg.MakeStatefulSetService(p, c.config)); err != nil {
|
||||
if err := k8sutil.CreateOrUpdateService(ctx, svcClient, makeStatefulSetService(p, c.config)); err != nil {
|
||||
return errors.Wrap(err, "synchronizing governing service failed")
|
||||
}
|
||||
|
||||
|
@ -1195,7 +1162,7 @@ func (c *Operator) sync(ctx context.Context, key string) error {
|
|||
logger := log.With(logger, "statefulset", ssetName, "shard", fmt.Sprintf("%d", shard))
|
||||
level.Debug(logger).Log("msg", "reconciling statefulset")
|
||||
|
||||
obj, err := c.ssetInfs.Get(prometheusKeyToStatefulSetKey(key, shard))
|
||||
obj, err := c.ssetInfs.Get(prompkg.KeyToStatefulSetKey(p, key, shard))
|
||||
exists := !apierrors.IsNotFound(err)
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return errors.Wrap(err, "retrieving statefulset failed")
|
||||
|
@ -1297,7 +1264,7 @@ func (c *Operator) sync(ctx context.Context, key string) error {
|
|||
ssets[ssetName] = struct{}{}
|
||||
}
|
||||
|
||||
err = c.ssetInfs.ListAllByNamespace(p.Namespace, labels.SelectorFromSet(labels.Set{prompkg.PrometheusNameLabelName: p.Name}), func(obj interface{}) {
|
||||
err = c.ssetInfs.ListAllByNamespace(p.Namespace, labels.SelectorFromSet(labels.Set{prompkg.PrometheusNameLabelName: p.Name, prompkg.PrometheusModeLabeLName: prometheusMode}), func(obj interface{}) {
|
||||
s := obj.(*appsv1.StatefulSet)
|
||||
|
||||
if _, ok := ssets[s.Name]; ok {
|
||||
|
@ -1363,7 +1330,7 @@ func (c *Operator) UpdateStatus(ctx context.Context, key string) error {
|
|||
}
|
||||
|
||||
for shard := range prompkg.ExpectedStatefulSetShardNames(p) {
|
||||
ssetName := prometheusKeyToStatefulSetKey(key, shard)
|
||||
ssetName := prompkg.KeyToStatefulSetKey(p, key, shard)
|
||||
logger := log.With(logger, "statefulset", ssetName, "shard", shard)
|
||||
|
||||
obj, err := c.ssetInfs.Get(ssetName)
|
||||
|
@ -1628,7 +1595,7 @@ func (c *Operator) createOrUpdateConfigurationSecret(ctx context.Context, p *mon
|
|||
}
|
||||
|
||||
for i, remote := range p.Spec.RemoteWrite {
|
||||
if err := validateRemoteWriteSpec(remote); err != nil {
|
||||
if err := prompkg.ValidateRemoteWriteSpec(remote); err != nil {
|
||||
return errors.Wrapf(err, "remote write %d", i)
|
||||
}
|
||||
key := fmt.Sprintf("remoteWrite/%d", i)
|
||||
|
@ -1722,9 +1689,9 @@ func (c *Operator) createOrUpdateConfigurationSecret(ctx context.Context, p *mon
|
|||
|
||||
func (c *Operator) createOrUpdateTLSAssetSecrets(ctx context.Context, p *monitoringv1.Prometheus, store *assets.Store) (*operator.ShardedSecret, error) {
|
||||
labels := c.config.Labels.Merge(prompkg.ManagedByOperatorLabels)
|
||||
template := newTLSAssetSecret(p, labels)
|
||||
template := prompkg.NewTLSAssetSecret(p, labels)
|
||||
|
||||
sSecret := operator.NewShardedSecret(template, prompkg.TLSAssetsSecretName(p.Name))
|
||||
sSecret := operator.NewShardedSecret(template, prompkg.TLSAssetsSecretName(p))
|
||||
|
||||
for k, v := range store.TLSAssets {
|
||||
sSecret.AppendData(k.String(), []byte(v))
|
||||
|
@ -1741,27 +1708,6 @@ func (c *Operator) createOrUpdateTLSAssetSecrets(ctx context.Context, p *monitor
|
|||
return sSecret, nil
|
||||
}
|
||||
|
||||
func newTLSAssetSecret(p *monitoringv1.Prometheus, labels map[string]string) *v1.Secret {
|
||||
boolTrue := true
|
||||
return &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: prompkg.TLSAssetsSecretName(p.Name),
|
||||
Labels: labels,
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
APIVersion: p.APIVersion,
|
||||
BlockOwnerDeletion: &boolTrue,
|
||||
Controller: &boolTrue,
|
||||
Kind: p.Kind,
|
||||
Name: p.Name,
|
||||
UID: p.UID,
|
||||
},
|
||||
},
|
||||
},
|
||||
Data: map[string][]byte{},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Operator) createOrUpdateWebConfigSecret(ctx context.Context, p *monitoringv1.Prometheus) error {
|
||||
boolTrue := true
|
||||
|
||||
|
@ -1772,7 +1718,7 @@ func (c *Operator) createOrUpdateWebConfigSecret(ctx context.Context, p *monitor
|
|||
|
||||
webConfig, err := webconfig.New(
|
||||
prompkg.WebConfigDir,
|
||||
prompkg.WebConfigSecretName(p.Name),
|
||||
prompkg.WebConfigSecretName(p),
|
||||
fields,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -1796,28 +1742,3 @@ func (c *Operator) createOrUpdateWebConfigSecret(ctx context.Context, p *monitor
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateRemoteWriteSpec checks that mutually exclusive configurations are not
|
||||
// included in the Prometheus remoteWrite configuration section.
|
||||
// Reference:
|
||||
// https://github.com/prometheus/prometheus/blob/main/docs/configuration/configuration.md#remote_write
|
||||
func validateRemoteWriteSpec(spec monitoringv1.RemoteWriteSpec) error {
|
||||
var nonNilFields []string
|
||||
for k, v := range map[string]interface{}{
|
||||
"basicAuth": spec.BasicAuth,
|
||||
"oauth2": spec.OAuth2,
|
||||
"authorization": spec.Authorization,
|
||||
"sigv4": spec.Sigv4,
|
||||
} {
|
||||
if reflect.ValueOf(v).IsNil() {
|
||||
continue
|
||||
}
|
||||
nonNilFields = append(nonNilFields, fmt.Sprintf("%q", k))
|
||||
}
|
||||
|
||||
if len(nonNilFields) > 1 {
|
||||
return errors.Errorf("%s can't be set at the same time, at most one of them must be defined", strings.Join(nonNilFields, " and "))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -323,129 +323,3 @@ func TestGetNodeAddresses(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
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 TestPrometheusKeyToStatefulSetKey(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
shard int
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "namespace/test",
|
||||
shard: 0,
|
||||
expected: "namespace/prometheus-test",
|
||||
},
|
||||
{
|
||||
name: "namespace/test",
|
||||
shard: 1,
|
||||
expected: "namespace/prometheus-test-shard-1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
got := prometheusKeyToStatefulSetKey(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")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import (
|
|||
prompkg "github.com/prometheus-operator/prometheus-operator/pkg/prometheus"
|
||||
)
|
||||
|
||||
const labelPrometheusName = "prometheus-name"
|
||||
|
||||
// The maximum `Data` size of a ConfigMap seems to differ between
|
||||
// environments. This is probably due to different meta data sizes which count
|
||||
// into the overall maximum size of a ConfigMap. Thereby lets leave a
|
||||
|
@ -161,7 +159,7 @@ func (c *Operator) createOrUpdateRuleConfigMaps(ctx context.Context, p *monitori
|
|||
}
|
||||
|
||||
func prometheusRulesConfigMapSelector(prometheusName string) metav1.ListOptions {
|
||||
return metav1.ListOptions{LabelSelector: fmt.Sprintf("%v=%v", labelPrometheusName, prometheusName)}
|
||||
return metav1.ListOptions{LabelSelector: fmt.Sprintf("%v=%v", prompkg.LabelPrometheusName, prometheusName)}
|
||||
}
|
||||
|
||||
func (c *Operator) selectRuleNamespaces(p *monitoringv1.Prometheus) ([]string, error) {
|
||||
|
@ -255,7 +253,7 @@ func bucketSize(bucket map[string]string) int {
|
|||
func makeRulesConfigMap(p *monitoringv1.Prometheus, ruleFiles map[string]string) v1.ConfigMap {
|
||||
boolTrue := true
|
||||
|
||||
labels := map[string]string{labelPrometheusName: p.Name}
|
||||
labels := map[string]string{prompkg.LabelPrometheusName: p.Name}
|
||||
for k, v := range prompkg.ManagedByOperatorLabels {
|
||||
labels[k] = v
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
|
||||
|
@ -37,8 +38,59 @@ import (
|
|||
const (
|
||||
defaultRetention = "24h"
|
||||
defaultQueryLogVolume = "query-log-file"
|
||||
prometheusMode = "server"
|
||||
governingServiceName = "prometheus-operated"
|
||||
)
|
||||
|
||||
// TODO(ArthurSens): generalize it enough to be used by both server and agent.
|
||||
func makeStatefulSetService(p *monitoringv1.Prometheus, config operator.Config) *v1.Service {
|
||||
p = p.DeepCopy()
|
||||
|
||||
if p.Spec.PortName == "" {
|
||||
p.Spec.PortName = prompkg.DefaultPortName
|
||||
}
|
||||
|
||||
svc := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: governingServiceName,
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
Name: p.GetName(),
|
||||
Kind: p.Kind,
|
||||
APIVersion: p.APIVersion,
|
||||
UID: p.GetUID(),
|
||||
},
|
||||
},
|
||||
Labels: config.Labels.Merge(map[string]string{
|
||||
"operated-prometheus": "true",
|
||||
}),
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
ClusterIP: "None",
|
||||
Ports: []v1.ServicePort{
|
||||
{
|
||||
Name: p.Spec.PortName,
|
||||
Port: 9090,
|
||||
TargetPort: intstr.FromString(p.Spec.PortName),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{
|
||||
"app.kubernetes.io/name": "prometheus",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if p.Spec.Thanos != nil {
|
||||
svc.Spec.Ports = append(svc.Spec.Ports, v1.ServicePort{
|
||||
Name: "grpc",
|
||||
Port: 10901,
|
||||
TargetPort: intstr.FromString("grpc"),
|
||||
})
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
func makeStatefulSet(
|
||||
logger log.Logger,
|
||||
name string,
|
||||
|
@ -99,6 +151,7 @@ func makeStatefulSet(
|
|||
}
|
||||
labels[prompkg.ShardLabelName] = fmt.Sprintf("%d", shard)
|
||||
labels[prompkg.PrometheusNameLabelName] = objMeta.GetName()
|
||||
labels[prompkg.PrometheusModeLabeLName] = prometheusMode
|
||||
|
||||
statefulset := &appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -133,7 +186,7 @@ func makeStatefulSet(
|
|||
storageSpec := cpf.Storage
|
||||
if storageSpec == nil {
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: prompkg.VolumeName(objMeta.GetName()),
|
||||
Name: prompkg.VolumeName(p),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
},
|
||||
|
@ -141,7 +194,7 @@ func makeStatefulSet(
|
|||
} else if storageSpec.EmptyDir != nil {
|
||||
emptyDir := storageSpec.EmptyDir
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: prompkg.VolumeName(objMeta.GetName()),
|
||||
Name: prompkg.VolumeName(p),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
EmptyDir: emptyDir,
|
||||
},
|
||||
|
@ -149,7 +202,7 @@ func makeStatefulSet(
|
|||
} else if storageSpec.Ephemeral != nil {
|
||||
ephemeral := storageSpec.Ephemeral
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: prompkg.VolumeName(objMeta.GetName()),
|
||||
Name: prompkg.VolumeName(p),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
Ephemeral: ephemeral,
|
||||
},
|
||||
|
@ -157,7 +210,7 @@ func makeStatefulSet(
|
|||
} else {
|
||||
pvcTemplate := operator.MakeVolumeClaimTemplate(storageSpec.VolumeClaimTemplate)
|
||||
if pvcTemplate.Name == "" {
|
||||
pvcTemplate.Name = prompkg.VolumeName(objMeta.GetName())
|
||||
pvcTemplate.Name = prompkg.VolumeName(p)
|
||||
}
|
||||
if storageSpec.VolumeClaimTemplate.Spec.AccessModes == nil {
|
||||
pvcTemplate.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}
|
||||
|
@ -249,7 +302,7 @@ func makeStatefulSetSpec(
|
|||
fields = cpf.Web.WebConfigFileFields
|
||||
}
|
||||
|
||||
webConfig, err := webconfig.New(prompkg.WebConfigDir, prompkg.WebConfigSecretName(promName), fields)
|
||||
webConfig, err := webconfig.New(prompkg.WebConfigDir, prompkg.WebConfigSecretName(p), fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -445,7 +498,7 @@ func makeStatefulSetSpec(
|
|||
// PodManagementPolicy is set to Parallel to mitigate issues in kubernetes: https://github.com/kubernetes/kubernetes/issues/60164
|
||||
// This is also mentioned as one of limitations of StatefulSets: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations
|
||||
return &appsv1.StatefulSetSpec{
|
||||
ServiceName: prompkg.GoverningServiceName,
|
||||
ServiceName: governingServiceName,
|
||||
Replicas: cpf.Replicas,
|
||||
PodManagementPolicy: appsv1.ParallelPodManagement,
|
||||
UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
|
||||
|
@ -683,7 +736,7 @@ func createThanosContainer(
|
|||
})
|
||||
}
|
||||
|
||||
volName := prompkg.VolumeName(p.GetObjectMeta().GetName())
|
||||
volName := prompkg.VolumeName(p)
|
||||
thanosArgs = append(thanosArgs, monitoringv1.Argument{Name: "tsdb.path", Value: prompkg.StorageDir})
|
||||
container.VolumeMounts = append(
|
||||
container.VolumeMounts,
|
||||
|
|
|
@ -100,6 +100,7 @@ func TestStatefulSetLabelingAndAnnotations(t *testing.T) {
|
|||
"testlabel": "testlabelvalue",
|
||||
"operator.prometheus.io/name": "",
|
||||
"operator.prometheus.io/shard": "0",
|
||||
"operator.prometheus.io/mode": "server",
|
||||
}
|
||||
|
||||
expectedPodLabels := map[string]string{
|
||||
|
@ -302,6 +303,19 @@ func TestStatefulSetEphemeral(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStatefulSetVolumeInitial(t *testing.T) {
|
||||
p := monitoringv1.Prometheus{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "volume-init-test",
|
||||
},
|
||||
Spec: monitoringv1.PrometheusSpec{
|
||||
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
|
||||
Secrets: []string{
|
||||
"test-secret1",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &appsv1.StatefulSet{
|
||||
Spec: appsv1.StatefulSetSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
|
@ -355,7 +369,7 @@ func TestStatefulSetVolumeInitial(t *testing.T) {
|
|||
Name: "config",
|
||||
VolumeSource: v1.VolumeSource{
|
||||
Secret: &v1.SecretVolumeSource{
|
||||
SecretName: prompkg.ConfigSecretName("volume-init-test"),
|
||||
SecretName: prompkg.ConfigSecretName(&p),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -367,7 +381,7 @@ func TestStatefulSetVolumeInitial(t *testing.T) {
|
|||
{
|
||||
Secret: &v1.SecretProjection{
|
||||
LocalObjectReference: v1.LocalObjectReference{
|
||||
Name: prompkg.TLSAssetsSecretName("volume-init-test") + "-0",
|
||||
Name: prompkg.TLSAssetsSecretName(&p) + "-0",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -422,18 +436,6 @@ func TestStatefulSetVolumeInitial(t *testing.T) {
|
|||
}
|
||||
|
||||
logger := newLogger()
|
||||
p := monitoringv1.Prometheus{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "volume-init-test",
|
||||
},
|
||||
Spec: monitoringv1.PrometheusSpec{
|
||||
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
|
||||
Secrets: []string{
|
||||
"test-secret1",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cg, err := prompkg.NewConfigGenerator(logger, &p, false)
|
||||
require.NoError(t, err)
|
||||
|
@ -457,7 +459,7 @@ func TestStatefulSetVolumeInitial(t *testing.T) {
|
|||
[]string{"rules-configmap-one"},
|
||||
"",
|
||||
0,
|
||||
[]string{prompkg.TLSAssetsSecretName("volume-init-test") + "-0"})
|
||||
[]string{prompkg.TLSAssetsSecretName(&p) + "-0"})
|
||||
require.NoError(t, err)
|
||||
|
||||
if !reflect.DeepEqual(expected.Spec.Template.Spec.Volumes, sset.Spec.Template.Spec.Volumes) {
|
||||
|
|
|
@ -26,12 +26,12 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
|
||||
)
|
||||
|
||||
const (
|
||||
GoverningServiceName = "prometheus-operated"
|
||||
defaultReplicaExternalLabelName = "prometheus_replica"
|
||||
StorageDir = "/prometheus"
|
||||
ConfDir = "/etc/prometheus/config"
|
||||
|
@ -60,34 +60,38 @@ var (
|
|||
}
|
||||
ShardLabelName = "operator.prometheus.io/shard"
|
||||
PrometheusNameLabelName = "operator.prometheus.io/name"
|
||||
PrometheusModeLabeLName = "operator.prometheus.io/mode"
|
||||
ProbeTimeoutSeconds int32 = 3
|
||||
LabelPrometheusName = "prometheus-name"
|
||||
)
|
||||
|
||||
func ExpectedStatefulSetShardNames(
|
||||
p *monitoringv1.Prometheus,
|
||||
p monitoringv1.PrometheusInterface,
|
||||
) []string {
|
||||
cpf := p.GetCommonPrometheusFields()
|
||||
|
||||
res := []string{}
|
||||
shards := minShards
|
||||
if p.Spec.Shards != nil && *p.Spec.Shards > 1 {
|
||||
shards = *p.Spec.Shards
|
||||
if cpf.Shards != nil && *cpf.Shards > 1 {
|
||||
shards = *cpf.Shards
|
||||
}
|
||||
|
||||
for i := int32(0); i < shards; i++ {
|
||||
res = append(res, prometheusNameByShard(p.Name, i))
|
||||
res = append(res, prometheusNameByShard(p, i))
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func prometheusNameByShard(name string, shard int32) string {
|
||||
base := prefixedName(name)
|
||||
func prometheusNameByShard(p monitoringv1.PrometheusInterface, shard int32) string {
|
||||
base := prefixedName(p)
|
||||
if shard == 0 {
|
||||
return base
|
||||
}
|
||||
return fmt.Sprintf("%s-shard-%d", base, shard)
|
||||
}
|
||||
|
||||
func MakeEmptyConfigurationSecret(p *monitoringv1.Prometheus, config operator.Config) (*v1.Secret, error) {
|
||||
func MakeEmptyConfigurationSecret(p monitoringv1.PrometheusInterface, config operator.Config) (*v1.Secret, error) {
|
||||
s := MakeConfigSecret(p, config)
|
||||
|
||||
s.ObjectMeta.Annotations = map[string]string{
|
||||
|
@ -97,20 +101,23 @@ func MakeEmptyConfigurationSecret(p *monitoringv1.Prometheus, config operator.Co
|
|||
return s, nil
|
||||
}
|
||||
|
||||
func MakeConfigSecret(p *monitoringv1.Prometheus, config operator.Config) *v1.Secret {
|
||||
func MakeConfigSecret(p monitoringv1.PrometheusInterface, config operator.Config) *v1.Secret {
|
||||
objMeta := p.GetObjectMeta()
|
||||
typeMeta := p.GetTypeMeta()
|
||||
|
||||
boolTrue := true
|
||||
return &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: ConfigSecretName(p.Name),
|
||||
Name: ConfigSecretName(p),
|
||||
Labels: config.Labels.Merge(ManagedByOperatorLabels),
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
APIVersion: p.APIVersion,
|
||||
APIVersion: typeMeta.APIVersion,
|
||||
BlockOwnerDeletion: &boolTrue,
|
||||
Controller: &boolTrue,
|
||||
Kind: p.Kind,
|
||||
Name: p.Name,
|
||||
UID: p.UID,
|
||||
Kind: typeMeta.Kind,
|
||||
Name: objMeta.GetName(),
|
||||
UID: objMeta.GetUID(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -120,72 +127,35 @@ func MakeConfigSecret(p *monitoringv1.Prometheus, config operator.Config) *v1.Se
|
|||
}
|
||||
}
|
||||
|
||||
func MakeStatefulSetService(p *monitoringv1.Prometheus, config operator.Config) *v1.Service {
|
||||
p = p.DeepCopy()
|
||||
func ConfigSecretName(p monitoringv1.PrometheusInterface) string {
|
||||
return prefixedName(p)
|
||||
}
|
||||
|
||||
if p.Spec.PortName == "" {
|
||||
p.Spec.PortName = DefaultPortName
|
||||
func TLSAssetsSecretName(p monitoringv1.PrometheusInterface) string {
|
||||
return fmt.Sprintf("%s-tls-assets", prefixedName(p))
|
||||
}
|
||||
|
||||
func WebConfigSecretName(p monitoringv1.PrometheusInterface) string {
|
||||
return fmt.Sprintf("%s-web-config", prefixedName(p))
|
||||
}
|
||||
|
||||
func VolumeName(p monitoringv1.PrometheusInterface) string {
|
||||
return fmt.Sprintf("%s-db", prefixedName(p))
|
||||
}
|
||||
|
||||
func prefixedName(p monitoringv1.PrometheusInterface) string {
|
||||
return fmt.Sprintf("%s-%s", prefix(p), p.GetObjectMeta().GetName())
|
||||
}
|
||||
|
||||
func prefix(p monitoringv1.PrometheusInterface) string {
|
||||
switch p.(type) {
|
||||
case *monitoringv1.Prometheus:
|
||||
return "prometheus"
|
||||
case *monitoringv1alpha1.PrometheusAgent:
|
||||
return "prom-agent"
|
||||
default:
|
||||
panic("unknown prometheus type")
|
||||
}
|
||||
|
||||
svc := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: GoverningServiceName,
|
||||
OwnerReferences: []metav1.OwnerReference{
|
||||
{
|
||||
Name: p.GetName(),
|
||||
Kind: p.Kind,
|
||||
APIVersion: p.APIVersion,
|
||||
UID: p.GetUID(),
|
||||
},
|
||||
},
|
||||
Labels: config.Labels.Merge(map[string]string{
|
||||
"operated-prometheus": "true",
|
||||
}),
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
ClusterIP: "None",
|
||||
Ports: []v1.ServicePort{
|
||||
{
|
||||
Name: p.Spec.PortName,
|
||||
Port: 9090,
|
||||
TargetPort: intstr.FromString(p.Spec.PortName),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{
|
||||
"app.kubernetes.io/name": "prometheus",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if p.Spec.Thanos != nil {
|
||||
svc.Spec.Ports = append(svc.Spec.Ports, v1.ServicePort{
|
||||
Name: "grpc",
|
||||
Port: 10901,
|
||||
TargetPort: intstr.FromString("grpc"),
|
||||
})
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
func ConfigSecretName(name string) string {
|
||||
return prefixedName(name)
|
||||
}
|
||||
|
||||
func TLSAssetsSecretName(name string) string {
|
||||
return fmt.Sprintf("%s-tls-assets", prefixedName(name))
|
||||
}
|
||||
|
||||
func WebConfigSecretName(name string) string {
|
||||
return fmt.Sprintf("%s-web-config", prefixedName(name))
|
||||
}
|
||||
|
||||
func VolumeName(name string) string {
|
||||
return fmt.Sprintf("%s-db", prefixedName(name))
|
||||
}
|
||||
|
||||
func prefixedName(name string) string {
|
||||
return fmt.Sprintf("prometheus-%s", name)
|
||||
}
|
||||
|
||||
// TODO: Storage methods should be moved to server package.
|
||||
|
@ -272,7 +242,6 @@ func BuildCommonPrometheusArgs(cpf monitoringv1.CommonPrometheusFields, cg *Conf
|
|||
// BuildCommonVolumes returns a set of volumes to be mounted on statefulset spec that are common between Prometheus Server and Agent
|
||||
func BuildCommonVolumes(p monitoringv1.PrometheusInterface, tlsAssetSecrets []string) ([]v1.Volume, []v1.VolumeMount, error) {
|
||||
cpf := p.GetCommonPrometheusFields()
|
||||
promName := p.GetObjectMeta().GetName()
|
||||
|
||||
assetsVolume := v1.Volume{
|
||||
Name: "tls-assets",
|
||||
|
@ -296,7 +265,7 @@ func BuildCommonVolumes(p monitoringv1.PrometheusInterface, tlsAssetSecrets []st
|
|||
Name: "config",
|
||||
VolumeSource: v1.VolumeSource{
|
||||
Secret: &v1.SecretVolumeSource{
|
||||
SecretName: ConfigSecretName(promName),
|
||||
SecretName: ConfigSecretName(p),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -312,7 +281,7 @@ func BuildCommonVolumes(p monitoringv1.PrometheusInterface, tlsAssetSecrets []st
|
|||
},
|
||||
}
|
||||
|
||||
volName := VolumeName(promName)
|
||||
volName := VolumeName(p)
|
||||
if cpf.Storage != nil {
|
||||
if cpf.Storage.VolumeClaimTemplate.Name != "" {
|
||||
volName = cpf.Storage.VolumeClaimTemplate.Name
|
||||
|
|
|
@ -45,7 +45,7 @@ func testAlertmanagerInstanceNamespacesAllNs(t *testing.T) {
|
|||
nonInstanceNs := framework.CreateNamespace(context.Background(), t, testCtx)
|
||||
framework.SetupPrometheusRBACGlobal(context.Background(), t, testCtx, instanceNs)
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, nil, nil, []string{instanceNs}, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, nil, nil, []string{instanceNs}, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func testAlertmanagerInstanceNamespacesDenyNs(t *testing.T) {
|
|||
instanceNs := framework.CreateNamespace(context.Background(), t, testCtx)
|
||||
framework.SetupPrometheusRBACGlobal(context.Background(), t, testCtx, instanceNs)
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, []string{instanceNs}, nil, []string{instanceNs}, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, []string{instanceNs}, nil, []string{instanceNs}, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func testAlertmanagerInstanceNamespacesAllowList(t *testing.T) {
|
|||
}
|
||||
|
||||
// Configure the operator to watch also a non-existing namespace (e.g. "notfound").
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, []string{"notfound", allowedNs}, nil, nil, []string{"notfound", instanceNs}, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, []string{"notfound", allowedNs}, nil, nil, []string{"notfound", instanceNs}, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func testDenyPrometheus(t *testing.T) {
|
|||
|
||||
framework.SetupPrometheusRBAC(context.Background(), t, testCtx, operatorNamespace)
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNamespace, nil, deniedNamespaces, nil, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNamespace, nil, deniedNamespaces, nil, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func testDenyServiceMonitor(t *testing.T) {
|
|||
|
||||
framework.SetupPrometheusRBAC(context.Background(), t, testCtx, operatorNamespace)
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNamespace, nil, deniedNamespaces, nil, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNamespace, nil, deniedNamespaces, nil, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func testDenyThanosRuler(t *testing.T) {
|
|||
|
||||
framework.SetupPrometheusRBAC(context.Background(), t, testCtx, operatorNamespace)
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNamespace, nil, deniedNamespaces, nil, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNamespace, nil, deniedNamespaces, nil, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ func TestAllNS(t *testing.T) {
|
|||
|
||||
ns := framework.CreateNamespace(context.Background(), t, testCtx)
|
||||
|
||||
finalizers, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), ns, nil, nil, nil, nil, true, true)
|
||||
finalizers, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), ns, nil, nil, nil, nil, true, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func testPrometheusInstanceNamespacesAllNs(t *testing.T) {
|
|||
nonInstanceNs := framework.CreateNamespace(context.Background(), t, testCtx)
|
||||
framework.SetupPrometheusRBACGlobal(context.Background(), t, testCtx, instanceNs)
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, nil, []string{instanceNs}, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, nil, []string{instanceNs}, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ func testPrometheusInstanceNamespacesDenyList(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, []string{deniedNs, instanceNs}, []string{instanceNs}, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, nil, []string{deniedNs, instanceNs}, []string{instanceNs}, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ func testPrometheusInstanceNamespacesAllowList(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, []string{allowedNs}, nil, []string{instanceNs}, nil, false, false)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, []string{allowedNs}, nil, []string{instanceNs}, nil, false, false, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ func testPrometheusInstanceNamespacesNamespaceNotFound(t *testing.T) {
|
|||
}
|
||||
|
||||
// Configure the operator to watch also a non-existing namespace (e.g. "notfound").
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, []string{"notfound", allowedNs}, nil, []string{"notfound", instanceNs}, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNs, []string{"notfound", allowedNs}, nil, []string{"notfound", instanceNs}, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -2766,7 +2766,7 @@ func testOperatorNSScope(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prometheus Operator only watches single namespace mainNS, not arbitraryNS.
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNS, []string{mainNS}, nil, nil, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNS, []string{mainNS}, nil, nil, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -2837,7 +2837,7 @@ func testOperatorNSScope(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prometheus Operator only watches prometheusNS and ruleNS, not arbitraryNS.
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNS, []string{prometheusNS, ruleNS}, nil, nil, nil, false, true)
|
||||
_, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), operatorNS, []string{prometheusNS, ruleNS}, nil, nil, nil, false, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func testOperatorUpgrade(t *testing.T) {
|
|||
}
|
||||
|
||||
// Create Prometheus Operator with previous stable minor version
|
||||
_, err = previousVersionFramework.CreateOrUpdatePrometheusOperator(context.Background(), ns, nil, nil, nil, nil, true, true)
|
||||
_, err = previousVersionFramework.CreateOrUpdatePrometheusOperator(context.Background(), ns, nil, nil, nil, nil, true, true, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ func testOperatorUpgrade(t *testing.T) {
|
|||
|
||||
framework.SetupPrometheusRBAC(context.Background(), t, testCtx, ns)
|
||||
// Update Prometheus Operator to current version
|
||||
finalizers, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), ns, nil, nil, nil, nil, true, true)
|
||||
finalizers, err := framework.CreateOrUpdatePrometheusOperator(context.Background(), ns, nil, nil, nil, nil, true, true, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ func (f *Framework) MakeEchoDeployment(group string) *appsv1.Deployment {
|
|||
// Returns the CA, which can bs used to access the operator over TLS
|
||||
func (f *Framework) CreateOrUpdatePrometheusOperator(ctx context.Context, ns string, namespaceAllowlist,
|
||||
namespaceDenylist, prometheusInstanceNamespaces, alertmanagerInstanceNamespaces []string,
|
||||
createResourceAdmissionHooks, createClusterRoleBindings bool) ([]FinalizerFn, error) {
|
||||
createResourceAdmissionHooks, createClusterRoleBindings, createAgentCrd bool) ([]FinalizerFn, error) {
|
||||
|
||||
var finalizers []FinalizerFn
|
||||
|
||||
|
@ -304,6 +304,17 @@ func (f *Framework) CreateOrUpdatePrometheusOperator(ctx context.Context, ns str
|
|||
return nil, errors.Wrap(err, "wait for AlertmanagerConfig v1beta1 CRD")
|
||||
}
|
||||
|
||||
// TODO(ArthurSens): The OperatorUpgrade tests won't pass because the operator v0.63.0 doesn't have the agent CRD.
|
||||
// This check can be removed after the next release of the operator.
|
||||
if createAgentCrd {
|
||||
err = f.CreateOrUpdateCRDAndWaitUntilReady(ctx, monitoringv1alpha1.PrometheusAgentName, func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return f.MonClientV1alpha1.PrometheusAgents(v1.NamespaceAll).List(ctx, opts)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "initialize PrometheusAgent v1alpha1 CRD")
|
||||
}
|
||||
}
|
||||
|
||||
certBytes, keyBytes, err := certutil.GenerateSelfSignedCertKey(fmt.Sprintf("%s.%s.svc", prometheusOperatorServiceDeploymentName, ns), nil, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to generate certificate and key")
|
||||
|
|
Loading…
Add table
Reference in a new issue