From 98e9fe0fbcc78ba3cb523bc338c4e28ea02fb20b Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 3 Jan 2022 15:39:49 +0000 Subject: [PATCH] osd: allow for injecting extra env. variables via ConfigMap This patch brings a mechanism to define arbitrary environment variables in OSD containers (both prepare and main ones). It bases on idea proposed by Sebastien Han to use an optional `ConfigMap` instance named `aook-ceph-daemon-env-override` as the source of these settings. The need for the patch comes from the fact that, although crimson finally exposes the same CLI interface as the classical OSD, the broadly used development builds have ASan built in. As ASan, by default, complains if it isn't the very first loaded DSO, we need a way to set the `ASAN_OPTIONS` environment variable to `verify_asan_link_order=0` to mitigate the early aborts. Signed-off-by: Radoslaw Zarzynski (cherry picked from commit 17ca41f557867714d747df4c70834798cded590d) --- deploy/examples/osd-env-override.yaml | 19 +++++++++++++++++++ pkg/operator/ceph/cluster/osd/envs.go | 14 ++++++++++++++ .../ceph/cluster/osd/provision_spec.go | 1 + pkg/operator/ceph/cluster/osd/spec.go | 3 +++ 4 files changed, 37 insertions(+) create mode 100644 deploy/examples/osd-env-override.yaml diff --git a/deploy/examples/osd-env-override.yaml b/deploy/examples/osd-env-override.yaml new file mode 100644 index 000000000..454ccc50a --- /dev/null +++ b/deploy/examples/osd-env-override.yaml @@ -0,0 +1,19 @@ +# ############################################################################################################### +# The `rook-ceph-osd-env-override` ConfigMap is a development feature +# that allows to inject arbitrary environment variables to OSD-related +# containers created by the operator. +# ############################################################################################################### + +apiVersion: v1 +kind: ConfigMap +metadata: + name: rook-ceph-osd-env-override + namespace: rook-ceph +data: + # Bypass the ASan's assertion that it is the very first loaded DSO. + # This is necessary for crimson-osd as it's currently built with + # the ASan sanitizer turned on which means the `libasan.so` must + # the be the very first loaded dynamic library. Unfortunately, this + # isn't fulfilled as the containers use `ld.preload`, so ASan was + # aborting the entire OSD. + ASAN_OPTIONS: verify_asan_link_order=0 diff --git a/pkg/operator/ceph/cluster/osd/envs.go b/pkg/operator/ceph/cluster/osd/envs.go index 11b714d88..7e3cf1831 100644 --- a/pkg/operator/ceph/cluster/osd/envs.go +++ b/pkg/operator/ceph/cluster/osd/envs.go @@ -32,6 +32,7 @@ const ( osdWalSizeEnvVarName = "ROOK_OSD_WAL_SIZE" osdsPerDeviceEnvVarName = "ROOK_OSDS_PER_DEVICE" osdDeviceClassEnvVarName = "ROOK_OSD_DEVICE_CLASS" + osdConfigMapOverrideName = "rook-ceph-osd-env-override" // EncryptedDeviceEnvVarName is used in the pod spec to indicate whether the OSD is encrypted or not EncryptedDeviceEnvVarName = "ROOK_ENCRYPTED_DEVICE" PVCNameEnvVarName = "ROOK_PVC_NAME" @@ -213,6 +214,19 @@ func osdActivateEnvVar() []v1.EnvVar { return append(cephVolumeEnvVar(), monEnvVars...) } +func getEnvFromSources() []v1.EnvFromSource { + optionalConfigMapRef := true + + return []v1.EnvFromSource{ + { + ConfigMapRef: &v1.ConfigMapEnvSource{ + LocalObjectReference: v1.LocalObjectReference{Name: osdConfigMapOverrideName}, + Optional: &optionalConfigMapRef, + }, + }, + } +} + func getTcmallocMaxTotalThreadCacheBytes(tcmallocMaxTotalThreadCacheBytes string) v1.EnvVar { var value string // If empty we read the default value from the file coming with the package diff --git a/pkg/operator/ceph/cluster/osd/provision_spec.go b/pkg/operator/ceph/cluster/osd/provision_spec.go index e9dbec33f..c4a7d32b7 100644 --- a/pkg/operator/ceph/cluster/osd/provision_spec.go +++ b/pkg/operator/ceph/cluster/osd/provision_spec.go @@ -302,6 +302,7 @@ func (c *Cluster) provisionOSDContainer(osdProps osdProperties, copyBinariesMoun Image: c.spec.CephVersion.Image, VolumeMounts: volumeMounts, Env: envVars, + EnvFrom: getEnvFromSources(), SecurityContext: &v1.SecurityContext{ Privileged: &privileged, RunAsUser: &runAsUser, diff --git a/pkg/operator/ceph/cluster/osd/spec.go b/pkg/operator/ceph/cluster/osd/spec.go index 2f57fa52a..09e195e73 100644 --- a/pkg/operator/ceph/cluster/osd/spec.go +++ b/pkg/operator/ceph/cluster/osd/spec.go @@ -466,6 +466,7 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC Image: c.rookVersion, VolumeMounts: configVolumeMounts, Env: configEnvVars, + EnvFrom: getEnvFromSources(), SecurityContext: securityContext, }) } @@ -549,6 +550,7 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC Image: c.spec.CephVersion.Image, VolumeMounts: volumeMounts, Env: envVars, + EnvFrom: getEnvFromSources(), Resources: osdProps.resources, SecurityContext: securityContext, StartupProbe: controller.GenerateStartupProbeExecDaemon(opconfig.OsdType, osdID), @@ -767,6 +769,7 @@ func (c *Cluster) getActivateOSDInitContainer(configDir, namespace, osdID string VolumeMounts: volMounts, SecurityContext: controller.PrivilegedContext(true), Env: envVars, + EnvFrom: getEnvFromSources(), Resources: osdProps.resources, }