Skip to content

Commit

Permalink
feat: add garbage collection (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis committed Jun 28, 2023
1 parent ff99b10 commit 1741970
Show file tree
Hide file tree
Showing 38 changed files with 782 additions and 58 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,18 @@ kind-test: docker-build ## Deploy including test
kustomize build config/base/crd | kubectl --context kind-${CLUSTER} apply -f -
kind load docker-image ${IMG} --name ${CLUSTER}
kubectl -n k8sgrowthbook-system delete pods --all
kustomize build config/tests/cases/${TEST_PROFILE} --enable-helm | kubectl --context kind-${CLUSTER} apply -f -

echo "pre-test"
kustomize build config/tests/cases/${TEST_PROFILE}/pre-test --enable-helm | kubectl --context kind-${CLUSTER} apply -f -
kubectl --context kind-${CLUSTER} -n k8sgrowthbook-system wait --for=condition=Ready pods -l control-plane=controller-manager -l app.kubernetes.io/managed-by!=Helm -l verify!=yes --timeout=3m

echo "test"
kustomize build config/tests/cases/${TEST_PROFILE}/test --enable-helm | kubectl --context kind-${CLUSTER} apply -f -
kubectl --context kind-${CLUSTER} -n k8sgrowthbook-system wait --for=jsonpath='{.status.conditions[1].reason}'=PodCompleted pods -l control-plane=controller-manager -l app.kubernetes.io/managed-by!=Helm -l verify=yes --timeout=3m

echo "post-test"
kustomize build config/tests/cases/${TEST_PROFILE}/test --enable-helm | kubectl --context kind-${CLUSTER} delete -f -
kustomize build config/tests/cases/${TEST_PROFILE}/post-test --enable-helm | kubectl --context kind-${CLUSTER} apply -f -
kubectl --context kind-${CLUSTER} -n k8sgrowthbook-system wait --for=jsonpath='{.status.conditions[1].reason}'=PodCompleted pods -l control-plane=controller-manager -l app.kubernetes.io/managed-by!=Helm -l verify=yes --timeout=3m

##@ Deployment
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/growthbookinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type GrowthbookInstanceSpec struct {
// Interval reconciliation
Interval *metav1.Duration `json:"interval,omitempty"`

// Prune
// +kubebuilder:validation:Required
Prune bool `json:"prune"`

// Timeout while reconciling the instance
// +kubebuilder:default:="5m"
Timeout *metav1.Duration `json:"timeout,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
SynchronizedReason = "Synchronized"
ProgressingReason = "Progressing"
FailedReason = "Failed"
Finalizer = "finalizers.doodle.com"
)

// ConditionalResource is a resource with conditions
Expand Down
2 changes: 1 addition & 1 deletion chart/k8sgrowthbook-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ keywords:
name: k8sgrowthbook-controller
sources:
- https://github.com/DoodleScheduling/k8sgrowthbook-controller
version: 0.1.0
version: 0.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ spec:
description: Address is a MongoDB comptaible URI `mongodb://xxx`
type: string
type: object
prune:
description: Prune
type: boolean
resourceSelector:
description: ResourceSelector defines a selector to select Growthbook
resources associated with this instance
Expand Down Expand Up @@ -124,6 +127,8 @@ spec:
default: 5m
description: Timeout while reconciling the instance
type: string
required:
- prune
type: object
status:
description: GrowthbookInstanceStatus defines the observed state of GrowthbookInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ spec:
description: Address is a MongoDB comptaible URI `mongodb://xxx`
type: string
type: object
prune:
description: Prune
type: boolean
resourceSelector:
description: ResourceSelector defines a selector to select Growthbook
resources associated with this instance
Expand Down Expand Up @@ -124,6 +127,8 @@ spec:
default: 5m
description: Timeout while reconciling the instance
type: string
required:
- prune
type: object
status:
description: GrowthbookInstanceStatus defines the observed state of GrowthbookInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
spec:
interval: 5m
suspend: false
prune: false
mongodb:
uri: mongodb://mongodb.k8sgrowthbook-system:27017/growthbook
rootSecret:
Expand Down
5 changes: 5 additions & 0 deletions config/tests/base/catalog/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- catalog.yaml
8 changes: 0 additions & 8 deletions config/tests/base/kustomization.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- verify-get-features-clienttoken.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../base

images:
- name: growthbook/growthbook
newTag: 2.1.1
- ../../../base/verify-get-features-clienttoken
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../base
- ../../../base/mongodb
- ../../../base/growthbook/backend
- ../../../base/growthbook-controller

images:
- name: growthbook/growthbook
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/catalog
- ../../../base/verify-get-features-clienttoken
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/verify-get-features-clienttoken
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../base
- ../../base/growthbook/proxy
- verify-proxy-get-features-clienttoken.yaml
- ../../../base/mongodb
- ../../../base/growthbook/backend
- ../../../base/growthbook/proxy
- ../../../base/growthbook-controller

images:
- name: growthbook/growthbook
Expand All @@ -26,4 +27,4 @@ patches:
value: "http://growthbook-proxy"
- op: replace
path: /data/PROXY_HOST_PUBLIC
value: "http://growthbook-proxy"
value: "http://growthbook-proxy"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/catalog
- verify-proxy-get-features-clienttoken.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- verify-get-features-clienttoken.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: Pod
metadata:
name: verify-get-features-clienttoken
labels:
verify: yes
spec:
restartPolicy: OnFailure
containers:
- image: curlimages/curl:8.1.2
imagePullPolicy: IfNotPresent
name: verify
command:
- /bin/sh
- "-c"
- |
code=$(curl -s -o /dev/null -I -w "%{http_code}" http://growthbook-api/api/features/sdk-token)
if [ "$code" = "400" ]; then
exit 0
else
exit 1
fi
resources: {}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: false
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/mongodb
- ../../../base/growthbook/backend
- ../../../base/growthbook-controller

images:
- name: growthbook/growthbook
newTag: 2.1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/catalog
- ../../../base/verify-get-features-clienttoken

patches:
- target:
kind: GrowthbookInstance
name: my-instance
patch: |-
- op: replace
path: /spec/prune
value: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/verify-get-features-clienttoken
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/mongodb
- ../../../base/growthbook/backend
- ../../../base/growthbook-controller

images:
- name: growthbook/growthbook
newTag: 2.1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: k8sgrowthbook-system

resources:
- ../../../base/catalog
- ../../../base/verify-get-features-clienttoken

0 comments on commit 1741970

Please sign in to comment.