-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Adding e2e tests for validating cascading deletion of federation resources #36630
Conversation
Adding to 1.5 milestone. |
@k8s-bot federation gce e2e test this |
federation e2e failed to come up. It timed out waiting for load balancer status. Unrelated to this PR. Retrying. @k8s-bot federation gce e2e test this |
looks like unrelated errors:
|
@k8s-bot federation gce e2e test this |
1 similar comment
@k8s-bot federation gce e2e test this |
Ack. Thanks. |
@k8s-bot federation gce e2e test this |
@nikhiljindal looks like the tests never ends. i see a started.json from 4 hours ago and it has not finished yet http://gcsweb.k8s.io/gcs/kubernetes-jenkins/pr-logs/pull/36630/pull-kubernetes-federation-e2e-gce/22 |
haha I still see it as running :) |
@k8s-bot federation gce e2e test this |
Jenkins GCE etcd3 e2e failed for commit b3759b9. Full PR test history. The magic incantation to run this job again is |
Jenkins GKE smoke e2e failed for commit b3759b9. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE e2e failed for commit b3759b9. Full PR test history. The magic incantation to run this job again is |
Jenkins GCI GCE e2e failed for commit b3759b9. Full PR test history. The magic incantation to run this job again is |
Jenkins Kubemark GCE e2e failed for commit b3759b9. Full PR test history. The magic incantation to run this job again is |
Jenkins Federation GCE e2e failed for commit b3759b9. Full PR test history. The magic incantation to run this job again is |
Adding @madhusudancs as second reviewer since @mwielgus seems busy this week. |
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.
@nikhiljindal Mostly minor comments.
IngressList, err := clientset.Extensions().Ingresses(nsName).List(v1.ListOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
orphanDependents := false | ||
for _, Ingress := range IngressList.Items { |
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.
Use DeleteCollection instead of looping through the items?
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.
found there was an existing function here doing the same thing. Changed the code to reuse that
// Verifies that ingresses are deleted from underlying clusters when orphan dependents is false | ||
// and they are not deleted when orphan dependents is true. | ||
func verifyCascadingDeletionForIngress(clientset *fedclientset.Clientset, | ||
clusters map[string]*cluster, orphanDependents *bool, nsName 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.
Why this line break? We generally don't do it in Go.
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.
old habit. Fixed
/* | ||
equivalent returns true if the two ingress spec are equivalent. | ||
*/ | ||
func equivalentIngress(federatedIngress, clusterIngress v1beta1.Ingress) bool { | ||
return reflect.DeepEqual(clusterIngress.Spec, federatedIngress.Spec) | ||
} | ||
|
||
// Verifies that ingresses are deleted from underlying clusters when orphan dependents is false |
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.
"verifyCascadingDeletionForIngress verifies that ..." is the recommended way, right?
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.
Yes. We are not as strict about that for private functions. Fixed it here
ingressName := ingress.Name | ||
// Check subclusters if the ingress was created there. | ||
By(fmt.Sprintf("Waiting for ingress %s to be created in all underlying clusters", ingressName)) | ||
err := wait.Poll(5*time.Second, 2*time.Minute, func() (bool, error) { |
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.
Make 5*time.Second
, 2*time.Minute
package level constants?
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.
removed this code to reuse an existing function
err := wait.Poll(5*time.Second, 2*time.Minute, func() (bool, error) { | ||
for _, cluster := range clusters { | ||
_, err := cluster.Extensions().Ingresses(nsName).Get(ingressName) | ||
if err != nil { |
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 think this is somewhat more straightforward and easier to read/understand if it is written as:
if !errors.IsNotFound(err) {
return false, err
}
if err != nil {
return false, nil
}
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.
Problem with that is that !errors.IsNotFound(err) is true when err = nil. We do not want to return false in that case.
Changed it to:
if err != nil && errors.IsNotFound(err) {
return false, nil
}
if err != nil {
return false, err
}
errMessages := []string{} | ||
for clusterName, clusterClientset := range clusters { | ||
_, err := clusterClientset.Extensions().ReplicaSets(nsName).Get(replicaSetName) | ||
if (orphanDependents == nil || *orphanDependents == true) && errors.IsNotFound(err) { |
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.
Same comment as above.
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.
fixed
By(fmt.Sprintf("Deleting replicaSet %s", replicaSetName)) | ||
deleteReplicaSetOrFail(clientset, nsName, replicaSetName, orphanDependents) | ||
|
||
By(fmt.Sprintf("Verifying replicaSets %s in underlying clusters", replicaSetName)) |
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.
ReplicaSets or replica sets. Here and everywhere else.
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.
done
} | ||
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Not all replicaSets created") |
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.
ReplicaSets or replica sets.
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.
fixed
replicaSet := createReplicaSetOrFail(clientset, nsName) | ||
replicaSetName := replicaSet.Name | ||
// Check subclusters if the replicaSet was created there. | ||
By(fmt.Sprintf("Waiting for replicaSet %s to be created in all underlying clusters", replicaSetName)) |
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.
ReplicaSets or replica sets.
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.
fixed. here and at other places
// Wait for the replicaSet to be deleted. | ||
err = wait.Poll(5*time.Second, wait.ForeverTestTimeout, func() (bool, error) { | ||
_, err := clientset.Extensions().ReplicaSets(nsName).Get(replicaSetName) | ||
if err != nil && errors.IsNotFound(err) { |
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.
Same comment as above.
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.
fixed
Thanks @madhusudancs Pushed a new commit with fixes. |
shouldExist := orphanDependents == nil || *orphanDependents == true | ||
for clusterName, clusterClientset := range clusters { | ||
_, err := clusterClientset.Extensions().Ingresses(nsName).Get(ingressName) | ||
if shouldExist && errors.IsNotFound(err) { |
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 am not a big fan of having lots of logic in tests and I still think it should be split into 3 separate functions. But it is fine for now, I guess.
LGTM! |
Squashed commits. |
Jenkins GCI GKE smoke e2e failed for commit 90645ce. Full PR test history. The magic incantation to run this job again is |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
Ref #33612
Adding e2e tests for code in #36330 and #36476.
Adding test cases to ensure that cascading deletion happens as expected.
Also adding code to ensure that all resources are cleaned up in AfterEach.
cc @kubernetes/sig-cluster-federation @caesarxuchao @madhusudancs
This change is