Skip to content
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

add automated tests for the chart #343

Merged
merged 24 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
97c23b0
add automated tests for the chart
QuantumEnigmaa Jul 24, 2024
77918c5
add ats to circleci config
QuantumEnigmaa Jul 24, 2024
15bfa06
persist chart archive for ats
QuantumEnigmaa Jul 24, 2024
607f9a9
move ats to python 3.9
QuantumEnigmaa Jul 24, 2024
3642e43
fix imports
QuantumEnigmaa Jul 24, 2024
8ae7df4
fix errors in testing code
QuantumEnigmaa Jul 25, 2024
41c12a0
add test values' content
QuantumEnigmaa Jul 25, 2024
e291d48
Merge branch 'main' of github.com:giantswarm/loki-app into add-automa…
QuantumEnigmaa Jul 29, 2024
4d73aed
update test values
QuantumEnigmaa Jul 29, 2024
96a71ed
update namespace in test file
QuantumEnigmaa Jul 30, 2024
6649315
fix test values
QuantumEnigmaa Jul 30, 2024
07a9f54
increase timeout
QuantumEnigmaa Jul 31, 2024
0a13a58
add chart templating test job
QuantumEnigmaa Jul 31, 2024
9b810c0
Merge branch 'main' of github.com:giantswarm/loki-app into add-automa…
QuantumEnigmaa Aug 1, 2024
9542785
merge with main
QuantumEnigmaa Aug 12, 2024
e0d114a
update ignore in circleci config
QuantumEnigmaa Aug 19, 2024
5b532b7
enable multi-tenant-proxy secret creation
QuantumEnigmaa Aug 19, 2024
c2a4476
add coredns netpol as extraObject in test values
QuantumEnigmaa Aug 19, 2024
ba10913
add discovery port
QuantumEnigmaa Aug 20, 2024
ee6e26c
update test-values and enable minio
QuantumEnigmaa Aug 30, 2024
e4f6f2e
merge with main and nitpicking
QuantumEnigmaa Aug 30, 2024
28bd814
more nitpicking
QuantumEnigmaa Aug 30, 2024
3600048
update test-values
QuantumEnigmaa Sep 3, 2024
02b82b8
merge with main
QuantumEnigmaa Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .ats/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
app-tests-app-config-file: tests/test-values.yaml
app-tests-deploy-namespace: loki

smoke-tests-cluster-type: kind
smoke-tests-cluster-config-file: tests/kind-config.yaml

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

skip-steps: [functional]

# --------
# Uncomment values below this line to be able to execute app-test-suite against an externally created
QuantumEnigmaa marked this conversation as resolved.
Show resolved Hide resolved
# Kubernetes cluster.
# Comment out everything above

# If you want to create a kind cluster, use the line below
# kind create cluster --config tests/kind-config.yaml --kubeconfig kube.config
# --------

# app-tests-app-config-file: tests/test-values.yaml
# app-tests-deploy-namespace: loki

# upgrade-tests-app-catalog-url: https://giantswarm.github.io/giantswarm-catalog
# upgrade-tests-app-config-file: tests/test-values.yaml

# skip-steps: [functional, upgrade]

# smoke-tests-cluster-type: external
# functional-tests-cluster-type: external
# upgrade-tests-cluster-type: external
# external-cluster-kubeconfig-path: kube.config
# external-cluster-type: kind
# external-cluster-version: 1.24.0

# app-tests-skip-app-delete: "Yes"
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
version: 2.1
orbs:
architect: giantswarm/[email protected]
jobs:
template-chart:
docker:
- image: giantswarm/helm-chart-testing:v3.11.0
steps:
- checkout
- run: cd helm/loki && helm dep up
- run: helm template helm/loki

workflows:
package-and-push-chart-on-tag:
Expand All @@ -13,6 +21,7 @@ workflows:
app_catalog_test: "giantswarm-test-catalog"
chart: "loki"
ct_config: ".circleci/ct-config.yaml"
persist_chart_archive: true
# Trigger job on git tag.
filters:
tags:
Expand All @@ -30,6 +39,24 @@ workflows:
filters:
tags:
only: /^v.*/

- template-chart:
name: "template-chart-test"
filters:
branches:
ignore:
- main
requires:
- "package and push loki chart"

- architect/run-tests-with-ats:
name: run-tests-with-ats
requires:
- "package and push loki chart"
filters:
branches:
ignore:
- main

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

## [Unreleased]

### Added

- Add automated tests for the chart using app-test-suite.

## [0.22.0] - 2024-08-12

### Changed
Expand Down
12 changes: 12 additions & 0 deletions tests/ats/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[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"

[requires]
python_version = "3.9"
357 changes: 357 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
85 changes: 85 additions & 0 deletions tests/ats/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import logging
from typing import List, Tuple

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


logger = logging.getLogger(__name__)

namespace_name = "loki"
write_sts_name = "loki-write"
QuantumEnigmaa marked this conversation as resolved.
Show resolved Hide resolved
backend_sts_name = "loki-backend"
read_deployment_name = "loki-read"
gateway_deployment_name = "loki-gateway"

timeout: int = 900

@pytest.mark.smoke
def test_api_working(kube_cluster: Cluster) -> None:
"""Very minimalistic example of using the [kube_cluster](pytest_helm_charts.fixtures.kube_cluster)
fixture to get an instance of [Cluster](pytest_helm_charts.clusters.Cluster) under test
and access its [kube_client](pytest_helm_charts.clusters.Cluster.kube_client) property
to get access to Kubernetes API of cluster under test.
Please refer to [pykube](https://pykube.readthedocs.io/en/latest/api/pykube.html) to get docs
for [HTTPClient](https://pykube.readthedocs.io/en/latest/api/pykube.html#pykube.http.HTTPClient).
"""
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_components(kube_cluster: Cluster) -> Tuple[List[pykube.Deployment], List[pykube.StatefulSet]]:
QuantumEnigmaa marked this conversation as resolved.
Show resolved Hide resolved
logger.info("Waiting for loki components to be deployed..")

components_ready = wait_for_ic_components(kube_cluster)

logger.info("loki components are deployed..")

return components_ready

def wait_for_ic_components(kube_cluster: Cluster) -> Tuple[List[pykube.Deployment], List[pykube.StatefulSet]]:
deployments = wait_for_deployments_to_run(
kube_cluster.kube_client,
[read_deployment_name, gateway_deployment_name],
namespace_name,
timeout,
)
statefulsets = wait_for_stateful_sets_to_run(
kube_cluster.kube_client,
[write_sts_name, backend_sts_name],
namespace_name,
timeout,
)
return (deployments, statefulsets)

@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': 'loki', 'app.kubernetes.io/instance': 'loki'})

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_components: Tuple[List[pykube.Deployment], List[pykube.StatefulSet]]):
QuantumEnigmaa marked this conversation as resolved.
Show resolved Hide resolved
# loop over the list of deployments
for d in ic_components[0]:
assert int(d.obj["status"]["readyReplicas"]) == int(d.obj["spec"]["replicas"])

# loop over the list of statefulsets
for s in ic_components[1]:
assert int(s.obj["status"]["readyReplicas"]) == int(s.obj["spec"]["replicas"])

# when we start the tests on circleci, we have to wait for pods to be available, hence
# this additional delay and retries
28 changes: 28 additions & 0 deletions tests/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
featureGates:
SeccompDefault: true
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: JoinConfiguration
nodeRegistration:
kubeletExtraArgs:
seccomp-default: "true"
- role: worker
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
seccomp-default: "true"
- role: worker
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
seccomp-default: "true"
Loading