From 4a4c5d68bdfd554ed45d309a98bba6fead7bc422 Mon Sep 17 00:00:00 2001 From: Ben Blattberg Date: Wed, 12 Feb 2025 10:34:20 -0600 Subject: [PATCH 1/2] Add configurable collector * Add RELATED_IMAGE_ var * Add func to pull image from spec or env Issues: [PGO-2167] --- .github/workflows/test.yaml | 1 + config/manager/manager.yaml | 2 ++ internal/collector/instance.go | 3 ++- internal/config/config.go | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e04d9ef131..12469ae91d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -143,6 +143,7 @@ jobs: --env 'RELATED_IMAGE_POSTGRES_17=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-17.2-2' \ --env 'RELATED_IMAGE_POSTGRES_17_GIS_3.4=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi8-17.2-3.4-2' \ --env 'RELATED_IMAGE_STANDALONE_PGADMIN=registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi8-8.14-1' \ + --env 'RELATED_IMAGE_COLLECTOR=ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.119.0' \ --env 'PGO_FEATURE_GATES=TablespaceVolumes=true' \ --name 'postgres-operator' ubuntu \ postgres-operator diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 8fb6bcf007..98a771bb32 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -44,6 +44,8 @@ spec: value: "registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:latest" - name: RELATED_IMAGE_STANDALONE_PGADMIN value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi8-8.14-1" + - name: RELATED_IMAGE_COLLECTOR + value: "ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.119.0" securityContext: allowPrivilegeEscalation: false capabilities: { drop: [ALL] } diff --git a/internal/collector/instance.go b/internal/collector/instance.go index 8cb90be32a..a3ddc1ae8a 100644 --- a/internal/collector/instance.go +++ b/internal/collector/instance.go @@ -9,6 +9,7 @@ import ( corev1 "k8s.io/api/core/v1" + "github.com/crunchydata/postgres-operator/internal/config" "github.com/crunchydata/postgres-operator/internal/feature" "github.com/crunchydata/postgres-operator/internal/initialize" "github.com/crunchydata/postgres-operator/internal/naming" @@ -72,7 +73,7 @@ func AddToPod( container := corev1.Container{ Name: naming.ContainerCollector, - Image: "ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.117.0", + Image: config.CollectorContainerImage(spec), ImagePullPolicy: pullPolicy, Command: []string{"/otelcol-contrib", "--config", "/etc/otel-collector/config.yaml"}, Env: []corev1.EnvVar{ diff --git a/internal/config/config.go b/internal/config/config.go index ff3c6507d0..7fbfadd63b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -99,6 +99,17 @@ func PGExporterContainerImage(cluster *v1beta1.PostgresCluster) string { return defaultFromEnv(image, "RELATED_IMAGE_PGEXPORTER") } +// CollectorContainerImage returns the container image to use for the +// collector container. +func CollectorContainerImage(instrumentation *v1beta1.InstrumentationSpec) string { + var image string + if instrumentation != nil { + image = instrumentation.Image + } + + return defaultFromEnv(image, "RELATED_IMAGE_COLLECTOR") +} + // PostgresContainerImage returns the container image to use for PostgreSQL. func PostgresContainerImage(cluster *v1beta1.PostgresCluster) string { image := cluster.Spec.Image @@ -143,6 +154,12 @@ func VerifyImageValues(cluster *v1beta1.PostgresCluster) error { cluster.Spec.Monitoring.PGMonitor.Exporter != nil { images = append(images, "crunchy-postgres-exporter") } + if PGExporterContainerImage(cluster) == "" && + cluster.Spec.Monitoring != nil && + cluster.Spec.Monitoring.PGMonitor != nil && + cluster.Spec.Monitoring.PGMonitor.Exporter != nil { + images = append(images, "crunchy-postgres-exporter") + } if PostgresContainerImage(cluster) == "" { if cluster.Spec.PostGISVersion != "" { images = append(images, "crunchy-postgres-gis") From f2f998e00340a7a2f699aa050244659dcaa5d11a Mon Sep 17 00:00:00 2001 From: Ben Blattberg Date: Wed, 12 Feb 2025 10:52:48 -0600 Subject: [PATCH 2/2] verify image update --- internal/config/config.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 7fbfadd63b..2c5f1bf769 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -154,11 +154,9 @@ func VerifyImageValues(cluster *v1beta1.PostgresCluster) error { cluster.Spec.Monitoring.PGMonitor.Exporter != nil { images = append(images, "crunchy-postgres-exporter") } - if PGExporterContainerImage(cluster) == "" && - cluster.Spec.Monitoring != nil && - cluster.Spec.Monitoring.PGMonitor != nil && - cluster.Spec.Monitoring.PGMonitor.Exporter != nil { - images = append(images, "crunchy-postgres-exporter") + if CollectorContainerImage(cluster.Spec.Instrumentation) == "" && + cluster.Spec.Instrumentation != nil { + images = append(images, "crunchy-collector") } if PostgresContainerImage(cluster) == "" { if cluster.Spec.PostGISVersion != "" {