1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

dedicated field for cluster_label ()

* dedicated field for cluster_label

fixes 

---------

Co-authored-by: Simon Pasquier <spasquie@redhat.com>
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
This commit is contained in:
Tommy Sauer 2023-12-20 16:56:20 +01:00 committed by GitHub
parent a8eb064ec7
commit cb53421441
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 85 additions and 3 deletions
Documentation
bundle.yaml
example
jsonnet/prometheus-operator
pkg
alertmanager
apis/monitoring/v1
client/applyconfiguration/monitoring/v1

24
Documentation/api.md generated
View file

@ -582,6 +582,18 @@ GoDuration
</tr>
<tr>
<td>
<code>clusterLabel</code><br/>
<em>
string
</em>
</td>
<td>
<p>Defines the identifier that uniquely identifies the Alertmanager cluster.
You should only set it when the Alertmanager cluster includes Alertmanager instances which are external to this Alertmanager resource. In practice, the addresses of the external instances are provided via the <code>.spec.additionalPeers</code> field.</p>
</td>
</tr>
<tr>
<td>
<code>clusterPushpullInterval</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.GoDuration">
@ -5048,6 +5060,18 @@ GoDuration
</tr>
<tr>
<td>
<code>clusterLabel</code><br/>
<em>
string
</em>
</td>
<td>
<p>Defines the identifier that uniquely identifies the Alertmanager cluster.
You should only set it when the Alertmanager cluster includes Alertmanager instances which are external to this Alertmanager resource. In practice, the addresses of the external instances are provided via the <code>.spec.additionalPeers</code> field.</p>
</td>
</tr>
<tr>
<td>
<code>clusterPushpullInterval</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.GoDuration">

7
bundle.yaml generated
View file

@ -7305,6 +7305,13 @@ spec:
description: Interval between gossip attempts.
pattern: ^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$
type: string
clusterLabel:
description: Defines the identifier that uniquely identifies the Alertmanager
cluster. You should only set it when the Alertmanager cluster includes
Alertmanager instances which are external to this Alertmanager resource.
In practice, the addresses of the external instances are provided
via the `.spec.additionalPeers` field.
type: string
clusterPeerTimeout:
description: Timeout for cluster peering.
pattern: ^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$

View file

@ -1582,6 +1582,13 @@ spec:
description: Interval between gossip attempts.
pattern: ^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$
type: string
clusterLabel:
description: Defines the identifier that uniquely identifies the Alertmanager
cluster. You should only set it when the Alertmanager cluster includes
Alertmanager instances which are external to this Alertmanager resource.
In practice, the addresses of the external instances are provided
via the `.spec.additionalPeers` field.
type: string
clusterPeerTimeout:
description: Timeout for cluster peering.
pattern: ^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$

View file

@ -1583,6 +1583,13 @@ spec:
description: Interval between gossip attempts.
pattern: ^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$
type: string
clusterLabel:
description: Defines the identifier that uniquely identifies the Alertmanager
cluster. You should only set it when the Alertmanager cluster includes
Alertmanager instances which are external to this Alertmanager resource.
In practice, the addresses of the external instances are provided
via the `.spec.additionalPeers` field.
type: string
clusterPeerTimeout:
description: Timeout for cluster peering.
pattern: ^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$

View file

@ -1460,6 +1460,10 @@
"pattern": "^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$",
"type": "string"
},
"clusterLabel": {
"description": "Defines the identifier that uniquely identifies the Alertmanager cluster. You should only set it when the Alertmanager cluster includes Alertmanager instances which are external to this Alertmanager resource. In practice, the addresses of the external instances are provided via the `.spec.additionalPeers` field.",
"type": "string"
},
"clusterPeerTimeout": {
"description": "Timeout for cluster peering.",
"pattern": "^(0|(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$",

View file

@ -313,10 +313,12 @@ func makeStatefulSetSpec(logger log.Logger, a *monitoringv1.Alertmanager, config
// connects with cluster A.
// --cluster.label flag was introduced in alertmanager v0.26, this helps to block
// any traffic that is not meant for the cluster.
// The value is hardcoded and the value is guaranteed to be unique in a given cluster but
// if there's a use case, we can consider a new field in the CRD.
if version.GTE(semver.MustParse("0.26.0")) {
amArgs = append(amArgs, fmt.Sprintf("--cluster.label=%s/%s", a.Namespace, a.Name))
clusterLabel := fmt.Sprintf("%s/%s", a.Namespace, a.Name)
if a.Spec.ClusterLabel != nil {
clusterLabel = *a.Spec.ClusterLabel
}
amArgs = append(amArgs, fmt.Sprintf("--cluster.label=%s", clusterLabel))
}
isHTTPS := a.Spec.Web != nil && a.Spec.Web.TLSConfig != nil && version.GTE(semver.MustParse("0.22.0"))

View file

@ -1193,10 +1193,16 @@ func TestClusterLabel(t *testing.T) {
scenario string
version string
expectedClusterLabelArg bool
customClusterLabel string
}{{
scenario: "--cluster.label set by default for version >= v0.26.0",
version: "0.26.0",
expectedClusterLabelArg: true,
}, {
scenario: "--cluster.label set if specified explicitly",
version: "0.26.0",
expectedClusterLabelArg: true,
customClusterLabel: "custom.cluster",
}, {
scenario: "no --cluster.label set for older versions",
version: "0.25.0",
@ -1216,11 +1222,19 @@ func TestClusterLabel(t *testing.T) {
},
}
if ts.customClusterLabel != "" {
a.Spec.ClusterLabel = &ts.customClusterLabel
}
ss, err := makeStatefulSetSpec(nil, &a, defaultTestConfig, nil)
require.NoError(t, err)
args := ss.Template.Spec.Containers[0].Args
if ts.expectedClusterLabelArg {
if ts.customClusterLabel != "" {
require.Contains(t, args, fmt.Sprintf("--cluster.label=%s", ts.customClusterLabel))
return
}
require.Contains(t, args, "--cluster.label=monitoring/alertmanager")
return
}

View file

@ -206,6 +206,9 @@ type AlertmanagerSpec struct {
ClusterAdvertiseAddress string `json:"clusterAdvertiseAddress,omitempty"`
// Interval between gossip attempts.
ClusterGossipInterval GoDuration `json:"clusterGossipInterval,omitempty"`
// Defines the identifier that uniquely identifies the Alertmanager cluster.
// You should only set it when the Alertmanager cluster includes Alertmanager instances which are external to this Alertmanager resource. In practice, the addresses of the external instances are provided via the `.spec.additionalPeers` field.
ClusterLabel *string `json:"clusterLabel,omitempty"`
// Interval between pushpull attempts.
ClusterPushpullInterval GoDuration `json:"clusterPushpullInterval,omitempty"`
// Timeout for cluster peering.

View file

@ -356,6 +356,11 @@ func (in *AlertmanagerSpec) DeepCopyInto(out *AlertmanagerSpec) {
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.ClusterLabel != nil {
in, out := &in.ClusterLabel, &out.ClusterLabel
*out = new(string)
**out = **in
}
if in.AlertmanagerConfigSelector != nil {
in, out := &in.AlertmanagerConfigSelector, &out.AlertmanagerConfigSelector
*out = new(metav1.LabelSelector)

View file

@ -60,6 +60,7 @@ type AlertmanagerSpecApplyConfiguration struct {
AdditionalPeers []string `json:"additionalPeers,omitempty"`
ClusterAdvertiseAddress *string `json:"clusterAdvertiseAddress,omitempty"`
ClusterGossipInterval *monitoringv1.GoDuration `json:"clusterGossipInterval,omitempty"`
ClusterLabel *string `json:"clusterLabel,omitempty"`
ClusterPushpullInterval *monitoringv1.GoDuration `json:"clusterPushpullInterval,omitempty"`
ClusterPeerTimeout *monitoringv1.GoDuration `json:"clusterPeerTimeout,omitempty"`
PortName *string `json:"portName,omitempty"`
@ -386,6 +387,14 @@ func (b *AlertmanagerSpecApplyConfiguration) WithClusterGossipInterval(value mon
return b
}
// WithClusterLabel sets the ClusterLabel 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 ClusterLabel field is set to the value of the last call.
func (b *AlertmanagerSpecApplyConfiguration) WithClusterLabel(value string) *AlertmanagerSpecApplyConfiguration {
b.ClusterLabel = &value
return b
}
// WithClusterPushpullInterval sets the ClusterPushpullInterval 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 ClusterPushpullInterval field is set to the value of the last call.