summaryrefslogtreecommitdiffstats
path: root/fluent-bit/.github/workflows/call-run-integration-test.yaml
blob: 47f44a9bf097a53b91e379f8c9b2f410ac68a67c (plain)
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
290
291
292
293
294
---
name: Reusable workflow to run integration tests with specific images
on:
  workflow_call:
    secrets:
      opensearch_aws_access_id:
        description: AWS access ID to use within the opensearch integration tests.
        required: true
      opensearch_aws_secret_key:
        description: AWS secret key to use within the opensearch integration tests.
        required: true
      opensearch_admin_password:
        description: Default admin password use within the opensearch integration tests.
        required: true
      terraform_api_token:
        description: Default terraform API token to use when running integration tests.
        required: true
      gcp-service-account-key:
        description: The GCP service account key to use.
        required: true
    inputs:
      image_name:
        description: The image repository and name to use.
        required: false
        default: ghcr.io/fluent/fluent-bit/master
        type: string
      image_tag:
        description: The image tag to use.
        required: false
        default: x86_64
        type: string
      ref:
        description: The commit, tag or branch of the repository to checkout
        type: string
        required: false
        default: main
jobs:
  call-run-terraform-setup:
    name: Run Terraform set up
    runs-on: ubuntu-latest
    permissions:
      packages: read
    outputs:
      aws-opensearch-endpoint: ${{ steps.aws-opensearch-endpoint.outputs.stdout }}
      gke-cluster-name: ${{ steps.gke-cluster-name.outputs.stdout }}
      gke-cluster-region: ${{ steps.gke-cluster-region.outputs.stdout }}
      gke-cluster-zone: ${{ steps.gke-cluster-zone.outputs.stdout }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ inputs.ref }}
          repository: fluent/fluent-bit-ci

      - uses: hashicorp/setup-terraform@v2
        with:
          cli_config_credentials_hostname: 'app.terraform.io'
          cli_config_credentials_token: ${{ secrets.terraform_api_token }}

      - id: 'auth'
        uses: 'google-github-actions/auth@v1'
        with:
          credentials_json: ${{ secrets.gcp-service-account-key }}

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v1'

      - name: Replace terraform variables.
        run: |
          sed -i -e "s|\$OPENSEARCH_AWS_ACCESS_ID|${{ secrets.opensearch_aws_access_id }}|g" default.auto.tfvars
          sed -i -e "s|\$OPENSEARCH_AWS_SECRET_KEY|${{ secrets.opensearch_aws_secret_key }}|g" default.auto.tfvars
          sed -i -e "s|\$OPENSEARCH_ADMIN_PASSWORD|${{ secrets.opensearch_admin_password }}|g" default.auto.tfvars

          cat <<EOT >> default.auto.tfvars
          gcp_sa_key    =  <<-EOF
          ${{ secrets.gcp-service-account-key }}
          EOF
          EOT
        working-directory: terraform/
        shell: bash

      - name: Terraform init
        id: init
        run: terraform init
        working-directory: terraform/

      - name: Terraform fmt
        id: fmt
        run: |
          find . -name "*.tf" -exec terraform fmt -check {} \;
        working-directory: terraform

      - name: Terraform validate
        id: validate
        run: terraform validate -no-color
        working-directory: terraform/

      - name: Terraform Plan
        if: github.event_name == 'pull_request'
        id: plan
        run: terraform plan -no-color
        working-directory: terraform
        continue-on-error: true

      - uses: actions/github-script@v6
        if: github.event_name == 'pull_request'
        env:
          PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
            #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
            #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
            #### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
            <details><summary>Show Plan</summary>
            \`\`\`\n
            ${process.env.PLAN}
            \`\`\`
            </details>
            *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: output
            })

      - name: Terraform Plan Status
        if: steps.plan.outcome == 'failure'
        run: exit 1

      - name: Terraform Apply
        if: github.event_name != 'pull_request'
        id: apply
        run: terraform apply -input=false -auto-approve
        working-directory: terraform
        env:
          TF_LOG: TRACE

      # We're using the terraform wrapper here so separate steps for each output variable
      - id: aws-opensearch-endpoint
        run: terraform output -no-color -raw aws-opensearch-endpoint
        working-directory: terraform
        shell: bash

      - id: gke-cluster-name
        run: terraform output -no-color -raw gke_kubernetes_cluster_name
        working-directory: terraform
        shell: bash

      - id: gke-cluster-region
        run: terraform output -no-color -raw gke_region
        working-directory: terraform
        shell: bash

      - id: gke-cluster-zone
        run: terraform output -no-color -raw gke_zone
        working-directory: terraform
        shell: bash

  call-run-integration-kind:
    name: Run integration tests on KIND
    needs:
      - call-run-terraform-setup
    # Can test for multiple K8S versions with KIND
    strategy:
      fail-fast: false
      matrix:
        k8s-release: [ 'v1.23.5', 'v1.22.7', 'v1.21.10' ]
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: read
    steps:
      - name: Test image exists and cache locally
        run: docker pull ${{ inputs.image_name }}:${{ inputs.image_tag }}

      - uses: actions/checkout@v4
        with:
          ref: ${{ inputs.ref }}
          repository: fluent/fluent-bit-ci

      - name: Configure system for Opensearch
        run: |
          sudo sysctl -w vm.max_map_count=262144
          sysctl -p
        shell: bash

      - name: Setup BATS
        uses: mig4/setup-bats@v1
        with:
          bats-version: 1.9.0

      - name: Create k8s Kind Cluster
        uses: helm/kind-action@v1.8.0
        with:
          node_image: kindest/node:${{ matrix.k8s-release }}
          cluster_name: kind

      - name: Set up Helm
        uses: azure/setup-helm@v3.5
        with:
          version: v3.8.1

      - name: Set up Kubectl
        uses: azure/setup-kubectl@v3.2

      - name: Run tests
        timeout-minutes: 60
        run:  |
          kind load docker-image ${{ inputs.image_name }}:${{ inputs.image_tag }}
          ./run-tests.sh
        shell: bash
        env:
          FLUENTBIT_IMAGE_REPOSITORY: ${{ inputs.image_name }}
          FLUENTBIT_IMAGE_TAG: ${{ inputs.image_tag }}
          HOSTED_OPENSEARCH_HOST: ${{ needs.call-run-terraform-setup.outputs.aws-opensearch-endpoint }}
          HOSTED_OPENSEARCH_PORT: 443
          HOSTED_OPENSEARCH_USERNAME: admin
          HOSTED_OPENSEARCH_PASSWORD: ${{ secrets.opensearch_admin_password }}

  call-run-integration-cloud:
    name: Run integration tests on cloud providers
    needs:
      - call-run-terraform-setup
    runs-on: ubuntu-latest
    permissions:
      contents: read
    strategy:
      fail-fast: false
      matrix:
        cloud:
          - gke
    env:
      USE_GKE_GCLOUD_AUTH_PLUGIN: true
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ inputs.ref }}
          repository: fluent/fluent-bit-ci

      - if: matrix.cloud == 'gke'
        uses: 'google-github-actions/auth@v1'
        with:
          credentials_json: ${{ secrets.gcp-service-account-key }}

      - if: matrix.cloud == 'gke'
        uses: 'google-github-actions/setup-gcloud@v1'
        with:
          install_components: 'gke-gcloud-auth-plugin'

      - name: Setup BATS
        uses: mig4/setup-bats@v1
        with:
          bats-version: 1.9.0

      - name: Set up Helm
        uses: azure/setup-helm@v3.5
        with:
          version: v3.8.1

      - name: Set up Kubectl
        uses: azure/setup-kubectl@v3.2

      - name: Get the GKE Kubeconfig
        if: matrix.cloud == 'gke'
        uses: 'google-github-actions/get-gke-credentials@v1'
        with:
          cluster_name: ${{ needs.call-run-terraform-setup.outputs.gke-cluster-name }}
          location: ${{ needs.call-run-terraform-setup.outputs.gke-cluster-zone }}

      - name: Check Kubeconfig set up
        run: |
          kubectl cluster-info
          kubectl get nodes --show-labels
          kubectl get pods --all-namespaces --show-labels
          kubectl get ns
        shell: bash

      - name: Run tests
        timeout-minutes: 60
        run:  |
          ./run-tests.sh
        shell: bash
        env:
          # Namespace per test run to hopefully isolate a bit
          TEST_NAMESPACE: test-${{ github.run_id }}
          FLUENTBIT_IMAGE_REPOSITORY: ${{ inputs.image_name }}
          FLUENTBIT_IMAGE_TAG: ${{ inputs.image_tag }}
          HOSTED_OPENSEARCH_HOST: ${{ needs.call-run-terraform-setup.outputs.aws-opensearch-endpoint }}
          HOSTED_OPENSEARCH_PORT: 443
          HOSTED_OPENSEARCH_USERNAME: admin
          USE_GKE_GCLOUD_AUTH_PLUGIN: true
          HOSTED_OPENSEARCH_PASSWORD: ${{ secrets.opensearch_admin_password }}