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

update ats tests #229

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
11 changes: 9 additions & 2 deletions .ats/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
skip-steps: smoke
app-tests-app-config-file: tests/test-values.yaml
app-tests-deploy-namespace: monitoring

functional-tests-cluster-type: kind
smoke-tests-cluster-type: kind

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

skip-steps: [functional]

36 changes: 27 additions & 9 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/grafana && helm dep up
- run: helm template helm/grafana

workflows:
package-and-push-chart-on-tag:
Expand Down Expand Up @@ -32,6 +40,25 @@ workflows:
tags:
only: /^v.*/

- template-chart:
name: "template-chart"
filters:
branches:
ignore:
- master
requires:
- "app-catalog"

- architect/run-tests-with-ats:
name: run-chart-tests-with-ats
filters:
# Do not trigger the job on merge to master.
branches:
ignore:
- master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean main right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have preferred but unfortunately, this repo's "main" branch is called "master" :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? Maybe we should change it then :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would totally agree :)

requires:
- "app-catalog"

- architect/push-to-app-collection:
context: "architect"
name: aws-app-collection
Expand Down Expand Up @@ -139,12 +166,3 @@ workflows:
ignore: /.*/
tags:
only: /^v.*/
# - architect/run-tests-with-ats:
# name: execute chart tests
# filters:
# # Do not trigger the job on merge to master.
# branches:
# ignore:
# - master
# requires:
# - "package and push grafana chart"
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]

### Changed

- Update tests for ats usage.

## [2.13.0] - 2024-07-15

### Changed
Expand Down
11 changes: 5 additions & 6 deletions tests/ats/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ verify_ssl = true
name = "pypi"

[packages]
pytest-helm-charts = ">=0.3.1"
pytest = ">=6.1.2"
pytest-rerunfailures = "*"

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

[requires]
python_version = "3.8"
python_version = "3.9"
386 changes: 289 additions & 97 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
73 changes: 63 additions & 10 deletions tests/ats/test_grafana.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
from typing import cast
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__)

# when grafana pod is up, it might be still starting and returning 503
@pytest.mark.flaky(reruns=10, reruns_delay=10)
@pytest.mark.functional
def test_grafana_login_page_available(kube_cluster: Cluster) -> None:
srv = cast(pykube.Service, pykube.Service.objects(kube_cluster.kube_client).get_or_none(name="grafana"))
if srv is None:
raise ValueError("'grafana service not found in the 'default' namespace")
login_page_res = srv.proxy_http_get("/login")
assert login_page_res.ok
namespace_name = "monitoring"
deployment_name= "grafana"

timeout: int = 560

@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this test?
According to the comments it's just supposed to be an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not absolutely necessary but still nice to make sure that the apiserver is reachable before proceeding with any further tests right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, why not, but then that's what the comment should say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment.


# 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 grafana deployment..")

deployment_ready = wait_for_ic_deployment(kube_cluster)

logger.info("grafana 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': 'grafana', 'app.kubernetes.io/instance': 'grafana'})

return pods

# when we start the tests on circleci, we have to wait for pods to be available, hence
# this additional delay and retries
QuantumEnigmaa marked this conversation as resolved.
Show resolved Hide resolved


@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"])
113 changes: 113 additions & 0 deletions tests/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
global:
imageRegistry: gsoci.azurecr.io
grafana:
dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
providers:
- allowUiUpdates: false
disableDeletion: true
editable: false
folder: Giant Swarm private dashboards
folderUid: GMtRhFeGz
name: private
options:
path: /var/lib/grafana/dashboards/private
type: file
updateIntervalSeconds: 60
- allowUiUpdates: false
disableDeletion: true
editable: false
folder: Giant Swarm public dashboards
folderUid: b6utHHg7z
name: public
options:
path: /var/lib/grafana/dashboards/public
type: file
updateIntervalSeconds: 60
- allowUiUpdates: false
disableDeletion: true
editable: false
folder: Your dashboards
folderUid: customerDashboards
name: customer-provided
options:
path: /var/lib/grafana/dashboards/customer
type: file
updateIntervalSeconds: 60
grafana.ini:
analytics:
check_for_updates: false
feedback_links_enabled: false
reporting_enabled: false
auth:
disable_login_form: true
disable_signout_menu: true
auth.basic:
enabled: true
auth.generic_oauth:
allow_assign_grafana_admin: true
allow_sign_up: true
api_url: https://dex.grizzly.gaws.gigantic.io/userinfo
auth_url: https://dex.grizzly.gaws.gigantic.io/auth
auto_login: true
client_id: 2qRgNb5qQBk3QqWxI1WLgB5zTQ1M4eB+
enabled: true
name: grafana-dex
role_attribute_path: contains(groups, 'giantswarm-ad:giantswarm-admins') &&
'GrafanaAdmin' || contains(groups, 'customer:giantswarm:Employees') && 'Viewer'
|| contains (groups, 'giantswarm-github:giantswarm:giantswarm-admins') &&
'GrafanaAdmin'
role_attribute_strict: true
scopes: openid profile email groups offline_access
token_url: https://dex.grizzly.gaws.gigantic.io/token
use_refresh_token: true
dashboards:
default_home_dashboard_path: /var/lib/grafana/dashboards/public/home/home.json
public_dashboards:
enabled: false
security:
cookie_secure: true
disable_gravatar: true
server:
protocol: http
root_url: https://grafana.grizzly.gaws.gigantic.io
users:
allow_org_create: false
allow_sign_up: false
viewers_can_edit: true
image:
repository: giantswarm/grafana
ingress:
annotations:
cert-manager.io/cluster-issuer: letsencrypt-giantswarm
kubernetes.io/tls-acme: "true"
enabled: true
hosts:
- grafana.grizzly.gaws.gigantic.io
ingressClassName: nginx
tls:
- hosts:
- grafana.grizzly.gaws.gigantic.io
secretName: grafana-tls
rbac:
pspEnabled: false
serviceMonitor:
enabled: true
sidecar:
dashboards:
SCProvider: false
enabled: true
folder: /var/lib/grafana/dashboards
label: app.giantswarm.io/kind
labelValue: dashboard
searchNamespace: ALL
datasources:
enabled: true
label: app.giantswarm.io/kind
labelValue: datasource
resource: both
searchNamespace: ALL
image:
repository: giantswarm/k8s-sidecar

QuantumEnigmaa marked this conversation as resolved.
Show resolved Hide resolved