AddToPod adds the OpenTelemetry collector container to a given Pod
( ctx context.Context, spec *v1beta1.InstrumentationSpec, pullPolicy corev1.PullPolicy, inInstanceConfigMap *corev1.ConfigMap, template *corev1.PodTemplateSpec, volumeMounts []corev1.VolumeMount, sqlQueryPassword string, logDirectories []string, includeLogrotate bool, thisPodServesMetrics bool, )
| 38 | |
| 39 | // AddToPod adds the OpenTelemetry collector container to a given Pod |
| 40 | func AddToPod( |
| 41 | ctx context.Context, |
| 42 | spec *v1beta1.InstrumentationSpec, |
| 43 | pullPolicy corev1.PullPolicy, |
| 44 | inInstanceConfigMap *corev1.ConfigMap, |
| 45 | template *corev1.PodTemplateSpec, |
| 46 | volumeMounts []corev1.VolumeMount, |
| 47 | sqlQueryPassword string, |
| 48 | logDirectories []string, |
| 49 | includeLogrotate bool, |
| 50 | thisPodServesMetrics bool, |
| 51 | ) { |
| 52 | if !OpenTelemetryLogsOrMetricsEnabled(ctx, spec) { |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | // We only want to include log rotation if this type of pod requires it |
| 57 | // (indicate by the includeLogrotate boolean) AND if logging is enabled |
| 58 | // for this PostgresCluster/PGAdmin |
| 59 | includeLogrotate = includeLogrotate && OpenTelemetryLogsEnabled(ctx, spec) |
| 60 | |
| 61 | // Create volume and volume mount for otel collector config |
| 62 | configVolumeMount := corev1.VolumeMount{ |
| 63 | Name: "collector-config", |
| 64 | MountPath: configDirectory, |
| 65 | ReadOnly: true, |
| 66 | } |
| 67 | configVolume := corev1.Volume{Name: configVolumeMount.Name} |
| 68 | configVolume.Projected = &corev1.ProjectedVolumeSource{ |
| 69 | Sources: []corev1.VolumeProjection{{ |
| 70 | ConfigMap: &corev1.ConfigMapProjection{ |
| 71 | LocalObjectReference: corev1.LocalObjectReference{ |
| 72 | Name: inInstanceConfigMap.Name, |
| 73 | }, |
| 74 | Items: []corev1.KeyToPath{{ |
| 75 | Key: "collector.yaml", |
| 76 | Path: "config.yaml", |
| 77 | }}, |
| 78 | }, |
| 79 | }}, |
| 80 | } |
| 81 | |
| 82 | // If the user has specified files to be mounted in the spec, add them to |
| 83 | // the projected config volume |
| 84 | if spec.Config != nil && spec.Config.Files != nil { |
| 85 | configVolume.Projected.Sources = append(configVolume.Projected.Sources, |
| 86 | spec.Config.Files...) |
| 87 | } |
| 88 | |
| 89 | // Create collector container |
| 90 | container := corev1.Container{ |
| 91 | Name: naming.ContainerCollector, |
| 92 | Image: config.CollectorContainerImage(spec), |
| 93 | ImagePullPolicy: pullPolicy, |
| 94 | Command: startCommand(logDirectories, includeLogrotate), |
| 95 | Env: []corev1.EnvVar{ |
| 96 | { |
| 97 | Name: "K8S_POD_NAMESPACE", |