-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy patheks-performance-cluster-addon-install.yml
More file actions
289 lines (260 loc) · 10.9 KB
/
Copy patheks-performance-cluster-addon-install.yml
File metadata and controls
289 lines (260 loc) · 10.9 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT
name: "Install/Remove Helm Charts After Scaling"
on:
# Use workflow_run to trigger this workflow after the scaling workflow completes
workflow_run:
workflows: ["EKS Cluster Scaling"]
types:
- completed
branches:
- main
# Keep the manual trigger option
workflow_dispatch:
inputs:
# Required Core Settings
cluster_name:
description: 'EKS Cluster Name'
required: true
type: string
default: 'eks-performance'
region:
description: 'AWS Region'
required: true
type: string
default: 'us-west-2'
# Optional Settings
cloudwatch_agent_repository:
description: 'CloudWatch Agent Repository'
type: string
cloudwatch_agent_tag:
description: 'CloudWatch Agent Tag'
type: string
cloudwatch_agent_operator_repository:
description: 'CloudWatch Agent Operator Repository'
type: string
cloudwatch_agent_operator_tag:
description: 'CloudWatch Agent Operator Tag'
type: string
helm-charts-branch:
description: 'Branch of the helm charts to test'
type: string
default: 'main'
operator-branch:
description: 'Branch of the operator to test'
type: string
default: 'main'
terraform_assume_role:
description: 'AWS IAM Role to assume'
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Cluster environment variables
AWS_REGION: ${{ inputs.region || 'us-west-2' }}
CLUSTER_NAME: ${{ inputs.cluster_name || 'eks-performance' }}
TERRAFORM_AWS_ASSUME_ROLE: ${{ inputs.terraform_assume_role || vars.TERRAFORM_AWS_ASSUME_ROLE }}
TERRAFORM_AWS_ASSUME_ROLE_DURATION: 3600 # 1 hour duration
# ECR repository environment variables
AGENT_ECR_TEST_REPO: "cwagent-integration-test"
OPERATOR_ECR_TEST_REPO: "cwagent-operator-pre-release"
# Github repository environment variables
OPERATOR_GITHUB_REPO_NAME: "aws/amazon-cloudwatch-agent-operator"
CWA_GITHUB_TEST_REPO_NAME: "aws/amazon-cloudwatch-agent-test"
CWA_GITHUB_TEST_REPO_BRANCH: "main"
jobs:
# Check if this workflow should run
check-trigger:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'schedule') }}
steps:
- name: Check trigger type
id: check-trigger
run: |
if [ "${{ github.event_name }}" == "workflow_run" ]; then
echo "Triggered by workflow_run from a scheduled event"
else
echo "Triggered manually via workflow_dispatch"
fi
outputs:
should_continue: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'schedule') }}
# Get latest operator commit from github repo
GetLatestOperatorCommitSHA:
needs: check-trigger
if: ${{ needs.check-trigger.outputs.should_continue == 'true' }}
runs-on: ubuntu-latest
outputs:
operator_commit_sha: ${{steps.get_latest_sha.outputs.operator_sha}}
operator_repo_name: ${{env.OPERATOR_GITHUB_REPO_NAME}}
steps:
- name: Checkout the target repo
uses: actions/checkout@v4
with:
repository: ${{env.OPERATOR_GITHUB_REPO_NAME}}
ref: ${{ inputs.operator-branch || 'main' }}
path: operator-repo
- name: Get latest commit SHA
id: get_latest_sha
run: |
cd operator-repo
latest_sha=$(git rev-parse HEAD)
echo "operator_sha=$latest_sha" >> "$GITHUB_OUTPUT"
# Build and upload agent image to ECR repo
BuildAgent:
needs: check-trigger
if: ${{ needs.check-trigger.outputs.should_continue == 'true' }}
uses: ./.github/workflows/build-test-artifacts.yml
concurrency:
group: "Build-Test-Artifacts-${{github.ref_name}}"
cancel-in-progress: true
secrets: inherit
permissions:
id-token: write
contents: read
actions: write
with:
run-tests: false
# Build and upload operator image to ECR repo
BuildOperator:
needs: [ check-trigger, GetLatestOperatorCommitSHA ]
if: ${{ needs.check-trigger.outputs.should_continue == 'true' }}
uses: aws/amazon-cloudwatch-agent-operator/.github/workflows/build-and-upload.yml@main
permissions:
id-token: write
contents: read
concurrency:
group: ${{ github.workflow }}-operator-${{ inputs.operator-branch || 'main' }}
cancel-in-progress: true
secrets: inherit
with:
tag: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha}}
target-sha: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha}}
repository: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_repo_name}}
test-image-before-upload: false
install-helm:
needs: [ check-trigger, BuildAgent, BuildOperator, GetLatestOperatorCommitSHA ]
if: ${{ needs.check-trigger.outputs.should_continue == 'true' }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE}}
aws-region: ${{ env.AWS_REGION}}
role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }}
- name: Login ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Install kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 'latest'
- name: Update kubeconfig
run: |
aws eks update-kubeconfig --name $CLUSTER_NAME --region $AWS_REGION
# TODO: Revert to using main helm branch when changes from leader-election are merged in
- name: Clone Helm Charts Repository
env:
HELM_CHARTS_BRANCH: ${{ inputs.helm-charts-branch || 'sky333999/leader-election' }}
run: |
rm -rf ./helm-charts
git clone -b "$HELM_CHARTS_BRANCH" https://github.com/aws-observability/helm-charts.git ./helm-charts
- name: Clone Test Repo
uses: actions/checkout@v4
with:
repository: ${{ env.CWA_GITHUB_TEST_REPO_NAME }}
ref: ${{ env.CWA_GITHUB_TEST_REPO_BRANCH }}
path: ./test-repo
- name: Replace hostname in override files
run: |
HOSTNAME=$(kubectl get nodes -l eks.amazonaws.com/nodegroup=$CLUSTER_NAME-leader-node -o jsonpath='{.items[0].metadata.name}')
for file in ./test-repo/test/performance/eks/resources/leader_election_overrides/*; do
sed -i "s/<hostname>/$HOSTNAME/g" "$file"
done
# TODO: Revert to using workflow built agent image once required changes are made on main branch
- name: Check node count and manage Helm chart
env:
INPUT_CLUSTER_NAME: ${{ inputs.cluster_name }}
INPUT_REGION: ${{ inputs.region }}
INPUT_AGENT_REPO: ${{ inputs.cloudwatch_agent_repository }}
INPUT_AGENT_TAG: ${{ inputs.cloudwatch_agent_tag }}
INPUT_OPERATOR_REPO: ${{ inputs.cloudwatch_agent_operator_repository }}
INPUT_OPERATOR_TAG: ${{ inputs.cloudwatch_agent_operator_tag }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
OPERATOR_SHA: ${{ needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha }}
GITHUB_SHA_VAL: ${{ github.sha }}
run: |
NODE_COUNT=$(kubectl get nodes --no-headers | wc -l)
if [ "$NODE_COUNT" -eq 0 ]; then
echo "Node count is 0, removing Helm chart"
helm uninstall amazon-cloudwatch-observability -n amazon-cloudwatch || echo "Chart not found or already removed"
else
echo "Node count is $NODE_COUNT, installing/updating Helm chart"
# Set variables with defaults
HELM_CLUSTER_NAME="${INPUT_CLUSTER_NAME:-$CLUSTER_NAME}"
HELM_REGION="${INPUT_REGION:-$AWS_REGION}"
HELM_AGENT_REPO="${INPUT_AGENT_REPO:-$AGENT_ECR_TEST_REPO}"
HELM_AGENT_TAG="${INPUT_AGENT_TAG:-$GITHUB_SHA_VAL}"
HELM_OPERATOR_REPO="${INPUT_OPERATOR_REPO:-$OPERATOR_ECR_TEST_REPO}"
HELM_OPERATOR_TAG="${INPUT_OPERATOR_TAG:-$OPERATOR_SHA}"
# Echo all variables being passed to helm
echo "CLUSTER_NAME: $HELM_CLUSTER_NAME"
echo "REGION: $HELM_REGION"
echo "AGENT_REPOSITORY: $HELM_AGENT_REPO"
echo "AGENT_TAG: $HELM_AGENT_TAG"
echo "AGENT_REPOSITORY_DOMAIN: $ECR_REGISTRY"
echo "MANAGER_REPOSITORY: $HELM_OPERATOR_REPO"
echo "MANAGER_TAG: $HELM_OPERATOR_TAG"
echo "MANAGER_REPOSITORY_DOMAIN: $ECR_REGISTRY"
helm upgrade --install --wait amazon-cloudwatch-observability \
./helm-charts/charts/amazon-cloudwatch-observability \
--namespace amazon-cloudwatch \
--create-namespace \
--set clusterName="$HELM_CLUSTER_NAME" \
--set region="$HELM_REGION" \
--set agent.image.repository="cloudwatch-agent" \
--set agent.image.tag="latest" \
--set agent.image.repositoryDomainMap.public="public.ecr.aws/q4e2d9n7" \
--set manager.image.repository="$HELM_OPERATOR_REPO" \
--set manager.image.tag="$HELM_OPERATOR_TAG" \
--set manager.image.repositoryDomainMap.public="$ECR_REGISTRY" \
--values ./test-repo/test/performance/eks/resources/leader_election_overrides/base-overrides.yml
fi
cleanup-on-failure:
if: ${{ failure() || cancelled() }}
runs-on: ubuntu-latest
needs: [ install-helm ]
permissions:
id-token: write
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE}}
aws-region: ${{ env.AWS_REGION}}
role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }}
- name: Install kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 'latest'
- name: Update kubeconfig
run: |
aws eks update-kubeconfig --name $CLUSTER_NAME --region $AWS_REGION
- name: Uninstall Helm chart
run: |
echo "Test was cancelled or failed. Cleaning up resources..."
helm uninstall amazon-cloudwatch-observability -n amazon-cloudwatch || echo "Chart not found or already removed"
echo "Cleanup completed"