Skip to content

Commit

Permalink
statefulset: Use stateful sets for posgres deployments (PROJQUAY-6672)
Browse files Browse the repository at this point in the history
- Swap Postgres and Clair Postgres Deployments to StatefulSets
  • Loading branch information
jonathankingfc committed Jun 5, 2024
1 parent 62884a1 commit 5791b5f
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 22 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,5 @@ jobs:
uses: actions/checkout@v3
- name: OS Dependencies
run: apt-get update && apt-get install -y tar make gcc
- name: Install Kubebuilder
run: |
os=$(go env GOOS)
arch=$(go env GOARCH)
curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_${os}_${arch}.tar.gz | tar -xz -C /tmp/
mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder
export PATH=$PATH:/usr/local/kubebuilder/bin
- name: Tests
run: go test -v ./...
run: make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all: manager

# Run tests
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./... -coverprofile cover.out

test-e2e:
mkdir -p ./bin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: clair-postgres
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ resources:
- ./clair-pg-old.persistentvolumeclaim.yaml
- ./clair-pg-old.deployment.yaml
patchesStrategicMerge:
- ./clair-pg.deployment.patch.yaml
- ./clair-pg.statefulset.patch.yaml
4 changes: 2 additions & 2 deletions kustomize/components/clairpostgres/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Clair component adds Clair v4 security scanner and its database.
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
resources:
- ./postgres.serviceaccount.yaml
- ./postgres.persistentvolumeclaim.yaml
- ./postgres.deployment.yaml
- ./postgres.statefulset.yaml
- ./postgres.service.yaml
- ./clair-postgres-conf-sample.configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: clair-postgres
labels:
quay-component: clair-postgres
annotations:
quay-component: clair-postgres
spec:
serviceName: clair-postgres
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
quay-component: clair-postgres
Expand Down Expand Up @@ -57,3 +56,4 @@ spec:
requests:
cpu: 500m
memory: 2Gi
volumeClaimTemplates: []
2 changes: 1 addition & 1 deletion kustomize/components/pgupgrade/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ resources:
- ./quay-pg-old.deployment.yaml
patchesStrategicMerge:
- ./quay.deployment.patch.yaml
- ./quay-pg.deployment.patch.yaml
- ./quay-pg.statefulset.patch.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: quay-database
spec:
Expand Down
2 changes: 1 addition & 1 deletion kustomize/components/postgres/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Component
resources:
- ./postgres.serviceaccount.yaml
- ./postgres.persistentvolumeclaim.yaml
- ./postgres.deployment.yaml
- ./postgres.statefulset.yaml
- ./postgres.service.yaml
- ./postgres-conf-sample.configmap.yaml
secretGenerator:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: quay-database
labels:
quay-component: postgres
annotations:
quay-component: postgres
spec:
serviceName: quay-database
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
quay-component: postgres
Expand Down Expand Up @@ -76,3 +75,4 @@ spec:
requests:
cpu: 500m
memory: 2Gi
volumeClaimTemplates: []
2 changes: 2 additions & 0 deletions pkg/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ func ModelFor(gvk schema.GroupVersionKind) client.Object {
return &prometheusv1.ServiceMonitor{}
case schema.GroupVersionKind{Group: "monitoring.coreos.com", Version: "v1", Kind: "PrometheusRule"}.String():
return &prometheusv1.PrometheusRule{}
case schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}.String():
return &apps.StatefulSet{}
default:
panic(fmt.Sprintf("Missing model for GVK %s", gvk.String()))
}
Expand Down

0 comments on commit 5791b5f

Please sign in to comment.