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 full core testing coverage #42

Merged
merged 6 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .github/workflows/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ jobs:
shell: bash -l {0}
run: |
ci/code_checks.sh doctests
pip install sphinx
pip install sphinx_rtd_theme
pip install -r docs/requirements.txt
cd docs
make html
if: always()

- name: Docstring validation
Expand Down
26 changes: 14 additions & 12 deletions avionix/kube/apiextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ class JSONSchemaProps(HelmYaml):
items.
:param x_kubernetes_list_type: x-kubernetes-list-type annotates an array to further \
describe its topology. This extension must only be used on lists and may have \
3 possible values: 1) `atomic`: the list is treated as a single entity, like \
a scalar. Atomic lists will be entirely replaced when updated. This \
extension may be used on any type of list (struct, scalar, ...). 2) \
`set`: Sets are lists that must not have multiple items with the same \
value. Each value must be a scalar, an object with x-kubernetes-map-type \
`atomic` or an array with x-kubernetes-list-type `atomic`. 3) `map`: \
These lists are like maps in that their elements have a non-index key \
used to identify them. Order is preserved upon merge. The map tag must \
only be used on a list with elements of type object. Defaults to atomic for \
arrays.
3 possible values:
1) `atomic`: the list is treated as a single entity, like a scalar.
Atomic lists will be entirely replaced when updated. This extension
may be used on any type of list (struct, scalar, ...).
2) `set`: Sets are lists that must not have multiple items with the same \
value. Each value must be a scalar, an object with x-kubernetes-map-type \
`atomic` or an array with x-kubernetes-list-type `atomic`.
3) `map`: These lists are like maps in that their elements have a non-index
key used to identify them. Order is preserved upon merge. The map tag must \
only be used on a list with elements of type object. Defaults to atomic
for arrays.
:param x_kubernetes_map_type: x-kubernetes-map-type annotates an object to further \
describe its topology. This extension must only be used when type is object \
and may have 2 possible values: 1) `granular`: These maps are actual \
Expand Down Expand Up @@ -434,9 +435,10 @@ class CustomResourceConversion(HelmYaml):
:param strategy: strategy specifies how custom resources are converted between \
versions. Allowed values are:
- `None`: The converter only change the apiVersion and would not touch any
other field in the custom resource.
other field in the custom resource.
- `Webhook`: API Server will call to an external webhook to do the
conversion.
conversion.

Additional information is needed for this option. This requires \
spec.preserveUnknownFields to be false, and spec.conversion.webhook to be set.
"""
Expand Down
24 changes: 5 additions & 19 deletions avionix/kube/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,11 @@ class TopologySpreadConstraint(HelmYaml):
doesn't satisfy the spread constraint.
- DoNotSchedule (default) tells the scheduler not to schedule it
- ScheduleAnyway tells the scheduler to still schedule it It's considered as
"Unsatisfiable" if and only if placing incoming pod on any topology
violates "MaxSkew". For example, in a 3-zone cluster, MaxSkew is set to 1,
and pods with the same labelSelector spread as
3/1/1: | zone1 | zone2 | zone3 | | P P P | P | P |
"Unsatisfiable" if and only if placing incoming pod on any topology
violates "MaxSkew". For example, in a 3-zone cluster, MaxSkew is set to
1, and pods with the same labelSelector spread as
3/1/1: | zone1 | zone2 | zone3 | | P P P | P | P |

If WhenUnsatisfiable is set to DoNotSchedule, incoming pod can only be
scheduled to zone2(zone3) to become 3/2/1(3/1/2) as ActualSkew(2-1) on
zone2(zone3) satisfies MaxSkew(1). In other words, the cluster can still be
Expand Down Expand Up @@ -2841,21 +2842,6 @@ def __init__(
self.secrets = secrets


class ComponentCondition(HelmYaml):
"""
:param error: Condition error code for a component. For example, a health check \
error code.
:param message: Message about the condition for a component. For example, \
information about a health check.
:param type: Type of condition for a component. Valid value: "Healthy"
"""

def __init__(self, error: str, message: str, type: str):
self.error = error
self.message = message
self.type = type


class TypedLocalObjectReference(KubernetesBaseObject):
"""
:param name: Name is the name of resource being referenced
Expand Down
69 changes: 59 additions & 10 deletions avionix/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
LimitRange,
LimitRangeItem,
LimitRangeSpec,
LocalVolumeSource,
Namespace,
NamespaceSpec,
Node,
Expand Down Expand Up @@ -90,6 +91,7 @@
TopologySpreadConstraint,
Volume,
VolumeMount,
VolumeNodeAffinity,
VolumeProjection,
WeightedPodAffinityTerm,
WindowsSecurityContextOptions,
Expand Down Expand Up @@ -307,24 +309,69 @@ def test_node(chart_info, node: Node):


@pytest.fixture
def persistent_volume(access_modes):
def persistent_volume_spec():
"""
A generic persistent volume spec
"""
return PersistentVolumeSpec(
["ReadWriteMany"],
capacity={"storage": 1},
host_path=HostPathVolumeSource("/home/test/tmp"),
storage_class_name="standard",
)


@pytest.fixture
def persistent_volume(persistent_volume_spec):
"""
A generic persistent volume
"""
return PersistentVolume(
ObjectMeta(name="test-persistent-volume"),
ObjectMeta(name="test-persistent-volume"), persistent_volume_spec,
)


@pytest.mark.parametrize(
"persistent_volume_spec",
[
PersistentVolumeSpec(
access_modes,
["ReadWriteMany"],
capacity={"storage": 1},
host_path=HostPathVolumeSource("/home/test/tmp"),
storage_class_name="standard",
),
PersistentVolumeSpec(
["ReadWriteMany"],
capacity={"storage": 1},
storage_class_name="standard",
local=LocalVolumeSource("test", "/usr/tmp"),
node_affinity=VolumeNodeAffinity(
NodeSelector(
[
NodeSelectorTerm(
match_expressions=[
NodeSelectorRequirement(
"kubernetes.io/os", "In", ["linux"]
)
]
)
]
)
),
),
],
)
def test_persistent_volume(chart_info, persistent_volume_spec):
persistent_volume = PersistentVolume(
ObjectMeta(name="test-persistent-volume"), persistent_volume_spec
)


def test_persistent_volume(chart_info, persistent_volume):
builder = ChartBuilder(chart_info, [persistent_volume])
builder = ChartBuilder(chart_info, [persistent_volume],)
with ChartInstallationContext(builder):
volume_info = kubectl_get("persistentvolumes")
assert volume_info["NAME"][0] == "test-persistent-volume"
assert volume_info["CAPACITY"][0] == "1"
assert volume_info["NAME"][0] == persistent_volume.metadata.name
assert volume_info["CAPACITY"][0] == str(
persistent_volume.spec.capacity["storage"]
)
assert volume_info["ACCESS MODES"][0] == modes_expected_value


Expand Down Expand Up @@ -506,14 +553,16 @@ def test_create_binding(chart_info: ChartInfo, binding: Binding, pod: Pod):

@pytest.fixture
def persistent_volume_claim(persistent_volume):
"""
A generic persistent volume claim
"""
return PersistentVolumeClaim(
ObjectMeta(name="test-pv-claim"),
PersistentVolumeClaimSpec(
persistent_volume.spec.accessModes,
resources=ResourceRequirements(
requests={"storage": persistent_volume.spec.capacity["storage"]}
),
# volume_mode="Block"
),
)

Expand Down