-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
LimitRange e2e test improved. #55065
Merged
+84
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,14 @@ package scheduling | |
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/kubernetes/test/e2e/framework" | ||
|
||
. "github.com/onsi/ginkgo" | ||
|
@@ -47,9 +51,34 @@ var _ = SIGDescribe("LimitRange", func() { | |
min, max, | ||
defaultLimit, defaultRequest, | ||
maxLimitRequestRatio) | ||
limitRange, err := f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Create(limitRange) | ||
|
||
By("Setting up watch") | ||
selector := labels.SelectorFromSet(labels.Set(map[string]string{"name": limitRange.Name})) | ||
options := metav1.ListOptions{LabelSelector: selector.String()} | ||
limitRanges, err := f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).List(options) | ||
Expect(err).NotTo(HaveOccurred(), "failed to query for limitRanges") | ||
Expect(len(limitRanges.Items)).To(Equal(0)) | ||
options = metav1.ListOptions{ | ||
LabelSelector: selector.String(), | ||
ResourceVersion: limitRanges.ListMeta.ResourceVersion, | ||
} | ||
w, err := f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Watch(metav1.ListOptions{}) | ||
Expect(err).NotTo(HaveOccurred(), "failed to set up watch") | ||
|
||
By("Submitting a LimitRange") | ||
limitRange, err = f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Create(limitRange) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update vs. Create based on previous value of list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should Update at line 140 use a new LimitRange structure, not the old with changed limit value? |
||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verifying LimitRange creation was observed") | ||
select { | ||
case event, _ := <-w.ResultChan(): | ||
if event.Type != watch.Added { | ||
framework.Failf("Failed to observe pod creation: %v", event) | ||
} | ||
case <-time.After(framework.ServiceRespondingTimeout): | ||
framework.Failf("Timeout while waiting for LimitRange creation") | ||
} | ||
|
||
By("Fetching the LimitRange to ensure it has proper values") | ||
limitRange, err = f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Get(limitRange.Name, metav1.GetOptions{}) | ||
expected := v1.ResourceRequirements{Requests: defaultRequest, Limits: defaultLimit} | ||
|
@@ -104,6 +133,59 @@ var _ = SIGDescribe("LimitRange", func() { | |
pod = f.NewTestPod(podName, getResourceList("600m", "600Mi"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).To(HaveOccurred()) | ||
|
||
By("Updating a LimitRange") | ||
newMin := getResourceList("9m", "49Mi") | ||
limitRange.Spec.Limits[0].Min = newMin | ||
limitRange, err = f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Update(limitRange) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Creating a Pod with less than former min resources") | ||
pod = f.NewTestPod(podName, getResourceList("10m", "50Mi"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Failing to create a Pod with more than max resources") | ||
pod = f.NewTestPod(podName, getResourceList("600m", "600Mi"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).To(HaveOccurred()) | ||
|
||
By("Deleting a LimitRange") | ||
err = f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Delete(limitRange.Name, metav1.NewDeleteOptions(30)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verifying the LimitRange was deleted") | ||
Expect(wait.Poll(time.Second*5, time.Second*30, func() (bool, error) { | ||
selector := labels.SelectorFromSet(labels.Set(map[string]string{"name": limitRange.Name})) | ||
options := metav1.ListOptions{LabelSelector: selector.String()} | ||
limitRanges, err := f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).List(options) | ||
|
||
if err != nil { | ||
framework.Logf("Unable to retrieve LimitRanges: %v", err) | ||
return false, nil | ||
} | ||
|
||
if len(limitRanges.Items) == 0 { | ||
framework.Logf("limitRange is already deleted") | ||
return true, nil | ||
} | ||
|
||
if len(limitRanges.Items) > 0 { | ||
if limitRanges.Items[0].ObjectMeta.DeletionTimestamp == nil { | ||
framework.Logf("deletion has not yet been observed") | ||
return false, nil | ||
} | ||
return true, nil | ||
} | ||
|
||
return false, nil | ||
|
||
})).NotTo(HaveOccurred(), "kubelet never observed the termination notice") | ||
|
||
By("Creating a Pod with more than former max resources") | ||
pod = f.NewTestPod(podName+"2", getResourceList("600m", "600Mi"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would warn here b/c we've seen a number of test conditions fail on loaded clusters due to waiting on cleanup conditions. I realize that it shouldn't occur, but we've seen patterns of odd cleanup when running (N) overlapping test cases with namespaces names that are not completely unique.
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.
What can you suggest to do to avoid the problems here?