Skip to content

Commit a992ff1

Browse files
committed
Merge upstream/main into update-archive-dep
2 parents a79d5db + 7d2ba17 commit a992ff1

File tree

11 files changed

+287
-36
lines changed

11 files changed

+287
-36
lines changed

.buildkite/configs/cleanup.aws.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ accounts:
55
- name: "${ACCOUNT_PROJECT}"
66
driver: "aws"
77
options:
8-
key: '${ACCOUNT_KEY}'
9-
secret: '${ACCOUNT_SECRET}'
8+
key: '${AWS_ACCESS_KEY_ID}'
9+
secret: '${AWS_SECRET_ACCESS_KEY}'
1010

1111
scanners:
1212
- account_name: "${ACCOUNT_PROJECT}"

.buildkite/hooks/pre-command

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export SERVERLESS=${SERVERLESS:-"false"}
1010
WORKSPACE=$(pwd)
1111
export WORKSPACE
1212

13-
AWS_SERVICE_ACCOUNT_SECRET_PATH=kv/ci-shared/platform-ingest/aws_ingest_ci
1413
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account
1514

1615
EC_TOKEN_PATH=kv/ci-shared/platform-ingest/platform-ingest-ec-qa
@@ -91,7 +90,10 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package-test-with-integrations" &&
9190
export GITHUB_TOKEN=$VAULT_GITHUB_TOKEN
9291
fi
9392

93+
# NOTE: this approach is deprecated and will be removed in the near future.
94+
# see https://github.com/elastic/observability-robots/issues/2771 (only accessible by Elastic employees)
9495
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package-cloud-cleanup" && "$BUILDKITE_STEP_KEY" == "cloud-cleanup" ]]; then
96+
AWS_SERVICE_ACCOUNT_SECRET_PATH=kv/ci-shared/platform-ingest/aws_ingest_ci
9597
ELASTIC_PACKAGE_AWS_SECRET_KEY=$(retry 5 vault kv get -field secret_key ${AWS_SERVICE_ACCOUNT_SECRET_PATH})
9698
export ELASTIC_PACKAGE_AWS_SECRET_KEY
9799
ELASTIC_PACKAGE_AWS_ACCESS_KEY=$(retry 5 vault kv get -field access_key ${AWS_SERVICE_ACCOUNT_SECRET_PATH})

.buildkite/pipeline.cloud-cleanup.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ steps:
2525
if: "build.source == 'ui'"
2626
allow_dependency_failure: false
2727

28-
- label: "Cloud Cleanup"
28+
- label: "Cloud Cleanup OIDC"
29+
key: "cloud-cleanup-oidc"
30+
command: ".buildkite/scripts/cloud-cleanup-oidc.sh"
31+
env:
32+
RESOURCE_RETENTION_PERIOD: "24 hours"
33+
DRY_RUN: "${DRY_RUN:-true}"
34+
agents:
35+
provider: "gcp" # this step requires docker
36+
plugins:
37+
- elastic/oblt-aws-auth#v0.1.0:
38+
duration: 3600 # seconds
39+
40+
- label: "Cloud Cleanup (deprecated)"
2941
key: "cloud-cleanup"
3042
command: ".buildkite/scripts/cloud-cleanup.sh"
3143
env:
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
#!/usr/bin/env bash
2+
3+
source .buildkite/scripts/install_deps.sh
4+
5+
cleanup_cloud_stale() {
6+
local exit_code=$?
7+
8+
cd "$WORKSPACE"
9+
rm -f "${AWS_RESOURCES_FILE}"
10+
rm -f "${AWS_REDSHIFT_RESOURCES_FILE}"
11+
12+
exit "$exit_code"
13+
}
14+
15+
trap cleanup_cloud_stale EXIT
16+
17+
set -euo pipefail
18+
19+
AWS_RESOURCES_FILE="aws.resources.txt"
20+
AWS_REDSHIFT_RESOURCES_FILE="redshift_clusters.json"
21+
22+
RESOURCE_RETENTION_PERIOD="${RESOURCE_RETENTION_PERIOD:-"24 hours"}"
23+
DELETE_RESOURCES_BEFORE_DATE=$(date -Is -d "${RESOURCE_RETENTION_PERIOD} ago")
24+
export DELETE_RESOURCES_BEFORE_DATE
25+
26+
CLOUD_REAPER_IMAGE="${DOCKER_REGISTRY}/observability-ci/cloud-reaper:0.3.0"
27+
28+
DRY_RUN="$(buildkite-agent meta-data get DRY_RUN --default "${DRY_RUN:-"true"}")"
29+
30+
resources_to_delete=0
31+
32+
COMMAND="validate"
33+
if [[ "${DRY_RUN}" != "true" ]]; then
34+
# TODO: to be changed to "destroy --confirm" once it can be tested
35+
# that filters work as expected
36+
COMMAND="plan"
37+
else
38+
COMMAND="plan"
39+
fi
40+
41+
any_resources_to_delete() {
42+
local file=$1
43+
local number=0
44+
# First three lines are like:
45+
# ⇒ Loading configuration...
46+
# ✓ Succeeded to load configuration
47+
# Scanning resources... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
48+
number=$(tail -n +4 "${file}" | wc -l)
49+
if [ "${number}" -eq 0 ]; then
50+
return 1
51+
fi
52+
return 0
53+
}
54+
55+
# As long as cloud reaper does not support OIDC authentication.
56+
create_aws_ephemeral_user() {
57+
# Generate a unique name for the ephemeral IAM user.
58+
EPHEMERAL_USER="ephemeral-admin-$(date +%s)"
59+
echo "Creating IAM user: ${EPHEMERAL_USER}"
60+
aws iam create-user --user-name "${EPHEMERAL_USER}" \
61+
--tags Key=ephemeral,Value=true Key=division,Value=engineering Key=org,Value=obs Key=environment,Value=ci Key=repo,Value=elastic-package Key=created_at,Value="$(date -Is)"
62+
63+
echo "Attaching AdministratorAccess policy to ${EPHEMERAL_USER}..."
64+
aws iam attach-user-policy --user-name "${EPHEMERAL_USER}" --policy-arn arn:aws:iam::aws:policy/AdministratorAccess
65+
66+
echo "Creating access keys for ${EPHEMERAL_USER}..."
67+
creds_json=$(aws iam create-access-key --user-name "${EPHEMERAL_USER}")
68+
AWS_ACCESS_KEY_ID_EPHEMERAL=$(echo "$creds_json" | jq -r '.AccessKey.AccessKeyId')
69+
AWS_SECRET_ACCESS_KEY_EPHEMERAL=$(echo "$creds_json" | jq -r '.AccessKey.SecretAccessKey')
70+
export EPHEMERAL_USER AWS_ACCESS_KEY_ID_EPHEMERAL AWS_SECRET_ACCESS_KEY_EPHEMERAL
71+
}
72+
73+
# Define cleanup function to delete the ephemeral IAM user regardless of script outcome.
74+
cleanup_ephemeral_user() {
75+
echo "Cleaning up ephemeral IAM user: ${EPHEMERAL_USER}"
76+
aws iam detach-user-policy --user-name "${EPHEMERAL_USER}" --policy-arn arn:aws:iam::aws:policy/AdministratorAccess
77+
key_id=$(echo "$creds_json" | jq -r '.AccessKey.AccessKeyId')
78+
aws iam delete-access-key --user-name "${EPHEMERAL_USER}" --access-key-id "${key_id}"
79+
aws iam delete-user --user-name "${EPHEMERAL_USER}"
80+
echo "Ephemeral IAM user ${EPHEMERAL_USER} deleted."
81+
unset EPHEMERAL_USER AWS_ACCESS_KEY_ID_EPHEMERAL AWS_SECRET_ACCESS_KEY_EPHEMERAL
82+
}
83+
trap cleanup_ephemeral_user EXIT
84+
85+
cloud_reaper_aws() {
86+
echo "--- Configuring ephemeral user"
87+
create_aws_ephemeral_user
88+
89+
echo "Validating configuration"
90+
docker run --rm -v "$(pwd)/.buildkite/configs/cleanup.aws.yml":/etc/cloud-reaper/config.yml \
91+
-e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID_EPHEMERAL" \
92+
-e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY_EPHEMERAL" \
93+
-e ACCOUNT_PROJECT="observability-ci" \
94+
-e CREATION_DATE="${DELETE_RESOURCES_BEFORE_DATE}" \
95+
"${CLOUD_REAPER_IMAGE}" \
96+
cloud-reaper \
97+
--debug \
98+
--config /etc/cloud-reaper/config.yml \
99+
validate
100+
101+
echo "Scanning resources"
102+
docker run --rm -v "$(pwd)/.buildkite/configs/cleanup.aws.yml":/etc/cloud-reaper/config.yml \
103+
-e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID_EPHEMERAL" \
104+
-e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY_EPHEMERAL" \
105+
-e ACCOUNT_PROJECT="observability-ci" \
106+
-e CREATION_DATE="${DELETE_RESOURCES_BEFORE_DATE}" \
107+
"${CLOUD_REAPER_IMAGE}" \
108+
cloud-reaper \
109+
--config /etc/cloud-reaper/config.yml \
110+
${COMMAND} | tee "${AWS_RESOURCES_FILE}"
111+
}
112+
113+
echo "--- Installing awscli"
114+
with_aws_cli
115+
116+
echo "--- Cleaning up AWS resources older than ${DELETE_RESOURCES_BEFORE_DATE}..."
117+
cloud_reaper_aws
118+
119+
if any_resources_to_delete "${AWS_RESOURCES_FILE}" ; then
120+
echo "Pending AWS resources"
121+
resources_to_delete=1
122+
fi
123+
124+
if [ "${resources_to_delete}" -eq 1 ]; then
125+
message="There are resources to be deleted"
126+
echo "${message}"
127+
if running_on_buildkite ; then
128+
buildkite-agent annotate \
129+
"${message}" \
130+
--context "ctx-cloud-reaper-error" \
131+
--style "error"
132+
fi
133+
fi
134+
135+
echo "--- Cleaning up other AWS resources older than ${DELETE_RESOURCES_BEFORE_DATE}"
136+
137+
export AWS_DEFAULT_REGION=us-east-1
138+
# Avoid to send the output of the CLI to a pager
139+
export AWS_PAGER=""
140+
141+
echo "--- Checking if any Redshift cluster still created"
142+
aws redshift describe-clusters \
143+
--tag-keys "environment" \
144+
--tag-values "ci" > "${AWS_REDSHIFT_RESOURCES_FILE}"
145+
146+
clusters_num=$(jq -rc '.Clusters | length' "${AWS_REDSHIFT_RESOURCES_FILE}")
147+
148+
echo "Number of clusters found: ${clusters_num}"
149+
150+
redshift_clusters_to_delete=0
151+
while read -r i ; do
152+
identifier=$(echo "$i" | jq -rc ".ClusterIdentifier")
153+
# tags
154+
repo=$(echo "$i" | jq -rc '.Tags[] | select(.Key == "repo").Value')
155+
environment=$(echo "$i" | jq -rc '.Tags[] | select(.Key == "environment").Value')
156+
# creation time tag in milliseconds
157+
createdAt=$(echo "$i" | jq -rc '.Tags[] | select(.Key == "created_date").Value')
158+
# epoch in milliseconds minus retention period
159+
thresholdEpoch=$(date -d "${RESOURCE_RETENTION_PERIOD} ago" +"%s%3N")
160+
161+
if [[ ! "${identifier}" =~ ^elastic-package-test- ]]; then
162+
echo "Skip cluster ${identifier}, do not match required identifiers."
163+
continue
164+
fi
165+
166+
if [[ "${repo}" != "integrations" && "${repo}" != "elastic-package" ]]; then
167+
echo "Skip cluster ${identifier}, not from the expected repo: ${repo}."
168+
continue
169+
fi
170+
171+
if [[ "${environment}" != "ci" ]]; then
172+
echo "Skip cluster ${identifier}, not from the expected environment: ${environment}."
173+
continue
174+
fi
175+
176+
if [ "${createdAt}" -gt "${thresholdEpoch}" ]; then
177+
echo "Skip cluster $identifier. It was created < ${RESOURCE_RETENTION_PERIOD} ago"
178+
continue
179+
fi
180+
181+
echo "To be deleted cluster: $identifier. It was created > ${RESOURCE_RETENTION_PERIOD} ago"
182+
if [ "${DRY_RUN}" != "false" ]; then
183+
redshift_clusters_to_delete=1
184+
continue
185+
fi
186+
187+
echo "Deleting: $identifier. It was created > ${RESOURCE_RETENTION_PERIOD} ago"
188+
if ! aws redshift delete-cluster \
189+
--cluster-identifier "${identifier}" \
190+
--skip-final-cluster-snapshot \
191+
--output json \
192+
--query "Cluster.{ClusterStatus:ClusterStatus,ClusterIdentifier:ClusterIdentifier}" ; then
193+
194+
echo "Failed delete-cluster"
195+
buildkite-agent annotate \
196+
"Deleted redshift cluster: ${identifier}" \
197+
--context "ctx-aws-readshift-deleted-error-${identifier}" \
198+
--style "error"
199+
200+
redshift_clusters_to_delete=1
201+
else
202+
echo "Done."
203+
# if deletion works, no need to mark this one as to be deleted
204+
buildkite-agent annotate \
205+
"Deleted redshift cluster: ${identifier}" \
206+
--context "ctx-aws-readshift-deleted-${identifier}" \
207+
--style "success"
208+
fi
209+
done <<< "$(jq -c '.Clusters[]' "${AWS_REDSHIFT_RESOURCES_FILE}")"
210+
211+
if [ "${redshift_clusters_to_delete}" -eq 1 ]; then
212+
resources_to_delete=1
213+
message="There are redshift resources to be deleted"
214+
echo "${message}"
215+
if running_on_buildkite ; then
216+
buildkite-agent annotate \
217+
"${message}" \
218+
--context "ctx-aws-readshift-error" \
219+
--style "error"
220+
fi
221+
fi
222+
223+
# TODO: List and delete the required resources using aws cli or using cloud-reaper tool
224+
echo "--- TODO: Cleaning up IAM roles"
225+
echo "--- TODO: Cleaning up IAM policies"
226+
echo "--- TODO: Cleaning up Schedulers"
227+
228+
if [ "${resources_to_delete}" -eq 1 ]; then
229+
exit 1
230+
fi

.buildkite/scripts/cloud-cleanup.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ any_resources_to_delete() {
5555
cloud_reaper_aws() {
5656
echo "Validating configuration"
5757
docker run --rm -v "$(pwd)/.buildkite/configs/cleanup.aws.yml":/etc/cloud-reaper/config.yml \
58-
-e ACCOUNT_SECRET="${ELASTIC_PACKAGE_AWS_SECRET_KEY}" \
59-
-e ACCOUNT_KEY="${ELASTIC_PACKAGE_AWS_ACCESS_KEY}" \
58+
-e AWS_SECRET_ACCESS_KEY="${ELASTIC_PACKAGE_AWS_SECRET_KEY}" \
59+
-e AWS_ACCESS_KEY_ID="${ELASTIC_PACKAGE_AWS_ACCESS_KEY}" \
6060
-e ACCOUNT_PROJECT="${ELASTIC_PACKAGE_AWS_USER_SECRET}" \
6161
-e CREATION_DATE="${DELETE_RESOURCES_BEFORE_DATE}" \
6262
"${CLOUD_REAPER_IMAGE}" \
@@ -66,8 +66,8 @@ cloud_reaper_aws() {
6666

6767
echo "Scanning resources"
6868
docker run --rm -v "$(pwd)/.buildkite/configs/cleanup.aws.yml":/etc/cloud-reaper/config.yml \
69-
-e ACCOUNT_SECRET="${ELASTIC_PACKAGE_AWS_SECRET_KEY}" \
70-
-e ACCOUNT_KEY="${ELASTIC_PACKAGE_AWS_ACCESS_KEY}" \
69+
-e AWS_SECRET_ACCESS_KEY="${ELASTIC_PACKAGE_AWS_SECRET_KEY}" \
70+
-e AWS_ACCESS_KEY_ID="${ELASTIC_PACKAGE_AWS_ACCESS_KEY}" \
7171
-e ACCOUNT_PROJECT="${ELASTIC_PACKAGE_AWS_USER_SECRET}" \
7272
-e CREATION_DATE="${DELETE_RESOURCES_BEFORE_DATE}" \
7373
"${CLOUD_REAPER_IMAGE}" \

.github/workflows/bump-elastic-stack-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
echo "UPDATECLI_ACTION=apply" >> $GITHUB_ENV
3636
3737
- name: Install Updatecli in the runner
38-
uses: updatecli/updatecli-action@ae3030ce1710c6496214fb1f8fd3bd9437b2a69d #v2.82.0
38+
uses: updatecli/updatecli-action@cf942226b953240efac9ff60bf42df2b908c2fa0 #v2.83.0
3939

4040
- name: Update default stack version
4141
# --experimental needed for commitusingapi option.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test-stack-command-8x:
7676
./scripts/test-stack-command.sh 8.19.0-e182bbbc-SNAPSHOT
7777

7878
test-stack-command-9x:
79-
./scripts/test-stack-command.sh 9.1.0-cf1fa15b-SNAPSHOT
79+
./scripts/test-stack-command.sh 9.1.0-62329fee-SNAPSHOT
8080

8181
test-stack-command-with-apm-server:
8282
APM_SERVER_ENABLED=true ./scripts/test-stack-command.sh

catalog-info.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ spec:
6060
access_level: MANAGE_BUILD_AND_READ
6161
ingest-fp:
6262
access_level: MANAGE_BUILD_AND_READ
63+
observablt-ci:
64+
access_level: MANAGE_BUILD_AND_READ
6365
everyone:
6466
access_level: READ_ONLY
6567

@@ -152,6 +154,8 @@ spec:
152154
teams:
153155
ingest-fp:
154156
access_level: MANAGE_BUILD_AND_READ
157+
observablt-ci:
158+
access_level: MANAGE_BUILD_AND_READ
155159
everyone:
156160
access_level: READ_ONLY
157161

@@ -203,6 +207,8 @@ spec:
203207
teams:
204208
ingest-fp:
205209
access_level: MANAGE_BUILD_AND_READ
210+
observablt-ci:
211+
access_level: MANAGE_BUILD_AND_READ
206212
everyone:
207213
access_level: BUILD_AND_READ
208214

docs/howto/format_version.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This is controlled in two places now:
2323
At the moment of writing this document, the following rules can be assumed:
2424
- Stacks older than 8.16 support all versions of the spec till 3.0.x.
2525
- Stacks from 8.16 support all versions of the spec till 3.3.x.
26+
- Stacks from 9.0 support versions of the stack from 2.3.0 to 3.3.x.
2627
- Serverless projects support versions of the stack from 3.0.0 to 3.3.x.
2728

2829
In case of doubt, you can check the Fleet default configuration, and the

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ require (
3434
github.com/spf13/cobra v1.9.1
3535
github.com/stretchr/testify v1.10.0
3636
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
37-
golang.org/x/tools v0.32.0
37+
golang.org/x/tools v0.33.0
3838
gopkg.in/dnaeon/go-vcr.v3 v3.2.0
3939
gopkg.in/yaml.v3 v3.0.1
40-
gotest.tools/gotestsum v1.12.1
40+
gotest.tools/gotestsum v1.12.2
4141
helm.sh/helm/v3 v3.17.3
4242
honnef.co/go/tools v0.6.1
4343
k8s.io/apimachinery v0.33.0
@@ -153,15 +153,15 @@ require (
153153
github.com/yusufpapurcu/wmi v1.2.4 // indirect
154154
go.mongodb.org/mongo-driver v1.11.1 // indirect
155155
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
156-
golang.org/x/crypto v0.37.0 // indirect
156+
golang.org/x/crypto v0.38.0 // indirect
157157
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect
158158
golang.org/x/mod v0.24.0 // indirect
159-
golang.org/x/net v0.39.0 // indirect
159+
golang.org/x/net v0.40.0 // indirect
160160
golang.org/x/oauth2 v0.27.0 // indirect
161-
golang.org/x/sync v0.13.0 // indirect
162-
golang.org/x/sys v0.32.0 // indirect
163-
golang.org/x/term v0.31.0 // indirect
164-
golang.org/x/text v0.24.0 // indirect
161+
golang.org/x/sync v0.14.0 // indirect
162+
golang.org/x/sys v0.33.0 // indirect
163+
golang.org/x/term v0.32.0 // indirect
164+
golang.org/x/text v0.25.0 // indirect
165165
golang.org/x/time v0.9.0 // indirect
166166
google.golang.org/protobuf v1.36.5 // indirect
167167
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect

0 commit comments

Comments
 (0)