diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index 6f62b62b73..98dfa9e52a 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -112,6 +112,11 @@ type OpenTelemetryCollectorSpec struct { // +optional Tolerations []v1.Toleration `json:"tolerations,omitempty"` + // NodeSelector to schedule OpenTelemetry Collector pods. + // This is only relevant to daemonsets, statefulsets and deployments + // +optional + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + // PodAnnotations is the set of annotations that will be attached to // Collector and Target Allocator pods. // +optional diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index e2d1070709..90e3ae0a8e 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -330,6 +330,13 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.PodAnnotations != nil { in, out := &in.PodAnnotations, &out.PodAnnotations *out = make(map[string]string, len(*in)) diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 733ac90a83..9bb28e7234 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -230,6 +230,12 @@ spec: - sidecar - statefulset type: string + nodeSelector: + additionalProperties: + type: string + description: NodeSelector to schedule OpenTelemetry Collector pods. + This is only relevant to daemonsets, statefulsets and deployments + type: object podAnnotations: additionalProperties: type: string diff --git a/pkg/collector/daemonset.go b/pkg/collector/daemonset.go index 4da5b04092..8a1b373b8d 100644 --- a/pkg/collector/daemonset.go +++ b/pkg/collector/daemonset.go @@ -53,6 +53,7 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem Containers: []corev1.Container{Container(cfg, logger, otelcol)}, Volumes: Volumes(cfg, otelcol), Tolerations: otelcol.Spec.Tolerations, + NodeSelector: otelcol.Spec.NodeSelector, HostNetwork: otelcol.Spec.HostNetwork, DNSPolicy: getDnsPolicy(otelcol), SecurityContext: otelcol.Spec.PodSecurityContext, diff --git a/pkg/collector/deployment.go b/pkg/collector/deployment.go index 8a4abd212c..93256d2eba 100644 --- a/pkg/collector/deployment.go +++ b/pkg/collector/deployment.go @@ -57,6 +57,7 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele DNSPolicy: getDnsPolicy(otelcol), HostNetwork: otelcol.Spec.HostNetwork, Tolerations: otelcol.Spec.Tolerations, + NodeSelector: otelcol.Spec.NodeSelector, SecurityContext: otelcol.Spec.PodSecurityContext, }, }, diff --git a/pkg/collector/statefulset.go b/pkg/collector/statefulset.go index 6427633c0a..335846dddc 100644 --- a/pkg/collector/statefulset.go +++ b/pkg/collector/statefulset.go @@ -57,6 +57,7 @@ func StatefulSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTel DNSPolicy: getDnsPolicy(otelcol), HostNetwork: otelcol.Spec.HostNetwork, Tolerations: otelcol.Spec.Tolerations, + NodeSelector: otelcol.Spec.NodeSelector, SecurityContext: otelcol.Spec.PodSecurityContext, }, },