Skip to content

Commit

Permalink
test: adds deps for entity synthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-newrelic committed Feb 25, 2025
1 parent 141b6b8 commit e225802
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 178 deletions.
1 change: 0 additions & 1 deletion test/charts/mocked_backend/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ spec:
labels:
app: *app
spec:
serviceAccountName: read-k8s-api-account
initContainers:
# Wait for the backend to be up before starting the collector
- name: wait-for-validation
Expand Down
40 changes: 0 additions & 40 deletions test/charts/mocked_backend/templates/deployment-collector.yaml

This file was deleted.

91 changes: 0 additions & 91 deletions test/charts/mocked_backend/templates/k8s-api-access.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions test/charts/nr_backend/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: kube-state-metrics
repository: https://prometheus-community.github.io/helm-charts
version: 5.18.0
digest: sha256:c32e765ebe122825fcd7be743ab21357dd203d62d56146b00a4e87a3ec64cfe9
generated: "2025-02-25T11:50:20.535455-08:00"
7 changes: 7 additions & 0 deletions test/charts/nr_backend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ name: nrdot-nr-backend
description: A Helm chart for deploying an nrdot collector as a DaemonSet writing to New Relic
version: 0.1.0
appVersion: "1.0"

dependencies:
# supplies required metrics for entity synthesis of most k8s resources
- name: kube-state-metrics
version: 5.18.0
condition: kube-state-metrics.enabled
repository: https://prometheus-community.github.io/helm-charts
8 changes: 8 additions & 0 deletions test/charts/nr_backend/templates/collector-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: collector-secrets
type: Opaque
data:
backendUrl: {{ .Values.secrets.nrBackendUrl | b64enc }}
nrIngestKey: {{ .Values.secrets.nrIngestKey | b64enc }}
30 changes: 12 additions & 18 deletions test/charts/nr_backend/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ spec:
labels:
app: *app
spec:
{{- if .Values.image.repository | hasSuffix "k8s" }}
serviceAccountName: read-k8s-api-account
{{- end }}
initContainers:
# Wait for the backend to be up before starting the collector
- name: wait-for-validation
Expand All @@ -30,31 +32,23 @@ spec:
- name: health
containerPort: 13133
env:
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: OTEL_EXPORTER_OTLP_ENDPOINT
valueFrom:
secretKeyRef:
name: daemonset-secrets
name: collector-secrets
key: backendUrl
- name: NEW_RELIC_LICENSE_KEY
valueFrom:
secretKeyRef:
name: daemonset-secrets
name: collector-secrets
key: nrIngestKey
- name: OTEL_RESOURCE_ATTRIBUTES
value: "host.name={{ .Values.collector.hostname }}-$(KUBE_NODE_NAME)"
# used to populate k8s.cluster.name
{{- if .Values.image.repository | hasSuffix "k8s" }}
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: K8S_CLUSTER_NAME
value: {{ .Values.clusterName }}
---
apiVersion: v1
kind: Secret
metadata:
name: daemonset-secrets
type: Opaque
data:
backendUrl: {{ .Values.secrets.nrBackendUrl | b64enc }}
nrIngestKey: {{ .Values.secrets.nrIngestKey | b64enc }}
{{- end }}
- name: OTEL_RESOURCE_ATTRIBUTES
value: "host.name={{ .Values.collector.hostname }}-$(KUBE_NODE_NAME)"
9 changes: 5 additions & 4 deletions test/charts/nr_backend/templates/deployment-collector.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.image.repository | hasSuffix "k8s" }}
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -6,7 +7,7 @@ metadata:
labels:
app: *app
spec:
replicas: {{ .Values.image.repository | hasSuffix "k8s" | ternary 1 0 }}
replicas: 1
selector:
matchLabels:
app: *app
Expand All @@ -32,14 +33,14 @@ spec:
- name: OTEL_EXPORTER_OTLP_ENDPOINT
valueFrom:
secretKeyRef:
name: daemonset-secrets
name: collector-secrets
key: backendUrl
- name: NEW_RELIC_LICENSE_KEY
valueFrom:
secretKeyRef:
name: daemonset-secrets
name: collector-secrets
key: nrIngestKey
# used to populate k8s.cluster.name
- name: K8S_CLUSTER_NAME
value: {{ .Values.clusterName }}

{{- end }}
55 changes: 31 additions & 24 deletions test/charts/nr_backend/templates/k8s-api-access.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.image.repository | hasSuffix "k8s" }}
# namespace suffixes to avoid conflicts when installing chart multiple times
apiVersion: v1
kind: ServiceAccount
Expand All @@ -9,73 +10,78 @@ kind: ClusterRole
metadata:
# namespace suffix to avoid conflicts when installing chart multiple times
name: read-k8s-api-role-{{ .Release.Namespace }}
# if not mentioned otherwise, required rules copied from:
# - k8seventsreceiever: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/k8seventsreceiver/README.md#rbac
# if not mentioned otherwise, required rules copied from nr-k8s-otel-collector helm chart: https://github.com/newrelic/helm-charts/blob/3e7dc5d77694c3d661dc6509b2def6076b660c34/charts/nr-k8s-otel-collector/templates/clusterrole.yaml
rules:
- apiGroups:
- ""
resources:
# following required for k8s_events, k8s_cluster receiver
- events
- endpoints # prometheus/api_server
# following required for k8s_cluster receiver
- namespaces
- namespaces/status
# following required for prometheus, k8s_cluster receiver
- nodes
- nodes/spec
- nodes/metrics
- pods
- pods/status
- replicationcontrollers
- replicationcontrollers/status
- resourcequotas
- services
- endpoints
verbs:
- get
- list
- watch
- apiGroups:
- apps
- ""
resources:
- daemonsets
- deployments
- replicasets
- statefulsets
# following required for hostmetrics, prometheus receiver
- nodes/spec
- nodes/stats
- nodes/proxy
# following required for filelog receiver
- pods/logs
verbs:
- get
# following required for prometheus receiver
- apiGroups:
- ""
resources:
- replicationcontrollers
- resourcequotas
verbs:
- list
- watch
# following required for prometheus receiver
- apiGroups:
- extensions
- apps
resources:
- daemonsets
- deployments
- replicasets
- statefulsets
verbs:
- get
- list
- watch
# following required for prometheus receiver
- apiGroups:
- batch
resources:
- jobs
- cronjobs
verbs:
- get
- list
- watch
# following required for prometheus receiver
- apiGroups:
- autoscaling
resources:
- horizontalpodautoscalers
verbs:
- get
- list
- watch
# kubeletstatsreceiver: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/kubeletstatsreceiver#role-based-access-control
- apiGroups: [ "" ]
resources: [ "nodes/stats" ]
verbs: [ "get" ]
- apiGroups: [ "" ]
resources: [ "nodes/proxy" ]
verbs: [ "get" ]
# following required for prometheus receiver
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -88,4 +94,5 @@ roleRef:
subjects:
- kind: ServiceAccount
name: read-k8s-api-account
namespace: {{ .Release.Namespace }}
namespace: {{ .Release.Namespace }}
{{- end }}
5 changes: 5 additions & 0 deletions test/charts/nr_backend/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ collector:
hostname: nrdot-collector-default-hostname

clusterName: default-cluster-name

# provides metrics required for entity synthesis of various k8s resources
kube-state-metrics:
enabled: true
prometheusScrape: false
1 change: 1 addition & 0 deletions test/e2e/util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func NewHelmOptions(kubectlOptions *k8s.KubectlOptions, chartValues map[string]s
installArg := []string{
"--namespace", kubectlOptions.Namespace,
"--create-namespace",
"--dependency-update",
}
for key, val := range chartValues {
installArg = append(installArg, "--set", fmt.Sprintf("%s=%s", key, val))
Expand Down

0 comments on commit e225802

Please sign in to comment.