Skip to content

Commit

Permalink
Add more strict Helm Chart schema checks for image pullPolicy & dags …
Browse files Browse the repository at this point in the history
…accessMode (#15040)

`values.schema.json` can be used to help check the structure & the values in `values.yaml`. 

- In this PR I extend the `values.schema.json` to ensure we have more strict checks on the values users add in `values.yaml`.
- Tests are added.
  • Loading branch information
XD-DENG authored Mar 26, 2021
1 parent 614be87 commit 28859ca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
39 changes: 39 additions & 0 deletions chart/tests/test_basic_helm_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Any, Dict, List, Union

import jmespath
from parameterized import parameterized

from tests.helm_template_generator import render_chart

Expand Down Expand Up @@ -146,3 +147,41 @@ def test_unsupported_executor(self):
'executor must be one of the following: "LocalExecutor", "CeleryExecutor", '
'"KubernetesExecutor", "CeleryKubernetesExecutor"' in ex_ctx.exception.stderr.decode()
)

@parameterized.expand(
[
("airflow",),
("pod_template",),
("flower",),
("statsd",),
("redis",),
("pgbouncer",),
("pgbouncerExporter",),
("gitSync",),
]
)
def test_invalid_pull_policy(self, image):
with self.assertRaises(CalledProcessError) as ex_ctx:
render_chart(
"TEST-BASIC",
{
"images": {image: {"pullPolicy": "InvalidPolicy"}},
},
)
assert (
'pullPolicy must be one of the following: "Always", "Never", "IfNotPresent"'
in ex_ctx.exception.stderr.decode()
)

def test_invalid_dags_access_mode(self):
with self.assertRaises(CalledProcessError) as ex_ctx:
render_chart(
"TEST-BASIC",
{
"dags": {"persistence": {"accessMode": "InvalidMode"}},
},
)
assert (
'accessMode must be one of the following: "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany"'
in ex_ctx.exception.stderr.decode()
)
27 changes: 18 additions & 9 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
},
"pullPolicy": {
"description": "The airflow image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -216,7 +217,8 @@
},
"pullPolicy": {
"description": "The pod_template image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -240,7 +242,8 @@
},
"pullPolicy": {
"description": "The flower image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -258,7 +261,8 @@
},
"pullPolicy": {
"description": "The statsd image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -276,7 +280,8 @@
},
"pullPolicy": {
"description": "The redis image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -294,7 +299,8 @@
},
"pullPolicy": {
"description": "The PgBouncer image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -312,7 +318,8 @@
},
"pullPolicy": {
"description": "The PgBouncer exporter image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
},
Expand All @@ -330,7 +337,8 @@
},
"pullPolicy": {
"description": "The gitSync image pull policy.",
"type": "string"
"type": "string",
"enum": ["Always", "Never", "IfNotPresent"]
}
}
}
Expand Down Expand Up @@ -1386,7 +1394,8 @@
},
"accessMode": {
"description": "Access mode of the persistent volume.",
"type": "string"
"type": "string",
"enum": ["ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany"]
},
"existingClaim": {
"description": "The name of an existing PVC to use.",
Expand Down

0 comments on commit 28859ca

Please sign in to comment.