Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add envFrom to collector spec #419

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -75,6 +75,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 @@ -238,3 +238,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)
}