Skip to content

Commit

Permalink
Remove admin as user-settable field (#3742)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminjb authored Oct 12, 2023
1 parent 33e497b commit beac752
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ spec:
spec:
description: PGAdminSpec defines the desired state of PGAdmin
properties:
adminUsername:
description: AdminUsername is the username to set during pgAdmin startup.
pgAdmin requires this to have a valid email form in order to log
in. Once set, this cannot be changed.
type: string
affinity:
description: 'Scheduling constraints of the PGAdmin pod. More info:
https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node'
Expand Down
5 changes: 0 additions & 5 deletions docs/content/references/crd.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/controller/standalone_pgadmin/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func pod(
Env: []corev1.EnvVar{
{
Name: "PGADMIN_SETUP_EMAIL",
Value: inPGAdmin.Spec.AdminUsername,
Value: fmt.Sprintf("admin@%s.%s.svc", inPGAdmin.Name, inPGAdmin.Namespace),
},
{
Name: "PGADMIN_SETUP_PASSWORD",
Expand Down Expand Up @@ -199,7 +199,7 @@ func startupScript(pgadmin *v1beta1.PGAdmin) []string {
var loadServerCommand = fmt.Sprintf(`python3 ${PGADMIN_DIR}/setup.py --load-servers %s/~postgres-operator/%s --user %s --replace`,
configMountPath,
settingsClusterMapKey,
pgadmin.Spec.AdminUsername)
fmt.Sprintf("admin@%s.%s.svc", pgadmin.Name, pgadmin.Namespace))

// This script sets up, starts pgadmin, and runs the `loadServerCommand` to register the discovered servers.
var startScript = fmt.Sprintf(`
Expand Down
39 changes: 19 additions & 20 deletions internal/controller/standalone_pgadmin/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestPod(t *testing.T) {

pgadmin := new(v1beta1.PGAdmin)
pgadmin.Name = "pgadmin"
pgadmin.Spec.AdminUsername = "admin@pgo.com"
pgadmin.Namespace = "postgres-operator"
config := new(corev1.ConfigMap)
testpod := new(corev1.PodSpec)
pvc := new(corev1.PersistentVolumeClaim)
Expand All @@ -53,19 +53,19 @@ containers:
\"Running pgAdmin4 Setup\"\npython3 ${PGADMIN_DIR}/setup.py\n\necho \"Starting
pgAdmin4\"\nPGADMIN4_PIDFILE=/tmp/pgadmin4.pid\npgadmin4 &\necho $! > $PGADMIN4_PIDFILE\n\npython3
${PGADMIN_DIR}/setup.py --load-servers /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
--user admin@pgo.com --replace\n\nexec {fd}<> <(:)\nwhile read -r -t 5 -u \"${fd}\"
|| true; do\n\tif [ \"${cluster_file}\" -nt \"/proc/self/fd/${fd}\" ] && python3
${PGADMIN_DIR}/setup.py --load-servers /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
--user admin@pgo.com --replace\n\tthen\n\t\texec {fd}>&- && exec {fd}<> <(:)\n\t\tstat
--format='Loaded shared servers dated %y' \"${cluster_file}\"\n\tfi\n\tif [ !
-d /proc/$(cat $PGADMIN4_PIDFILE) ]\n\tthen\n\t\tpgadmin4 &\n\t\techo $! > $PGADMIN4_PIDFILE\n\t\techo
\"Restarting pgAdmin4\"\n\tfi\ndone\n}; export cluster_file=\"$1\"; export -f
monitor; exec -a \"$0\" bash -ceu monitor"
--user admin@pgadmin.postgres-operator.svc --replace\n\nexec {fd}<> <(:)\nwhile
read -r -t 5 -u \"${fd}\" || true; do\n\tif [ \"${cluster_file}\" -nt \"/proc/self/fd/${fd}\"
] && python3 ${PGADMIN_DIR}/setup.py --load-servers /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
--user admin@pgadmin.postgres-operator.svc --replace\n\tthen\n\t\texec {fd}>&-
&& exec {fd}<> <(:)\n\t\tstat --format='Loaded shared servers dated %y' \"${cluster_file}\"\n\tfi\n\tif
[ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]\n\tthen\n\t\tpgadmin4 &\n\t\techo $! >
$PGADMIN4_PIDFILE\n\t\techo \"Restarting pgAdmin4\"\n\tfi\ndone\n}; export cluster_file=\"$1\";
export -f monitor; exec -a \"$0\" bash -ceu monitor"
- pgadmin
- /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
env:
- name: PGADMIN_SETUP_EMAIL
value: admin@pgo.com
value: admin@pgadmin.postgres-operator.svc
- name: PGADMIN_SETUP_PASSWORD
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -134,7 +134,6 @@ volumes:
pgadmin.Spec.Resources.Requests = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
}
pgadmin.Spec.AdminUsername = "admin@pgo.com"

call()

Expand All @@ -148,19 +147,19 @@ containers:
\"Running pgAdmin4 Setup\"\npython3 ${PGADMIN_DIR}/setup.py\n\necho \"Starting
pgAdmin4\"\nPGADMIN4_PIDFILE=/tmp/pgadmin4.pid\npgadmin4 &\necho $! > $PGADMIN4_PIDFILE\n\npython3
${PGADMIN_DIR}/setup.py --load-servers /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
--user admin@pgo.com --replace\n\nexec {fd}<> <(:)\nwhile read -r -t 5 -u \"${fd}\"
|| true; do\n\tif [ \"${cluster_file}\" -nt \"/proc/self/fd/${fd}\" ] && python3
${PGADMIN_DIR}/setup.py --load-servers /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
--user admin@pgo.com --replace\n\tthen\n\t\texec {fd}>&- && exec {fd}<> <(:)\n\t\tstat
--format='Loaded shared servers dated %y' \"${cluster_file}\"\n\tfi\n\tif [ !
-d /proc/$(cat $PGADMIN4_PIDFILE) ]\n\tthen\n\t\tpgadmin4 &\n\t\techo $! > $PGADMIN4_PIDFILE\n\t\techo
\"Restarting pgAdmin4\"\n\tfi\ndone\n}; export cluster_file=\"$1\"; export -f
monitor; exec -a \"$0\" bash -ceu monitor"
--user admin@pgadmin.postgres-operator.svc --replace\n\nexec {fd}<> <(:)\nwhile
read -r -t 5 -u \"${fd}\" || true; do\n\tif [ \"${cluster_file}\" -nt \"/proc/self/fd/${fd}\"
] && python3 ${PGADMIN_DIR}/setup.py --load-servers /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
--user admin@pgadmin.postgres-operator.svc --replace\n\tthen\n\t\texec {fd}>&-
&& exec {fd}<> <(:)\n\t\tstat --format='Loaded shared servers dated %y' \"${cluster_file}\"\n\tfi\n\tif
[ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]\n\tthen\n\t\tpgadmin4 &\n\t\techo $! >
$PGADMIN4_PIDFILE\n\t\techo \"Restarting pgAdmin4\"\n\tfi\ndone\n}; export cluster_file=\"$1\";
export -f monitor; exec -a \"$0\" bash -ceu monitor"
- pgadmin
- /etc/pgadmin/conf.d/~postgres-operator/pgadmin-shared-clusters.json
env:
- name: PGADMIN_SETUP_EMAIL
value: admin@pgo.com
value: admin@pgadmin.postgres-operator.svc
- name: PGADMIN_SETUP_PASSWORD
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ type PGAdminSpec struct {
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// AdminUsername is the username to set during pgAdmin startup.
// pgAdmin requires this to have a valid email form in order to log in.
// Once set, this cannot be changed.
// +optional
AdminUsername string `json:"adminUsername"`

// ServerGroups for importing PostgresClusters to pgAdmin.
// To create a pgAdmin with no selectors, leave this field empty.
// A pgAdmin created with no `ServerGroups` will not automatically
Expand All @@ -113,13 +107,6 @@ type PGAdminSpec struct {
ServerGroups []ServerGroup `json:"serverGroups"`
}

// Default defines several key default values for a pgAdmin instance.
func (s *PGAdminSpec) Default() {
if s.AdminUsername == "" {
s.AdminUsername = "admin@pgo.com"
}
}

type ServerGroup struct {
// The name for the ServerGroup in pgAdmin.
// Must be unique in the pgAdmin's ServerGroups since it becomes the ServerGroup name in pgAdmin.
Expand Down Expand Up @@ -170,7 +157,6 @@ func (p *PGAdmin) Default() {
if len(p.Kind) == 0 {
p.Kind = "PGAdmin"
}
p.Spec.Default()
}

//+kubebuilder:object:root=true
Expand Down

0 comments on commit beac752

Please sign in to comment.