Skip to content

Commit

Permalink
add tests for the chart (#61)
Browse files Browse the repository at this point in the history
* add tests for the chart

* Update .ats/main.yaml

Co-authored-by: Hervé Nicol <[email protected]>

* change job dependency for push-to-registries

---------

Co-authored-by: Hervé Nicol <[email protected]>
  • Loading branch information
QuantumEnigmaa and hervenicol authored Aug 19, 2024
1 parent d1d5bd8 commit 5344001
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .ats/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
app-tests-app-config-file: tests/test-values.yaml
app-tests-deploy-namespace: monitoring

smoke-tests-cluster-type: kind

upgrade-tests-cluster-type: kind
upgrade-tests-app-catalog-url: https://giantswarm.github.io/control-plane-catalog
upgrade-tests-app-config-file: tests/test-values.yaml

skip-steps: [functional]
29 changes: 28 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ jobs:
- run:
name: "Run unit tests"
command: CGO_ENABLED=0 make test-unit
template-chart:
docker:
- image: giantswarm/helm-chart-testing:v3.11.0
steps:
- checkout
- run: cd helm/observability-operator && helm dep up
- run: helm template helm/observability-operator

workflows:
build:
Expand All @@ -28,12 +35,21 @@ workflows:
filters:
tags:
only: /^v.*/

- template-chart:
name: "template-chart"
filters:
branches:
ignore:
- master
requires:
- "go-build"

- architect/push-to-registries:
context: architect
name: push-to-registries
requires:
- go-build
- template-chart
filters:
tags:
only: /^v.*/
Expand All @@ -45,11 +61,22 @@ workflows:
app_catalog: "control-plane-catalog"
app_catalog_test: "control-plane-test-catalog"
chart: "observability-operator"
persist_chart_archive: true
requires:
- push-to-registries
filters:
tags:
only: /^v.*/

- architect/run-tests-with-ats:
name: run-chart-tests-with-ats
filters:
# Do not trigger the job on merge to master.
branches:
ignore:
- master
requires:
- push-to-app-catalog

- architect/push-to-app-collection:
context: "architect"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add tests with ats in ci pipeline.
- Add helm chart templating test in ci pipeline.
- Add support for Alloy to be used as monitoring agent in-place of Prometheus Agent. This is configurable via the `--monitoring-agent` flag.

## [0.3.1] - 2024-07-22
Expand Down
13 changes: 13 additions & 0 deletions tests/ats/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pytest-helm-charts = ">=1.0.2"
pytest = ">=6.2.5"
pykube-ng = ">=22.1.0"
pytest-rerunfailures = "~=14.0"

[requires]
python_version = "3.9"
366 changes: 366 additions & 0 deletions tests/ats/Pipfile.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tests/ats/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
markers =
smoke
functional
upgrade
65 changes: 65 additions & 0 deletions tests/ats/test_olly_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import logging
from typing import List

import pykube
import pytest
from pytest_helm_charts.clusters import Cluster
from pytest_helm_charts.k8s.deployment import wait_for_deployments_to_run

logger = logging.getLogger(__name__)

namespace_name = "monitoring"
deployment_name= "observability-operator"

timeout: int = 560

@pytest.mark.smoke
def test_api_working(kube_cluster: Cluster) -> None:
"""
Testing apiserver availability.
"""
assert kube_cluster.kube_client is not None
assert len(pykube.Node.objects(kube_cluster.kube_client)) >= 1

# scope "module" means this is run only once, for the first test case requesting! It might be tricky
# if you want to assert this multiple times
@pytest.fixture(scope="module")
def ic_deployment(kube_cluster: Cluster) -> List[pykube.Deployment]:
logger.info("Waiting for observability-operator deployment..")

deployment_ready = wait_for_ic_deployment(kube_cluster)

logger.info("observability-operator deployment looks satisfied..")

return deployment_ready

def wait_for_ic_deployment(kube_cluster: Cluster) -> List[pykube.Deployment]:
deployments = wait_for_deployments_to_run(
kube_cluster.kube_client,
[deployment_name],
namespace_name,
timeout,
)
return deployments


@pytest.fixture(scope="module")
def pods(kube_cluster: Cluster) -> List[pykube.Pod]:
pods = pykube.Pod.objects(kube_cluster.kube_client)

pods = pods.filter(namespace=namespace_name, selector={
'app.kubernetes.io/name': 'observability-operator', 'app.kubernetes.io/instance': 'observability-operator'})

return pods

# when we start the tests on circleci, we have to wait for pods to be available, hence
# this additional delay and retries


@pytest.mark.smoke
@pytest.mark.upgrade
@pytest.mark.flaky(reruns=5, reruns_delay=10)
def test_pods_available(ic_deployment: List[pykube.Deployment]):
for s in ic_deployment:
assert int(s.obj["status"]["readyReplicas"]) == int(
s.obj["spec"]["replicas"])
Empty file added tests/test-values.yaml
Empty file.

0 comments on commit 5344001

Please sign in to comment.