-
Notifications
You must be signed in to change notification settings - Fork 10
246 lines (218 loc) · 7.82 KB
/
ci.yaml
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
name: CI
on:
pull_request:
push:
branches:
- main
- renovate/**
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
goos: [ linux ]
goarch: [ amd64, arm64, arm ]
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Build binary
run: make build
- name: Build Docker image
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
run: make image
- name: Run CI checks
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
run: make ci
chart-lint:
name: Helm chart Lint
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
kubernetes-version: ["v1.31.0", "v1.30.0", "v1.29.5", "v1.28.3", "v1.27.5"]
cri: [ containerd ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: azure/setup-kubectl@v4
with:
version: v1.31.0
- uses: azure/setup-helm@v4
with:
version: v3.10.0
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- uses: helm/[email protected]
- name: Add newrelic repository
run: helm repo add newrelic https://helm-charts.newrelic.com
- name: Lint charts
run: ct --config .github/ct.yaml lint --debug
- name: Check for changed installable charts
id: list-changed
run: |
changed=$(ct --config .github/ct.yaml list-changed)
if [[ -n "$changed" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run helm unit tests
if: steps.list-changed.outputs.changed == 'true'
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest
for chart in $(ct --config .github/ct.yaml list-changed); do
if [ -d "$chart/tests/" ]; then
helm unittest $chart
else
echo "No unit tests found for $chart"
fi
done
- name: Setup Minikube
uses: manusa/[email protected]
if: steps.list-changed.outputs.changed == 'true'
with:
minikube version: v1.34.0
kubernetes version: ${{ matrix.kubernetes-version }}
driver: docker
github token: ${{ secrets.GITHUB_TOKEN }}
start args: "--container-runtime=${{ matrix.cri }}"
- uses: actions/setup-go@v5
if: steps.list-changed.outputs.changed == 'true'
with:
go-version-file: 'go.mod'
- name: Create image for chart testing
if: steps.list-changed.outputs.changed == 'true'
run: |
GOOS=linux GOARCH=amd64 make build # Set GOOS and GOARCH explicitly since Dockerfile expects them in the binary name
DOCKER_BUILDKIT=1 docker build -t e2e/newrelic-metrics-adapter:test .
minikube image load e2e/newrelic-metrics-adapter:test
kubectl create ns ct
- name: Test install charts
if: steps.list-changed.outputs.changed == 'true'
run: ct install --namespace ct --config .github/ct.yaml --debug
- name: Test upgrade charts
if: steps.list-changed.outputs.changed == 'true'
run: ct install --namespace ct --config .github/ct.yaml --debug --upgrade
integration:
name: Integration and E2E tests
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
k8sVersion: ["v1.31.0", "v1.30.0", "v1.29.5", "v1.28.3", "v1.27.5"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Kind action
uses: helm/[email protected]
with:
kubectl_version: ${{ matrix.k8sVersion }}
- name: Create k8s Kind Cluster
run: make kind-up
- name: Run unit tests
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
with:
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Run integration tests
env:
NEWRELIC_API_KEY: "${{ secrets.K8S_AGENTS_E2E_API_KEY }}"
NEWRELIC_ACCOUNT_ID: "${{ secrets.K8S_AGENTS_E2E_ACCOUNT_ID }}"
run: make test-integration
- name: Build Docker image
run: make image-push IMAGE_REPO=localhost:5000/newrelic-k8s-metrics-adapter
- name: Add newrelic repository
run: helm repo add newrelic https://helm-charts.newrelic.com
- name: Create Helm release
env:
KUBECONFIG: ./kubeconfig # Generated by `make kind-up`
NEWRELIC_API_KEY: "${{ secrets.K8S_AGENTS_E2E_API_KEY }}"
NEWRELIC_ACCOUNT_ID: "${{ secrets.K8S_AGENTS_E2E_ACCOUNT_ID }}"
run: |
make generate-local-values
helm dependency build ./charts/newrelic-k8s-metrics-adapter
helm install newrelic-k8s-metrics-adapter ./charts/newrelic-k8s-metrics-adapter \
--set image.repository=localhost:5000/newrelic-k8s-metrics-adapter \
--set image.pullPolicy=IfNotPresent \
--values values-dev.yaml --values values-local.yaml \
--wait --timeout 240s
- name: Confirm external.metrics.k8s.io API implementation details
env:
ENDPOINT: '/apis/external.metrics.k8s.io/v1beta1/namespaces/*/e2e/'
KUBECONFIG: ./kubeconfig # Generated by `make kind-up`
run: |
sleep 30
KIND=$(kubectl get --raw "${ENDPOINT}" | jq '.kind')
API_VERSION=$(kubectl get --raw "${ENDPOINT}" | jq '.apiVersion')
METRIC_NAME=$(kubectl get --raw "${ENDPOINT}" | jq '.items[0].metricName')
VALUE=$(kubectl get --raw "${ENDPOINT}" | jq '.items[0].value')
if [[ ${KIND} != '"ExternalMetricValueList"' ]]; then
echo "KIND: found '${KIND}' != expected '\"ExternalMetricValueList\"'"
exit 1
fi
if [[ ${API_VERSION} != '"external.metrics.k8s.io/v1beta1"' ]]; then
echo "API_VERSION: found '${API_VERSION}' != expected '\"external.metrics.k8s.io/v1beta1\"'"
exit 1
fi
if [[ ${METRIC_NAME} != '"e2e"' ]]; then
echo "METRIC_NAME: found '${METRIC_NAME}' != expected '\"e2e\"'"
exit 1
fi
if [[ ${VALUE} != '"123m"' ]]; then
echo "VALUE: found '${VALUE}' != expected '\"123m\"'"
exit 1
fi
- name: Run E2E tests
run: make test-e2e
static-analysis:
name: Static analysis and linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: newrelic/newrelic-infra-checkers@v1
with:
golangci-lint-config: golangci-lint
# - name: Semgrep
# uses: returntocorp/semgrep-action@v1
# with:
# auditOn: push
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
continue-on-error: ${{ github.event_name != 'pull_request' }}
with:
only-new-issues: true
skip-pkg-cache: true
skip-build-cache: true
codespell:
name: Codespell
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Codespell test
uses: codespell-project/actions-codespell@master
with:
check_filenames: true
check_hidden: true
ignore_words_list: te,enver,NotIn,Bu
skip: ./.git,./internal/generated