Skip to content

ci: build agent from snapshot DRA #9048

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 10 deletions .buildkite/integration.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ steps:
env:
PACKAGES: "docker"
PLATFORMS: "linux/amd64"
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud"
command: |
source .buildkite/scripts/common.sh
.buildkite/scripts/steps/integration-package.sh
echo "~~~ Pushing cloud image"
mage cloud:push
.buildkite/scripts/steps/integration-cloud-image-push.sh
artifact_paths:
- build/distributions/**
agents:
Expand Down Expand Up @@ -139,13 +135,9 @@ steps:
PACKAGES: "docker"
PLATFORMS: "linux/amd64"
FIPS: "true"
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips"
command: |
source .buildkite/scripts/common.sh
.buildkite/scripts/steps/integration-package.sh
echo "~~~ Pushing cloud image"
mage cloud:push
.buildkite/scripts/steps/integration-cloud-image-push.sh
artifact_paths:
- build/distributions/**
agents:
Expand Down
11 changes: 9 additions & 2 deletions .buildkite/scripts/buildkite-integration-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ go install gotest.tools/gotestsum
gotestsum --version

$env:TEST_BINARY_NAME = "elastic-agent"
if (-not $env:AGENT_VERSION) {
if (Test-Path .package-version)
{
$packageContent = Get-Content .package-version -Raw | ConvertFrom-Json
$env:AGENT_VERSION = $packageContent.version
Write-Output "~~~ Agent version: $env:AGENT_VERSION (from .package-version)"
}
else
{
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
$AGENT_VERSION = (Get-Content version/version.go | Select-String -Pattern 'const defaultBeatVersion =' | ForEach-Object { $_ -replace '.*?"(.*?)".*', '$1' })
$env:AGENT_VERSION = $AGENT_VERSION + "-SNAPSHOT"
Write-Output "~~~ Agent version: $env:AGENT_VERSION (from version/version.go)"
}

Write-Output "~~~ Agent version: $env:AGENT_VERSION"
$env:SNAPSHOT = $true

Write-Host "~~~ Running integration tests as $env:USERNAME"
Expand Down
8 changes: 5 additions & 3 deletions .buildkite/scripts/buildkite-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ echo "~~~ Running integration tests as $USER"

make install-gotestsum

if [[ -z "${AGENT_VERSION:-}" ]]; then
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
if [[ -f "${WORKSPACE}/.package-version" ]]; then
AGENT_VERSION="$(jq -r '.version' .package-version)"
echo "~~~ Agent version: ${AGENT_VERSION} (from .package-version)"
else
AGENT_VERSION=$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
echo "~~~ Agent version: ${AGENT_VERSION} (from version/version.go)"
fi

export AGENT_VERSION
echo "~~~ Agent version: ${AGENT_VERSION}"

os_data=$(uname -spr | tr ' ' '_')
root_suffix=""
Expand Down
9 changes: 7 additions & 2 deletions .buildkite/scripts/buildkite-k8s-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ set -euo pipefail
DOCKER_VARIANTS="${DOCKER_VARIANTS:-basic,wolfi,complete,complete-wolfi,service,cloud}"
CLUSTER_NAME="${K8S_VERSION}-kubernetes"

if [[ -z "${AGENT_VERSION:-}" ]]; then
# If not specified, use the version in version/version.go
if [[ -f "${WORKSPACE}/.package-version" ]]; then
AGENT_VERSION="$(jq -r '.version' .package-version)"
echo "~~~ Agent version: ${AGENT_VERSION} (from .package-version)"
else
AGENT_VERSION="$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)"
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
echo "~~~ Agent version: ${AGENT_VERSION} (from version/version.go)"
fi

export AGENT_VERSION

echo "~~~ Create kind cluster '${CLUSTER_NAME}'"
kind create cluster --image "kindest/node:${K8S_VERSION}" --name "${CLUSTER_NAME}" --wait 60s --config - <<EOF
kind: Cluster
Expand Down
7 changes: 5 additions & 2 deletions .buildkite/scripts/steps/ess.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function ess_up {
param (
[string]$StackVersion,
[string]$StackBuildId = "",
[string]$EssRegion = "gcp-us-west2"
)

Expand All @@ -22,6 +23,7 @@ function ess_up {
& terraform init
& terraform apply -auto-approve `
-var="stack_version=$StackVersion" `
-var="stack_build_id=$StackBuildId" `
-var="ess_region=$EssRegion" `
-var="creator=$BuildkiteBuildCreator" `
-var="buildkite_id=$BuildkiteBuildNumber" `
Expand Down Expand Up @@ -99,12 +101,13 @@ function Retry-Command {

function Get-Ess-Stack {
param (
[string]$StackVersion
[string]$StackVersion,
[string]$StackBuildId = ""
)

if ($Env:BUILDKITE_RETRY_COUNT -gt 0) {
Write-Output "The step is retried, starting the ESS stack again"
ess_up $StackVersion
ess_up $StackVersion $StackBuildId
Write-Output "ESS stack is up. ES_HOST: $Env:ELASTICSEARCH_HOST"
} else {
# For the first run, we retrieve ESS stack metadata
Expand Down
4 changes: 3 additions & 1 deletion .buildkite/scripts/steps/ess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function ess_up() {
local WORKSPACE=$(git rev-parse --show-toplevel)
local TF_DIR="${WORKSPACE}/test_infra/ess/"
local STACK_VERSION=$1
local ESS_REGION=${2:-"gcp-us-west2"}
local STACK_BUILD_ID=${2:-""}
local ESS_REGION=${3:-"gcp-us-west2"}

if [ -z "$STACK_VERSION" ]; then
echo "Error: Specify stack version: ess_up [stack_version]" >&2
Expand All @@ -22,6 +23,7 @@ function ess_up() {
terraform apply \
-auto-approve \
-var="stack_version=${STACK_VERSION}" \
-var="stack_build_id=${STACK_BUILD_ID}" \
-var="ess_region=${ESS_REGION}" \
-var="creator=${BUILDKITE_BUILD_CREATOR}" \
-var="buildkite_id=${BUILDKITE_BUILD_NUMBER}" \
Expand Down
6 changes: 3 additions & 3 deletions .buildkite/scripts/steps/ess_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set -euo pipefail
source .buildkite/scripts/steps/ess.sh
source .buildkite/scripts/steps/fleet.sh

OVERRIDE_STACK_VERSION="$(cat .package-version)"
OVERRIDE_STACK_VERSION=${OVERRIDE_STACK_VERSION}"-SNAPSHOT"
STACK_VERSION="$(jq -r '.version' .package-version)"
STACK_BUILD_ID="$(jq -r '.stack_build_id' .package-version)"

ess_up $OVERRIDE_STACK_VERSION
ess_up "$STACK_VERSION" "$STACK_BUILD_ID"

preinstall_fleet_packages

Expand Down
20 changes: 20 additions & 0 deletions .buildkite/scripts/steps/integration-cloud-image-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

source .buildkite/scripts/common.sh

echo "~~~ Pushing cloud image"

if [ "${FIPS:-false}" == "true" ]; then
CI_ELASTIC_AGENT_DOCKER_IMAGE="docker.elastic.co/beats-ci/elastic-agent-cloud-fips"
else
CI_ELASTIC_AGENT_DOCKER_IMAGE="docker.elastic.co/beats-ci/elastic-agent-cloud"
fi
export CI_ELASTIC_AGENT_DOCKER_IMAGE
echo "CI_ELASTIC_AGENT_DOCKER_IMAGE: ${CI_ELASTIC_AGENT_DOCKER_IMAGE}"


export CUSTOM_IMAGE_TAG="git-${BUILDKITE_COMMIT:0:12}"
export USE_PACKAGE_VERSION="true"

mage cloud:push
1 change: 1 addition & 0 deletions .buildkite/scripts/steps/integration-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ source .buildkite/scripts/common.sh

export SNAPSHOT="true"
export EXTERNAL="true"
export USE_PACKAGE_VERSION="true"

mage package
11 changes: 1 addition & 10 deletions .buildkite/scripts/steps/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ source .buildkite/scripts/common.sh
STACK_PROVISIONER="${1:-"stateful"}"
MAGE_TARGET="${2:-"integration:test"}"
MAGE_SUBTARGET="${3:-""}"


# Override the stack version from `.package-version` contents
# There is a time when the current snapshot is not available on cloud yet, so we cannot use the latest version automatically
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready.

STACK_VERSION="$(cat .package-version)"
if [[ -n "$STACK_VERSION" ]]; then
STACK_VERSION=${STACK_VERSION}"-SNAPSHOT"
fi
USE_PACKAGE_VERSION="true"

# Run integration tests
set +e
Expand Down
15 changes: 10 additions & 5 deletions .buildkite/scripts/steps/integration_tests_tf.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ $PSVersionTable.PSVersion

. "$PWD\.buildkite\scripts\steps\ess.ps1"

# Read package version from .package-version file
$PACKAGE_VERSION = Get-Content .package-version -ErrorAction SilentlyContinue
if ($PACKAGE_VERSION) {
$PACKAGE_VERSION = "${PACKAGE_VERSION}-SNAPSHOT"
# Override the stack version from `.package-version` contents
# There is a time when the current snapshot is not available on cloud yet, so we cannot use the latest version automatically
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready
$packageVersionContent = Get-Content .package-version -Raw -ErrorAction SilentlyContinue | ConvertFrom-Json
if ($packageVersionContent -and $packageVersionContent.version ) {
$STACK_VERSION = $packageVersionContent.version
}
if ($packageVersionContent -and $packageVersionContent.stack_build_id ) {
$STACK_BUILD_ID = $packageVersionContent.stack_build_id
}

Write-Output "~~~ Building test binaries"
Expand All @@ -27,7 +32,7 @@ $TestsExitCode = 0
try {
Write-Output "~~~ Running integration tests"
# Get-Ess-Stack will start the ESS stack if it is a BK retry, otherwise it will retrieve ESS stack metadata
Get-Ess-Stack -StackVersion $PACKAGE_VERSION
Get-Ess-Stack -StackVersion $STACK_VERSION $STACK_BUILD_ID
& "$PWD\.buildkite\scripts\buildkite-integration-tests.ps1" $GROUP_NAME $TEST_SUDO
$TestsExitCode = $LASTEXITCODE
if ($TestsExitCode -ne 0)
Expand Down
10 changes: 5 additions & 5 deletions .buildkite/scripts/steps/integration_tests_tf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ if [ -z "$TEST_SUDO" ]; then
exit 1
fi

# Override the agent package version using a string with format <major>.<minor>.<patch>
# There is a time when the snapshot is not built yet, so we cannot use the latest version automatically
# Override the stack version from `.package-version` contents
# There is a time when the current snapshot is not available on cloud yet, so we cannot use the latest version automatically
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready.
OVERRIDE_STACK_VERSION="$(cat .package-version)"
OVERRIDE_STACK_VERSION=${OVERRIDE_STACK_VERSION}"-SNAPSHOT"
STACK_VERSION="$(jq -r '.version' .package-version)"
STACK_BUILD_ID="$(jq -r '.stack_build_id' .package-version)"

echo "~~~ Building test binaries"
mage build:testBinaries
Expand All @@ -35,7 +35,7 @@ mage build:testBinaries
if [[ "${BUILDKITE_RETRY_COUNT}" -gt 0 || "${FORCE_ESS_CREATE:-false}" == "true" ]]; then
echo "~~~ The steps is retried, starting the ESS stack again"
trap 'ess_down' EXIT
ess_up $OVERRIDE_STACK_VERSION || (echo -e "^^^ +++\nFailed to start ESS stack")
ess_up "$STACK_VERSION" "$STACK_BUILD_ID" || (echo -e "^^^ +++\nFailed to start ESS stack")
else
# For the first run, we start the stack in the start_ess.sh step and it sets the meta-data
echo "~~~ Receiving ESS stack metadata"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bump-agent-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
git add testing/integration/testdata/.upgrade-test-agent-versions.yml .package-version

nl=$'\n' # otherwise the new line character is not recognized properly
commit_desc="These files are used for picking the starting (pre-upgrade) or ending (post-upgrade) agent versions in upgrade integration tests.${nl}${nl}The content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co${nl}${nl}The current update is generated based on the following requirements:${nl}${nl}Package version: ${package_version}${nl}${nl}\`\`\`json${nl}${version_requirements}${nl}\`\`\`"
commit_desc="These files are used for picking the starting (pre-upgrade) or ending (post-upgrade) agent versions in upgrade integration tests.${nl}${nl}The content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co${nl}${nl}The current update is generated based on the following requirements:${nl}${nl}Package version: \`\`\`json${nl}${package_version}${nl}\`\`\`${nl}${nl}\`\`\`json${nl}${version_requirements}${nl}\`\`\`"

git commit -m "[$current_ref][Automation] Update versions" -m "$commit_desc"
git push --set-upstream origin "$pr_branch"
Expand Down
9 changes: 8 additions & 1 deletion .package-version
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
9.2.0
{
"version": "9.2.0-SNAPSHOT",
"build_id": "9.2.0-293a6bca",
"manifest_url": "https://snapshots.elastic.co/9.2.0-293a6bca/manifest-9.2.0-SNAPSHOT.json",
"summary_url": "https://snapshots.elastic.co/9.2.0-293a6bca/summary-9.2.0-SNAPSHOT.html",
"core_version": "9.2.0",
"stack_build_id": "9.2.0-293a6bca-SNAPSHOT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ crds:
defaultCRConfig:
image:
repository: "docker.elastic.co/elastic-agent/elastic-agent"
tag: "9.2.0"
tag: "9.3.0"
targetAllocator:
enabled: false # Enable/disable the Operator's Target allocator.
# Refer to: https://github.com/open-telemetry/opentelemetry-operator/tree/main/cmd/otel-allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ crds:
defaultCRConfig:
image:
repository: "docker.elastic.co/elastic-agent/elastic-agent"
tag: "9.2.0"
tag: "9.3.0"
targetAllocator:
enabled: false # Enable/disable the Operator's Target allocator.
# Refer to: https://github.com/open-telemetry/opentelemetry-operator/tree/main/cmd/otel-allocator
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/edot-collector/kube-stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ crds:
defaultCRConfig:
image:
repository: "docker.elastic.co/elastic-agent/elastic-agent"
tag: "9.2.0"
tag: "9.3.0"
targetAllocator:
enabled: false # Enable/disable the Operator's Target allocator.
# Refer to: https://github.com/open-telemetry/opentelemetry-operator/tree/main/cmd/otel-allocator
Expand Down
4 changes: 2 additions & 2 deletions deploy/helm/elastic-agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: elastic-agent
description: Elastic-Agent Helm Chart
kubeVersion: ">= 1.27.0-0"
type: application
appVersion: 9.2.0
version: 9.2.0-beta
appVersion: 9.3.0
version: 9.3.0-beta
dependencies:
- name: kube-state-metrics
version: "5.30.1"
Expand Down
Loading
Loading