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 Jul 9, 2024
1 parent 7ccfecd commit 84e5ac2
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 24 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
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -87,7 +87,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v5.2.1
CONTROLLER_TOOLS_VERSION ?= v0.13.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
Expand All @@ -107,7 +107,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20230216140739-c98506dc3b8e

# This target called from the prepare-release github action.
# CHANNEL - operator channel (eg. stable-3.6, candidate-3.9)
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 84e5ac2

Please sign in to comment.