-
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.
Partly accomplishes: aws-controllers-k8s/community#858 Description of changes: Add initial smoke tests for creating and then deleting a `Cluster` Add smoke test for creating and deleting a `FargateProfile` - using a `Cluster` as the fixture 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
6d7cf6b
commit 191a020
Showing
14 changed files
with
277 additions
and
30 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
.idea | ||
/docs/site | ||
bin | ||
build | ||
build | ||
.env |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
**/bootstrap.yaml | ||
**/bootstrap.yaml | ||
**/bootstrap.pkl |
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
Empty file.
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 @@ | ||
CLUSTER_RESOURCE_PLURAL = 'clusters' |
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 |
---|---|---|
@@ -1 +1 @@ | ||
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@955d7831ee374a212250179e95a5f3b75e555fd9 | ||
acktest @ git+https://github.com/aws-controllers-k8s/test-infra.git@955d7831ee374a212250179e95a5f3b75e555fd9 |
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,13 @@ | ||
apiVersion: eks.services.k8s.aws/v1alpha1 | ||
kind: Cluster | ||
metadata: | ||
name: $CLUSTER_NAME | ||
spec: | ||
name: $CLUSTER_NAME | ||
roleARN: $CLUSTER_ROLE | ||
resourcesVPCConfig: | ||
endpointPrivateAccess: true | ||
endpointPublicAccess: true | ||
subnetIDs: | ||
- "$PUBLIC_SUBNET_1" | ||
- "$PUBLIC_SUBNET_2" |
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,13 @@ | ||
apiVersion: eks.services.k8s.aws/v1alpha1 | ||
kind: FargateProfile | ||
metadata: | ||
name: $PROFILE_NAME | ||
spec: | ||
name: $PROFILE_NAME | ||
clusterName: $CLUSTER_NAME | ||
podExecutionRoleARN: $FARGATE_POD_ROLE | ||
subnets: | ||
- "$PRIVATE_SUBNET_1" | ||
- "$PRIVATE_SUBNET_2" | ||
selectors: | ||
- namespace: default |
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,99 @@ | ||
# 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 Cluster resource | ||
""" | ||
|
||
import boto3 | ||
import datetime | ||
import logging | ||
import time | ||
from typing import Dict | ||
|
||
import pytest | ||
|
||
from acktest.k8s import resource as k8s | ||
from acktest.resources import random_suffix_name | ||
from e2e import service_marker, CRD_GROUP, CRD_VERSION, load_eks_resource | ||
from e2e.common.types import CLUSTER_RESOURCE_PLURAL | ||
from e2e.replacement_values import REPLACEMENT_VALUES | ||
|
||
DELETE_WAIT_AFTER_SECONDS = 30 | ||
|
||
def wait_for_cluster_active(eks_client, cluster_name): | ||
waiter = eks_client.get_waiter('cluster_active') | ||
waiter.wait(name=cluster_name) | ||
|
||
@pytest.fixture(scope="module") | ||
def eks_client(): | ||
return boto3.client('eks') | ||
|
||
@pytest.fixture | ||
def simple_cluster(): | ||
cluster_name = random_suffix_name("simple-cluster", 32) | ||
|
||
replacements = REPLACEMENT_VALUES.copy() | ||
replacements["CLUSTER_NAME"] = cluster_name | ||
|
||
resource_data = load_eks_resource( | ||
"cluster_simple", | ||
additional_replacements=replacements, | ||
) | ||
logging.debug(resource_data) | ||
|
||
# Create the k8s resource | ||
ref = k8s.CustomResourceReference( | ||
CRD_GROUP, CRD_VERSION, CLUSTER_RESOURCE_PLURAL, | ||
cluster_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) | ||
|
||
yield (ref, cr) | ||
|
||
# Try to delete, if doesn't already exist | ||
try: | ||
_, deleted = k8s.delete_custom_resource(ref, 3, 10) | ||
assert deleted | ||
except: | ||
pass | ||
|
||
@service_marker | ||
@pytest.mark.canary | ||
class TestCluster: | ||
def test_create_delete_cluster(self, eks_client, simple_cluster): | ||
(ref, cr) = simple_cluster | ||
|
||
cluster_name = cr["spec"]["name"] | ||
|
||
try: | ||
aws_res = eks_client.describe_cluster(name=cluster_name) | ||
assert aws_res is not None | ||
except eks_client.exceptions.ResourceNotFoundException: | ||
pytest.fail(f"Could not find cluster '{cluster_name}' in EKS") | ||
|
||
# Delete the k8s resource on teardown of the module | ||
k8s.delete_custom_resource(ref) | ||
|
||
time.sleep(DELETE_WAIT_AFTER_SECONDS) | ||
|
||
# Cluster should no longer appear in EKS | ||
try: | ||
aws_res = eks_client.describe_cluster(name=cluster_name) | ||
assert aws_res is not None | ||
pytest.fail(f"Cluster '{cluster_name}' was not deleted from EKS") | ||
except eks_client.exceptions.ResourceNotFoundException: | ||
pass |
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,99 @@ | ||
# 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 FargateProfile resource | ||
""" | ||
|
||
from dataclasses import replace | ||
import boto3 | ||
import datetime | ||
import logging | ||
import time | ||
from typing import Dict | ||
|
||
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.common.types import CLUSTER_RESOURCE_PLURAL | ||
from e2e.replacement_values import REPLACEMENT_VALUES | ||
from e2e.bootstrap_resources import get_bootstrap_resources | ||
|
||
from .test_cluster import simple_cluster, wait_for_cluster_active | ||
|
||
RESOURCE_PLURAL = 'fargateprofiles' | ||
|
||
DELETE_WAIT_AFTER_SECONDS = 10 | ||
|
||
def wait_for_profile_active(eks_client, cluster_name, profile_name): | ||
waiter = eks_client.get_waiter('fargate_profile_active') | ||
waiter.wait(clusterName=cluster_name, fargateProfileName=profile_name) | ||
|
||
def wait_for_profile_deleted(eks_client, cluster_name, profile_name): | ||
waiter = eks_client.get_waiter('fargate_profile_deleted') | ||
waiter.wait(clusterName=cluster_name, fargateProfileName=profile_name) | ||
|
||
@pytest.fixture(scope="module") | ||
def eks_client(): | ||
return boto3.client('eks') | ||
|
||
@service_marker | ||
@pytest.mark.canary | ||
class TestFargateProfile: | ||
def test_create_delete_fargate_profile(self, simple_cluster, eks_client): | ||
(ref, cr) = simple_cluster | ||
cluster_name = cr["spec"]["name"] | ||
|
||
wait_for_cluster_active(eks_client, cluster_name) | ||
|
||
profile_name = random_suffix_name("profile", 32) | ||
|
||
replacements = REPLACEMENT_VALUES.copy() | ||
replacements["CLUSTER_NAME"] = cluster_name | ||
replacements["PROFILE_NAME"] = profile_name | ||
|
||
resource_data = load_eks_resource( | ||
"fargateprofile_default", | ||
additional_replacements=replacements, | ||
) | ||
logging.debug(resource_data) | ||
|
||
# Create the k8s resource | ||
ref = k8s.CustomResourceReference( | ||
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL, | ||
profile_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) | ||
|
||
try: | ||
aws_res = eks_client.describe_fargate_profile( | ||
clusterName=cluster_name, | ||
fargateProfileName=profile_name | ||
) | ||
assert aws_res is not None | ||
|
||
assert aws_res["fargateProfile"]["selectors"][0]["namespace"] == "default" | ||
except eks_client.exceptions.ResourceNotFoundException: | ||
pytest.fail(f"Could not find fargate profile '{profile_name}' in EKS") | ||
|
||
wait_for_profile_active(eks_client, cluster_name, profile_name) | ||
|
||
_, deleted = k8s.delete_custom_resource(ref, 3, 10) | ||
assert deleted | ||
|
||
wait_for_profile_deleted(eks_client, cluster_name, profile_name) |