Skip to content

Commit 38f2862

Browse files
BupycHukademidoff
andauthored
PMM-11261 Update PMM via watchtower (#2844)
* PMM-11261 Update PMM via watchtower * PMM-11261 address comments and fix linter * PMM-11261 fix linters and tests. * PMM-11261 fix linters and tests. * PMM-11261 fix linters. * PMM-11261 fix linters. * Update managed/cmd/pmm-managed/main.go Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com> * Update managed/cmd/pmm-managed/main.go Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com> * PMM-11261 Address comments. * PMM-11261 fix build. * Update docker-compose.yml * Update docker-compose.yml Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com> * Update docker-compose.yml Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com> * PMM-11261 Replace switch with if-else * Update managed/services/server/updater.go Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com> --------- Co-authored-by: Alex Demidoff <alexander.demidoff@percona.com>
1 parent c43ab4e commit 38f2862

12 files changed

+632
-332
lines changed

api/serverpb/json/client/server/start_update_parameters.go

+5-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/serverpb/json/client/server/start_update_responses.go

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/serverpb/json/serverpb.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,13 @@
805805
"in": "body",
806806
"required": true,
807807
"schema": {
808-
"type": "object"
808+
"type": "object",
809+
"properties": {
810+
"new_image": {
811+
"type": "string",
812+
"x-order": 0
813+
}
814+
}
809815
}
810816
}
811817
],

api/serverpb/server.pb.go

+306-295
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/serverpb/server.pb.validate.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/serverpb/server.proto

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ message CheckUpdatesResponse {
7979
google.protobuf.Timestamp last_check = 5;
8080
}
8181

82-
message StartUpdateRequest {}
82+
message StartUpdateRequest {
83+
string new_image = 1;
84+
}
8385

8486
message StartUpdateResponse {
8587
// Authentication token for getting update statuses.

api/swagger/swagger-dev.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,13 @@
36493649
"in": "body",
36503650
"required": true,
36513651
"schema": {
3652-
"type": "object"
3652+
"type": "object",
3653+
"properties": {
3654+
"new_image": {
3655+
"type": "string",
3656+
"x-order": 0
3657+
}
3658+
}
36533659
}
36543660
}
36553661
],

api/swagger/swagger.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,13 @@
805805
"in": "body",
806806
"required": true,
807807
"schema": {
808-
"type": "object"
808+
"type": "object",
809+
"properties": {
810+
"new_image": {
811+
"type": "string",
812+
"x-order": 0
813+
}
814+
}
809815
}
810816
}
811817
],

docker-compose.yml

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ services:
2323
- ENABLE_RBAC=${ENABLE_RBAC:-0}
2424
- LESS_LOG_NOISE=1
2525
- PERCONA_TEST_VERSION_SERVICE_URL=${PERCONA_TEST_VERSION_SERVICE_URL}
26+
- PMM_WATCHTOWER_HOST=${PMM_WATCHTOWER_HOST:-http://watchtower:8080}
27+
- PMM_WATCHTOWER_TOKEN=${PMM_WATCHTOWER_TOKEN:-INSECURE_TOKEN}
2628
# - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost
2729
# - PERCONA_TEST_PLATFORM_INSECURE=1
2830
# - PERCONA_TEST_PLATFORM_PUBLIC_KEY=<public key>
@@ -94,6 +96,22 @@ services:
9496
# /opt/entrypoint.sh
9597
# "
9698

99+
# docker run -v /var/run/docker.sock:/var/run/docker.sock -e WATCHTOWER_HTTP_API_UPDATE=1 -e WATCHTOWER_HTTP_API_TOKEN=123 --hostname=watchtower --network=pmm_default docker.io/bupychuk/watchtower
100+
watchtower:
101+
profiles:
102+
- pmm
103+
image: ${WATCHTOWER_IMAGE:-perconalab/watchtower}
104+
container_name: watchtower
105+
environment:
106+
- WATCHTOWER_HTTP_LISTEN_PORT=8080
107+
- WATCHTOWER_HTTP_API_UPDATE=1
108+
- WATCHTOWER_HTTP_API_TOKEN=${PMM_WATCHTOWER_TOKEN:-INSECURE_TOKEN}
109+
hostname: watchtower
110+
networks:
111+
- ${NETWORK:-default}
112+
volumes:
113+
- /var/run/docker.sock:${DOCKER_PATH:-/var/run/docker.sock}
114+
97115
# PMM with external DBs
98116
ch:
99117
profiles:

managed/cmd/pmm-managed/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ func main() { //nolint:cyclop,maintidx
723723
clickHouseDatabaseF := kingpin.Flag("clickhouse-name", "Clickhouse database name").Default("pmm").Envar("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE").String()
724724
clickhouseAddrF := kingpin.Flag("clickhouse-addr", "Clickhouse database address").Default("127.0.0.1:9000").Envar("PERCONA_TEST_PMM_CLICKHOUSE_ADDR").String()
725725

726+
watchtowerHostF := kingpin.Flag("watchtower-host", "Watchtower host").Default("http://watchtower:8080").Envar("PMM_WATCHTOWER_HOST").URL()
727+
726728
kingpin.Parse()
727729

728730
logger.SetupGlobalLogger()
@@ -969,6 +971,8 @@ func main() { //nolint:cyclop,maintidx
969971

970972
dumpService := dump.New(db)
971973

974+
updater := server.NewUpdater(supervisord, *watchtowerHostF)
975+
972976
serverParams := &server.Params{
973977
DB: db,
974978
VMDB: vmdb,
@@ -981,6 +985,7 @@ func main() { //nolint:cyclop,maintidx
981985
AwsInstanceChecker: awsInstanceChecker,
982986
GrafanaClient: grafanaClient,
983987
VMAlertExternalRules: externalRules,
988+
Updater: updater,
984989
}
985990

986991
server, err := server.NewServer(serverParams)

managed/services/server/server.go

+10-26
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type Server struct {
6060
awsInstanceChecker *AWSInstanceChecker
6161
grafanaClient grafanaClient
6262
haService haService
63+
updater *Updater
6364

6465
l *logrus.Entry
6566

@@ -91,6 +92,7 @@ type Params struct {
9192
TelemetryService telemetryService
9293
AwsInstanceChecker *AWSInstanceChecker
9394
GrafanaClient grafanaClient
95+
Updater *Updater
9496
}
9597

9698
// NewServer returns new server for Server service.
@@ -113,6 +115,7 @@ func NewServer(params *Params) (*Server, error) {
113115
telemetryService: params.TelemetryService,
114116
awsInstanceChecker: params.AwsInstanceChecker,
115117
grafanaClient: params.GrafanaClient,
118+
updater: params.Updater,
116119
l: logrus.WithField("component", "server"),
117120
pmmUpdateAuthFile: path,
118121
envSettings: &models.ChangeSettingsParams{},
@@ -232,42 +235,23 @@ func (s *Server) LeaderHealthCheck(ctx context.Context, req *serverpb.LeaderHeal
232235
return nil, status.Error(codes.FailedPrecondition, "this PMM Server isn't the leader")
233236
}
234237

235-
func (s *Server) onlyInstalledVersionResponse(ctx context.Context) *serverpb.CheckUpdatesResponse {
236-
v := s.supervisord.InstalledPMMVersion(ctx)
237-
r := &serverpb.CheckUpdatesResponse{
238-
Installed: &serverpb.VersionInfo{
239-
Version: v.Version,
240-
FullVersion: v.FullVersion,
241-
},
242-
}
243-
244-
if v.BuildTime != nil {
245-
t := v.BuildTime.UTC().Truncate(24 * time.Hour) // return only date
246-
r.Installed.Timestamp = timestamppb.New(t)
247-
}
248-
249-
r.LastCheck = timestamppb.New(time.Now())
250-
251-
return r
252-
}
253-
254238
// CheckUpdates checks PMM Server updates availability.
255239
func (s *Server) CheckUpdates(ctx context.Context, req *serverpb.CheckUpdatesRequest) (*serverpb.CheckUpdatesResponse, error) {
256240
s.envRW.RLock()
257241
updatesDisabled := s.envSettings.DisableUpdates
258242
s.envRW.RUnlock()
259243

260244
if req.OnlyInstalledVersion {
261-
return s.onlyInstalledVersionResponse(ctx), nil
245+
return s.updater.onlyInstalledVersionResponse(), nil
262246
}
263247

264248
if req.Force {
265-
if err := s.supervisord.ForceCheckUpdates(ctx); err != nil {
249+
if err := s.updater.ForceCheckUpdates(ctx); err != nil {
266250
return nil, err
267251
}
268252
}
269253

270-
v, lastCheck := s.supervisord.LastCheckUpdatesResult(ctx)
254+
v, lastCheck := s.updater.LastCheckUpdatesResult(ctx)
271255
if v == nil {
272256
return nil, status.Error(codes.Unavailable, "failed to check for updates")
273257
}
@@ -281,7 +265,7 @@ func (s *Server) CheckUpdates(ctx context.Context, req *serverpb.CheckUpdatesReq
281265
Version: v.Latest.Version,
282266
FullVersion: v.Latest.FullVersion,
283267
},
284-
UpdateAvailable: v.UpdateAvailable,
268+
UpdateAvailable: true,
285269
LatestNewsUrl: v.LatestNewsURL,
286270
}
287271

@@ -314,19 +298,19 @@ func (s *Server) StartUpdate(ctx context.Context, req *serverpb.StartUpdateReque
314298
return nil, status.Error(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.")
315299
}
316300

317-
offset, err := s.supervisord.StartUpdate()
301+
err := s.updater.StartUpdate(ctx, req.GetNewImage())
318302
if err != nil {
319303
return nil, err
320304
}
321305

322306
authToken := uuid.New().String()
323-
if err = s.writeUpdateAuthToken(authToken); err != nil {
307+
if err := s.writeUpdateAuthToken(authToken); err != nil {
324308
return nil, err
325309
}
326310

327311
return &serverpb.StartUpdateResponse{
328312
AuthToken: authToken,
329-
LogOffset: offset,
313+
LogOffset: 0,
330314
}, nil
331315
}
332316

0 commit comments

Comments
 (0)