This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathupgrades.go
134 lines (109 loc) · 4.22 KB
/
upgrades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"fmt"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/elastic/e2e-testing/internal/common"
"github.com/elastic/e2e-testing/internal/deploy"
"github.com/elastic/e2e-testing/internal/installer"
"github.com/elastic/e2e-testing/internal/utils"
"github.com/elastic/e2e-testing/pkg/downloads"
log "github.com/sirupsen/logrus"
)
const (
upgradeMaxTimeout = 10 * time.Minute
)
func (fts *FleetTestSuite) agentInVersion(version string) error {
switch version {
case "latest":
version = downloads.GetSnapshotVersion(common.ElasticAgentVersion)
}
log.Tracef("Checking if agent is in version %s. Current version: %s", version, fts.Version)
retryCount := 0
maxTimeout := upgradeMaxTimeout
exp := utils.GetExponentialBackOff(maxTimeout)
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
manifest, _ := fts.getDeployer().GetServiceManifest(fts.currentContext, agentService)
agentInVersionFn := func() error {
retryCount++
agent, err := fts.kibanaClient.GetAgentByHostname(fts.currentContext, manifest.Hostname)
if err != nil {
log.WithFields(log.Fields{
"agent": agent,
"error": err,
"maxTimeout": maxTimeout,
"elapsedTime": exp.GetElapsedTime(),
"retries": retryCount,
"version": version,
}).Warn("Could not get agent by hostname")
return err
}
retrievedVersion := agent.LocalMetadata.Elastic.Agent.Version
if isSnapshot := agent.LocalMetadata.Elastic.Agent.Snapshot; isSnapshot {
retrievedVersion += "-SNAPSHOT"
}
if retrievedVersion != version {
err := fmt.Errorf("version mismatch required '%s' retrieved '%s'", version, retrievedVersion)
log.WithFields(log.Fields{
"elapsedTime": exp.GetElapsedTime(),
"error": err,
"maxTimeout": maxTimeout,
"retries": retryCount,
"retrievedVersion": retrievedVersion,
"version": version,
}).Warn("Version mismatch")
return err
}
return nil
}
return backoff.Retry(agentInVersionFn, exp)
}
func (fts *FleetTestSuite) anAgentIsUpgradedToVersion(desiredVersion string) error {
switch desiredVersion {
case "latest":
desiredVersion = common.ElasticAgentVersion
}
log.Tracef("Desired version is %s. Current version: %s", desiredVersion, fts.Version)
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
/*
// upgrading using the command is needed for stand-alone mode, only
agentInstaller, _ := installer.Attach(fts.currentContext, fts.getDeployer(), agentService, fts.InstallerType)
log.Tracef("Upgrading agent from %s to %s with 'upgrade' command.", desiredVersion, fts.Version)
return agentInstaller.Upgrade(fts.currentContext, desiredVersion)
*/
manifest, _ := fts.getDeployer().GetServiceManifest(fts.currentContext, agentService)
return fts.kibanaClient.UpgradeAgent(fts.currentContext, manifest.Hostname, desiredVersion)
}
func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(staleVersion string, installerType string) error {
switch staleVersion {
case "latest":
staleVersion = common.ElasticAgentVersion
}
fts.Version = staleVersion
log.Tracef("The stale version is %s", fts.Version)
return fts.anAgentIsDeployedToFleetWithInstaller(installerType)
}
func (fts *FleetTestSuite) installCerts() error {
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
agentInstaller, _ := installer.Attach(fts.currentContext, fts.getDeployer(), agentService, fts.InstallerType)
err := agentInstaller.InstallCerts(fts.currentContext)
if err != nil {
log.WithFields(log.Fields{
"agentVersion": common.ElasticAgentVersion,
"agentStaleVersion": fts.Version,
"error": err,
"installer": agentInstaller,
}).Error("Could not install the certificates")
return err
}
log.WithFields(log.Fields{
"agentVersion": common.ElasticAgentVersion,
"agentStaleVersion": fts.Version,
"error": err,
"installer": agentInstaller,
}).Tracef("Certs were installed")
return nil
}