Skip to content

Commit

Permalink
Initial scaffolding for standalone pgAdmin implementation
Browse files Browse the repository at this point in the history
Includes basic implementation for CRD, installation, and a dummy
reconciliation loop. Reconciliation is feature-gated.
  • Loading branch information
tjmoore4 committed Sep 28, 2023
1 parent a90d107 commit 1b56723
Show file tree
Hide file tree
Showing 19 changed files with 2,845 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,14 @@ generate-crd: ## Generate crd
paths='./pkg/apis/...' \
output:dir='build/crd/pgupgrades/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml
@
GOBIN='$(CURDIR)/hack/tools' ./hack/controller-generator.sh \
crd:crdVersions='v1' \
paths='./pkg/apis/...' \
output:dir='build/crd/pgadmins/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml
@
kubectl kustomize ./build/crd/postgresclusters > ./config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml
kubectl kustomize ./build/crd/pgupgrades > ./config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml
kubectl kustomize ./build/crd/pgadmins > ./config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

.PHONY: generate-crd-docs
generate-crd-docs: ## Generate crd-docs
Expand Down
3 changes: 2 additions & 1 deletion build/crd/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/postgresclusters/generated/
/pgupgrades/generated/
/pgupgrades/generated/
/pgadmins/generated/
37 changes: 37 additions & 0 deletions build/crd/pgadmins/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- generated/postgres-operator.crunchydata.com_pgadmins.yaml

patches:
# Remove the zero status field included by controller-gen@v0.8.0. These zero
# values conflict with the CRD controller in Kubernetes before v1.22.
# - https://github.com/kubernetes-sigs/controller-tools/pull/630
# - https://pr.k8s.io/100970
- target:
group: apiextensions.k8s.io
version: v1
kind: CustomResourceDefinition
name: pgadmins.postgres-operator.crunchydata.com
patch: |-
- op: remove
path: /status
- target:
group: apiextensions.k8s.io
version: v1
kind: CustomResourceDefinition
name: pgadmins.postgres-operator.crunchydata.com
path: todos.yaml
- target:
group: apiextensions.k8s.io
version: v1
kind: CustomResourceDefinition
name: pgadmins.postgres-operator.crunchydata.com
# The version below should match the version on the PostgresCluster CRD
patch: |-
- op: add
path: "/metadata/labels"
value:
app.kubernetes.io/name: pgo
app.kubernetes.io/version: latest
8 changes: 8 additions & 0 deletions build/crd/pgadmins/todos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- op: add
path: /work
value: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
- op: copy
from: /work
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/imagePullSecrets/items/properties/name/description
- op: remove
path: /work
14 changes: 14 additions & 0 deletions cmd/postgres-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/crunchydata/postgres-operator/internal/controller/pgupgrade"
"github.com/crunchydata/postgres-operator/internal/controller/postgrescluster"
"github.com/crunchydata/postgres-operator/internal/controller/runtime"
"github.com/crunchydata/postgres-operator/internal/controller/standalone_pgadmin"
"github.com/crunchydata/postgres-operator/internal/logging"
"github.com/crunchydata/postgres-operator/internal/upgradecheck"
"github.com/crunchydata/postgres-operator/internal/util"
Expand Down Expand Up @@ -149,6 +150,19 @@ func addControllersToManager(mgr manager.Manager, openshift bool, log logr.Logge
log.Error(err, "unable to create PGUpgrade controller")
os.Exit(1)
}

if util.DefaultMutableFeatureGate.Enabled(util.StandalonePGAdmin) {
pgAdminReconciler := &standalone_pgadmin.PGAdminReconciler{
Client: mgr.GetClient(),
Owner: "pgadmin-controller",
Scheme: mgr.GetScheme(),
}

if err := pgAdminReconciler.SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create PGAdmin controller")
os.Exit(1)
}
}
}

func isOpenshift(cfg *rest.Config) bool {
Expand Down
972 changes: 972 additions & 0 deletions config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ kind: Kustomization
resources:
- bases/postgres-operator.crunchydata.com_postgresclusters.yaml
- bases/postgres-operator.crunchydata.com_pgupgrades.yaml
- bases/postgres-operator.crunchydata.com_pgadmins.yaml
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ spec:
value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:latest"
- name: RELATED_IMAGE_PGUPGRADE
value: "registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:latest"
- name: RELATED_IMAGE_STANDALONE_PGADMIN
value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi8-4.30-17"
securityContext:
allowPrivilegeEscalation: false
capabilities: { drop: [ALL] }
Expand Down
24 changes: 23 additions & 1 deletion config/rbac/cluster/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,40 @@ rules:
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgupgrades
- pgadmins
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgadmins/finalizers
- pgupgrades/finalizers
- postgresclusters/finalizers
verbs:
- update
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgadmins/status
verbs:
- get
- patch
- update
- watch
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgupgrades
verbs:
- get
- list
- watch
- apiGroups:
- postgres-operator.crunchydata.com
resources:
Expand Down
24 changes: 23 additions & 1 deletion config/rbac/namespace/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,40 @@ rules:
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgupgrades
- pgadmins
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgadmins/finalizers
- pgupgrades/finalizers
- postgresclusters/finalizers
verbs:
- update
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgadmins/status
verbs:
- get
- patch
- update
- watch
- apiGroups:
- postgres-operator.crunchydata.com
resources:
- pgupgrades
verbs:
- get
- list
- watch
- apiGroups:
- postgres-operator.crunchydata.com
resources:
Expand Down
Loading

0 comments on commit 1b56723

Please sign in to comment.