-
Notifications
You must be signed in to change notification settings - Fork 124
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
PMM-12573 Update podman via UI. #3128
Open
BupycHuk
wants to merge
12
commits into
v3
Choose a base branch
from
PMM-12573-update-ui-podman
base: v3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−13
Open
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
41c0323
PMM-12573 Update UI podman.
BupycHuk c47aa2c
PMM-12573 Fix tests and linters.
BupycHuk b198056
PMM-12573 Added empty line at end of file.
BupycHuk e095a8c
PMM-12573 Simplify update logic.
BupycHuk 36dfcc9
PMM-12573 don't expose watchtower.
BupycHuk 7cf938f
PMM-12573 change path of env file.
BupycHuk 95e9f3b
Merge branch 'v3' into PMM-12573-update-ui-podman
BupycHuk ecfeadc
PMM-12573 Revert unnecessary changes.
BupycHuk 5b2c6bf
PMM-12573 Refactoring.
BupycHuk 47c925c
PMM-12573 update watchtower config.
BupycHuk 4c3e6f8
PMM-212573 fix path to watchtower env file.
BupycHuk 17312aa
Merge branch 'v3' into PMM-12573-update-ui-podman
BupycHuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
build/packer/ansible/roles/podman-setup/templates/pmm-server.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
PMM_WATCHTOWER_HOST=http://watchtower:8080 | ||
PMM_WATCHTOWER_TOKEN=123 | ||
PMM_SERVER_UPDATE_VERSION=docker.io/perconalab/pmm-server:3-dev-container | ||
PMM_DEV_UPDATE_DOCKER_IMAGE=docker.io/perconalab/pmm-server:3-dev-container | ||
PMM_IMAGE={{ pmm_server_image_name }} | ||
PMM_DISTRIBUTION_METHOD={{ pmm_distribution_method }} | ||
PMM_DISTRIBUTION_METHOD={{ pmm_distribution_method }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import ( | |
"google.golang.org/grpc/codes" | ||
grpcstatus "google.golang.org/grpc/status" | ||
|
||
"github.com/percona/pmm/managed/utils/distribution" | ||
"github.com/percona/pmm/version" | ||
) | ||
|
||
|
@@ -44,6 +45,7 @@ const ( | |
updateCheckInterval = 24 * time.Hour | ||
updateCheckResultFresh = updateCheckInterval + 10*time.Minute | ||
updateDefaultTimeout = 30 * time.Second | ||
envfilePath = "/home/pmm/update/pmm-server.env" | ||
) | ||
|
||
var fileName = "/etc/pmm-server-update-version.json" | ||
|
@@ -52,6 +54,7 @@ var fileName = "/etc/pmm-server-update-version.json" | |
type Updater struct { | ||
l *logrus.Entry | ||
watchtowerHost *url.URL | ||
dus *distribution.Service | ||
gRPCMessageMaxSize uint32 | ||
|
||
performM sync.Mutex | ||
|
@@ -63,10 +66,11 @@ type Updater struct { | |
} | ||
|
||
// NewUpdater creates a new Updater service. | ||
func NewUpdater(watchtowerHost *url.URL, gRPCMessageMaxSize uint32) *Updater { | ||
func NewUpdater(watchtowerHost *url.URL, dus *distribution.Service, gRPCMessageMaxSize uint32) *Updater { | ||
u := &Updater{ | ||
l: logrus.WithField("service", "updater"), | ||
watchtowerHost: watchtowerHost, | ||
dus: dus, | ||
gRPCMessageMaxSize: gRPCMessageMaxSize, | ||
} | ||
return u | ||
|
@@ -157,6 +161,20 @@ func (up *Updater) StartUpdate(ctx context.Context, newImageName string) error { | |
return grpcstatus.Errorf(codes.FailedPrecondition, "failed to check watchtower host") | ||
} | ||
|
||
fileInfo, err := os.Stat(envfilePath) | ||
if os.IsExist(err) && fileInfo != nil { | ||
err := up.updateEnvironmentVariables(envfilePath, newImageName) | ||
if err != nil { | ||
up.running = false | ||
up.l.WithError(err).Error("Failed to update environment variables file") | ||
return errors.Wrap(err, "failed to update environment variables file") | ||
} | ||
} else if err != nil { | ||
up.running = false | ||
up.l.WithError(err).Error("Failed to check file") | ||
return errors.Wrap(err, "failed to check file") | ||
} | ||
|
||
if err := up.sendRequestToWatchtower(ctx, newImageName); err != nil { | ||
up.l.WithError(err).Error("Failed to trigger update") | ||
return errors.Wrap(err, "failed to trigger update") | ||
|
@@ -409,6 +427,27 @@ func (up *Updater) checkWatchtowerHost() error { | |
return nil | ||
} | ||
|
||
func (up *Updater) updateEnvironmentVariables(filename string, name string) error { | ||
if len(strings.Split(name, "/")) < 3 { | ||
name = "docker.io/" + name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. podman requires full name to update. |
||
} | ||
file, err := os.ReadFile(filename) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to read file") | ||
} | ||
lines := strings.Split(string(file), "\n") | ||
for i, line := range lines { | ||
if strings.Contains(line, "PMM_IMAGE") { | ||
lines[i] = fmt.Sprintf("PMM_IMAGE=%s", name) | ||
} | ||
} | ||
err = os.WriteFile(filename, []byte(strings.Join(lines, "\n")), 0o644) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to write file") | ||
} | ||
return nil | ||
} | ||
|
||
func isHostAvailable(host string, port string, timeout time.Duration) bool { | ||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), timeout) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PMM_WATCHTOWER_HOST=http://watchtower:8080 | ||
PMM_WATCHTOWER_TOKEN=123 | ||
PMM_IMAGE=docker.io/perconalab/pmm-server:3-dev-latest | ||
PMM_DISTRIBUTION_METHOD=ami |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will be dropped before GA