-
Notifications
You must be signed in to change notification settings - Fork 52
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
Test framework improvement, doing proper clean up in BeforeSuite(), AfterEach(), AfterSuite() #225
Conversation
- Add service import and export traffic test - Further Test Framework imporvement - Bug fix for service import and export, when handling Kind: ServiceExport k8s resource, the latticestore should create create a IsServiceImport==true cache for it
Closed the previous PR |
Pull Request Test Coverage Report for Build 4789745461
💛 - Coveralls |
clientDeployment, clientService := testFramework.NewHttpApp(test.HTTPAppOptions{Name: "client"}) | ||
serverDeployment, serverService := testFramework.NewHttpApp(test.HTTPAppOptions{Name: "https-gw-server"}) | ||
httproute := testFramework.NewPathMatchHttpRoute(gateway, []client.Object{serverService}, "https") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to pass "https" in the NewPathMatchHttpRoute(), it will refer the "https" section in the gateway
listener
Update: removed https traffic test in the new revision now it only have 2 test case |
Pull Request Test Coverage Report for Build 4812312590
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this mess that folks(most of us) doing development on clouddesktop ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Developer should run (or set it in GoLand manually) load_env_variables.sh manually, and no where refer it.
I have some comments in this script, if it is still confusing, I could remove this script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today, Makefile takes care of all these environment variable setting. @ellistarn should we merge these into Makefile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with golang env vars, but I'd avoid any ide specific configuration. At the end of the day, your team needs to choose the development practices that work best for you. I setup what works for me, and how I run other OSS projects. Feel free to change things.
test/pkg/test/http_gateway.go
Outdated
@@ -5,7 +5,7 @@ import ( | |||
"sigs.k8s.io/gateway-api/apis/v1beta1" | |||
) | |||
|
|||
func (env *Framework) NewGateway() *v1beta1.Gateway { | |||
func (env *Framework) NewHttpGateway() *v1beta1.Gateway { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make this? A gateway can have multiple listener(s), one for HTTP and one for HTTPs. And need a e2e test case to cover a single HTTPRoute can be accessed through HTTP and HTTPs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put 2 listeners in one GW is better, I will change to that one in the next revision
Spec: v1beta1.GatewaySpec{
GatewayClassName: "amazon-vpc-lattice",
Listeners: []v1beta1.Listener{
{
Name: "http",
Protocol: v1beta1.HTTPProtocolType,
Port: 80,
},
{
Name: "https",
Protocol: v1beta1.HTTPSProtocolType,
Port: 443,
},
},
},
t.SetName(RandomName()) | ||
} | ||
if t.GetNamespace() == "" { | ||
t.SetNamespace("default") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, we also need to test things in non-default namespace, e.g.
- httproute
- gateway
Makefile
Outdated
@@ -2,6 +2,8 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin | |||
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1) | |||
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId") | |||
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text) | |||
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= dubug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: debug?
Makefile
Outdated
@@ -2,6 +2,8 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin | |||
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1) | |||
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId") | |||
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text) | |||
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these from Makefile
Makefile
Outdated
@@ -2,6 +2,8 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin | |||
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1) | |||
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId") | |||
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text) | |||
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= debug | |||
export REGION ?= us-west-2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these from Makefile
@@ -0,0 +1,46 @@ | |||
#!/bin/sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update docs/developer.md and mentioned that this can be used for when u want to run it inside golang IDE locally
test/pkg/test/framework.go
Outdated
@@ -82,10 +83,20 @@ func NewFramework(ctx context.Context) *Framework { | |||
|
|||
SetDefaultEventuallyTimeout(180 * time.Second) | |||
SetDefaultEventuallyPollingInterval(10 * time.Second) | |||
AfterEach(func() { framework.ExpectToBeClean(ctx) }) | |||
BeforeSuite(func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change to:
BeforeEach((func(){ExpectToBeClean()})
and remove current BeforeSuite()
test/pkg/test/framework.go
Outdated
} | ||
framework.TestCasesCreatedK8sResource = nil | ||
framework.CleanServiceNetworkVpcAssociationForCurrentK8sClusterVpc() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In AfterEach do framework.CleanTestEnvironment(ctx)
to clean all pevious test created k8s resource and vpcLattice resource
New test result, make e2etest still passed https://gist.github.com/zijun726911/3240c8e9a6990db894237015a31753bb |
Do CleanTestEnvironment() in AfterEach()
docs/developer.md
Outdated
Pass `FOCUS` environment variable to run some specific test cases based on filter condition: | ||
```bash | ||
export REGION=us-west-2 | ||
export FOCUS="HTTPRoute should support multiple path matches" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a note on how to find out the this FOCUS
string to a particular test. thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Added more description in the next revision
Logger(ctx).Infof("Deleting k8s resource %s %s/%s", reflect.TypeOf(object), object.GetNamespace(), object.GetName()) | ||
env.Delete(ctx, object) | ||
//Ignore resource-not-found error here, as the test case logic itself could already clear the resources | ||
} | ||
|
||
//Theoretically, Deleting all k8s resource by `env.ExpectDeleteAllToSucceed()`, will make controller delete all related VPC Lattice resource, | ||
//but the controller is still developing in the progress and may leaking some vPCLattice resource, need to invoke vpcLattice api to double confirm and delete leaking resource. | ||
env.DeleteAllFrameworkTracedServiceNetworks(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's NOT
do these automatically. The test should failed and stopped if this is the case, and let developer debug why
it is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, actually now no where invoke the CleanTestEnvironment(), we could remove this method, but maybe we could keep it in case we use it in the future?
@@ -324,7 +320,25 @@ func (env *Framework) DeleteAllFrameworkTracedServiceNetworks(ctx aws.Context) { | |||
} | |||
} | |||
|
|||
//TODO: check and delete serviceNetwork VPC associations | |||
var allServiceNetworkVpcAssociationIdsToBeDeleted []*string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not
use test code to cleanup the resource for now. Let developer debug why it is leaked and manually clean them up.
Also, if these are not cleanup, the test should stop
podList := &v1.PodList{} | ||
g.Expect(env.List(ctx, podList, client.MatchingLabels(deployment.Spec.Selector.MatchLabels))).To(Succeed()) | ||
expectedMatchingLabels := make(map[string]string, len(deployment.Spec.Selector.MatchLabels)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible these are the one causing my 2nd test stucked waiting for target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
Changes
client.Object
to create HttpRoute, so that backendRefObjects could be either Service or Service Import for future useTest
make e2etest
passUpdate removed https traffic test in the new revision now it only have 2 test case
Full log: https://gist.github.com/zijun726911/7c8ed592b02f4f9911632c8c6a439a3d