1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 03:38:43 +00:00

feat: support pod spec field "enableServiceLinks" () ()

This commit is contained in:
Simon Pasquier 2025-03-11 09:29:41 +01:00 committed by GitHub
commit 1efbed1d61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 389 additions and 0 deletions

View file

@ -515,6 +515,18 @@ PodDNSConfig
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>serviceName</code><br/>
<em>
string
@ -2455,6 +2467,18 @@ instead of the Pod IP&rsquo;s address.</p>
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>containers</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#container-v1-core">
@ -4272,6 +4296,18 @@ PodDNSConfig
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>priorityClassName</code><br/>
<em>
string
@ -5994,6 +6030,18 @@ PodDNSConfig
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>serviceName</code><br/>
<em>
string
@ -7743,6 +7791,18 @@ instead of the Pod IP&rsquo;s address.</p>
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>containers</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#container-v1-core">
@ -12640,6 +12700,18 @@ instead of the Pod IP&rsquo;s address.</p>
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>containers</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#container-v1-core">
@ -16904,6 +16976,18 @@ PodDNSConfig
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>priorityClassName</code><br/>
<em>
string
@ -19566,6 +19650,18 @@ instead of the Pod IP&rsquo;s address.</p>
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>containers</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#container-v1-core">
@ -27766,6 +27862,18 @@ instead of the Pod IP&rsquo;s address.</p>
</tr>
<tr>
<td>
<code>enableServiceLinks</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Indicates whether information about services should be injected into pod&rsquo;s environment variables</p>
</td>
</tr>
<tr>
<td>
<code>containers</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#container-v1-core">

16
bundle.yaml generated
View file

@ -14023,6 +14023,10 @@ spec:
items:
type: string
type: array
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
externalUrl:
description: |-
The external URL the Alertmanager instances will be available under. This is
@ -24486,6 +24490,10 @@ spec:
It requires Prometheus >= v2.33.0.
type: boolean
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedBodySizeLimit:
description: |-
When defined, enforcedBodySizeLimit specifies a global limit on the size
@ -36076,6 +36084,10 @@ spec:
It requires Prometheus >= v2.33.0.
type: boolean
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedBodySizeLimit:
description: |-
When defined, enforcedBodySizeLimit specifies a global limit on the size
@ -61982,6 +61994,10 @@ spec:
- Default
- None
type: string
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedNamespaceLabel:
description: |-
EnforcedNamespaceLabel enforces adding a namespace label of origin for each alert

View file

@ -3984,6 +3984,10 @@ spec:
items:
type: string
type: array
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
externalUrl:
description: |-
The external URL the Alertmanager instances will be available under. This is

View file

@ -2935,6 +2935,10 @@ spec:
It requires Prometheus >= v2.33.0.
type: boolean
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedBodySizeLimit:
description: |-
When defined, enforcedBodySizeLimit specifies a global limit on the size

View file

@ -3691,6 +3691,10 @@ spec:
It requires Prometheus >= v2.33.0.
type: boolean
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedBodySizeLimit:
description: |-
When defined, enforcedBodySizeLimit specifies a global limit on the size

View file

@ -2607,6 +2607,10 @@ spec:
- Default
- None
type: string
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedNamespaceLabel:
description: |-
EnforcedNamespaceLabel enforces adding a namespace label of origin for each alert

View file

@ -3985,6 +3985,10 @@ spec:
items:
type: string
type: array
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
externalUrl:
description: |-
The external URL the Alertmanager instances will be available under. This is

View file

@ -2936,6 +2936,10 @@ spec:
It requires Prometheus >= v2.33.0.
type: boolean
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedBodySizeLimit:
description: |-
When defined, enforcedBodySizeLimit specifies a global limit on the size

View file

@ -3692,6 +3692,10 @@ spec:
It requires Prometheus >= v2.33.0.
type: boolean
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedBodySizeLimit:
description: |-
When defined, enforcedBodySizeLimit specifies a global limit on the size

View file

@ -2608,6 +2608,10 @@ spec:
- Default
- None
type: string
enableServiceLinks:
description: Indicates whether information about services should be
injected into pod's environment variables
type: boolean
enforcedNamespaceLabel:
description: |-
EnforcedNamespaceLabel enforces adding a namespace label of origin for each alert

View file

@ -3549,6 +3549,10 @@
},
"type": "array"
},
"enableServiceLinks": {
"description": "Indicates whether information about services should be injected into pod's environment variables",
"type": "boolean"
},
"externalUrl": {
"description": "The external URL the Alertmanager instances will be available under. This is\nnecessary to generate correct URLs. This is necessary if Alertmanager is not\nserved from root of a DNS name.",
"type": "string"

View file

@ -2536,6 +2536,10 @@
"description": "Enable Prometheus to be used as a receiver for the Prometheus remote\nwrite protocol.\n\nWARNING: This is not considered an efficient way of ingesting samples.\nUse it with caution for specific low-volume use cases.\nIt is not suitable for replacing the ingestion via scraping and turning\nPrometheus into a push-based metrics collection system.\nFor more information see https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver\n\nIt requires Prometheus >= v2.33.0.",
"type": "boolean"
},
"enableServiceLinks": {
"description": "Indicates whether information about services should be injected into pod's environment variables",
"type": "boolean"
},
"enforcedBodySizeLimit": {
"description": "When defined, enforcedBodySizeLimit specifies a global limit on the size\nof uncompressed response body that will be accepted by Prometheus.\nTargets responding with a body larger than this many bytes will cause\nthe scrape to fail.\n\nIt requires Prometheus >= v2.28.0.\n\nWhen both `enforcedBodySizeLimit` and `bodySizeLimit` are defined and greater than zero, the following rules apply:\n* Scrape objects without a defined bodySizeLimit value will inherit the global bodySizeLimit value (Prometheus >= 2.45.0) or the enforcedBodySizeLimit value (Prometheus < v2.45.0).\n If Prometheus version is >= 2.45.0 and the `enforcedBodySizeLimit` is greater than the `bodySizeLimit`, the `bodySizeLimit` will be set to `enforcedBodySizeLimit`.\n* Scrape objects with a bodySizeLimit value less than or equal to enforcedBodySizeLimit keep their specific value.\n* Scrape objects with a bodySizeLimit value greater than enforcedBodySizeLimit are set to enforcedBodySizeLimit.",
"pattern": "(^0|([0-9]*[.])?[0-9]+((K|M|G|T|E|P)i?)?B)$",

View file

@ -3178,6 +3178,10 @@
"description": "Enable Prometheus to be used as a receiver for the Prometheus remote\nwrite protocol.\n\nWARNING: This is not considered an efficient way of ingesting samples.\nUse it with caution for specific low-volume use cases.\nIt is not suitable for replacing the ingestion via scraping and turning\nPrometheus into a push-based metrics collection system.\nFor more information see https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver\n\nIt requires Prometheus >= v2.33.0.",
"type": "boolean"
},
"enableServiceLinks": {
"description": "Indicates whether information about services should be injected into pod's environment variables",
"type": "boolean"
},
"enforcedBodySizeLimit": {
"description": "When defined, enforcedBodySizeLimit specifies a global limit on the size\nof uncompressed response body that will be accepted by Prometheus.\nTargets responding with a body larger than this many bytes will cause\nthe scrape to fail.\n\nIt requires Prometheus >= v2.28.0.\n\nWhen both `enforcedBodySizeLimit` and `bodySizeLimit` are defined and greater than zero, the following rules apply:\n* Scrape objects without a defined bodySizeLimit value will inherit the global bodySizeLimit value (Prometheus >= 2.45.0) or the enforcedBodySizeLimit value (Prometheus < v2.45.0).\n If Prometheus version is >= 2.45.0 and the `enforcedBodySizeLimit` is greater than the `bodySizeLimit`, the `bodySizeLimit` will be set to `enforcedBodySizeLimit`.\n* Scrape objects with a bodySizeLimit value less than or equal to enforcedBodySizeLimit keep their specific value.\n* Scrape objects with a bodySizeLimit value greater than enforcedBodySizeLimit are set to enforcedBodySizeLimit.",
"pattern": "(^0|([0-9]*[.])?[0-9]+((K|M|G|T|E|P)i?)?B)$",

View file

@ -2256,6 +2256,10 @@
],
"type": "string"
},
"enableServiceLinks": {
"description": "Indicates whether information about services should be injected into pod's environment variables",
"type": "boolean"
},
"enforcedNamespaceLabel": {
"description": "EnforcedNamespaceLabel enforces adding a namespace label of origin for each alert\nand metric that is user created. The label value will always be the namespace of the object that is\nbeing created.",
"type": "string"

View file

@ -769,6 +769,7 @@ func makeStatefulSetSpec(logger *slog.Logger, a *monitoringv1.Alertmanager, conf
Affinity: a.Spec.Affinity,
TopologySpreadConstraints: a.Spec.TopologySpreadConstraints,
HostAliases: operator.MakeHostAliases(a.Spec.HostAliases),
EnableServiceLinks: a.Spec.EnableServiceLinks,
},
},
}

View file

@ -1336,3 +1336,29 @@ func TestPersistentVolumeClaimRetentionPolicy(t *testing.T) {
t.Fatalf("expected persistentVolumeClaimDeletePolicy.WhenScaled to be %s but got %s", appsv1.DeletePersistentVolumeClaimRetentionPolicyType, sset.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled)
}
}
func TestStatefulSetEnableServiceLinks(t *testing.T) {
tests := []struct {
enableServiceLinks *bool
expectedEnableService *bool
}{
{enableServiceLinks: ptr.To(false), expectedEnableService: ptr.To(false)},
{enableServiceLinks: ptr.To(true), expectedEnableService: ptr.To(true)},
{enableServiceLinks: nil, expectedEnableService: nil},
}
for _, test := range tests {
sset, err := makeStatefulSet(nil, &monitoringv1.Alertmanager{
ObjectMeta: metav1.ObjectMeta{},
Spec: monitoringv1.AlertmanagerSpec{EnableServiceLinks: test.expectedEnableService},
}, defaultTestConfig, "", &operator.ShardedSecret{})
require.NoError(t, err)
if test.expectedEnableService != nil {
require.NotNil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks not nil")
require.Equal(t, *test.expectedEnableService, *sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to match")
} else {
require.Nil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks is nil")
}
}
}

View file

@ -193,6 +193,9 @@ type AlertmanagerSpec struct {
//
// +optional
DNSConfig *PodDNSConfig `json:"dnsConfig,omitempty"`
// Indicates whether information about services should be injected into pod's environment variables
// +optional
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"`
// The name of the service name used by the underlying StatefulSet(s) as the governing service.
// If defined, the Service must be created before the Alertmanager resource in the same namespace and it must define a selector that matches the pod labels.
// If empty, the operator will create and manage a headless service named `alertmanager-operated` for Alermanager resources.

View file

@ -464,6 +464,10 @@ type CommonPrometheusFields struct {
// instead of the Pod IP's address.
ListenLocal bool `json:"listenLocal,omitempty"`
// Indicates whether information about services should be injected into pod's environment variables
// +optional
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"`
// Containers allows injecting additional containers or modifying operator
// generated containers. This can be used to allow adding an authentication
// proxy to the Pods or to change the behavior of an operator generated

View file

@ -137,6 +137,10 @@ type ThanosRulerSpec struct {
// +optional
DNSConfig *PodDNSConfig `json:"dnsConfig,omitempty"`
// Indicates whether information about services should be injected into pod's environment variables
// +optional
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"`
// Priority class assigned to the Pods
PriorityClassName string `json:"priorityClassName,omitempty"`

View file

@ -377,6 +377,11 @@ func (in *AlertmanagerSpec) DeepCopyInto(out *AlertmanagerSpec) {
*out = new(PodDNSConfig)
(*in).DeepCopyInto(*out)
}
if in.EnableServiceLinks != nil {
in, out := &in.EnableServiceLinks, &out.EnableServiceLinks
*out = new(bool)
**out = **in
}
if in.ServiceName != nil {
in, out := &in.ServiceName, &out.ServiceName
*out = new(string)
@ -903,6 +908,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) {
*out = new(PodDNSConfig)
(*in).DeepCopyInto(*out)
}
if in.EnableServiceLinks != nil {
in, out := &in.EnableServiceLinks, &out.EnableServiceLinks
*out = new(bool)
**out = **in
}
if in.Containers != nil {
in, out := &in.Containers, &out.Containers
*out = make([]corev1.Container, len(*in))
@ -3442,6 +3452,11 @@ func (in *ThanosRulerSpec) DeepCopyInto(out *ThanosRulerSpec) {
*out = new(PodDNSConfig)
(*in).DeepCopyInto(*out)
}
if in.EnableServiceLinks != nil {
in, out := &in.EnableServiceLinks, &out.EnableServiceLinks
*out = new(bool)
**out = **in
}
if in.ServiceName != nil {
in, out := &in.ServiceName, &out.ServiceName
*out = new(string)

View file

@ -56,6 +56,7 @@ type AlertmanagerSpecApplyConfiguration struct {
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
DNSPolicy *monitoringv1.DNSPolicy `json:"dnsPolicy,omitempty"`
DNSConfig *PodDNSConfigApplyConfiguration `json:"dnsConfig,omitempty"`
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"`
ServiceName *string `json:"serviceName,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
ListenLocal *bool `json:"listenLocal,omitempty"`
@ -348,6 +349,14 @@ func (b *AlertmanagerSpecApplyConfiguration) WithDNSConfig(value *PodDNSConfigAp
return b
}
// WithEnableServiceLinks sets the EnableServiceLinks 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 EnableServiceLinks field is set to the value of the last call.
func (b *AlertmanagerSpecApplyConfiguration) WithEnableServiceLinks(value bool) *AlertmanagerSpecApplyConfiguration {
b.EnableServiceLinks = &value
return b
}
// WithServiceName sets the ServiceName 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 ServiceName field is set to the value of the last call.

View file

@ -76,6 +76,7 @@ type CommonPrometheusFieldsApplyConfiguration struct {
DNSPolicy *monitoringv1.DNSPolicy `json:"dnsPolicy,omitempty"`
DNSConfig *PodDNSConfigApplyConfiguration `json:"dnsConfig,omitempty"`
ListenLocal *bool `json:"listenLocal,omitempty"`
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"`
Containers []corev1.Container `json:"containers,omitempty"`
InitContainers []corev1.Container `json:"initContainers,omitempty"`
AdditionalScrapeConfigs *corev1.SecretKeySelector `json:"additionalScrapeConfigs,omitempty"`
@ -566,6 +567,14 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithListenLocal(value bool) *
return b
}
// WithEnableServiceLinks sets the EnableServiceLinks 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 EnableServiceLinks field is set to the value of the last call.
func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableServiceLinks(value bool) *CommonPrometheusFieldsApplyConfiguration {
b.EnableServiceLinks = &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.

View file

@ -498,6 +498,14 @@ func (b *PrometheusSpecApplyConfiguration) WithListenLocal(value bool) *Promethe
return b
}
// WithEnableServiceLinks sets the EnableServiceLinks 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 EnableServiceLinks field is set to the value of the last call.
func (b *PrometheusSpecApplyConfiguration) WithEnableServiceLinks(value bool) *PrometheusSpecApplyConfiguration {
b.CommonPrometheusFieldsApplyConfiguration.EnableServiceLinks = &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.

View file

@ -40,6 +40,7 @@ type ThanosRulerSpecApplyConfiguration struct {
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
DNSPolicy *monitoringv1.DNSPolicy `json:"dnsPolicy,omitempty"`
DNSConfig *PodDNSConfigApplyConfiguration `json:"dnsConfig,omitempty"`
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"`
PriorityClassName *string `json:"priorityClassName,omitempty"`
ServiceName *string `json:"serviceName,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
@ -219,6 +220,14 @@ func (b *ThanosRulerSpecApplyConfiguration) WithDNSConfig(value *PodDNSConfigApp
return b
}
// WithEnableServiceLinks sets the EnableServiceLinks 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 EnableServiceLinks field is set to the value of the last call.
func (b *ThanosRulerSpecApplyConfiguration) WithEnableServiceLinks(value bool) *ThanosRulerSpecApplyConfiguration {
b.EnableServiceLinks = &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.

View file

@ -486,6 +486,14 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithListenLocal(value bool) *Pro
return b
}
// WithEnableServiceLinks sets the EnableServiceLinks 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 EnableServiceLinks field is set to the value of the last call.
func (b *PrometheusAgentSpecApplyConfiguration) WithEnableServiceLinks(value bool) *PrometheusAgentSpecApplyConfiguration {
b.CommonPrometheusFieldsApplyConfiguration.EnableServiceLinks = &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.

View file

@ -224,6 +224,7 @@ func makeDaemonSetSpec(
TopologySpreadConstraints: prompkg.MakeK8sTopologySpreadConstraint(finalSelectorLabels, cpf.TopologySpreadConstraints),
HostAliases: operator.MakeHostAliases(cpf.HostAliases),
HostNetwork: cpf.HostNetwork,
EnableServiceLinks: cpf.EnableServiceLinks,
},
},
}

View file

@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
@ -180,3 +181,32 @@ func TestDaemonSetLabelingAndAnnotations(t *testing.T) {
require.Equal(t, expectedDaemonSetAnnotations, dset.Annotations)
require.Equal(t, expectedPodLabels, dset.Spec.Template.ObjectMeta.Labels)
}
func TestDaemonSetenableServiceLinks(t *testing.T) {
tests := []struct {
enableServiceLinks *bool
expectedEnableServiceLinks *bool
}{
{enableServiceLinks: ptr.To(false), expectedEnableServiceLinks: ptr.To(false)},
{enableServiceLinks: ptr.To(true), expectedEnableServiceLinks: ptr.To(true)},
{enableServiceLinks: nil, expectedEnableServiceLinks: nil},
}
for _, test := range tests {
sset, err := makeDaemonSetFromPrometheus(monitoringv1alpha1.PrometheusAgent{
Spec: monitoringv1alpha1.PrometheusAgentSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
EnableServiceLinks: test.enableServiceLinks,
},
},
})
require.NoError(t, err)
if test.expectedEnableServiceLinks != nil {
require.NotNil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be non-nil")
require.Equal(t, *test.expectedEnableServiceLinks, *sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to match")
} else {
require.Nil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be nil")
}
}
}

View file

@ -287,6 +287,7 @@ func makeStatefulSetSpec(
TopologySpreadConstraints: prompkg.MakeK8sTopologySpreadConstraint(finalSelectorLabels, cpf.TopologySpreadConstraints),
HostAliases: operator.MakeHostAliases(cpf.HostAliases),
HostNetwork: cpf.HostNetwork,
EnableServiceLinks: cpf.EnableServiceLinks,
}
if cpf.HostNetwork {

View file

@ -332,3 +332,32 @@ func TestScrapeFailureLogFileVolumeMountNotPresent(t *testing.T) {
require.False(t, found, "Scrape failure log file mounted, when it shouldn't be.")
}
func TestStatefulSetenableServiceLinks(t *testing.T) {
tests := []struct {
enableServiceLinks *bool
expectedEnableServiceLinks *bool
}{
{enableServiceLinks: ptr.To(false), expectedEnableServiceLinks: ptr.To(false)},
{enableServiceLinks: ptr.To(true), expectedEnableServiceLinks: ptr.To(true)},
{enableServiceLinks: nil, expectedEnableServiceLinks: nil},
}
for _, test := range tests {
sset, err := makeStatefulSetFromPrometheus(monitoringv1alpha1.PrometheusAgent{
Spec: monitoringv1alpha1.PrometheusAgentSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
EnableServiceLinks: test.enableServiceLinks,
},
},
})
require.NoError(t, err)
if test.expectedEnableServiceLinks != nil {
require.NotNil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be non-nil")
require.Equal(t, *test.expectedEnableServiceLinks, *sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to match")
} else {
require.Nil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be nil")
}
}
}

View file

@ -368,6 +368,7 @@ func makeStatefulSetSpec(
TopologySpreadConstraints: prompkg.MakeK8sTopologySpreadConstraint(finalSelectorLabels, cpf.TopologySpreadConstraints),
HostAliases: operator.MakeHostAliases(cpf.HostAliases),
HostNetwork: cpf.HostNetwork,
EnableServiceLinks: cpf.EnableServiceLinks,
},
},
}

View file

@ -3180,3 +3180,32 @@ func TestDNSPolicyAndDNSConfig(t *testing.T) {
})
}
}
func TestStatefulSetenableServiceLinks(t *testing.T) {
tests := []struct {
enableServiceLinks *bool
expectedEnableServiceLinks *bool
}{
{enableServiceLinks: ptr.To(false), expectedEnableServiceLinks: ptr.To(false)},
{enableServiceLinks: ptr.To(true), expectedEnableServiceLinks: ptr.To(true)},
{enableServiceLinks: nil, expectedEnableServiceLinks: nil},
}
for _, test := range tests {
sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{
Spec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
EnableServiceLinks: test.enableServiceLinks,
},
},
})
require.NoError(t, err)
if test.expectedEnableServiceLinks != nil {
require.NotNil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be non-nil")
require.Equal(t, *test.expectedEnableServiceLinks, *sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to match")
} else {
require.Nil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be nil")
}
}
}

View file

@ -478,6 +478,7 @@ func makeStatefulSetSpec(tr *monitoringv1.ThanosRuler, config Config, ruleConfig
Affinity: tr.Spec.Affinity,
TopologySpreadConstraints: tr.Spec.TopologySpreadConstraints,
HostAliases: operator.MakeHostAliases(tr.Spec.HostAliases),
EnableServiceLinks: tr.Spec.EnableServiceLinks,
},
},
}

View file

@ -1015,3 +1015,32 @@ func TestStatefulSetDNSPolicyAndDNSConfig(t *testing.T) {
},
}, sset.Spec.Template.Spec.DNSConfig, "expected DNS configuration to match")
}
func TestStatefulSetenableServiceLinks(t *testing.T) {
tests := []struct {
enableServiceLinks *bool
expectedEnableServiceLinks *bool
}{
{enableServiceLinks: ptr.To(false), expectedEnableServiceLinks: ptr.To(false)},
{enableServiceLinks: ptr.To(true), expectedEnableServiceLinks: ptr.To(true)},
{enableServiceLinks: nil, expectedEnableServiceLinks: nil},
}
for _, test := range tests {
sset, err := makeStatefulSet(&monitoringv1.ThanosRuler{
ObjectMeta: metav1.ObjectMeta{},
Spec: monitoringv1.ThanosRulerSpec{
QueryEndpoints: emptyQueryEndpoints,
EnableServiceLinks: test.enableServiceLinks,
},
}, defaultTestConfig, nil, "", &operator.ShardedSecret{})
require.NoError(t, err)
if test.expectedEnableServiceLinks != nil {
require.NotNil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be non-nil")
require.Equal(t, *test.expectedEnableServiceLinks, *sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to match")
} else {
require.Nil(t, sset.Spec.Template.Spec.EnableServiceLinks, "expected enableServiceLinks to be nil")
}
}
}