Skip to content

Commit 8f4e976

Browse files
committed
Add ability to add environment variables to the collector container. Allows users to authenticate exporters with major cloud providers.
1 parent 57f0ae2 commit 8f4e976

File tree

5 files changed

+279
-0
lines changed

5 files changed

+279
-0
lines changed

config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,135 @@ spec:
16921692
x-kubernetes-list-map-keys:
16931693
- name
16941694
x-kubernetes-list-type: map
1695+
environmentVariables:
1696+
description: |-
1697+
EnvironmentVariables allows the user to add environment variables to the
1698+
collector container.
1699+
items:
1700+
description: EnvVar represents an environment variable present
1701+
in a Container.
1702+
properties:
1703+
name:
1704+
description: Name of the environment variable. Must
1705+
be a C_IDENTIFIER.
1706+
type: string
1707+
value:
1708+
description: |-
1709+
Variable references $(VAR_NAME) are expanded
1710+
using the previously defined environment variables in the container and
1711+
any service environment variables. If a variable cannot be resolved,
1712+
the reference in the input string will be unchanged. Double $$ are reduced
1713+
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e.
1714+
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
1715+
Escaped references will never be expanded, regardless of whether the variable
1716+
exists or not.
1717+
Defaults to "".
1718+
type: string
1719+
valueFrom:
1720+
description: Source for the environment variable's value.
1721+
Cannot be used if value is not empty.
1722+
properties:
1723+
configMapKeyRef:
1724+
description: Selects a key of a ConfigMap.
1725+
properties:
1726+
key:
1727+
description: The key to select.
1728+
type: string
1729+
name:
1730+
default: ""
1731+
description: |-
1732+
Name of the referent.
1733+
This field is effectively required, but due to backwards compatibility is
1734+
allowed to be empty. Instances of this type with an empty value here are
1735+
almost certainly wrong.
1736+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
1737+
type: string
1738+
optional:
1739+
description: Specify whether the ConfigMap or
1740+
its key must be defined
1741+
type: boolean
1742+
required:
1743+
- key
1744+
type: object
1745+
x-kubernetes-map-type: atomic
1746+
fieldRef:
1747+
description: |-
1748+
Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['<KEY>']`, `metadata.annotations['<KEY>']`,
1749+
spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
1750+
properties:
1751+
apiVersion:
1752+
description: Version of the schema the FieldPath
1753+
is written in terms of, defaults to "v1".
1754+
type: string
1755+
fieldPath:
1756+
description: Path of the field to select in
1757+
the specified API version.
1758+
type: string
1759+
required:
1760+
- fieldPath
1761+
type: object
1762+
x-kubernetes-map-type: atomic
1763+
resourceFieldRef:
1764+
description: |-
1765+
Selects a resource of the container: only resources limits and requests
1766+
(limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
1767+
properties:
1768+
containerName:
1769+
description: 'Container name: required for volumes,
1770+
optional for env vars'
1771+
type: string
1772+
divisor:
1773+
anyOf:
1774+
- type: integer
1775+
- type: string
1776+
description: Specifies the output format of
1777+
the exposed resources, defaults to "1"
1778+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1779+
x-kubernetes-int-or-string: true
1780+
resource:
1781+
description: 'Required: resource to select'
1782+
type: string
1783+
required:
1784+
- resource
1785+
type: object
1786+
x-kubernetes-map-type: atomic
1787+
secretKeyRef:
1788+
description: Selects a key of a secret in the pod's
1789+
namespace
1790+
properties:
1791+
key:
1792+
description: The key of the secret to select
1793+
from. Must be a valid secret key.
1794+
type: string
1795+
name:
1796+
default: ""
1797+
description: |-
1798+
Name of the referent.
1799+
This field is effectively required, but due to backwards compatibility is
1800+
allowed to be empty. Instances of this type with an empty value here are
1801+
almost certainly wrong.
1802+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
1803+
type: string
1804+
optional:
1805+
description: Specify whether the Secret or its
1806+
key must be defined
1807+
type: boolean
1808+
required:
1809+
- key
1810+
type: object
1811+
x-kubernetes-map-type: atomic
1812+
type: object
1813+
required:
1814+
- name
1815+
type: object
1816+
x-kubernetes-validations:
1817+
- message: Cannot overwrite environment variables set by
1818+
operator
1819+
rule: self.name != 'K8S_POD_NAMESPACE' && self.name !=
1820+
'K8S_POD_NAME' && self.name != 'PGPASSWORD'
1821+
minItems: 1
1822+
type: array
1823+
x-kubernetes-list-type: atomic
16951824
exporters:
16961825
description: |-
16971826
Exporters allows users to configure OpenTelemetry exporters that exist

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11537,6 +11537,135 @@ spec:
1153711537
x-kubernetes-list-map-keys:
1153811538
- name
1153911539
x-kubernetes-list-type: map
11540+
environmentVariables:
11541+
description: |-
11542+
EnvironmentVariables allows the user to add environment variables to the
11543+
collector container.
11544+
items:
11545+
description: EnvVar represents an environment variable present
11546+
in a Container.
11547+
properties:
11548+
name:
11549+
description: Name of the environment variable. Must
11550+
be a C_IDENTIFIER.
11551+
type: string
11552+
value:
11553+
description: |-
11554+
Variable references $(VAR_NAME) are expanded
11555+
using the previously defined environment variables in the container and
11556+
any service environment variables. If a variable cannot be resolved,
11557+
the reference in the input string will be unchanged. Double $$ are reduced
11558+
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e.
11559+
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
11560+
Escaped references will never be expanded, regardless of whether the variable
11561+
exists or not.
11562+
Defaults to "".
11563+
type: string
11564+
valueFrom:
11565+
description: Source for the environment variable's value.
11566+
Cannot be used if value is not empty.
11567+
properties:
11568+
configMapKeyRef:
11569+
description: Selects a key of a ConfigMap.
11570+
properties:
11571+
key:
11572+
description: The key to select.
11573+
type: string
11574+
name:
11575+
default: ""
11576+
description: |-
11577+
Name of the referent.
11578+
This field is effectively required, but due to backwards compatibility is
11579+
allowed to be empty. Instances of this type with an empty value here are
11580+
almost certainly wrong.
11581+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
11582+
type: string
11583+
optional:
11584+
description: Specify whether the ConfigMap or
11585+
its key must be defined
11586+
type: boolean
11587+
required:
11588+
- key
11589+
type: object
11590+
x-kubernetes-map-type: atomic
11591+
fieldRef:
11592+
description: |-
11593+
Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['<KEY>']`, `metadata.annotations['<KEY>']`,
11594+
spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
11595+
properties:
11596+
apiVersion:
11597+
description: Version of the schema the FieldPath
11598+
is written in terms of, defaults to "v1".
11599+
type: string
11600+
fieldPath:
11601+
description: Path of the field to select in
11602+
the specified API version.
11603+
type: string
11604+
required:
11605+
- fieldPath
11606+
type: object
11607+
x-kubernetes-map-type: atomic
11608+
resourceFieldRef:
11609+
description: |-
11610+
Selects a resource of the container: only resources limits and requests
11611+
(limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
11612+
properties:
11613+
containerName:
11614+
description: 'Container name: required for volumes,
11615+
optional for env vars'
11616+
type: string
11617+
divisor:
11618+
anyOf:
11619+
- type: integer
11620+
- type: string
11621+
description: Specifies the output format of
11622+
the exposed resources, defaults to "1"
11623+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
11624+
x-kubernetes-int-or-string: true
11625+
resource:
11626+
description: 'Required: resource to select'
11627+
type: string
11628+
required:
11629+
- resource
11630+
type: object
11631+
x-kubernetes-map-type: atomic
11632+
secretKeyRef:
11633+
description: Selects a key of a secret in the pod's
11634+
namespace
11635+
properties:
11636+
key:
11637+
description: The key of the secret to select
11638+
from. Must be a valid secret key.
11639+
type: string
11640+
name:
11641+
default: ""
11642+
description: |-
11643+
Name of the referent.
11644+
This field is effectively required, but due to backwards compatibility is
11645+
allowed to be empty. Instances of this type with an empty value here are
11646+
almost certainly wrong.
11647+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
11648+
type: string
11649+
optional:
11650+
description: Specify whether the Secret or its
11651+
key must be defined
11652+
type: boolean
11653+
required:
11654+
- key
11655+
type: object
11656+
x-kubernetes-map-type: atomic
11657+
type: object
11658+
required:
11659+
- name
11660+
type: object
11661+
x-kubernetes-validations:
11662+
- message: Cannot overwrite environment variables set by
11663+
operator
11664+
rule: self.name != 'K8S_POD_NAMESPACE' && self.name !=
11665+
'K8S_POD_NAME' && self.name != 'PGPASSWORD'
11666+
minItems: 1
11667+
type: array
11668+
x-kubernetes-list-type: atomic
1154011669
exporters:
1154111670
description: |-
1154211671
Exporters allows users to configure OpenTelemetry exporters that exist

internal/collector/instance.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ func AddToPod(
116116
VolumeMounts: append(volumeMounts, configVolumeMount),
117117
}
118118

119+
// Add any user specified environment variables to the collector container
120+
if spec.Config != nil && spec.Config.EnvironmentVariables != nil {
121+
container.Env = append(container.Env, spec.Config.EnvironmentVariables...)
122+
}
123+
119124
// If metrics feature is enabled and this Pod serves metrics, add the
120125
// Prometheus port to this container
121126
if feature.Enabled(ctx, feature.OpenTelemetryMetrics) && thisPodServesMetrics {

pkg/apis/postgres-operator.crunchydata.com/v1beta1/instrumentation_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ type InstrumentationConfigSpec struct {
6565
// +listType=atomic
6666
// +optional
6767
Files []corev1.VolumeProjection `json:"files,omitempty"`
68+
69+
// EnvironmentVariables allows the user to add environment variables to the
70+
// collector container.
71+
// ---
72+
// +kubebuilder:validation:MinItems=1
73+
// +kubebuilder:validation:items:XValidation:rule=`self.name != 'K8S_POD_NAMESPACE' && self.name != 'K8S_POD_NAME' && self.name != 'PGPASSWORD'`,message="Cannot overwrite environment variables set by operator"
74+
// +listType=atomic
75+
// +optional
76+
EnvironmentVariables []corev1.EnvVar `json:"environmentVariables,omitempty"`
6877
}
6978

7079
// InstrumentationLogsSpec defines the configuration for collecting logs via

pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)