Skip to content

Commit

Permalink
Merge pull request #4 from csatib02/feat/add-e2e-tests
Browse files Browse the repository at this point in the history
feat(e2e): add e2e tests
  • Loading branch information
csatib02 authored Sep 3, 2024
2 parents 205627c + 6a06a0e commit b4cd037
Show file tree
Hide file tree
Showing 23 changed files with 531 additions and 140 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ on:
required: true
default: false
type: boolean

outputs:
container-image-tag:
description: Container image tag
value: ${{ jobs.container-image.outputs.tag }}
jobs:
container-image:
name: Container-Image
runs-on: ubuntu-latest

outputs:
tag: ${{ steps.meta.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -29,8 +35,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest = false
flavor: latest = false
tags: |
type=ref,event=branch
type=ref,event=pr,prefix=pr-
Expand All @@ -50,30 +55,30 @@ jobs:
if: ${{ inputs.publish == false }}
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=oci,dest=image.tar
outputs: type=docker,dest=image.tar

- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
if: ${{ inputs.publish == true }}
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: linux/amd64, linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image, push=true
outputs: type=image,push=true

- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: Kube-Pod-Autocomplete image
name: Kube-Pod-Autocomplete Image
path: image.tar

binary:
Expand Down Expand Up @@ -110,7 +115,7 @@ jobs:
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: Kube-Pod-Autocomplete-Binary
name: Kube-Pod-Autocomplete Binary
path: build/dist/*

helm-chart:
Expand All @@ -122,9 +127,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.15.4
uses: azure/[email protected]

- name: Helm lint
run: make lint-helm
Expand All @@ -136,5 +139,5 @@ jobs:
- name: Upload Helm chart artifact
uses: actions/upload-artifact@v4
with:
name: Kube-Pod-Autocomplete-Helm-Chart
name: Kube-Pod-Autocomplete Helm-Chart
path: build/*.tgz
40 changes: 31 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,22 @@ jobs:
with:
version: latest

artifacts:
name: Artifacts
uses: ./.github/workflows/artifacts.yaml
with:
publish: false
permissions:
contents: read
packages: write

e2e-test:
name: E2E Test
runs-on: ubuntu-latest
needs: artifacts
strategy:
matrix:
KIND_K8S_VERSION: ["v1.28.9", "v1.29.4", "v1.30.0"]

steps:
- name: Checkout repository
Expand All @@ -69,14 +82,23 @@ jobs:
with:
go-version-file: '.go-version'

- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: Kube-Pod-Autocomplete Image

- name: Download Helm chart
uses: actions/download-artifact@v4
with:
name: Kube-Pod-Autocomplete Helm-Chart

- name: Install Kubectl
run: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

- name: Run E2E tests
run: make test-e2e

artifacts:
name: Artifacts
uses: ./.github/workflows/artifacts.yaml
with:
publish: false
permissions:
contents: read
packages: write
env:
KIND_K8S_VERSION: ${{ matrix.KIND_K8S_VERSION }}
LOAD_IMAGE_ARCHIVE: ${{ github.workspace }}/image.tar
VERSION: ${{ needs.artifacts.outputs.container-image-tag }}
HELM_CHART: ${{ github.workspace }}/kube-pod-autocomplete-0.0.0.tgz
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export PATH := $(abspath bin/):${PATH}

CONTAINER_IMAGE_REF = ghcr.io/csatib02/kube-pod-autocomplete:dev

##@ General

# Targets commented with ## will be visible in "make help" info.
Expand Down Expand Up @@ -29,7 +31,7 @@ deploy: ## Deploy kube-pod-autocomplete to the development environment
deploy-testdata: ## Deploy testdata to the development environment
kubectl create ns staging
kubectl create ns prod
kubectl apply -f test/testdata/
kubectl apply -f e2e/test/

##@ Build

Expand All @@ -42,23 +44,23 @@ build: ## Build binary
artifacts: container-image helm-chart binary-snapshot
artifacts: ## Build artifacts

.PHONY: container-image
container-image: ## Build container image
docker build -t ${CONTAINER_IMAGE_REF} .

.PHONY: helm-chart
helm-chart: ## Build Helm chart
@mkdir -p build
$(HELM_BIN) package -d build/ deploy/charts/kube-pod-autocomplete

.PHONY: container-image
container-image: ## Build container image
docker build .

.PHONY: binary-snapshot
binary-snapshot: ## Build binary snapshot
VERSION=v${GORELEASER_VERSION} ${GORELEASER_BIN} release --clean --skip=publish --snapshot

##@ Checks

.PHONY: check
check: test lint-go ## Run tests and lint check
check: test lint ## Run tests and lint check

.PHONY: test
test: ## Run tests
Expand All @@ -68,8 +70,12 @@ test: ## Run tests
test-e2e: ## Run end-to-end tests
go test -race -v -timeout 900s -tags e2e ./e2e/

.PHONY: test-e2e-local
test-e2e-local: container-image ## Run e2e tests locally
LOAD_IMAGE=${CONTAINER_IMAGE_REF} VERSION=dev ${MAKE} test-e2e

.PHONY: lint
list: lint-go lint-helm ## Run linters
lint: lint-go lint-helm ## Run linters

.PHONY: lint-go
lint-go:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

## TODO

- Add e2e-tests.
- Consider adding garden config to simplify testing.

- Add search pods by label/ns/phase endpoint as a possible use-case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
serviceAccountName: {{ .Values.serviceAccount.name }}
containers:
- name: {{ .Values.name }}
image: {{ .Values.image }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- containerPort: {{ .Values.containerPort }}
resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.ingress.enabled }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.ingress.name }}
namespace: {{ .Values.Namespace }}
spec:
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: {{ .Values.service.name }}
port:
number: {{ .Values.service.externalPort }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.name }}
name: {{ .Values.service.name }}
namespace: {{ .Values.namespace }}
spec:
selector:
app.kubernetes.io/name: {{ .Values.name }}
type: {{ .Values.service.type }}
ports:
- protocol: TCP
port: {{ .Values.servicePort }}
port: {{ .Values.service.servicePort }}
targetPort: {{ .Values.containerPort }}
externalPort: {{ .Values.service.externalPort }}
19 changes: 16 additions & 3 deletions deploy/charts/kube-pod-autocomplete/values.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
# Namespace where the application will be deployed
namespace: kube-pod-autocomplete

# General settings for the service
# General settings for the application
name: kube-pod-autocomplete
replicas: 1
image: csatib02/kube-pod-autocomplete:v0.1.0
containerPort: 8080
servicePort: 8080

# image
image:
repository: ghcr.io/csatib02/kube-pod-autocomplete
tag: ""
pullPolicy: IfNotPresent

# Service settings
service:
name: kube-pod-autocomplete-service
type: ClusterIP
servicePort: 8080
externalPort: 8080

# Service Account settings
serviceAccount:
name: kube-pod-autocomplete-sa

# Ingress settings
ingress:
enabled: false
name: kube-pod-autocomplete-ingress
host: ""

# RBAC settings
rbac:
clusterRoleName: kube-pod-autocomplete-clusterrole
Expand Down
13 changes: 7 additions & 6 deletions docs/docs.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Kube Pod Autocomplete documentation

Kube Pod Autocomplete is a service designed to enhance the user experience when navigating resource lists in Kubernetes clusters. It can retrieve specific data based on the requested resource type and supported filters.
Kube Pod Autocomplete is a service designed to enhance the user experience when navigating resource lists in Kubernetes clusters. It retrieves specific data based on the requested resource type and supported filters.

## Supported resources

| **Resource** | available Filters |
| **Resource** | Available Filters |
|------------------|---------------------------------------|
| pods ✅ | namespace, phase, labels, annotations |
| services 🟡 | _Next up_ |
| services 🟡 | _Coming Soon_ |

## API-Spec

Checkout the [openapi](openapi.yaml) file, or use the [swagger spec](swagger.html).
Checkout the [OpenAPI](openapi.yaml) file or use the [Swagger spec](swagger.html).

## Quick-start

Expand Down Expand Up @@ -47,5 +47,6 @@ curl -X GET http://localhost:8080/search/autocomplete/pods

## Future improvements

- [ ] Add support for caching. (Based on tests with the current implementation with small amount of pods, the response speed is blazingly fast, but there can be problems in production environments.)
- [ ] Generate API specification from OpenAPI spec. (The current implementation is a really simple POC, if the project is later expanded with additional endpoints code generation should be utilised.)
- [ ] Add support for `caching`. (While the current implementation is fast with a small number of pods, but there can be problems in production environments.)
- [ ] `Generate` API specification from `OpenAPI spec`. (The current solution is a really simple POC, if the project is later expanded with additional endpoints code generation from the OpenAPI spec should be utilised.)
- [ ] `Improve End-to-End` Tests: (The existing end-to-end test setup is quite basic, using `cmd.Exec()` and port-forward to access the service is rather limited. Future improvements could include using an ingress controller like NGINX for more robust testing.)
28 changes: 28 additions & 0 deletions e2e/deploy/kube-pod-autocomplete/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace: kube-pod-autocomplete

name: kube-pod-autocomplete
replicas: 1
containerPort: 8080

service:
name: kube-pod-autocomplete-service
type: ClusterIP
servicePort: 8080
externalPort: 8080

serviceAccount:
name: kube-pod-autocomplete-sa

ingress:
enabled: false

rbac:
clusterRoleName: kube-pod-autocomplete-clusterrole
resourceTypes:
- "pods"
clusterRoleBindingName: kube-pod-autocomplete-clusterrolebinding

resources:
limits:
cpu: "1"
memory: "512Mi"
2 changes: 2 additions & 0 deletions e2e/kind.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
Loading

0 comments on commit b4cd037

Please sign in to comment.