Skip to content

Commit

Permalink
Add e2e tests (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao authored Aug 4, 2022
1 parent 0bd2278 commit 8f4b6ba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## About

Memcache server discovery based on Kubernetes endpoints for [Go memcache client](https://github.com/bradfitz/gomemcache).
Memcache server discovery based on Kubernetes endpoints for [Go memcache client](https://github.com/bradfitz/gomemcache)

How it works:
* Watches endpoints containing memcache pod ips using [tiny k8s client](https://github.com/castai/k8s-client-go)
Expand All @@ -10,8 +10,8 @@ How it works:

In dynamic environments like Kubernetes both clients (pods calling memcache) and memcache pods could change.
There are few issues:
1. Calling memcache using clusterIP service is quite useless (unless you have one replica) as kernel will perform round robbin across service endpoints.
2. You can make clusterIP service better by adding sessionAffinity. This will ensure that client pod always goes to the same memcache instance. But what happens if pods are redeployed?
1. Calling memcache using clusterIP service is quite useless (unless you have one replica) as kernel will perform round-robin across service endpoints.
2. You can enable sessionAffinity. This will ensure that client pod always goes to the same memcache instance. But what happens if pods are redeployed?
3. Using StatefulSet with headless services and passing each endpoint is kind of static too.

## Installing
Expand Down Expand Up @@ -62,7 +62,7 @@ metadata:
name: endpoints-watcher
rules:
- apiGroups: [ "" ]
resources: [ "pods" ]
resources: [ "endpoints" ]
verbs: [ "get", "watch" ]
---
kind: RoleBinding
Expand Down
6 changes: 4 additions & 2 deletions e2e/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: e2e
namespace: e2e
rules:
- apiGroups: [ "" ]
resources: [ "pods" ]
resources: [ "endpoints" ]
verbs: [ "get", "watch" ]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: e2e
namespace: e2e
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand All @@ -40,6 +42,6 @@ spec:
serviceAccount: e2e
containers:
- name: e2e
image: replace-img
image: ghcr.io/castai/k8s-memcache-selector/e2e:08c1a77b1161295ac24a83d6f0c558560374b7da
restartPolicy: Never
backoffLimit: 0
9 changes: 0 additions & 9 deletions e2e/memcache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ spec:
labels:
app.kubernetes.io/name: memcache
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/name: memcache
topologyKey: kubernetes.io/hostname
weight: 1
securityContext:
fsGroup: 1001
containers:
Expand Down
4 changes: 4 additions & 0 deletions e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ kubectl wait pods -l app.kubernetes.io/name=memcache --for condition=Ready --tim

kubectl apply -f e2e.yaml --dry-run=client -oyaml | sed "s/replace-img/$(echo "$img" | sed 's/\//\\\//g')/" | kubectl apply -f - -n e2e
kubectl wait job/e2e --for=condition=complete --timeout=15s -n e2e

echo "Test completed"
echo "Logs:"
kubectl logs -l app=e2e -n e2e

0 comments on commit 8f4b6ba

Please sign in to comment.