Skip to content
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-11261 Update PMM via watchtower #2844

Merged
merged 20 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions api/serverpb/json/client/server/start_update_parameters.go

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

37 changes: 37 additions & 0 deletions api/serverpb/json/client/server/start_update_responses.go

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

8 changes: 7 additions & 1 deletion api/serverpb/json/serverpb.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
601 changes: 306 additions & 295 deletions api/serverpb/server.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/serverpb/server.pb.validate.go

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

4 changes: 3 additions & 1 deletion api/serverpb/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ message CheckUpdatesResponse {
google.protobuf.Timestamp last_check = 5;
}

message StartUpdateRequest {}
message StartUpdateRequest {
string new_image = 1;
}

message StartUpdateResponse {
// Authentication token for getting update statuses.
Expand Down
8 changes: 7 additions & 1 deletion api/swagger/swagger-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -3649,7 +3649,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
8 changes: 7 additions & 1 deletion api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ services:
- ENABLE_RBAC=${ENABLE_RBAC:-0}
- LESS_LOG_NOISE=1
- PERCONA_TEST_VERSION_SERVICE_URL=${PERCONA_TEST_VERSION_SERVICE_URL}
- PMM_WATCHTOWER_HOST=${PMM_WATCHTOWER_HOST:-http://host.docker.internal:8080}
- PMM_WATCHTOWER_TOKEN=${PMM_WATCHTOWER_TOKEN:-123}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
# - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost
# - PERCONA_TEST_PLATFORM_INSECURE=1
# - PERCONA_TEST_PLATFORM_PUBLIC_KEY=<public key>
Expand Down
15 changes: 15 additions & 0 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,20 @@ func main() { //nolint:cyclop,maintidx

dumpService := dump.New(db)

// Get the hostname from the environment variable
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
watchtowerHostname := os.Getenv("PMM_WATCHTOWER_HOSTNAME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep in mind that, host would contain the port, while hostname wouldn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to provide evidence :)

Screenshot 2024-02-26 at 15 38 58

if watchtowerHostname == "" {
watchtowerHostname = "http://watchtower:8080"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if watchtowerHostname == "" {
watchtowerHostname = "http://watchtower:8080"
}
if watchtowerHost == "" {
watchtowerHost = "http://watchtower:8080"
}


// Create a URL with the images and new image name as query parameters
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
u, err := url.Parse(watchtowerHostname)
if err != nil {
l.Fatalf("Failed to parse watchtower hostname: %s", err)
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
}

updater := server.NewUpdater(supervisord, u)

serverParams := &server.Params{
DB: db,
VMDB: vmdb,
Expand All @@ -981,6 +995,7 @@ func main() { //nolint:cyclop,maintidx
AwsInstanceChecker: awsInstanceChecker,
GrafanaClient: grafanaClient,
VMAlertExternalRules: externalRules,
Updater: updater,
}

server, err := server.NewServer(serverParams)
Expand Down
20 changes: 10 additions & 10 deletions managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Server struct {
awsInstanceChecker *AWSInstanceChecker
grafanaClient grafanaClient
haService haService
updater *Updater

l *logrus.Entry

Expand Down Expand Up @@ -91,6 +92,7 @@ type Params struct {
TelemetryService telemetryService
AwsInstanceChecker *AWSInstanceChecker
GrafanaClient grafanaClient
Updater *Updater
}

// NewServer returns new server for Server service.
Expand All @@ -113,6 +115,7 @@ func NewServer(params *Params) (*Server, error) {
telemetryService: params.TelemetryService,
awsInstanceChecker: params.AwsInstanceChecker,
grafanaClient: params.GrafanaClient,
updater: params.Updater,
l: logrus.WithField("component", "server"),
pmmUpdateAuthFile: path,
envSettings: &models.ChangeSettingsParams{},
Expand Down Expand Up @@ -258,16 +261,16 @@ func (s *Server) CheckUpdates(ctx context.Context, req *serverpb.CheckUpdatesReq
s.envRW.RUnlock()

if req.OnlyInstalledVersion {
return s.onlyInstalledVersionResponse(ctx), nil
return s.updater.onlyInstalledVersionResponse(), nil
}

if req.Force {
if err := s.supervisord.ForceCheckUpdates(ctx); err != nil {
if err := s.updater.ForceCheckUpdates(ctx); err != nil {
return nil, err
}
}

v, lastCheck := s.supervisord.LastCheckUpdatesResult(ctx)
v, lastCheck := s.updater.LastCheckUpdatesResult(ctx)
if v == nil {
return nil, status.Error(codes.Unavailable, "failed to check for updates")
}
Expand All @@ -281,7 +284,7 @@ func (s *Server) CheckUpdates(ctx context.Context, req *serverpb.CheckUpdatesReq
Version: v.Latest.Version,
FullVersion: v.Latest.FullVersion,
},
UpdateAvailable: v.UpdateAvailable,
UpdateAvailable: true,
LatestNewsUrl: v.LatestNewsURL,
}

Expand Down Expand Up @@ -314,19 +317,16 @@ func (s *Server) StartUpdate(ctx context.Context, req *serverpb.StartUpdateReque
return nil, status.Error(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.")
}

offset, err := s.supervisord.StartUpdate()
if err != nil {
return nil, err
}
s.updater.StartUpdate(ctx, req.NewImage)
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved

authToken := uuid.New().String()
if err = s.writeUpdateAuthToken(authToken); err != nil {
if err := s.writeUpdateAuthToken(authToken); err != nil {
return nil, err
}

return &serverpb.StartUpdateResponse{
AuthToken: authToken,
LogOffset: offset,
LogOffset: 0,
}, nil
}

Expand Down
Loading
Loading