Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit f043003

Browse files
authored
Feat installer rework 2 (#1208)
* Installer refactor Supports installing services no matter the deployment backend. Also support installation methods for tar, rpm, deb and easily extensible to exe/dmg for mac and windows. Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com> * Fixes #1200 Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com> * Cleanup dead code Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
1 parent 888ecfe commit f043003

21 files changed

Lines changed: 957 additions & 1259 deletions

e2e/_suites/fleet/fleet.go

Lines changed: 114 additions & 247 deletions
Large diffs are not rendered by default.

e2e/_suites/fleet/ingest_manager_test.go

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import (
1313
"github.com/elastic/e2e-testing/cli/config"
1414
"github.com/elastic/e2e-testing/internal/common"
1515
"github.com/elastic/e2e-testing/internal/deploy"
16-
"github.com/elastic/e2e-testing/internal/installer"
1716
"github.com/elastic/e2e-testing/internal/kibana"
1817
"github.com/elastic/e2e-testing/internal/shell"
19-
"github.com/elastic/e2e-testing/internal/utils"
2018
log "github.com/sirupsen/logrus"
2119
)
2220

@@ -32,31 +30,17 @@ func setUpSuite() {
3230
}
3331

3432
common.Provider = shell.GetEnv("PROVIDER", common.Provider)
35-
developerMode := shell.GetEnvBool("DEVELOPER_MODE")
36-
if developerMode {
33+
common.DeveloperMode = shell.GetEnvBool("DEVELOPER_MODE")
34+
if common.DeveloperMode {
3735
log.Info("Running in Developer mode 💻: runtime dependencies between different test runs will be reused to speed up dev cycle")
3836
}
3937

4038
common.InitVersions()
4139

42-
common.KibanaVersion = shell.GetEnv("KIBANA_VERSION", "")
43-
if common.KibanaVersion == "" {
44-
// we want to deploy a released version for Kibana
45-
// if not set, let's use stackVersion
46-
common.KibanaVersion, err = utils.GetElasticArtifactVersion(common.StackVersion)
47-
if err != nil {
48-
log.WithFields(log.Fields{
49-
"error": err,
50-
"version": common.KibanaVersion,
51-
}).Fatal("Failed to get kibana version, aborting")
52-
}
53-
}
54-
5540
imts = IngestManagerTestSuite{
5641
Fleet: &FleetTestSuite{
5742
kibanaClient: kibanaClient,
5843
deployer: deploy.New(common.Provider),
59-
Installers: map[string]installer.ElasticAgentInstaller{}, // do not pre-initialise the map
6044
},
6145
}
6246
}
@@ -79,8 +63,6 @@ func InitializeIngestManagerTestScenario(ctx *godog.ScenarioContext) {
7963
}
8064

8165
func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
82-
developerMode := shell.GetEnvBool("DEVELOPER_MODE")
83-
8466
ctx.BeforeSuite(func() {
8567
setUpSuite()
8668

@@ -120,30 +102,10 @@ func InitializeIngestManagerTestSuite(ctx *godog.TestSuiteContext) {
120102
})
121103

122104
ctx.AfterSuite(func() {
123-
if !developerMode {
105+
if !common.DeveloperMode {
124106
log.Debug("Destroying Fleet runtime dependencies")
125107
deployer := deploy.New(common.Provider)
126108
deployer.Destroy()
127109
}
128-
129-
installers := imts.Fleet.Installers
130-
for k, v := range installers {
131-
agentPath := v.BinaryPath
132-
if _, err := os.Stat(agentPath); err == nil {
133-
err = os.Remove(agentPath)
134-
if err != nil {
135-
log.WithFields(log.Fields{
136-
"err": err,
137-
"installer": k,
138-
"path": agentPath,
139-
}).Warn("Elastic Agent binary could not be removed.")
140-
} else {
141-
log.WithFields(log.Fields{
142-
"installer": k,
143-
"path": agentPath,
144-
}).Debug("Elastic Agent binary was removed.")
145-
}
146-
}
147-
}
148110
})
149111
}

e2e/_suites/fleet/stand-alone.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ func (fts *FleetTestSuite) thereIsNewDataInTheIndexFromAgent() error {
5151
maxTimeout := time.Duration(utils.TimeoutFactor) * time.Minute * 2
5252
minimumHitsCount := 50
5353

54-
result, err := searchAgentData(fts.Hostname, fts.RuntimeDependenciesStartDate, minimumHitsCount, maxTimeout)
54+
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName).WithFlavour(fts.Image)
55+
56+
manifest, _ := fts.deployer.Inspect(agentService)
57+
result, err := searchAgentData(manifest.Hostname, fts.RuntimeDependenciesStartDate, minimumHitsCount, maxTimeout)
5558
if err != nil {
5659
return err
5760
}
@@ -62,11 +65,8 @@ func (fts *FleetTestSuite) thereIsNewDataInTheIndexFromAgent() error {
6265
}
6366

6467
func (fts *FleetTestSuite) theDockerContainerIsStopped(serviceName string) error {
65-
services := []deploy.ServiceRequest{
66-
deploy.NewServiceRequest(common.FleetProfileName),
67-
deploy.NewServiceRequest(serviceName),
68-
}
69-
err := fts.deployer.Remove(services, common.ProfileEnv)
68+
agentService := deploy.NewServiceRequest(serviceName)
69+
err := fts.deployer.Stop(agentService)
7070
if err != nil {
7171
return err
7272
}
@@ -79,7 +79,9 @@ func (fts *FleetTestSuite) thereIsNoNewDataInTheIndexAfterAgentShutsDown() error
7979
maxTimeout := time.Duration(30) * time.Second
8080
minimumHitsCount := 1
8181

82-
result, err := searchAgentData(fts.Hostname, fts.AgentStoppedDate, minimumHitsCount, maxTimeout)
82+
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
83+
manifest, _ := fts.deployer.Inspect(agentService)
84+
result, err := searchAgentData(manifest.Hostname, fts.AgentStoppedDate, minimumHitsCount, maxTimeout)
8385
if err != nil {
8486
if strings.Contains(err.Error(), "type:index_not_found_exception") {
8587
return err
@@ -102,14 +104,14 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, flavour string, en
102104

103105
useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS")
104106
beatsLocalPath := shell.GetEnv("BEATS_LOCAL_PATH", "")
107+
105108
if useCISnapshots || beatsLocalPath != "" {
106109
// load the docker images that were already:
107110
// a. downloaded from the GCP bucket
108111
// b. fetched from the local beats binaries
109-
dockerInstaller := installer.GetElasticAgentInstaller("docker", image, common.BeatVersion, deployedAgentsCount)
110-
111-
dockerInstaller.PreInstallFn()
112-
112+
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
113+
dockerInstaller, _ := installer.Attach(fts.deployer, agentService, "docker")
114+
dockerInstaller.Preinstall()
113115
dockerImageTag += "-amd64"
114116
}
115117

@@ -140,14 +142,7 @@ func (fts *FleetTestSuite) startStandAloneAgent(image string, flavour string, en
140142
return err
141143
}
142144

143-
// get container hostname once
144-
hostname, err := deploy.GetContainerHostname(containerName)
145-
if err != nil {
146-
return err
147-
}
148-
149145
fts.Image = image
150-
fts.Hostname = hostname
151146

152147
err = fts.installTestTools(containerName)
153148
if err != nil {
@@ -208,7 +203,7 @@ func (fts *FleetTestSuite) installTestTools(containerName string) error {
208203
"containerName": containerName,
209204
}).Trace("Installing test tools ")
210205

211-
_, err := deploy.ExecCommandIntoContainer(context.Background(), deploy.NewServiceRequest(containerName), "root", cmd)
206+
_, err := deploy.ExecCommandIntoContainer(context.Background(), containerName, "root", cmd)
212207
if err != nil {
213208
log.WithFields(log.Fields{
214209
"command": cmd,

e2e/_suites/fleet/world.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ type IngestManagerTestSuite struct {
2323
}
2424

2525
func (imts *IngestManagerTestSuite) processStateOnTheHost(process string, state string) error {
26-
return imts.thereAreInstancesOfTheProcessInTheState("1", process, state)
26+
ocurrences := "1"
27+
if state == "uninstalled" || state == "stopped" {
28+
ocurrences = "0"
29+
}
30+
return imts.thereAreInstancesOfTheProcessInTheState(ocurrences, process, state)
2731
}
2832

2933
func (imts *IngestManagerTestSuite) thereAreInstancesOfTheProcessInTheState(ocurrences string, process string, state string) error {
@@ -34,8 +38,9 @@ func (imts *IngestManagerTestSuite) thereAreInstancesOfTheProcessInTheState(ocur
3438
if imts.Fleet.StandAlone {
3539
containerName = fmt.Sprintf("%s_%s_%d", profile, common.ElasticAgentServiceName, 1)
3640
} else {
37-
agentInstaller := imts.Fleet.getInstaller()
38-
containerName = imts.Fleet.getContainerName(agentInstaller)
41+
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
42+
manifest, _ := imts.Fleet.deployer.Inspect(agentService)
43+
containerName = manifest.Name
3944
}
4045

4146
count, err := strconv.Atoi(ocurrences)
@@ -100,6 +105,22 @@ func waitForProcess(deployer deploy.Deployment, service string, process string,
100105
cmds := []string{"pgrep", "-d", ",", process}
101106
output, err := deployer.ExecIn(serviceRequest, cmds)
102107
if err != nil {
108+
109+
if !mustBePresent && ocurrences == 0 {
110+
log.WithFields(log.Fields{
111+
"cmds": cmds,
112+
"desiredState": desiredState,
113+
"elapsedTime": exp.GetElapsedTime(),
114+
"error": err,
115+
"service": service,
116+
"mustBePresent": mustBePresent,
117+
"ocurrences": ocurrences,
118+
"process": process,
119+
"retry": retryCount,
120+
}).Warn("Process is not present and number of occurences is 0")
121+
return nil
122+
}
123+
103124
log.WithFields(log.Fields{
104125
"cmds": cmds,
105126
"desiredState": desiredState,

internal/common/defaults.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@ const FleetProfileName = "fleet"
2828
// FleetServerAgentServiceName the name of the service for the Elastic Agent
2929
const FleetServerAgentServiceName = "fleet-server"
3030

31+
// AgentStaleVersion is the version of the agent to use as a base during upgrade
32+
// It can be overriden by ELASTIC_AGENT_STALE_VERSION env var. Using latest GA as a default.
33+
var AgentStaleVersion = "7.13-SNAPSHOT"
34+
3135
// BeatVersionBase is the base version of the Beat to use
3236
var BeatVersionBase = "8.0.0-SNAPSHOT"
3337

3438
// BeatVersion is the version of the Beat to use
3539
// It can be overriden by BEAT_VERSION env var
3640
var BeatVersion = BeatVersionBase
3741

38-
// AgentStaleVersion is the version of the agent to use as a base during upgrade
39-
// It can be overriden by ELASTIC_AGENT_STALE_VERSION env var. Using latest GA as a default.
40-
var AgentStaleVersion = "7.13-SNAPSHOT"
41-
42-
// StackVersion is the version of the stack to use
43-
// It can be overriden by STACK_VERSION env var
44-
var StackVersion = BeatVersionBase
42+
// DeveloperMode if enabled will keep deployments around after test runs
43+
var DeveloperMode = false
4544

4645
// KibanaVersion is the version of kibana to use
4746
// It can be override by KIBANA_VERSION
@@ -54,6 +53,10 @@ var ProfileEnv map[string]string
5453
// Provider is the deployment provider used, currently docker is supported
5554
var Provider = "docker"
5655

56+
// StackVersion is the version of the stack to use
57+
// It can be overriden by STACK_VERSION env var
58+
var StackVersion = BeatVersionBase
59+
5760
// InitVersions initialise default versions. We do not want to do it in the init phase
5861
// supporting lazy-loading the versions when needed. Basically, the CLI part does not
5962
// need to load them
@@ -91,4 +94,24 @@ func InitVersions() {
9194
}).Fatal("Failed to get stack version, aborting")
9295
}
9396
StackVersion = v
97+
98+
KibanaVersion = shell.GetEnv("KIBANA_VERSION", "")
99+
if KibanaVersion == "" {
100+
// we want to deploy a released version for Kibana
101+
// if not set, let's use StackVersion
102+
KibanaVersion, err = utils.GetElasticArtifactVersion(StackVersion)
103+
if err != nil {
104+
log.WithFields(log.Fields{
105+
"error": err,
106+
"version": KibanaVersion,
107+
}).Fatal("Failed to get kibana version, aborting")
108+
}
109+
}
110+
111+
log.WithFields(log.Fields{
112+
"BeatVersionBase": BeatVersionBase,
113+
"BeatVersion": BeatVersion,
114+
"StackVersion": StackVersion,
115+
"KibanaVersion": KibanaVersion,
116+
}).Trace("Initial artifact versions defined")
94117
}

internal/deploy/base.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,47 @@ import (
1212
// required for testing
1313
type Deployment interface {
1414
Add(services []ServiceRequest, env map[string]string) error // adds a service to deployment
15+
AddFiles(service ServiceRequest, files []string) error // adds files to a service
1516
Bootstrap(waitCB func() error) error // will bootstrap or reuse existing cluster if kubernetes is selected
1617
Destroy() error // Teardown deployment
1718
ExecIn(service ServiceRequest, cmd []string) (string, error) // Execute arbitrary commands in service
1819
Inspect(service ServiceRequest) (*ServiceManifest, error) // inspects service
20+
Logs(service ServiceRequest) error // prints logs of deployed service
1921
Remove(services []ServiceRequest, env map[string]string) error // Removes services from deployment
22+
Start(service ServiceRequest) error // Starts a service or container depending on Deployment
23+
Stop(service ServiceRequest) error // Stop a service or container depending on deployment
24+
}
25+
26+
// ServiceOperator represents the operations that can be performed by a service
27+
type ServiceOperator interface {
28+
AddFiles(files []string) error // adds files to service environment
29+
Enroll(token string) error // handle any enrollment/registering of service
30+
Exec(args []string) (string, error) // exec arbitrary commands in service environment
31+
Inspect() (ServiceOperatorManifest, error) // returns manifest for package
32+
Install() error
33+
InstallCerts() error
34+
Logs() error
35+
Postinstall() error
36+
Preinstall() error
37+
Start() error // will start a service
38+
Stop() error // will stop a service
39+
Uninstall() error
40+
}
41+
42+
// ServiceOperatorManifest is state information for each service operator
43+
type ServiceOperatorManifest struct {
44+
CommitFile string
45+
WorkDir string
2046
}
2147

2248
// ServiceManifest information about a service in a deployment
2349
type ServiceManifest struct {
2450
ID string
2551
Name string
2652
Connection string // a string representing how to connect to service
53+
Alias string // container network aliases
2754
Hostname string
55+
Platform string // running in linux, macos, windows
2856
}
2957

3058
// ServiceRequest represents the service to be created using the provider

0 commit comments

Comments
 (0)