From af44b1b62a656748b65fd73a1f34ca07bcc62b85 Mon Sep 17 00:00:00 2001 From: Lewis John McGibbney Date: Sat, 30 Mar 2024 18:28:55 -0700 Subject: [PATCH 1/3] TIKA-4232 Create and execute unit tests for tika-helm --- .github/workflows/lint-test.yaml | 9 ++--- .helmignore | 1 + README.md | 14 +++++--- templates/networkpolicy.yaml | 18 ++++++++++ tests/deployment_test.yaml | 62 ++++++++++++++++++++++++++++++++ tests/hpa_test.yaml | 41 +++++++++++++++++++++ tests/ingress_test.yaml | 40 +++++++++++++++++++++ tests/networkpolicy_test.yaml | 38 ++++++++++++++++++++ tests/service_test.yaml | 41 +++++++++++++++++++++ tests/serviceaccount_test.yaml | 32 +++++++++++++++++ values.yaml | 2 +- 11 files changed, 285 insertions(+), 13 deletions(-) create mode 100644 tests/deployment_test.yaml create mode 100644 tests/hpa_test.yaml create mode 100644 tests/ingress_test.yaml create mode 100644 tests/networkpolicy_test.yaml create mode 100644 tests/service_test.yaml create mode 100644 tests/serviceaccount_test.yaml diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index d3bc11c..c0c6584 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -30,20 +30,16 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set up Helm uses: azure/setup-helm@v3 with: version: v3.10.0 - - uses: actions/setup-python@v4 with: python-version: '3.9' check-latest: true - - name: Set up chart-testing uses: helm/chart-testing-action@v2.3.1 - - name: Run chart-testing (list-changed) id: list-changed run: | @@ -51,14 +47,13 @@ jobs: if [[ -n "$changed" ]]; then echo "::set-output name=changed::true" fi - - name: Run chart-testing (lint) run: ct lint --target-branch ${{ github.event.repository.default_branch }} --charts . - - name: Create kind cluster uses: helm/kind-action@v1.4.0 if: steps.list-changed.outputs.changed == 'true' - + - name: Run unit tests + uses: d3adb5/helm-unittest-action@v2 - name: Run chart-testing (install) run: ct install --target-branch ${{ github.event.repository.default_branch }} --charts . if: steps.list-changed.outputs.changed == 'true' \ No newline at end of file diff --git a/.helmignore b/.helmignore index 0e8a0eb..2d9d142 100644 --- a/.helmignore +++ b/.helmignore @@ -21,3 +21,4 @@ .idea/ *.tmproj .vscode/ +tests diff --git a/README.md b/README.md index e0b729d..0637f87 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ will work with the version of Tika you are installing. - [Upgrading](#upgrading) - [Configuration](#configuration) - [Deprecated](#deprecated) -- [FAQ](#faq) +- [Testing](#testing) - [Contributing](#contributing) @@ -95,11 +95,14 @@ Please check `artifacthub.io/changes` in `Chart.yaml` before upgrading. |--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------| | `...` | ... | ... | -### Deprecated +## Testing -| Parameter | Description | Default | -|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|---------| -| `...` | ... | `...` | +``` +helm plugin install https://github.com/helm-unittest/helm-unittest.git +helm unittest . +``` + +See [helm-unittest][] for canonical documentation. ## Contributing @@ -129,6 +132,7 @@ The code is licensed permissively under the [Apache License v2.0][]. [CHANGELOG.md]: https://github.com/apache/tika-helm/blob/master/CHANGELOG.md [CONTRIBUTING]: https://github.com/apache/tika#contributing-via-github [apache/tika]: https://github.com/apache/tika-docker +[helm-unittest]: https://github.com/helm-unittest/helm-unittest [Helm chart]: https://helm.sh/docs/topics/charts/ [Kubernetes]: https://kubernetes.io/ [Tika Docker image]: https://hub.docker.com/r/apache/tika/tags?page=1&ordering=last_updated diff --git a/templates/networkpolicy.yaml b/templates/networkpolicy.yaml index 5a2089f..4241840 100644 --- a/templates/networkpolicy.yaml +++ b/templates/networkpolicy.yaml @@ -1,3 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +--- {{- if .Values.networkPolicy.enabled }} apiVersion: networking.k8s.io/v1 kind: NetworkPolicy diff --git a/tests/deployment_test.yaml b/tests/deployment_test.yaml new file mode 100644 index 0000000..79902cb --- /dev/null +++ b/tests/deployment_test.yaml @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +suite: test deployment +templates: + - deployment.yaml +tests: + - it: should pass + set: + image.tag: latest + asserts: + - isKind: + of: Deployment + - isAPIVersion: + of: apps/v1 + - matchRegex: + path: metadata.name + pattern: RELEASE-NAME-tika + - equal: + path: spec.template.spec.containers[0].image + value: apache/tika:latest + - lengthEqual: + path: spec.template.spec.containers + count: 1 + - isSubset: + path: spec.template.spec.containers[0] + content: + livenessProbe: + httpGet: + path: / + port: 9998 + scheme: HTTP + initialDelaySeconds: 15 + timeoutSeconds: 30 + failureThreshold: 20 + periodSeconds: 5 + - isSubset: + path: spec.template.spec.containers[0] + content: + readinessProbe: + httpGet: + path: / + port: 9998 + scheme: HTTP + initialDelaySeconds: 15 + timeoutSeconds: 30 + failureThreshold: 20 + periodSeconds: 5 diff --git a/tests/hpa_test.yaml b/tests/hpa_test.yaml new file mode 100644 index 0000000..ececb85 --- /dev/null +++ b/tests/hpa_test.yaml @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +suite: test hpa +templates: + - hpa.yaml +tests: + - it: should pass + set: + autoscaling.enabled: true + asserts: + - isKind: + of: HorizontalPodAutoscaler + - isAPIVersion: + of: autoscaling/v2 + - matchRegex: + path: metadata.name + pattern: RELEASE-NAME-tika + - equal: + path: spec.minReplicas + value: 1 + - equal: + path: spec.maxReplicas + value: 100 + - lengthEqual: + path: spec.metrics + count: 2 diff --git a/tests/ingress_test.yaml b/tests/ingress_test.yaml new file mode 100644 index 0000000..48c8cf2 --- /dev/null +++ b/tests/ingress_test.yaml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +suite: test ingress +templates: + - ingress.yaml +tests: + - it: should pass + set: + image.tag: latest + ingress.enabled: true + Capabilities.KubeVersion.GitVersion: 1.20 + ingress.tls: + - secretName: chart-example-tls + hosts: + - chart-example.local + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + metadata.name: RELEASE-NAME-tika + - isNotNullOrEmpty: + path: spec.tls + - lengthEqual: + path: spec.rules + count: 1 diff --git a/tests/networkpolicy_test.yaml b/tests/networkpolicy_test.yaml new file mode 100644 index 0000000..5821fa2 --- /dev/null +++ b/tests/networkpolicy_test.yaml @@ -0,0 +1,38 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +suite: test networkpolicy +templates: + - networkpolicy.yaml +tests: + - it: should pass + set: + image.tag: latest + networkPolicy.enabled: true + networkPolicy.allowExternal: false + asserts: + - isKind: + of: NetworkPolicy + - matchRegex: + path: metadata.name + pattern: RELEASE-NAME-tika + - isAPIVersion: + of: networking.k8s.io/v1 + - isNullOrEmpty: + path: spec.egress[0] + - isNotNullOrEmpty: + path: spec.ingress[0].from diff --git a/tests/service_test.yaml b/tests/service_test.yaml new file mode 100644 index 0000000..41a3d1e --- /dev/null +++ b/tests/service_test.yaml @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +suite: test service +templates: + - service.yaml +tests: + - it: should pass + set: + image.tag: latest + asserts: + - isKind: + of: Service + - matchRegex: + path: metadata.name + pattern: RELEASE-NAME-tika + - isAPIVersion: + of: v1 + - equal: + path: spec.type + value: ClusterIP + - lengthEqual: + path: spec.ports + count: 1 + - equal: + path: spec.ports[0].port + value: 9998 diff --git a/tests/serviceaccount_test.yaml b/tests/serviceaccount_test.yaml new file mode 100644 index 0000000..6262685 --- /dev/null +++ b/tests/serviceaccount_test.yaml @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +suite: test serviceaccount +templates: + - serviceaccount.yaml +tests: + - it: should pass + set: + image.tag: latest + asserts: + - isKind: + of: ServiceAccount + - isAPIVersion: + of: v1 + - matchRegex: + path: metadata.name + pattern: RELEASE-NAME-tika diff --git a/values.yaml b/values.yaml index a446121..3ed0e77 100644 --- a/values.yaml +++ b/values.yaml @@ -97,7 +97,7 @@ resources: memory: 1500Mi autoscaling: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 enabled: false minReplicas: 1 maxReplicas: 100 From 6b62ac6bb5f1ab916a803698414bc7610d0445ce Mon Sep 17 00:00:00 2001 From: Lewis John McGibbney Date: Mon, 8 Apr 2024 16:09:08 -0700 Subject: [PATCH 2/3] TIKA-4232 Create and execute unit tests for tika-helm --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e3343cd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test-output.xml From c3eec9db2aa4e06dde5233c1f5fff92461485fe2 Mon Sep 17 00:00:00 2001 From: Lewis John McGibbney Date: Thu, 9 May 2024 08:25:09 -0700 Subject: [PATCH 3/3] TIKA-4232 Create and execute unit tests for tika-helm --- .github/workflows/lint-test.yaml | 30 ++++++++++++++++++++++++++++-- .github/workflows/pluto.yaml | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index 6e96eb9..e1cc61e 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -45,13 +45,39 @@ jobs: if [[ -n "$changed" ]]; then echo "::set-output name=changed::true" fi + shell: bash - name: Run chart-testing (lint) run: ct lint --target-branch ${{ github.event.repository.default_branch }} --charts . + shell: bash - name: Create kind cluster uses: helm/kind-action@v1.10.0 if: steps.list-changed.outputs.changed == 'true' + - name: Uninstall helm-unittest if present + run: | + helm plugin uninstall unittest >/dev/null 2>/dev/null \ + || echo "Failed to uninstall plugin, assuming it's not present." + shell: bash + - name: Install latest helm-unittest + run: | + echo "Installing latest version of helm-unittest" + helm plugin install https://github.com/helm-unittest/helm-unittest >/dev/null 2>/dev/null + shell: bash + - name: Assemble list of chart directories to test + run: | + tr ' ' '\n' <<< . | grep -v '^$' > charts-to-test || true + find . -type f -name 'Chart.yaml' -exec dirname {} \; > all-charts + [ -z . ] && mv all-charts charts-to-test || true + shell: bash + - name: Fetch chart dependencies + run: | + for chart in $(cat charts-to-test); do + helm dependency update "$chart" >/dev/null + done + shell: bash - name: Run unit tests - uses: d3adb5/helm-unittest-action@v2 + run: helm unittest --color $(cat charts-to-test) + shell: bash - name: Run chart-testing (install) + if: steps.list-changed.outputs.changed == 'true' run: ct install --target-branch ${{ github.event.repository.default_branch }} --charts . - if: steps.list-changed.outputs.changed == 'true' \ No newline at end of file + shell: bash diff --git a/.github/workflows/pluto.yaml b/.github/workflows/pluto.yaml index b3cd69c..d246f5e 100644 --- a/.github/workflows/pluto.yaml +++ b/.github/workflows/pluto.yaml @@ -35,8 +35,10 @@ jobs: wget https://github.com/FairwindsOps/pluto/releases/download/v${{ env.PLUTO_VERSION }}/pluto_${{ env.PLUTO_VERSION }}_linux_amd64.tar.gz -O - | tar -xz mv pluto /usr/local/bin/pluto chmod +x /usr/local/bin/pluto + shell: bash - name: Set up Helm uses: azure/setup-helm@v4.2.0 - name: verify helm chart run: | helm template . | pluto detect -omarkdown - >> $GITHUB_STEP_SUMMARY + shell: bash