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

feat: bootstrap fleet-server for the deployment of regular elastic-agents#1078

Merged
mdelapenya merged 34 commits intoelastic:masterfrom
mdelapenya:fleet-server-agents
Apr 27, 2021
Merged

feat: bootstrap fleet-server for the deployment of regular elastic-agents#1078
mdelapenya merged 34 commits intoelastic:masterfrom
mdelapenya:fleet-server-agents

Conversation

@mdelapenya
Copy link
Copy Markdown
Contributor

@mdelapenya mdelapenya commented Apr 22, 2021

What does this PR do?

It converts existing deployments of regular agents to use a bootstrapped fleet-server. For that, we:

  • cloned the centos/debian services into fleet-server centos/debian ones. This is needed to simplify the generation of namespaces, service names and container names.
  • extracted common logic to calculate the container and service name. This method will internally use the installer struct to get the image and service from there. For context, the container name follows the profile-image-service-index pattern.
  • turned back to use the step to deploy a regular agent instead of a fleet-server one (the latter bootstrapped fleet-server). This was added in the previous refactor to make test pass after recent kibana breaking changes when enrolling agents using fleet-server. This new step is always bootstrapping a fleet-server, waiting for it to be online first.
  • added a reference to the fleet server hostname in the fleet struct, so that it's empty at the beginning of each scenario, and populated right after a bootstrap happens. With this approach, the deployment will create the Fleet configuration using that hostname, and depending on that will create the right flags for installing/enrolling the agent with an already bootstrapped fleet server (if the fleet-server hostname is not empty), or bootstrapping fleet-server (if the hostname is empty).
  • fixed the flags used to communicate with fleet-server. As we bootstrap it with HTTPS, we need to use https in the connection URL.
  • fixed how the enrollment token was created. For agents using an already bootstrapped fleet-server, the token must becreated from the default fleet policy, not the fleet server one.
  • performed minor refactors, such as renaming a variable for consistency and readability

Why is it important?

It adds fleet-server support, keeping up with current development status for Fleet project.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have run the Unit tests for the CLI, and they are passing locally
  • I have run the End-2-End tests for the suite I'm working on, and they are passing locally
  • I have noticed new Go dependencies (run make notice in the proper directory)

How to test this PR locally

$ SUITE="fleet" TAGS="fleet_mode_agent && centos" TIMEOUT_FACTOR=3 LOG_LEVEL=TRACE BEATS_USE_CI_SNAPSHOT=false DEVELOPER_MODE=false make -C e2e functional-test

Related issues

@mdelapenya mdelapenya self-assigned this Apr 22, 2021
@mdelapenya mdelapenya requested a review from a team April 22, 2021 18:58
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 22, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #1078 updated

  • Start Time: 2021-04-27T16:25:14.544+0000

  • Duration: 22 min 19 sec

  • Commit: c5121f9

Test stats 🧪

Test Results
Failed 0
Passed 152
Skipped 0
Total 152

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 152
Skipped 0
Total 152

@mdelapenya
Copy link
Copy Markdown
Contributor Author

@adam-stokes I'm tempted to remove the fleet-server feature file, and move the bootstrap of the fleet server agent to the beforeSuite hook, so that the fleet server is always running (only bootstrapped once). This will reduce the build time, as we do not have to bootstrap-and-wait for the server to be online. Thoughts?

@adam-stokes
Copy link
Copy Markdown
Contributor

@adam-stokes I'm tempted to remove the fleet-server feature file, and move the bootstrap of the fleet server agent to the beforeSuite hook, so that the fleet server is always running (only bootstrapped once). This will reduce the build time, as we do not have to bootstrap-and-wait for the server to be online. Thoughts?

Yea I think this is a good idea +1

@mdelapenya
Copy link
Copy Markdown
Contributor Author

mdelapenya commented Apr 27, 2021

jenkins run the tests please

@adam-stokes adam-stokes marked this pull request as ready for review April 27, 2021 16:52
@mdelapenya mdelapenya merged commit 193337a into elastic:master Apr 27, 2021
mergify bot pushed a commit that referenced this pull request Apr 27, 2021
…ents (#1078)

* chore: provide a fleet-server base image based on centos/debian with systemd

* WIP

* fix: remove duplicated fields after merge conflicts

* fix: update method call after merge conflicts

* chore: extract service name calculation to a method

* chore: extract container name calculation to a method

* chore: refactor get container name method

* chore: refactor method even more

* chore: use installer state to retrieve container name

* chore: use installer when calculating service name

* fix: adapt service names for fleet server

* chore: enrich log when creating an installer

* fix: use fleet server host when creating fleet config

* fix: use https when connecting to fleet-server

It's creating its own self-signed certs

* feat: bootstrap a fleet server before a regular agent is deployed to fleet

It will define the server host to be used when enrolling agents

* fix: use fleet policy for agents, not the server one

* fix: get different installers for fleet-server and agents

* fix: use the old step for deploying regular agents

* chore: rename variable with consistent name

* chore: rename fleet-server scenario

* fix: use proper container name for standalone mode

* chore: save two variables

* chore: rename standalone scenario for bootstrapping fleet-server

* chore: rename bootstrap methods

* chore: encapsulate bootstrap fleet-server logic

* Update fleet.go

* chore: remove Fleet Server CI parallel execution

* chore: remove feature file for fleet-server

* chore: boostrap fleet server only once

We want to have it bootstrapped for the entire test suite, not for each scenario

* fix: an agent was needed when adding integrations

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
(cherry picked from commit 193337a)
mdelapenya added a commit to mdelapenya/e2e-testing that referenced this pull request Apr 27, 2021
* master:
  Support fleet-server-service-token (elastic#1096)
  fix: use wider selector for ARM workers (elastic#1103)
  feat: bootstrap fleet-server for the deployment of regular elastic-agents (elastic#1078)
  fix: use proper variable name (elastic#1102)
  fix: branch_specifier is needed (elastic#1097)
  Move kubernetes/kubectl/kind code to internal project layout (elastic#1092)
  fix: update JJBB with proper values (elastic#1093)
  feat: support building centos/debian Docker images in multiplatform format (elastic#1091)
  Kubernetes autodiscover suite (elastic#1064)
mdelapenya added a commit to mdelapenya/e2e-testing that referenced this pull request May 4, 2021
…ents (elastic#1078)

* chore: provide a fleet-server base image based on centos/debian with systemd

* WIP

* fix: remove duplicated fields after merge conflicts

* fix: update method call after merge conflicts

* chore: extract service name calculation to a method

* chore: extract container name calculation to a method

* chore: refactor get container name method

* chore: refactor method even more

* chore: use installer state to retrieve container name

* chore: use installer when calculating service name

* fix: adapt service names for fleet server

* chore: enrich log when creating an installer

* fix: use fleet server host when creating fleet config

* fix: use https when connecting to fleet-server

It's creating its own self-signed certs

* feat: bootstrap a fleet server before a regular agent is deployed to fleet

It will define the server host to be used when enrolling agents

* fix: use fleet policy for agents, not the server one

* fix: get different installers for fleet-server and agents

* fix: use the old step for deploying regular agents

* chore: rename variable with consistent name

* chore: rename fleet-server scenario

* fix: use proper container name for standalone mode

* chore: save two variables

* chore: rename standalone scenario for bootstrapping fleet-server

* chore: rename bootstrap methods

* chore: encapsulate bootstrap fleet-server logic

* Update fleet.go

* chore: remove Fleet Server CI parallel execution

* chore: remove feature file for fleet-server

* chore: boostrap fleet server only once

We want to have it bootstrapped for the entire test suite, not for each scenario

* fix: an agent was needed when adding integrations

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
@mdelapenya mdelapenya mentioned this pull request May 4, 2021
8 tasks
adam-stokes added a commit that referenced this pull request May 4, 2021
* feat: support building centos/debian Docker images in multiplatform format (#1091)

* chore: copy Centos+Systemd Dockerfile from origin

See https://github.com/CentOS/CentOS-Dockerfiles/tree/master/systemd/centos7

* chore: copy debian+systemd Dockerfile from origin

See https://github.com/alehaa/docker-debian-systemd

* chore: add script to build&push ARCH-based images for centos and debian

* chore: add script to push the multiplatform manifest for centos and debian

This script leverages infra's tool to write the manifest, which needs to
be ran right after the images have been built and pushed. Therefore, the
tool will write the manifest for both platforms (AMD/ARM), inspecting
the existing platform-specific repositories, combining them into the target.

FYI, the '-ARCH' placeholder will be replaced with the values in the
'--platforms' argument

* chore: add regular pipeline to build the docker images

* fix: default arch variable value

* chore: abstract image name from file system

* chore: couple agent's base box with stack platform

* Move kubernetes/kubectl/kind code to internal project layout (#1092)

This is mainly a cleanup to keep all internal related code that could be
reusable in our `internal` directory layout.

Next steps would be to take what's in `internal/kubectl` and merge with this code.

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* feat: bootstrap fleet-server for the deployment of regular elastic-agents (#1078)

* chore: provide a fleet-server base image based on centos/debian with systemd

* WIP

* fix: remove duplicated fields after merge conflicts

* fix: update method call after merge conflicts

* chore: extract service name calculation to a method

* chore: extract container name calculation to a method

* chore: refactor get container name method

* chore: refactor method even more

* chore: use installer state to retrieve container name

* chore: use installer when calculating service name

* fix: adapt service names for fleet server

* chore: enrich log when creating an installer

* fix: use fleet server host when creating fleet config

* fix: use https when connecting to fleet-server

It's creating its own self-signed certs

* feat: bootstrap a fleet server before a regular agent is deployed to fleet

It will define the server host to be used when enrolling agents

* fix: use fleet policy for agents, not the server one

* fix: get different installers for fleet-server and agents

* fix: use the old step for deploying regular agents

* chore: rename variable with consistent name

* chore: rename fleet-server scenario

* fix: use proper container name for standalone mode

* chore: save two variables

* chore: rename standalone scenario for bootstrapping fleet-server

* chore: rename bootstrap methods

* chore: encapsulate bootstrap fleet-server logic

* Update fleet.go

* chore: remove Fleet Server CI parallel execution

* chore: remove feature file for fleet-server

* chore: boostrap fleet server only once

We want to have it bootstrapped for the entire test suite, not for each scenario

* fix: an agent was needed when adding integrations

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* apm-server tests (#1083)

* some tests for apm-server
* clean op dir on init instead of after

* fix agent uninstall (#1111)

* Auto bootstrap fleet during initialize scenario (#1116)

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>

* feat: support running k8s autodiscover suite for Beats PRs and local repositories (#1115)

* chore: add license

* chore: initialise configurations before test suite

* chore: use timeout_factor from env

* fix: tell kind to skip pulling beats images

* chore: add a method to load images into kind

* feat: support running k8s autodiscover for Beats PRs or local filesystem

* chore: add license header

* chore: expose logger and use it, simplifying initialisation

* fix: only run APM services for local APM environment

* Revert "chore: expose logger and use it, simplifying initialisation"

This reverts commit a89325c.

* chore: log scenario name

* fix: always cache beat version for podName

* chore: reduce log level

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
Co-authored-by: Juan Álvarez <juan.alvarez@elastic.co>
@mdelapenya mdelapenya deleted the fleet-server-agents branch May 6, 2021 09:33
mdelapenya added a commit to mdelapenya/e2e-testing that referenced this pull request May 17, 2021
…ents (elastic#1078)

* chore: provide a fleet-server base image based on centos/debian with systemd

* WIP

* fix: remove duplicated fields after merge conflicts

* fix: update method call after merge conflicts

* chore: extract service name calculation to a method

* chore: extract container name calculation to a method

* chore: refactor get container name method

* chore: refactor method even more

* chore: use installer state to retrieve container name

* chore: use installer when calculating service name

* fix: adapt service names for fleet server

* chore: enrich log when creating an installer

* fix: use fleet server host when creating fleet config

* fix: use https when connecting to fleet-server

It's creating its own self-signed certs

* feat: bootstrap a fleet server before a regular agent is deployed to fleet

It will define the server host to be used when enrolling agents

* fix: use fleet policy for agents, not the server one

* fix: get different installers for fleet-server and agents

* fix: use the old step for deploying regular agents

* chore: rename variable with consistent name

* chore: rename fleet-server scenario

* fix: use proper container name for standalone mode

* chore: save two variables

* chore: rename standalone scenario for bootstrapping fleet-server

* chore: rename bootstrap methods

* chore: encapsulate bootstrap fleet-server logic

* Update fleet.go

* chore: remove Fleet Server CI parallel execution

* chore: remove feature file for fleet-server

* chore: boostrap fleet server only once

We want to have it bootstrapped for the entire test suite, not for each scenario

* fix: an agent was needed when adding integrations

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
mdelapenya added a commit that referenced this pull request May 17, 2021
* Move kubernetes/kubectl/kind code to internal project layout (#1092)

This is mainly a cleanup to keep all internal related code that could be
reusable in our `internal` directory layout.

Next steps would be to take what's in `internal/kubectl` and merge with this code.

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* feat: bootstrap fleet-server for the deployment of regular elastic-agents (#1078)

* chore: provide a fleet-server base image based on centos/debian with systemd

* WIP

* fix: remove duplicated fields after merge conflicts

* fix: update method call after merge conflicts

* chore: extract service name calculation to a method

* chore: extract container name calculation to a method

* chore: refactor get container name method

* chore: refactor method even more

* chore: use installer state to retrieve container name

* chore: use installer when calculating service name

* fix: adapt service names for fleet server

* chore: enrich log when creating an installer

* fix: use fleet server host when creating fleet config

* fix: use https when connecting to fleet-server

It's creating its own self-signed certs

* feat: bootstrap a fleet server before a regular agent is deployed to fleet

It will define the server host to be used when enrolling agents

* fix: use fleet policy for agents, not the server one

* fix: get different installers for fleet-server and agents

* fix: use the old step for deploying regular agents

* chore: rename variable with consistent name

* chore: rename fleet-server scenario

* fix: use proper container name for standalone mode

* chore: save two variables

* chore: rename standalone scenario for bootstrapping fleet-server

* chore: rename bootstrap methods

* chore: encapsulate bootstrap fleet-server logic

* Update fleet.go

* chore: remove Fleet Server CI parallel execution

* chore: remove feature file for fleet-server

* chore: boostrap fleet server only once

We want to have it bootstrapped for the entire test suite, not for each scenario

* fix: an agent was needed when adding integrations

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* apm-server tests (#1083)

* some tests for apm-server
* clean op dir on init instead of after

* fix agent uninstall (#1111)

* Kubernetes Deployment (#1110)

* Kubernetes Deployment

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* Expose hostPort for kibana, elasticsearch, fleet without needing ingress

This is nice for local development where you don't need an ingress and are
relatively sure that the host system has the required ports available to bind to.

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* Auto bootstrap fleet during initialize scenario (#1116)

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>

* feat: support running k8s autodiscover suite for Beats PRs and local repositories (#1115)

* chore: add license

* chore: initialise configurations before test suite

* chore: use timeout_factor from env

* fix: tell kind to skip pulling beats images

* chore: add a method to load images into kind

* feat: support running k8s autodiscover for Beats PRs or local filesystem

* chore: add license header

* chore: expose logger and use it, simplifying initialisation

* fix: only run APM services for local APM environment

* Revert "chore: expose logger and use it, simplifying initialisation"

This reverts commit a89325c.

* chore: log scenario name

* fix: always cache beat version for podName

* chore: reduce log level

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* chore: initialise timeout factor next to the declaration (#1118)

* chore: initialise timeout factor on its own package

* chore: reuse timeout factor from common

* Unify fleet and stand-alone suites (#1112)

* fix agent uninstall

* unify fleet and stand alone suites

* move things around a bit more

* fixe bad merge

* simplify some things

* chore: remove unused code (#1119)

* chore: remove unused code

* chore: remove all references to fleet server hostname

Because we assume it's a runtime dependency, provided by the initial
compose file, we do not need to calculate service names, or URIs for the
fleet-service endpoint. Instead, we assume it's listening in the 8220 port
in the "fleet-server" hostname, which is accessible from the network
created by docker-compose.

* fix: use HTTP to connect to fleet-server

* chore: remove fleet server policy code

We do not need it anymore, as the fleet server is already bootstrapped

* chore: remove all policies but system and fleet_server

* Update policies.go

* Update fleet.go

* Update stand-alone.go

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>

* Support multiple deployment backends (#1130)

* Abstract out deployment

Provides ability to plugin different deployment backends for use in testing.
Current deployment backends supported are "docker" and "kubernetes"

* remove unused import
* remove unsetting of fleet server hostname as it's not needed
* add deployer support to stand-alone
* add elastic-agent to k8s deployment specs
* Update internal/docker/docker.go

Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>

* fix: bump stale agent version to 7.12-snapshot

* chore: abstract process checks to the deployer (#1156)

* chore: abstract process checks to the deployer

* chore: rename variable in log entry

* docs: improve comment

* fix: go-fmt

* feat: simplify the initialisation of versions (#1159)

* chore: use fixed version in shell scripts

* chore: move retry to utils

We could move it to its own package, but at this moment it's very small

* chore: initialise stackVesion at one single place

* chore: initialise agent version base at one single place

* chore: initialise agent version at one single place

* chore: reduce the number of requests to Elastic's artifacts endpoint

* chore: rename AgentVersionBase variable to BeatVersionBase

* chore: rename AgentVersion variable to BeatVersion

* chore: use Beat version in metricbeat test suite

* chore: check if the version must use the fallback after coming from a Git SHA

* feat: support flavours in services, specially in the elastic-agent (#1162)

* chore: move compose to deploy package

* feat: use a ServiceRequest when adding services

* feat: add service flavour support

* chore: remove unused centos/debian services

* fixup: add service flavour

* chore: move docker client to the deploy package

We will need another abstraction to represent the Docker client operations,
as it's clear what is a deployment and what is an operation in the deployment.
Maybe a Client struct for each provider will help out in differenciate it

* chore: use ServiceRequest everywhere

* chore: run agent commands with a ServiceRequest

* chore: use ServiceRequest in metricbeat test suite

* chore: pass flavours to installers

* chore: add a step to install the agent for the underlying OS

* chore: always add flavour

* fix: use installer for fleet_mode when removing services at the end of the scenario

* fix: update broken references in metricbeat test suite

* fix: update broken references in helm test suite

* fix: standalone does not have an installer

* fix: use service instead of image to get a service request for the agent

* feat: support for scaling services in compose

* fix: run second agent using compose scale option

* fix: update kibana's default Docker namespace

* feat: make a stronger verification of fleet-server being bootstrapped (#1164)

* fix: resolve issues in k8s-autodiscover test suite (#1171)

* chore: use timeout factor when tagging docker images

* fix: resolve alias version in k8s-autodiscover test suite

* fix: use common versions for k8s-autodiscover

* fix: update background processes to 2 instances

Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
Co-authored-by: Juan Álvarez <juan.alvarez@elastic.co>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants