Skip to content

Commit

Permalink
chore: chainsaw improvements (#2642)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Mikołaj Świątek <mail+sumo@mikolajswiatek.com>
  • Loading branch information
eddycharly and swiatekm committed Feb 16, 2024
1 parent a62a081 commit 09cac33
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 293 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ KUBEBUILDER_ASSETS=$(./bin/setup-envtest use -p path 1.23) go test ./pkg...

To run the end-to-end tests, you'll need [`kind`](https://kind.sigs.k8s.io) and [`chainsaw`](https://kyverno.github.io/chainsaw). Refer to their documentation for installation instructions.

Once they are installed, the tests can be executed with `make prepare-e2e`, which will build an image to use with the tests, followed by `make e2e`. Each call to the `e2e` target will setup a fresh `kind` cluster, making it safe to be executed multiple times with a single `prepare-e2e` step.
Once they are installed, the tests can be executed with `make prepare-e2e`, which will build an image to use with the tests, followed by `make e2e`. Each call to the `e2e` target will set up a fresh `kind` cluster, making it safe to be executed multiple times with a single `prepare-e2e` step.

The tests are located under `tests/e2e` and are written to be used with `chainsaw`. Refer to their documentation to understand how tests are written.

To evert the changes made by the `make prepare-e2e` run `make reset`.
To revert the changes made by the `make prepare-e2e` run `make reset`.

### OpenShift End to End tests
To run the end-to-end tests written for OpenShift, you'll need a OpenShift cluster.
Expand Down
19 changes: 3 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,13 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
CHLOGGEN ?= $(LOCALBIN)/chloggen
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
CHAINSAW ?= $(LOCALBIN)/chainsaw

KUSTOMIZE_VERSION ?= v5.0.3
CONTROLLER_TOOLS_VERSION ?= v0.12.0
GOLANGCI_LINT_VERSION ?= v1.54.0
KIND_VERSION ?= v0.20.0

# Checks if chainsaw is in your PATH
ifneq ($(shell which chainsaw),)
CHAINSAW ?= $(shell which chainsaw)
else
CHAINSAW ?= $(LOCALBIN)/chainsaw
endif
CHAINSAW_VERSION ?= v0.1.4

.PHONY: install-tools
install-tools: kustomize golangci-lint kind controller-gen envtest crdoc kind operator-sdk chainsaw
Expand Down Expand Up @@ -406,15 +401,7 @@ crdoc: ## Download crdoc locally if necessary.

.PHONY: chainsaw
chainsaw: ## Find or download chainsaw
ifeq (, $(shell which chainsaw))
@{ \
set -e ;\
go install github.com/kyverno/chainsaw@v0.1.4 ;\
}
CHAINSAW ?= $(GOBIN)/chainsaw
else
CHAINSAW ?= $(shell which chainsaw)
endif
$(call go-get-tool,$(CHAINSAW), github.com/kyverno/chainsaw,$(CHAINSAW_VERSION))

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,16 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: instrumentation-apache-httpd
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 3000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=3000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-dotnet-musl
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=2000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-dotnet
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=2000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
11 changes: 5 additions & 6 deletions tests/e2e-instrumentation/instrumentation-go/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ metadata:
creationTimestamp: null
name: instrumentation-go
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 0/0
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-00
try:
Expand All @@ -14,12 +19,6 @@ spec:
file: 00-install-instrumentation.yaml
- name: step-01
try:
- script:
content: kubectl annotate namespace ${NAMESPACE} openshift.io/sa.scc.uid-range=0/0
--overwrite
- script:
content: kubectl annotate namespace ${NAMESPACE} openshift.io/sa.scc.supplemental-groups=2000/1000
--overwrite
- script:
content: ./add-scc.sh
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ metadata:
creationTimestamp: null
name: instrumentation-java-other-ns
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-01
try:
Expand All @@ -15,22 +20,6 @@ spec:
name: my-other-ns
- name: step-02
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=2000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 02-install-collector.yaml
- apply:
Expand Down
21 changes: 5 additions & 16 deletions tests/e2e-instrumentation/instrumentation-java/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-java
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=2000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-nginx-contnr-secctx
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 3000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=3000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-nginx-multicontainer
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 3000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=3000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
21 changes: 5 additions & 16 deletions tests/e2e-instrumentation/instrumentation-nginx/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-nginx
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 3000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=3000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-nodejs
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=2000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ metadata:
creationTimestamp: null
name: instrumentation-python
spec:
namespaceTemplate:
metadata:
annotations:
openshift.io/sa.scc.uid-range: 1000/1000
openshift.io/sa.scc.supplemental-groups: 2000/1000
steps:
- name: step-00
try:
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.uid-range=1000/1000
- --overwrite
entrypoint: kubectl
- command:
args:
- annotate
- namespace
- ${NAMESPACE}
- openshift.io/sa.scc.supplemental-groups=2000/1000
- --overwrite
entrypoint: kubectl
- apply:
file: 00-install-collector.yaml
- apply:
Expand Down
Loading

0 comments on commit 09cac33

Please sign in to comment.