From 036d6780a3293f06c90058639f6b76a4735526ba Mon Sep 17 00:00:00 2001 From: mmatache <89529881+mmatache@users.noreply.github.com> Date: Thu, 26 Aug 2021 18:43:37 +0300 Subject: [PATCH] Added imagePullPolicy option to CRD (#413) * Added imagePullPolicy option to CRD Signed-off-by: Mihai Matache * updated container test * Ran make bundle * reverted changes to bundle --- api/v1alpha1/opentelemetrycollector_types.go | 5 +++++ ...opentelemetry.io_opentelemetrycollectors.yaml | 4 ++++ ...opentelemetry.io_opentelemetrycollectors.yaml | 4 ++++ docs/otelcol_cr_spec.md | 3 +++ pkg/collector/container.go | 1 + pkg/collector/container_test.go | 16 ++++++++++++++++ 6 files changed, 33 insertions(+) diff --git a/api/v1alpha1/opentelemetrycollector_types.go b/api/v1alpha1/opentelemetrycollector_types.go index 4df3028536..eff35f8422 100644 --- a/api/v1alpha1/opentelemetrycollector_types.go +++ b/api/v1alpha1/opentelemetrycollector_types.go @@ -36,6 +36,11 @@ type OpenTelemetryCollectorSpec struct { // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true Replicas *int32 `json:"replicas,omitempty"` + // ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent) + // +optional + // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true + ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"` + // Image indicates the container image to use for the OpenTelemetry Collector. // +optional // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml index cdeb69596d..e30f13fbb7 100644 --- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -190,6 +190,10 @@ spec: description: Image indicates the container image to use for the OpenTelemetry Collector. type: string + imagePullPolicy: + description: ImagePullPolicy indicates the pull policy to be used + for retrieving the container image (Always, Never, IfNotPresent) + type: string mode: description: Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar) diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 80da912278..3fc5dc89ad 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -178,6 +178,10 @@ spec: description: Image indicates the container image to use for the OpenTelemetry Collector. type: string + imagePullPolicy: + description: ImagePullPolicy indicates the pull policy to be used + for retrieving the container image (Always, Never, IfNotPresent) + type: string mode: description: Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar) diff --git a/docs/otelcol_cr_spec.md b/docs/otelcol_cr_spec.md index fbca33397c..fd59381a44 100644 --- a/docs/otelcol_cr_spec.md +++ b/docs/otelcol_cr_spec.md @@ -37,6 +37,9 @@ spec: // +optional Image indicates the container image to use for the OpenTelemetry Collector. image: "" + + // +optional ImagePullPolicy indicates what image pull policy to be used to retrieve the container image to use for the OpenTelemetry Collector. + imagePullPolicy: "" // +optional ServiceAccount indicates the name of an existing service account to use with this instance. serviceAccount: "" diff --git a/pkg/collector/container.go b/pkg/collector/container.go index bf70d6ffa9..9f3aecfb80 100644 --- a/pkg/collector/container.go +++ b/pkg/collector/container.go @@ -71,6 +71,7 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem return corev1.Container{ Name: naming.Container(), Image: image, + ImagePullPolicy: otelcol.Spec.ImagePullPolicy, VolumeMounts: volumeMounts, Args: args, Env: envVars, diff --git a/pkg/collector/container_test.go b/pkg/collector/container_test.go index 82c70aab95..cb10e4bc2f 100644 --- a/pkg/collector/container_test.go +++ b/pkg/collector/container_test.go @@ -222,3 +222,19 @@ func TestContainerArgs(t *testing.T) { assert.Contains(t, c.Args, "--metrics-level=detailed") assert.Contains(t, c.Args, "--log-level=debug") } + +func TestContainerImagePullPolicy(t *testing.T) { + // prepare + otelcol := v1alpha1.OpenTelemetryCollector{ + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + ImagePullPolicy: corev1.PullIfNotPresent, + }, + } + cfg := config.New() + + // test + c := Container(cfg, logger, otelcol) + + // verify + assert.Equal(t, c.ImagePullPolicy, corev1.PullIfNotPresent) +}