From 73b5fa9d22f54443a9b483a65236a043af439656 Mon Sep 17 00:00:00 2001 From: bakito Date: Thu, 31 Oct 2024 22:47:03 +0100 Subject: [PATCH] start in pod --- .github/workflows/e2e.yaml | 16 +++++++++-- testdata/e2e/job-with-rbac.yaml | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 testdata/e2e/job-with-rbac.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b6b55b6..d964678 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -14,7 +14,7 @@ jobs: strategy: matrix: # https://hub.docker.com/r/kindest/node/tags - k8s_version: [ "v1.28.13", "v1.29.8", "v1.30.4" ] + k8s_version: ["v1.28.13", "v1.29.8", "v1.30.4"] steps: - name: Checkout uses: actions/checkout@v4 @@ -30,9 +30,21 @@ jobs: kubectl_version: ${{ matrix.k8s_version }} - name: Run Exporter from outside the cluster - run: go run . --config config.yaml --progress bar >> $GITHUB_STEP_SUMMARY + run: | + echo "## Run Exporter from outside the cluster" >> $GITHUB_STEP_SUMMARY + go run . --config config.yaml --progress bar >> $GITHUB_STEP_SUMMARY - name: Build the docker image run: | docker build -f Dockerfile --build-arg VERSION=e2e-tests -t localhost:5001/kubexporter:e2e . docker push localhost:5001/kubexporter:e2e + + - name: Run Exporter as k8s Job + run: | + kubectl create ns e2e + kubectl apply -n e2e -f testdata/e2e/job-with-rbac.yaml + kubectl wait --for=condition=complete job/kubexporter -n e2e --timeout=300s + - name: Print k8s logs + run: | + echo "## Run Exporter as k8s Job" >> $GITHUB_STEP_SUMMARY + kubectl logs -n e2e -l e2e=kubexporter >> $GITHUB_STEP_SUMMARY diff --git a/testdata/e2e/job-with-rbac.yaml b/testdata/e2e/job-with-rbac.yaml new file mode 100644 index 0000000..b0a0a1e --- /dev/null +++ b/testdata/e2e/job-with-rbac.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: read-only-sa + namespace: e2e +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cluster-read-only +rules: + - apiGroups: ["*"] + resources: ["*"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: read-only-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-read-only +subjects: + - kind: ServiceAccount + name: read-only-sa + namespace: e2e +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: kubexporter + namespace: e2e +spec: + template: + metadata: + labels: + e2e: kubexporter + spec: + serviceAccountName: read-only-sa + containers: + - name: kubexporter + image: localhost:5001/kubexporter:e2e + args: + - '--progress' + - 'bar' + restartPolicy: Never + backoffLimit: 4 \ No newline at end of file