-
Notifications
You must be signed in to change notification settings - Fork 636
Updates to support changes starting in pgAdmin 9.3 #4300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,40 +80,55 @@ func (r *PGAdminReconciler) reconcilePGAdminUsers(ctx context.Context, pgadmin * | |
| return nil | ||
| } | ||
|
|
||
| // If the pgAdmin version is not in the status or the image SHA has changed, get | ||
| // the pgAdmin version and store it in the status. | ||
| var pgadminVersion int | ||
| if pgadmin.Status.MajorVersion == 0 || pgadmin.Status.ImageSHA != pgAdminImageSha { | ||
| pgadminVersion, err = r.reconcilePGAdminMajorVersion(ctx, podExecutor) | ||
| // If the pgAdmin major or minor version is not in the status or the image | ||
| // SHA has changed, get the pgAdmin version and store it in the status. | ||
| var pgadminMajorVersion int | ||
| if pgadmin.Status.MajorVersion == 0 || pgadmin.Status.MinorVersion == "" || | ||
| pgadmin.Status.ImageSHA != pgAdminImageSha { | ||
|
|
||
| pgadminMinorVersion, err := r.reconcilePGAdminVersion(ctx, podExecutor) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| pgadmin.Status.MajorVersion = pgadminVersion | ||
|
|
||
| // ensure minor version is valid before storing in status | ||
| parsedMinorVersion, err := strconv.ParseFloat(pgadminMinorVersion, 64) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Note: "When converting a floating-point number to an integer, the | ||
| // fraction is discarded (truncation towards zero)." | ||
| // - https://go.dev/ref/spec#Conversions | ||
| pgadminMajorVersion = int(parsedMinorVersion) | ||
|
|
||
| pgadmin.Status.MinorVersion = pgadminMinorVersion | ||
| pgadmin.Status.MajorVersion = pgadminMajorVersion | ||
| pgadmin.Status.ImageSHA = pgAdminImageSha | ||
| } else { | ||
| pgadminVersion = pgadmin.Status.MajorVersion | ||
| pgadminMajorVersion = pgadmin.Status.MajorVersion | ||
| } | ||
|
|
||
| // If the pgAdmin version is not v8 or higher, return early as user management is | ||
| // only supported for pgAdmin v8 and higher. | ||
| if pgadminVersion < 8 { | ||
| if pgadminMajorVersion < 8 { | ||
| // If pgAdmin version is less than v8 and user management is being attempted, | ||
| // log a message clarifying that it is only supported for pgAdmin v8 and higher. | ||
| if len(pgadmin.Spec.Users) > 0 { | ||
| log.Info("User management is only supported for pgAdmin v8 and higher.", | ||
| "pgadminVersion", pgadminVersion) | ||
| "pgadminVersion", pgadminMajorVersion) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| return r.writePGAdminUsers(ctx, pgadmin, podExecutor) | ||
| } | ||
|
|
||
| // reconcilePGAdminMajorVersion execs into the pgAdmin pod and retrieves the pgAdmin major version | ||
| func (r *PGAdminReconciler) reconcilePGAdminMajorVersion(ctx context.Context, exec Executor) (int, error) { | ||
| // reconcilePGAdminVersion execs into the pgAdmin pod and retrieves the pgAdmin minor version | ||
| func (r *PGAdminReconciler) reconcilePGAdminVersion(ctx context.Context, exec Executor) (string, error) { | ||
| script := fmt.Sprintf(` | ||
| PGADMIN_DIR=%s | ||
| cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_RELEASE)" | ||
| cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_VERSION)" | ||
| `, pgAdminDir) | ||
|
|
||
| var stdin, stdout, stderr bytes.Buffer | ||
|
|
@@ -122,10 +137,10 @@ cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_RELEASE)" | |
| []string{"bash", "-ceu", "--", script}...) | ||
|
|
||
| if err != nil { | ||
| return 0, err | ||
| return "", err | ||
| } | ||
|
|
||
| return strconv.Atoi(strings.TrimSpace(stdout.String())) | ||
| return strings.TrimSpace(stdout.String()), nil | ||
| } | ||
|
|
||
| // writePGAdminUsers takes the users in the pgAdmin spec and writes (adds or updates) their data | ||
|
|
@@ -171,10 +186,23 @@ cd $PGADMIN_DIR | |
| for _, user := range existingUsersArr { | ||
| existingUsersMap[user.Username] = user | ||
| } | ||
|
|
||
| var olderThan9_3 bool | ||
| versionFloat, err := strconv.ParseFloat(pgadmin.Status.MinorVersion, 32) | ||
|
||
| if err != nil { | ||
| return err | ||
| } | ||
| if versionFloat < 9.3 { | ||
| olderThan9_3 = true | ||
| } | ||
|
|
||
| intentUsers := []pgAdminUserForJson{} | ||
| for _, user := range pgadmin.Spec.Users { | ||
| var stdin, stdout, stderr bytes.Buffer | ||
| typeFlag := "--nonadmin" | ||
| typeFlag := "--role User" | ||
tjmoore4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if olderThan9_3 { | ||
| typeFlag = "--nonadmin" | ||
| } | ||
| isAdmin := false | ||
| if user.Role == "Administrator" { | ||
| typeFlag = "--admin" | ||
|
|
@@ -230,6 +258,8 @@ cd $PGADMIN_DIR | |
| log.Error(err, "PodExec failed: ") | ||
| intentUsers = append(intentUsers, existingUser) | ||
| continue | ||
| } else if strings.Contains(strings.TrimSpace(stderr.String()), "UserWarning: pkg_resources is deprecated as an API") { | ||
tjmoore4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.Info(stderr.String()) | ||
| } else if strings.TrimSpace(stderr.String()) != "" { | ||
| log.Error(errors.New(stderr.String()), fmt.Sprintf("pgAdmin setup.py error for %s: ", | ||
| intentUser.Username)) | ||
|
|
@@ -264,7 +294,9 @@ cd $PGADMIN_DIR | |
| log.Error(err, "PodExec failed: ") | ||
| continue | ||
| } | ||
| if strings.TrimSpace(stderr.String()) != "" { | ||
| if strings.Contains(strings.TrimSpace(stderr.String()), "UserWarning: pkg_resources is deprecated as an API") { | ||
| log.Info(stderr.String()) | ||
| } else if strings.TrimSpace(stderr.String()) != "" { | ||
| log.Error(errors.New(stderr.String()), fmt.Sprintf("pgAdmin setup.py error for %s: ", | ||
tjmoore4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| intentUser.Username)) | ||
| continue | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 It looks like the result of this is only used when reconciling users. Can we move this into the commands there?
📝 It looks like pgAdmin 8.4 and newer have a version module with just these constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into whether moving the commands makes sense. My guess is that would probably be fine as a refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. The previous functions been removed and one test added to account for the scenario that wasn't being tested.