From 3492089397644e8395f5132f63f7ee60832b5d5a Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 15 Oct 2024 15:40:30 +0200 Subject: [PATCH] Switch K8s tests to Wolfi by default and make it configurable (#41222) By default we test Wolfi-based images but there is now an environment variable `IMAGE_MODIFIER` that can be used for specifying different image prefixes when calling the make target. Also, now the test verifies the actual container readiness and deletes resources after itself. --- deploy/kubernetes/Makefile | 15 +++++++++++---- deploy/kubernetes/auditbeat-kubernetes.yaml | 2 +- .../kubernetes/auditbeat/auditbeat-daemonset.yaml | 2 +- deploy/kubernetes/filebeat-kubernetes.yaml | 2 +- .../kubernetes/filebeat/filebeat-daemonset.yaml | 2 +- deploy/kubernetes/heartbeat-kubernetes.yaml | 2 +- .../heartbeat/heartbeat-deployment.yaml | 2 +- deploy/kubernetes/metricbeat-kubernetes.yaml | 2 +- .../metricbeat/metricbeat-daemonset.yaml | 2 +- 9 files changed, 19 insertions(+), 12 deletions(-) diff --git a/deploy/kubernetes/Makefile b/deploy/kubernetes/Makefile index 166c83bf515..d05b6a88683 100644 --- a/deploy/kubernetes/Makefile +++ b/deploy/kubernetes/Makefile @@ -1,4 +1,5 @@ ALL=filebeat metricbeat auditbeat heartbeat +IMAGE_MODIFIER?="-wolfi" BEAT_VERSION=$(shell head -n 1 ../../libbeat/docs/version.asciidoc | cut -c 17- ) .PHONY: all $(ALL) @@ -6,21 +7,27 @@ BEAT_VERSION=$(shell head -n 1 ../../libbeat/docs/version.asciidoc | cut -c 17- all: $(ALL) test: all - for FILE in $(shell ls *-kubernetes.yaml); do \ - BEAT=$$(echo $$FILE | cut -d \- -f 1); \ + @for BEAT in $(ALL); do \ + echo; \ + echo "$$BEAT"; \ + FILE="$$BEAT-kubernetes.yaml"; \ kubectl create -f $$FILE; \ + echo "Testing $$BEAT container for readiness..."; \ + kubectl wait pods -n kube-system -l k8s-app=$$BEAT --for=condition=Ready --timeout=90s; \ + echo "Deleting $$BEAT..."; \ + kubectl delete -f $$FILE; \ done clean: @for f in $(ALL); do rm -f "$$f-kubernetes.yaml"; done $(ALL): - @echo "Generating $@-kubernetes.yaml" + @echo "Generating $@-kubernetes.yaml for version ${BEAT_VERSION} and image modifier '${IMAGE_MODIFIER}'" @rm -f $@-kubernetes.yaml @for f in service-account role role-binding configmap deployment daemonset ; do \ if [ -f "$@/$@-$$f.yaml" ]; then \ echo "file: $@/$@-$$f.yaml"; \ - sed "s/%VERSION%/${BEAT_VERSION}/g" $@/$@-$$f.yaml >> $@-kubernetes.yaml; \ + cat $@/$@-$$f.yaml | sed "s/%VERSION%/${BEAT_VERSION}/g" | sed "s/%IMAGE_MODIFIER%/${IMAGE_MODIFIER}/g" >> $@-kubernetes.yaml; \ echo --- >> $@-kubernetes.yaml; \ fi \ done diff --git a/deploy/kubernetes/auditbeat-kubernetes.yaml b/deploy/kubernetes/auditbeat-kubernetes.yaml index db3588ad960..23c940ad4e0 100644 --- a/deploy/kubernetes/auditbeat-kubernetes.yaml +++ b/deploy/kubernetes/auditbeat-kubernetes.yaml @@ -209,7 +209,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: auditbeat - image: docker.elastic.co/beats/auditbeat:9.0.0 + image: docker.elastic.co/beats/auditbeat-wolfi:9.0.0 args: [ "-c", "/etc/auditbeat.yml", "-e", diff --git a/deploy/kubernetes/auditbeat/auditbeat-daemonset.yaml b/deploy/kubernetes/auditbeat/auditbeat-daemonset.yaml index 39eaf726eef..39a2c35c3f1 100644 --- a/deploy/kubernetes/auditbeat/auditbeat-daemonset.yaml +++ b/deploy/kubernetes/auditbeat/auditbeat-daemonset.yaml @@ -22,7 +22,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: auditbeat - image: docker.elastic.co/beats/auditbeat:%VERSION% + image: docker.elastic.co/beats/auditbeat%IMAGE_MODIFIER%:%VERSION% args: [ "-c", "/etc/auditbeat.yml", "-e", diff --git a/deploy/kubernetes/filebeat-kubernetes.yaml b/deploy/kubernetes/filebeat-kubernetes.yaml index e272abe9893..f028322c1ac 100644 --- a/deploy/kubernetes/filebeat-kubernetes.yaml +++ b/deploy/kubernetes/filebeat-kubernetes.yaml @@ -183,7 +183,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: filebeat - image: docker.elastic.co/beats/filebeat:9.0.0 + image: docker.elastic.co/beats/filebeat-wolfi:9.0.0 args: [ "-c", "/etc/filebeat.yml", "-e", diff --git a/deploy/kubernetes/filebeat/filebeat-daemonset.yaml b/deploy/kubernetes/filebeat/filebeat-daemonset.yaml index b6df8f31fdb..c027abede2a 100644 --- a/deploy/kubernetes/filebeat/filebeat-daemonset.yaml +++ b/deploy/kubernetes/filebeat/filebeat-daemonset.yaml @@ -20,7 +20,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: filebeat - image: docker.elastic.co/beats/filebeat:%VERSION% + image: docker.elastic.co/beats/filebeat%IMAGE_MODIFIER%:%VERSION% args: [ "-c", "/etc/filebeat.yml", "-e", diff --git a/deploy/kubernetes/heartbeat-kubernetes.yaml b/deploy/kubernetes/heartbeat-kubernetes.yaml index 90c5ca7a3cc..280c243d305 100644 --- a/deploy/kubernetes/heartbeat-kubernetes.yaml +++ b/deploy/kubernetes/heartbeat-kubernetes.yaml @@ -171,7 +171,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: heartbeat - image: docker.elastic.co/beats/heartbeat:9.0.0 + image: docker.elastic.co/beats/heartbeat-wolfi:9.0.0 args: [ "-c", "/etc/heartbeat.yml", "-e", diff --git a/deploy/kubernetes/heartbeat/heartbeat-deployment.yaml b/deploy/kubernetes/heartbeat/heartbeat-deployment.yaml index 3f1a73d3324..ec95e50ee53 100644 --- a/deploy/kubernetes/heartbeat/heartbeat-deployment.yaml +++ b/deploy/kubernetes/heartbeat/heartbeat-deployment.yaml @@ -20,7 +20,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: heartbeat - image: docker.elastic.co/beats/heartbeat:%VERSION% + image: docker.elastic.co/beats/heartbeat%IMAGE_MODIFIER%:%VERSION% args: [ "-c", "/etc/heartbeat.yml", "-e", diff --git a/deploy/kubernetes/metricbeat-kubernetes.yaml b/deploy/kubernetes/metricbeat-kubernetes.yaml index 8fb3e5e087d..418c902bffc 100644 --- a/deploy/kubernetes/metricbeat-kubernetes.yaml +++ b/deploy/kubernetes/metricbeat-kubernetes.yaml @@ -291,7 +291,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: metricbeat - image: docker.elastic.co/beats/metricbeat:9.0.0 + image: docker.elastic.co/beats/metricbeat-wolfi:9.0.0 args: [ "-c", "/etc/metricbeat.yml", "-e", diff --git a/deploy/kubernetes/metricbeat/metricbeat-daemonset.yaml b/deploy/kubernetes/metricbeat/metricbeat-daemonset.yaml index c4004d91e28..e8c0074be6d 100644 --- a/deploy/kubernetes/metricbeat/metricbeat-daemonset.yaml +++ b/deploy/kubernetes/metricbeat/metricbeat-daemonset.yaml @@ -21,7 +21,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: metricbeat - image: docker.elastic.co/beats/metricbeat:%VERSION% + image: docker.elastic.co/beats/metricbeat%IMAGE_MODIFIER%:%VERSION% args: [ "-c", "/etc/metricbeat.yml", "-e",