Skip to content

Commit

Permalink
feat: add envFrom to collector spec (#419)
Browse files Browse the repository at this point in the history
* feat: add `envFrom` to collector spec

* chore: add docs and tests
  • Loading branch information
ctison authored Oct 4, 2021
1 parent e86fd5c commit 05081b8
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ type OpenTelemetryCollectorSpec struct {
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Env []v1.EnvVar `json:"env,omitempty"`

// List of sources to populate environment variables on the OpenTelemetry Collector's Pods.
// These can then in certain cases be consumed in the config file for the Collector.
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
EnvFrom []v1.EnvFromSource `json:"envFrom,omitempty"`

// Resources to set on the OpenTelemetry Collector pods.
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,41 @@ spec:
- name
type: object
type: array
envFrom:
description: List of sources to populate environment variables on
the OpenTelemetry Collector's Pods. These can then in certain cases
be consumed in the config file for the Collector.
items:
description: EnvFromSource represents the source of a set of ConfigMaps
properties:
configMapRef:
description: The ConfigMap to select from
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the ConfigMap must be defined
type: boolean
type: object
prefix:
description: An optional identifier to prepend to each key in
the ConfigMap. Must be a C_IDENTIFIER.
type: string
secretRef:
description: The Secret to select from
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the Secret must be defined
type: boolean
type: object
type: object
type: array
hostNetwork:
description: HostNetwork indicates if the pod should run in the host
networking namespace.
Expand Down
35 changes: 35 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,41 @@ spec:
- name
type: object
type: array
envFrom:
description: List of sources to populate environment variables on
the OpenTelemetry Collector's Pods. These can then in certain cases
be consumed in the config file for the Collector.
items:
description: EnvFromSource represents the source of a set of ConfigMaps
properties:
configMapRef:
description: The ConfigMap to select from
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the ConfigMap must be defined
type: boolean
type: object
prefix:
description: An optional identifier to prepend to each key in
the ConfigMap. Must be a C_IDENTIFIER.
type: string
secretRef:
description: The Secret to select from
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the Secret must be defined
type: boolean
type: object
type: object
type: array
hostNetwork:
description: HostNetwork indicates if the pod should run in the host
networking namespace.
Expand Down
4 changes: 4 additions & 0 deletions docs/otelcol_cr_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ spec:
// consumed in the config file for the Collector.
env: []
// +optional List of sources to populate environment variables on the OpenTelemetry Collector's Pods.
// These can then in certain cases be consumed in the config file for the Collector.
envFrom: []
// +optional Resources to set on the OpenTelemetry Collector pods.
resources: {}
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
VolumeMounts: volumeMounts,
Args: args,
Env: envVars,
EnvFrom: otelcol.Spec.EnvFrom,
Resources: otelcol.Spec.Resources,
SecurityContext: otelcol.Spec.SecurityContext,
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/collector/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,37 @@ func TestContainerImagePullPolicy(t *testing.T) {
// verify
assert.Equal(t, c.ImagePullPolicy, corev1.PullIfNotPresent)
}

func TestContainerEnvFrom(t *testing.T) {
//prepare
envFrom1 := corev1.EnvFromSource{
SecretRef: &corev1.SecretEnvSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "env-as-secret",
},
},
}
envFrom2 := corev1.EnvFromSource{
ConfigMapRef: &corev1.ConfigMapEnvSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "env-as-configmap",
},
},
}
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
EnvFrom: []corev1.EnvFromSource{
envFrom1,
envFrom2,
},
},
}
cfg := config.New()

// test
c := Container(cfg, logger, otelcol)

// verify
assert.Contains(t, c.EnvFrom, envFrom1)
assert.Contains(t, c.EnvFrom, envFrom2)
}

0 comments on commit 05081b8

Please sign in to comment.