Skip to content

Commit

Permalink
operator: add kuttl test for decommission
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Jun 6, 2022
1 parent a44f36e commit 9052ac1
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/go/k8s/tests/e2e/decommission/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: redpanda.vectorized.io/v1alpha1
kind: Cluster
metadata:
name: decommissioning
status:
replicas: 3
---

apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=redpanda
tail: -1
- type: pod
namespace: redpanda-system
selector: control-plane=controller-manager
tail: -1
- type: command
command: kubectl get clusters -o jsonpath={@} -n $NAMESPACE
- type: command
command: kubectl get pods -o jsonpath={@} -n $NAMESPACE
25 changes: 25 additions & 0 deletions src/go/k8s/tests/e2e/decommission/00-redpanda-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: redpanda.vectorized.io/v1alpha1
kind: Cluster
metadata:
name: decommissioning
spec:
image: "localhost/redpanda"
version: "dev"
replicas: 3
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 1
memory: 500Mi
configuration:
rpcServer:
port: 33145
kafkaApi:
- port: 9092
adminApi:
- port: 9644
pandaproxyApi:
- port: 8082
developerMode: true
29 changes: 29 additions & 0 deletions src/go/k8s/tests/e2e/decommission/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Pod
metadata:
labels:
job-name: wait-for-3-brokers
status:
containerStatuses:
- name: curl
state:
terminated:
message: |
3
phase: Succeeded
---

apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=redpanda
tail: -1
- type: pod
namespace: redpanda-system
selector: control-plane=controller-manager
tail: -1
- type: command
command: kubectl get clusters -o jsonpath={@} -n $NAMESPACE
- type: command
command: kubectl get pods -o jsonpath={@} -n $NAMESPACE
30 changes: 30 additions & 0 deletions src/go/k8s/tests/e2e/decommission/01-probe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: batch/v1
kind: Job
metadata:
name: wait-for-3-brokers
spec:
backoffLimit: 10
template:
spec:
activeDeadlineSeconds: 90
containers:
- name: curl
image: curlimages/curl:latest
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
command:
- /bin/sh
- -c
- -ex
args:
- >
url=http://decommissioning-0.decommissioning.$NAMESPACE.svc.cluster.local:9644/v1/brokers
res=$(curl --silent -L $url | tr '{' '\n' | grep node_id | wc -l) &&
echo $res > /dev/termination-log &&
if [[ "$res" != "3" ]]; then
exit 1;
fi
restartPolicy: Never
22 changes: 22 additions & 0 deletions src/go/k8s/tests/e2e/decommission/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: redpanda.vectorized.io/v1alpha1
kind: Cluster
metadata:
name: decommissioning
status:
replicas: 2
---

apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=redpanda
tail: -1
- type: pod
namespace: redpanda-system
selector: control-plane=controller-manager
tail: -1
- type: command
command: kubectl get clusters -o jsonpath={@} -n $NAMESPACE
- type: command
command: kubectl get pods -o jsonpath={@} -n $NAMESPACE
6 changes: 6 additions & 0 deletions src/go/k8s/tests/e2e/decommission/02-redpanda-downscale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: redpanda.vectorized.io/v1alpha1
kind: Cluster
metadata:
name: decommissioning
spec:
replicas: 2
29 changes: 29 additions & 0 deletions src/go/k8s/tests/e2e/decommission/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Pod
metadata:
labels:
job-name: wait-for-2-brokers
status:
containerStatuses:
- name: curl
state:
terminated:
message: |
2
phase: Succeeded
---

apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=redpanda
tail: -1
- type: pod
namespace: redpanda-system
selector: control-plane=controller-manager
tail: -1
- type: command
command: kubectl get clusters -o jsonpath={@} -n $NAMESPACE
- type: command
command: kubectl get pods -o jsonpath={@} -n $NAMESPACE
30 changes: 30 additions & 0 deletions src/go/k8s/tests/e2e/decommission/03-probe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: batch/v1
kind: Job
metadata:
name: wait-for-2-brokers
spec:
backoffLimit: 10
template:
spec:
activeDeadlineSeconds: 90
containers:
- name: curl
image: curlimages/curl:latest
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
command:
- /bin/sh
- -c
- -ex
args:
- >
url=http://decommissioning-0.decommissioning.$NAMESPACE.svc.cluster.local:9644/v1/brokers
res=$(curl --silent -L $url | tr '{' '\n' | grep node_id | wc -l) &&
echo $res > /dev/termination-log &&
if [[ "$res" != "2" ]]; then
exit 1;
fi
restartPolicy: Never

0 comments on commit 9052ac1

Please sign in to comment.