@@ -86,11 +86,21 @@ func (r *PGAdminReconciler) reconcilePGAdminUsers(ctx context.Context, pgadmin *
8686 if pgadmin .Status .MajorVersion == 0 || pgadmin .Status .MinorVersion == "" ||
8787 pgadmin .Status .ImageSHA != pgAdminImageSha {
8888
89- pgadminMinorVersion , err := r .reconcilePGAdminVersion (ctx , podExecutor )
90- if err != nil {
89+ // exec into the pgAdmin pod and retrieve the pgAdmin minor version
90+ script := fmt .Sprintf (`
91+ PGADMIN_DIR=%s
92+ cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_VERSION)"
93+ ` , pgAdminDir )
94+
95+ var stdin , stdout , stderr bytes.Buffer
96+
97+ if err := podExecutor (ctx , & stdin , & stdout , & stderr ,
98+ []string {"bash" , "-ceu" , "--" , script }... ); err != nil {
9199 return err
92100 }
93101
102+ pgadminMinorVersion := strings .TrimSpace (stdout .String ())
103+
94104 // ensure minor version is valid before storing in status
95105 parsedMinorVersion , err := strconv .ParseFloat (pgadminMinorVersion , 64 )
96106 if err != nil {
@@ -124,25 +134,6 @@ func (r *PGAdminReconciler) reconcilePGAdminUsers(ctx context.Context, pgadmin *
124134 return r .writePGAdminUsers (ctx , pgadmin , podExecutor )
125135}
126136
127- // reconcilePGAdminVersion execs into the pgAdmin pod and retrieves the pgAdmin minor version
128- func (r * PGAdminReconciler ) reconcilePGAdminVersion (ctx context.Context , exec Executor ) (string , error ) {
129- script := fmt .Sprintf (`
130- PGADMIN_DIR=%s
131- cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_VERSION)"
132- ` , pgAdminDir )
133-
134- var stdin , stdout , stderr bytes.Buffer
135-
136- err := exec (ctx , & stdin , & stdout , & stderr ,
137- []string {"bash" , "-ceu" , "--" , script }... )
138-
139- if err != nil {
140- return "" , err
141- }
142-
143- return strings .TrimSpace (stdout .String ()), nil
144- }
145-
146137// writePGAdminUsers takes the users in the pgAdmin spec and writes (adds or updates) their data
147138// to both pgAdmin and the users.json file that is stored in the pgAdmin secret. If a user is
148139// removed from the spec, its data is removed from users.json, but it is not deleted from pgAdmin.
@@ -188,7 +179,7 @@ cd $PGADMIN_DIR
188179 }
189180
190181 var olderThan9_3 bool
191- versionFloat , err := strconv .ParseFloat (pgadmin .Status .MinorVersion , 32 )
182+ versionFloat , err := strconv .ParseFloat (pgadmin .Status .MinorVersion , 64 )
192183 if err != nil {
193184 return err
194185 }
@@ -199,6 +190,8 @@ cd $PGADMIN_DIR
199190 intentUsers := []pgAdminUserForJson {}
200191 for _ , user := range pgadmin .Spec .Users {
201192 var stdin , stdout , stderr bytes.Buffer
193+ // starting in pgAdmin 9.3, custom roles are supported and a new flag is used
194+ // - https://github.com/pgadmin-org/pgadmin4/pull/8631
202195 typeFlag := "--role User"
203196 if olderThan9_3 {
204197 typeFlag = "--nonadmin"
@@ -258,10 +251,13 @@ cd $PGADMIN_DIR
258251 log .Error (err , "PodExec failed: " )
259252 intentUsers = append (intentUsers , existingUser )
260253 continue
254+
261255 } else if strings .Contains (strings .TrimSpace (stderr .String ()), "UserWarning: pkg_resources is deprecated as an API" ) {
256+ // Started seeing this error with pgAdmin 9.7 when using Python 3.11.
257+ // Issue appears to resolve with Python 3.13.
262258 log .Info (stderr .String ())
263259 } else if strings .TrimSpace (stderr .String ()) != "" {
264- log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py error for %s: " ,
260+ log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py update-user error for %s: " ,
265261 intentUser .Username ))
266262 intentUsers = append (intentUsers , existingUser )
267263 continue
@@ -295,9 +291,11 @@ cd $PGADMIN_DIR
295291 continue
296292 }
297293 if strings .Contains (strings .TrimSpace (stderr .String ()), "UserWarning: pkg_resources is deprecated as an API" ) {
294+ // Started seeing this error with pgAdmin 9.7 when using Python 3.11.
295+ // Issue appears to resolve with Python 3.13.
298296 log .Info (stderr .String ())
299297 } else if strings .TrimSpace (stderr .String ()) != "" {
300- log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py error for %s: " ,
298+ log .Error (errors .New (stderr .String ()), fmt .Sprintf ("pgAdmin setup.py add-user error for %s: " ,
301299 intentUser .Username ))
302300 continue
303301 }
0 commit comments