-
Notifications
You must be signed in to change notification settings - Fork 7
Add kubernetes-plugins ci initial test #121
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load "$HELPERS_ROOT/test-helpers.bash" | ||
|
|
||
| ensure_variables_set BATS_SUPPORT_ROOT BATS_ASSERT_ROOT BATS_DETIK_ROOT BATS_FILE_ROOT TEST_NAMESPACE FLUENTBIT_IMAGE_REPOSITORY FLUENTBIT_IMAGE_TAG | ||
|
|
||
| load "$BATS_DETIK_ROOT/utils.bash" | ||
| load "$BATS_DETIK_ROOT/linter.bash" | ||
| load "$BATS_DETIK_ROOT/detik.bash" | ||
| load "$BATS_SUPPORT_ROOT/load.bash" | ||
| load "$BATS_ASSERT_ROOT/load.bash" | ||
| load "$BATS_FILE_ROOT/load.bash" | ||
|
|
||
| setup() { | ||
| echo "recreating namespace $TEST_NAMESPACE" | ||
| run kubectl delete namespace "$TEST_NAMESPACE" | ||
| run kubectl create namespace "$TEST_NAMESPACE" | ||
| # HELM_VALUES_EXTRA_FILE is a default file containing global helm | ||
| # options that can be optionally applied on helm install/upgrade | ||
| # by the test. This will fall back to $TEST_ROOT/defaults/values.yaml.tpl | ||
| # if not passed. | ||
| if [ -e "${HELM_VALUES_EXTRA_FILE}" ]; then | ||
| envsubst < "${HELM_VALUES_EXTRA_FILE}" > "${HELM_VALUES_EXTRA_FILE%.*}" | ||
| export HELM_VALUES_EXTRA_FILE="${HELM_VALUES_EXTRA_FILE%.*}" | ||
| fi | ||
| } | ||
|
|
||
| teardown() { | ||
| if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then | ||
| run kubectl delete namespace "$TEST_NAMESPACE" | ||
| rm -f ${HELM_VALUES_EXTRA_FILE} | ||
| fi | ||
| } | ||
|
|
||
| # These are required for bats-detik | ||
| # shellcheck disable=SC2034 | ||
| DETIK_CLIENT_NAME="kubectl -n $TEST_NAMESPACE" | ||
| # shellcheck disable=SC2034 | ||
| DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}" | ||
|
|
||
|
|
||
| @test "test fluent-bit reads k8s labels" { | ||
| helm repo add fluent https://fluent.github.io/helm-charts/ || helm repo add fluent https://fluent.github.io/helm-charts | ||
| helm repo update --fail-on-repo-update-fail | ||
|
|
||
| helm upgrade --install --debug --create-namespace --namespace "$TEST_NAMESPACE" fluent-bit fluent/fluent-bit \ | ||
| --values ${BATS_TEST_DIRNAME}/resources/fluentbit-basic.yaml \ | ||
| --set image.repository=${FLUENTBIT_IMAGE_REPOSITORY},image.tag=${FLUENTBIT_IMAGE_TAG},env[0].name=TEST_NAMESPACE,env[0].value=${TEST_NAMESPACE} \ | ||
| --values "$HELM_VALUES_EXTRA_FILE" \ | ||
| --timeout "${HELM_FB_TIMEOUT:-5m0s}" \ | ||
| --wait | ||
|
|
||
| try "at most 15 times every 2s " \ | ||
| "to find 1 pods named 'fluent-bit' " \ | ||
| "with 'status' being 'running'" | ||
|
|
||
ryanohnemus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # The hello-world-1 container MUST be on the same node as the fluentbit worker, so we use a nodeSelector to specify the same node name | ||
| run kubectl get pods -l "app.kubernetes.io/name=fluent-bit" -o jsonpath='{.items[0].spec.nodeName}' | ||
ryanohnemus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert_success | ||
| refute_output "" | ||
| node_name=$output | ||
ryanohnemus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| kubectl run -n $TEST_NAMESPACE hello-world-1 --image=docker.io/library/alpine:latest -l "this_is_a_test_label=true" \ | ||
| --overrides="{\"apiVersion\":\"v1\",\"spec\":{\"nodeSelector\":{\"kubernetes.io/hostname\":\"$node_name\"}}}" \ | ||
| --command -- sh -c 'while true; do echo "hello world"; sleep 1; done' | ||
|
|
||
| try "at most 15 times every 5s " \ | ||
| "to find 1 pods named 'hello-world-1' " \ | ||
| "with 'status' being 'Running'" | ||
|
|
||
| # We are sleeping here specifically for the Fluent-Bit's tail input's | ||
| # configured Refresh_Interval to have enough time to detect the new pod's log file | ||
| # and to have processed part of it. | ||
| # A future improvement instead of sleep could use fluentbit's metrics endpoints | ||
| # to know the tail lugin has processed records | ||
| sleep 10 | ||
|
|
||
| run kubectl logs -l "app.kubernetes.io/name=fluent-bit" -n "$TEST_NAMESPACE" | ||
ryanohnemus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert_success | ||
| refute_output "" | ||
| match1='kubernetes":{"pod_name":"hello-world-1","namespace_name":' | ||
| match1=${match1}\"${TEST_NAMESPACE}\" | ||
| match2='"labels":{"this_is_a_test_label":"true"}' | ||
|
|
||
| assert_output --partial $match1 | ||
patrick-stephens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert_output --partial $match2 | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| kind: Deployment | ||
| replicaCount: 1 | ||
| rbac: | ||
| create: true | ||
| extraVolumeMounts: | ||
| - mountPath: /var/log | ||
| name: varlog | ||
| extraVolumes: | ||
| - name: varlog | ||
| hostPath: | ||
| path: /var/log | ||
|
|
||
| config: | ||
| service: | | ||
| [SERVICE] | ||
| Flush 5 | ||
| Daemon Off | ||
| Log_Level error | ||
| HTTP_Server On | ||
| HTTP_Listen 0.0.0.0 | ||
| HTTP_Port 2020 | ||
|
|
||
| inputs: | | ||
| [INPUT] | ||
| name tail | ||
| read_from_head true | ||
| path /var/log/containers/*${TEST_NAMESPACE}*.log | ||
| multiline.parser docker, cri | ||
| Tag kube.* | ||
| buffer_chunk_size 2M | ||
| buffer_max_size 2M | ||
| Exclude_Path /var/log/containers/fluent-bit* | ||
| Refresh_Interval 1 | ||
|
|
||
| filters: | | ||
| [FILTER] | ||
| Name kubernetes | ||
| Match kube.* | ||
| Kube_URL https://kubernetes.default.svc:443 | ||
| Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | ||
| Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token | ||
| Kube_Tag_Prefix kube.var.log.containers. | ||
| Merge_Log Off | ||
| Annotations Off | ||
| Labels On | ||
|
|
||
| outputs: | | ||
| [OUTPUT] | ||
| Name stdout | ||
| Match * | ||
| Format json_lines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.