-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for Nodegroups and Addons (#13)
Description of changes: Add create/delete tests for Nodegroup and Addon types By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
1 parent
34da725
commit 547bf9f
Showing
9 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: eks.services.k8s.aws/v1alpha1 | ||
kind: Addon | ||
metadata: | ||
name: $CR_NAME | ||
spec: | ||
name: $ADDON_NAME | ||
addonVersion: $ADDON_VERSION | ||
clusterName: $CLUSTER_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: eks.services.k8s.aws/v1alpha1 | ||
kind: Nodegroup | ||
metadata: | ||
name: $NODEGROUP_NAME | ||
spec: | ||
name: $NODEGROUP_NAME | ||
clusterName: $CLUSTER_NAME | ||
subnets: | ||
- "$PUBLIC_SUBNET_1" | ||
- "$PUBLIC_SUBNET_2" | ||
nodeRole: $NODEGROUP_ROLE | ||
scalingConfig: | ||
minSize: 1 | ||
maxSize: 1 | ||
desiredSize: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
# not use this file except in compliance with the License. A copy of the | ||
# License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
"""Integration tests for the EKS Addon resource | ||
""" | ||
|
||
import logging | ||
import time | ||
from typing import Dict, Tuple | ||
|
||
import pytest | ||
|
||
from acktest.k8s import resource as k8s | ||
from acktest.resources import random_suffix_name | ||
from e2e import CRD_VERSION, service_marker, CRD_GROUP, load_eks_resource | ||
from e2e.replacement_values import REPLACEMENT_VALUES | ||
|
||
from .test_cluster import simple_cluster, wait_for_cluster_active | ||
|
||
RESOURCE_PLURAL = 'addons' | ||
|
||
CREATE_WAIT_AFTER_SECONDS = 10 | ||
|
||
def wait_for_addon_deleted(eks_client, cluster_name, addon_name): | ||
waiter = eks_client.get_waiter('addon_deleted') | ||
waiter.wait(clusterName=cluster_name, addonName=addon_name) | ||
|
||
@pytest.fixture | ||
def coredns_addon(eks_client, simple_cluster) -> Tuple[k8s.CustomResourceReference, Dict]: | ||
addon_name = "coredns" | ||
addon_version = "v1.8.4-eksbuild.1" | ||
|
||
(ref, cr) = simple_cluster | ||
cluster_name = cr["spec"]["name"] | ||
|
||
wait_for_cluster_active(eks_client, cluster_name) | ||
|
||
cr_name = random_suffix_name("addon", 32) | ||
|
||
replacements = REPLACEMENT_VALUES.copy() | ||
replacements["CLUSTER_NAME"] = cluster_name | ||
replacements["CR_NAME"] = cr_name | ||
replacements["ADDON_NAME"] = addon_name | ||
replacements["ADDON_VERSION"] = addon_version | ||
|
||
resource_data = load_eks_resource( | ||
"addon_simple", | ||
additional_replacements=replacements, | ||
) | ||
logging.debug(resource_data) | ||
|
||
# Create the k8s resource | ||
ref = k8s.CustomResourceReference( | ||
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL, | ||
cr_name, namespace="default", | ||
) | ||
k8s.create_custom_resource(ref, resource_data) | ||
cr = k8s.wait_resource_consumed_by_controller(ref) | ||
|
||
assert cr is not None | ||
assert k8s.get_resource_exists(ref) | ||
|
||
time.sleep(CREATE_WAIT_AFTER_SECONDS) | ||
|
||
yield (ref, cr) | ||
|
||
_, deleted = k8s.delete_custom_resource(ref, 3, 10) | ||
assert deleted | ||
|
||
wait_for_addon_deleted(eks_client, cluster_name, cr_name) | ||
|
||
@service_marker | ||
class TestAddon: | ||
def test_create_delete_addon(self, coredns_addon, eks_client): | ||
(ref, cr) = coredns_addon | ||
|
||
cluster_name = cr["spec"]["clusterName"] | ||
cr_name = ref.name | ||
|
||
addon_name = cr["spec"]["name"] | ||
|
||
try: | ||
aws_res = eks_client.describe_addon( | ||
clusterName=cluster_name, | ||
addonName=addon_name | ||
) | ||
assert aws_res is not None | ||
|
||
assert aws_res["addon"]["addonName"] == addon_name | ||
assert aws_res["addon"]["addonArn"] is not None | ||
except eks_client.exceptions.ResourceNotFoundException: | ||
pytest.fail(f"Could not find Addon '{cr_name}' in EKS") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
# not use this file except in compliance with the License. A copy of the | ||
# License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
"""Integration tests for the EKS Nodegroup resource | ||
""" | ||
|
||
import logging | ||
import time | ||
from typing import Dict, Tuple | ||
|
||
import pytest | ||
|
||
from acktest.k8s import resource as k8s | ||
from acktest.resources import random_suffix_name | ||
from e2e import CRD_VERSION, service_marker, CRD_GROUP, load_eks_resource | ||
from e2e.replacement_values import REPLACEMENT_VALUES | ||
|
||
from .test_cluster import simple_cluster, wait_for_cluster_active | ||
|
||
RESOURCE_PLURAL = 'nodegroups' | ||
|
||
CREATE_WAIT_AFTER_SECONDS = 10 | ||
|
||
def wait_for_nodegroup_active(eks_client, cluster_name, nodegroup_name): | ||
waiter = eks_client.get_waiter('nodegroup_active') | ||
waiter.wait(clusterName=cluster_name, nodegroupName=nodegroup_name) | ||
|
||
def wait_for_nodegroup_deleted(eks_client, cluster_name, nodegroup_name): | ||
waiter = eks_client.get_waiter('nodegroup_deleted') | ||
waiter.wait(clusterName=cluster_name, nodegroupName=nodegroup_name) | ||
|
||
@pytest.fixture | ||
def simple_nodegroup(eks_client, simple_cluster) -> Tuple[k8s.CustomResourceReference, Dict]: | ||
(ref, cr) = simple_cluster | ||
cluster_name = cr["spec"]["name"] | ||
|
||
wait_for_cluster_active(eks_client, cluster_name) | ||
|
||
nodegroup_name = random_suffix_name("nodegroup", 32) | ||
|
||
replacements = REPLACEMENT_VALUES.copy() | ||
replacements["CLUSTER_NAME"] = cluster_name | ||
replacements["NODEGROUP_NAME"] = nodegroup_name | ||
|
||
resource_data = load_eks_resource( | ||
"nodegroup_simple", | ||
additional_replacements=replacements, | ||
) | ||
logging.debug(resource_data) | ||
|
||
# Create the k8s resource | ||
ref = k8s.CustomResourceReference( | ||
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL, | ||
nodegroup_name, namespace="default", | ||
) | ||
k8s.create_custom_resource(ref, resource_data) | ||
cr = k8s.wait_resource_consumed_by_controller(ref) | ||
|
||
assert cr is not None | ||
assert k8s.get_resource_exists(ref) | ||
|
||
time.sleep(CREATE_WAIT_AFTER_SECONDS) | ||
|
||
yield (ref, cr) | ||
|
||
_, deleted = k8s.delete_custom_resource(ref, 3, 10) | ||
assert deleted | ||
|
||
wait_for_nodegroup_deleted(eks_client, cluster_name, nodegroup_name) | ||
|
||
@service_marker | ||
class TestNodegroup: | ||
def test_create_delete_nodegroup(self, simple_nodegroup, eks_client): | ||
(ref, cr) = simple_nodegroup | ||
|
||
cluster_name = cr["spec"]["clusterName"] | ||
cr_name = ref.name | ||
|
||
nodegroup_name = cr["spec"]["name"] | ||
|
||
try: | ||
aws_res = eks_client.describe_nodegroup( | ||
clusterName=cluster_name, | ||
nodegroupName=nodegroup_name | ||
) | ||
assert aws_res is not None | ||
|
||
assert aws_res["nodegroup"]["nodegroupName"] == nodegroup_name | ||
assert aws_res["nodegroup"]["nodegroupArn"] is not None | ||
except eks_client.exceptions.ResourceNotFoundException: | ||
pytest.fail(f"Could not find Nodegroup '{cr_name}' in EKS") |