kubenix/tests/helm/simple.nix

108 lines
3.6 KiB
Nix
Raw Normal View History

2021-05-06 16:07:24 -04:00
{ config, lib, pkgs, kubenix, helm, ... }:
2019-02-28 15:10:06 +01:00
with lib;
2019-03-07 18:02:26 +01:00
with kubenix.lib;
2019-02-28 15:10:06 +01:00
with pkgs.dockerTools;
let
2019-10-10 13:28:48 +02:00
corev1 = config.kubernetes.api.resources.core.v1;
2020-04-04 19:17:59 +07:00
appsv1 = config.kubernetes.api.resources.apps.v1;
2019-02-28 15:10:06 +01:00
postgresql = pullImage {
imageName = "docker.io/bitnami/postgresql";
2020-04-04 19:17:59 +07:00
imageDigest = "sha256:ec16eb9ff2e7bf0669cfc52e595f17d9c52efd864c3f943f404d525dafaaaf96";
2021-04-29 16:23:32 -05:00
sha256 = "12jr8pzvj1qglrp7sh857a5mv4nda67hw9si6ah2bl6y1ff19l65";
finalImageName = "docker.io/bitnami/postgresql";
2020-04-04 19:17:59 +07:00
finalImageTag = "11.7.0-debian-10-r55";
2019-02-28 15:10:06 +01:00
};
postgresqlExporter = pullImage {
2020-04-04 19:17:59 +07:00
imageName = "docker.io/bitnami/postgres-exporter";
2021-04-29 16:23:32 -05:00
imageDigest = "sha256:373ba8ac1892291b4121591d1d933b7f9501ae45b9b8d570d7deb4900f91cfe9";
sha256 = "0icrqmlj8127jhmiy3vh419cv7hwnw19xdn89hxxyj2l6a1chryh";
finalImageName = "docker.io/bitnami/postgres-exporter";
finalImageTag = "0.9.0-debian-10-r43";
2019-02-28 15:10:06 +01:00
};
2021-04-29 16:23:32 -05:00
bitnamiShell = pullImage {
imageName = "docker.io/bitnami/bitnami-shell";
imageDigest = "sha256:58ba68e1f1d9a55c1234ae5b439bdcf0de1931e4aa1bac7bd0851b66de14fd97";
sha256 = "00lmphm3ds17apbmh2m2r7cz05jhp4dc3ynswrj0pbpq0azif4zn";
finalImageName = "docker.io/bitnami/bitnami-shell";
finalImageTag = "10";
2019-02-28 15:10:06 +01:00
};
2021-05-13 17:27:08 -04:00
in
{
2021-05-13 22:58:11 -04:00
imports = [ kubenix.modules.test kubenix.modules.helm kubenix.modules.k8s kubenix.modules.docker ];
docker.images = {
2022-04-02 13:46:23 -07:00
postgresql.image = postgresql;
postgresqlExporter.image = postgresqlExporter;
bitnamiShell.image = bitnamiShell;
2021-05-13 22:58:11 -04:00
};
test = {
name = "helm-simple";
description = "Simple k8s testing wheter name, apiVersion and kind are preset";
assertions = [{
message = "should have generated resources";
assertion =
2021-04-29 16:23:32 -05:00
appsv1.StatefulSet ? "app-psql-postgresql-primary" &&
appsv1.StatefulSet ? "app-psql-postgresql-read" &&
corev1.Secret ? "app-psql-postgresql" &&
2021-05-13 17:27:08 -04:00
corev1.Service ? "app-psql-postgresql-headless";
}
{
message = "should have values passed";
assertion = appsv1.StatefulSet.app-psql-postgresql-read.spec.replicas == 2;
}
{
message = "should have namespace defined";
assertion =
appsv1.StatefulSet.app-psql-postgresql-primary.metadata.namespace == "test";
}];
2021-05-13 22:58:11 -04:00
script = ''
@pytest.mark.applymanifest('${config.kubernetes.resultYAML}')
def test_helm_deployment(kube):
"""Tests whether helm deployment gets successfully created"""
kube.wait_for_registered(timeout=30)
# TODO: implement those kind of checks from the host machine into the cluster
# via port forwarding, prepare all runtimes accordingly
# PGPASSWORD=postgres ${pkgs.postgresql}/bin/psql -h app-psql-postgresql.test.svc.cluster.local -U postgres -l
2019-02-28 15:10:06 +01:00
'';
};
kubernetes.helm.instances.app-psql = {
2021-05-13 22:58:11 -04:00
namespace = "some-overridden-by-kubetest";
chart = helm.fetch {
2020-04-04 19:17:59 +07:00
repo = "https://charts.bitnami.com/bitnami";
2020-01-14 19:13:33 +00:00
chart = "postgresql";
2021-04-29 16:23:32 -05:00
version = "10.3.8";
sha256 = "sha256-0hJ5pNIivpXeRal1DwJ2VSD3Yxtw2omOoIYGZKGtu9I=";
};
values = {
2019-02-28 15:10:06 +01:00
image = {
repository = "bitnami/postgresql";
2021-04-29 16:23:32 -05:00
tag = "11.11.0-debian-10-r71";
2019-02-28 15:10:06 +01:00
pullPolicy = "IfNotPresent";
};
volumePermissions.image = {
2021-04-29 16:23:32 -05:00
repository = "bitnami/bitnami-shell";
tag = "10";
2019-02-28 15:10:06 +01:00
pullPolicy = "IfNotPresent";
};
metrics.image = {
2021-04-29 16:23:32 -05:00
repository = "bitnami/postgres-exporter";
tag = "0.9.0-debian-10-r43";
2019-02-28 15:10:06 +01:00
pullPolicy = "IfNotPresent";
};
replication.enabled = true;
replication.slaveReplicas = 2;
2019-02-28 15:10:06 +01:00
postgresqlPassword = "postgres";
persistence.enabled = false;
};
};
}