@@ -85,11 +85,21 @@ func (r *PGAdminReconciler) reconcilePGAdminUsers(ctx context.Context, pgadmin *
8585 if pgadmin .Status .MajorVersion == 0 || pgadmin .Status .MinorVersion == "" ||
8686 pgadmin .Status .ImageSHA != pgAdminImageSha {
8787
88- pgadminMinorVersion , err := r .reconcilePGAdminVersion (ctx , podExecutor )
89- if err != nil {
88+ // exec into the pgAdmin pod and retrieve the pgAdmin minor version
89+ script := fmt .Sprintf (`
90+ PGADMIN_DIR=%s
91+ cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_VERSION)"
92+ ` , pgAdminDir )
93+
94+ var stdin , stdout , stderr bytes.Buffer
95+
96+ if err := podExecutor (ctx , & stdin , & stdout , & stderr ,
97+ []string {"bash" , "-ceu" , "--" , script }... ); err != nil {
9098 return err
9199 }
92100
101+ pgadminMinorVersion := strings .TrimSpace (stdout .String ())
102+
93103 // ensure minor version is valid before storing in status
94104 parsedMinorVersion , err := strconv .ParseFloat (pgadminMinorVersion , 64 )
95105 if err != nil {
@@ -123,25 +133,6 @@ func (r *PGAdminReconciler) reconcilePGAdminUsers(ctx context.Context, pgadmin *
123133 return r .writePGAdminUsers (ctx , pgadmin , podExecutor )
124134}
125135
126- // reconcilePGAdminVersion execs into the pgAdmin pod and retrieves the pgAdmin minor version
127- func (r * PGAdminReconciler ) reconcilePGAdminVersion (ctx context.Context , exec Executor ) (string , error ) {
128- script := fmt .Sprintf (`
129- PGADMIN_DIR=%s
130- cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_VERSION)"
131- ` , pgAdminDir )
132-
133- var stdin , stdout , stderr bytes.Buffer
134-
135- err := exec (ctx , & stdin , & stdout , & stderr ,
136- []string {"bash" , "-ceu" , "--" , script }... )
137-
138- if err != nil {
139- return "" , err
140- }
141-
142- return strings .TrimSpace (stdout .String ()), nil
143- }
144-
145136// writePGAdminUsers takes the users in the pgAdmin spec and writes (adds or updates) their data
146137// to both pgAdmin and the users.json file that is stored in the pgAdmin secret. If a user is
147138// removed from the spec, its data is removed from users.json, but it is not deleted from pgAdmin.
@@ -187,7 +178,7 @@ cd $PGADMIN_DIR
187178 }
188179
189180 var olderThan9_3 bool
190- versionFloat , err := strconv .ParseFloat (pgadmin .Status .MinorVersion , 32 )
181+ versionFloat , err := strconv .ParseFloat (pgadmin .Status .MinorVersion , 64 )
191182 if err != nil {
192183 return err
193184 }
@@ -198,6 +189,8 @@ cd $PGADMIN_DIR
198189 intentUsers := []pgAdminUserForJson {}
199190 for _ , user := range pgadmin .Spec .Users {
200191 var stdin , stdout , stderr bytes.Buffer
192+ // starting in pgAdmin 9.3, custom roles are supported and a new flag is used
193+ // - https://github.com/pgadmin-org/pgadmin4/pull/8631
201194 typeFlag := "--role User"
202195 if olderThan9_3 {
203196 typeFlag = "--nonadmin"
@@ -257,10 +250,13 @@ cd $PGADMIN_DIR
257250 log .Error (err , "PodExec failed: " )
258251 intentUsers = append (intentUsers , existingUser )
259252 continue
253+
260254 } else if strings .Contains (strings .TrimSpace (stderr .String ()), "UserWarning: pkg_resources is deprecated as an API" ) {
255+ // Started seeing this error with pgAdmin 9.7 when using Python 3.11.
256+ // Issue appears to resolve with Python 3.13.
261257 log .Info (stderr .String ())
262258 } else if strings .TrimSpace (stderr .String ()) != "" {
263- log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py error for %s: " ,
259+ log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py update-user error for %s: " ,
264260 intentUser .Username ))
265261 intentUsers = append (intentUsers , existingUser )
266262 continue
@@ -294,9 +290,11 @@ cd $PGADMIN_DIR
294290 continue
295291 }
296292 if strings .Contains (strings .TrimSpace (stderr .String ()), "UserWarning: pkg_resources is deprecated as an API" ) {
293+ // Started seeing this error with pgAdmin 9.7 when using Python 3.11.
294+ // Issue appears to resolve with Python 3.13.
297295 log .Info (stderr .String ())
298296 } else if strings .TrimSpace (stderr .String ()) != "" {
299- log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py error for %s: " ,
297+ log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py add-user error for %s: " ,
300298 intentUser .Username ))
301299 continue
302300 }
0 commit comments