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

Support nodeSelector field for non-sidecar collectors #789

Merged
merged 8 commits into from
Apr 7, 2022
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
7 changes: 6 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ type OpenTelemetryCollectorSpec struct {
Resources v1.ResourceRequirements `json:"resources,omitempty"`

// Toleration to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonsets, statefulsets and deployments
// This is only relevant to daemonset, statefulset, and deployment mode
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`

// NodeSelector to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// +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
Expand Down
7 changes: 7 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ spec:
- sidecar
- statefulset
type: string
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to schedule OpenTelemetry Collector pods.
This is only relevant to daemonset, statefulset, and deployment
mode
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down Expand Up @@ -676,7 +683,8 @@ spec:
type: object
tolerations:
description: Toleration to schedule OpenTelemetry Collector pods.
This is only relevant to daemonsets, statefulsets and deployments
This is only relevant to daemonset, statefulset, and deployment
mode
items:
description: The pod this Toleration is attached to tolerates any
taint that matches the triple <key,value,effect> using the matching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ spec:
- sidecar
- statefulset
type: string
nodeSelector:
additionalProperties:
type: string
description: NodeSelector to schedule OpenTelemetry Collector pods.
This is only relevant to daemonset, statefulset, and deployment
mode
type: object
podAnnotations:
additionalProperties:
type: string
Expand Down Expand Up @@ -674,7 +681,8 @@ spec:
type: object
tolerations:
description: Toleration to schedule OpenTelemetry Collector pods.
This is only relevant to daemonsets, statefulsets and deployments
This is only relevant to daemonset, statefulset, and deployment
mode
items:
description: The pod this Toleration is attached to tolerates any
taint that matches the triple <key,value,effect> using the matching
Expand Down
9 changes: 8 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,13 @@ OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
<i>Enum</i>: daemonset, deployment, sidecar, statefulset<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>nodeSelector</b></td>
<td>map[string]string</td>
<td>
NodeSelector to schedule OpenTelemetry Collector pods. This is only relevant to daemonset, statefulset, and deployment mode<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>podAnnotations</b></td>
<td>map[string]string</td>
Expand Down Expand Up @@ -1526,7 +1533,7 @@ OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
<td><b><a href="#opentelemetrycollectorspectolerationsindex">tolerations</a></b></td>
<td>[]object</td>
<td>
Toleration to schedule OpenTelemetry Collector pods. This is only relevant to daemonsets, statefulsets and deployments<br/>
Toleration to schedule OpenTelemetry Collector pods. This is only relevant to daemonset, statefulset, and deployment mode<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions pkg/collector/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,36 @@ func TestDaemonsetFilterLabels(t *testing.T) {
assert.NotContains(t, d.ObjectMeta.Labels, k)
}
}

func TestDaemonSetNodeSelector(t *testing.T) {
// Test default
otelcol_1 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
}

cfg := config.New()

d1 := DaemonSet(cfg, logger, otelcol_1)

assert.Empty(t, d1.Spec.Template.Spec.NodeSelector)

// Test nodeSelector
otelcol_2 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-nodeselector",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
HostNetwork: true,
NodeSelector: map[string]string{
"node-key": "node-value",
},
},
}

cfg = config.New()

d2 := DaemonSet(cfg, logger, otelcol_2)
assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"})
}
1 change: 1 addition & 0 deletions pkg/collector/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/collector/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,36 @@ func TestDeploymentFilterLabels(t *testing.T) {
assert.NotContains(t, d.ObjectMeta.Labels, k)
}
}

func TestDeploymentNodeSelector(t *testing.T) {
// Test default
otelcol_1 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
}

cfg := config.New()

d1 := Deployment(cfg, logger, otelcol_1)

assert.Empty(t, d1.Spec.Template.Spec.NodeSelector)

// Test nodeSelector
otelcol_2 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-nodeselector",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
HostNetwork: true,
NodeSelector: map[string]string{
"node-key": "node-value",
},
},
}

cfg = config.New()

d2 := Deployment(cfg, logger, otelcol_2)
assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"})
}
1 change: 1 addition & 0 deletions pkg/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/collector/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,36 @@ func TestStatefulSetFilterLabels(t *testing.T) {
assert.NotContains(t, d.ObjectMeta.Labels, k)
}
}

func TestStatefulSetNodeSelector(t *testing.T) {
// Test default
otelcol_1 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
},
}

cfg := config.New()

d1 := StatefulSet(cfg, logger, otelcol_1)

assert.Empty(t, d1.Spec.Template.Spec.NodeSelector)

// Test nodeSelector
otelcol_2 := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-nodeselector",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
HostNetwork: true,
NodeSelector: map[string]string{
"node-key": "node-value",
},
},
}

cfg = config.New()

d2 := StatefulSet(cfg, logger, otelcol_2)
assert.Equal(t, d2.Spec.Template.Spec.NodeSelector, map[string]string{"node-key": "node-value"})
}