Skip to content

Commit

Permalink
[nr-k8s-otel-collector] Add unit tests (#1384)
Browse files Browse the repository at this point in the history
<!--
Thank you for contributing to New Relic's Helm charts. Before you submit
this PR we'd like to
make sure you are aware of our technical requirements:

*
https://github.com/newrelic-experimental/helm-charts/blob/master/CONTRIBUTING.md#technical-requirements

For a quick overview across what we will look at reviewing your PR,
please read
our review guidelines:

*
https://github.com/newrelic-experimental/helm-charts/blob/master/REVIEW_GUIDELINES.md

Following our best practices right from the start will accelerate the
review process and
help get your PR merged quicker.

When updates to your PR are requested, please add new commits and do not
squash the
history. This will make it easier to identify new changes. The PR will
be squashed
anyways when it is merged. Thanks.

For fast feedback, please @-mention maintainers that are listed in the
Chart.yaml file.

Please make sure you test your changes before you push them. Once
pushed, a Github Action
will run across your changes and do some initial checks and linting.
These checks run
very quickly. Please check the results. We would like these checks to
pass before we
even continue reviewing your changes.
-->
#### Is this a new chart

#### What this PR does / why we need it:

#### Which issue this PR fixes
*(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)`
format, will close that issue when PR gets merged)*
  - fixes #NR-268534

#### Special notes for your reviewer:

#### Checklist
[Place an '[x]' (no spaces) in all applicable fields. Please remove
unrelated fields.]
- [x] Chart Version bumped
- [x] Variables are documented in the README.md
- [x] Title of the PR starts with chart name (e.g. `[mychartname]`)

---------

Co-authored-by: csongnr <[email protected]>
Co-authored-by: chris <[email protected]>
  • Loading branch information
3 people authored Jun 10, 2024
1 parent 98dacc3 commit 476dcb2
Show file tree
Hide file tree
Showing 15 changed files with 1,335 additions and 14 deletions.
2 changes: 1 addition & 1 deletion charts/nr-k8s-otel-collector/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.3.2
version: 0.3.3

dependencies:
- name: common-library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
labels:
{{- include "newrelic.common.labels" . | nindent 4 }}
data:
otel-collector-config.yaml: |
daemonset-config.yaml: |
receivers:
hostmetrics:
# TODO (chris): this is a linux specific configuration
Expand Down
10 changes: 4 additions & 6 deletions charts/nr-k8s-otel-collector/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ spec:
{{- end }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /otelcol-contrib
- --config=/conf/otel-collector-config.yaml
args: ["--config", "/config/daemonset-config.yaml"]
resources:
{{- toYaml .Values.daemonset.resources | nindent 12 }}
env:
Expand Down Expand Up @@ -83,8 +81,8 @@ spec:
mountPath: /var/log/pods
readOnly: true
{{- end }}
- name: config-volume
mountPath: /conf
- name: daemonset-config
mountPath: /config
volumes:
# TODO (chris): this is a linux specific configuration
{{- if include "newrelic.common.privileged" . }}
Expand All @@ -95,7 +93,7 @@ spec:
hostPath:
path: /var/log/pods
{{- end }}
- name: config-volume
- name: daemonset-config
configMap:
name: {{ include "nrKubernetesOtel.daemonset.configmap.fullname" . }}
{{- with include "nrKubernetesOtel.daemonset.nodeSelector" . }}
Expand Down
2 changes: 1 addition & 1 deletion charts/nr-k8s-otel-collector/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ spec:
{{- . | nindent 12 }}
{{- end }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
args: ["--config", "/config/deployment-config.yaml"]
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: ["--config", "/config/deployment-config.yaml"]
resources:
{{- toYaml .Values.deployment.resources | nindent 12 }}
env:
Expand Down
314 changes: 314 additions & 0 deletions charts/nr-k8s-otel-collector/tests/affinity_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
suite: affinity
templates:
- templates/deployment.yaml
- templates/deployment-configmap.yaml
- templates/daemonset.yaml
- templates/daemonset-configmap.yaml
release:
name: my-release
namespace: my-namespace
tests:
- it: sets affinity to default when no values provided
set:
cluster: my-cluster
licenseKey: us-whatever
asserts:
- notExists:
path: spec.template.spec.affinity
template: templates/deployment.yaml
- notExists:
path: spec.template.spec.affinity
template: templates/daemonset.yaml
- it: sets affinity from global by common-library
set:
cluster: test-cluster
licenseKey: us-whatever
global:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: globalKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: globalKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/deployment.yaml
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: globalKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/daemonset.yaml
- it: sets affinity from values by common-library
set:
cluster: test-cluster
licenseKey: us-whatever
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/deployment.yaml
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/daemonset.yaml
- it: sets affinity from values by common-library overriding global values
set:
cluster: test-cluster
licenseKey: us-whatever
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
global:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: globalKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/deployment.yaml
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/daemonset.yaml
- it: sets affinity from deployment values
set:
cluster: test-cluster
licenseKey: us-whatever
deployment:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: deploymentKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: deploymentKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/deployment.yaml
- it: sets affinity from daemonset values
set:
cluster: test-cluster
licenseKey: us-whatever
daemonset:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: daemonsetKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: daemonsetKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/daemonset.yaml
- it: sets affinity from deployment values overriding top level and global values
set:
cluster: test-cluster
licenseKey: us-whatever
deployment:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: deploymentKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
global:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: globalKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: deploymentKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/deployment.yaml
- it: sets affinity from daemonset values overriding top level and global values
set:
cluster: test-cluster
licenseKey: us-whatever
daemonset:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: daemonsetKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: topLevelKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
global:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: globalKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: daemonsetKey
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
template: templates/daemonset.yaml
Loading

0 comments on commit 476dcb2

Please sign in to comment.