-
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
Add ephemeral storage e2e tests #52523
Merged
k8s-github-robot
merged 3 commits into
kubernetes:master
from
NickrenREN:ephemeral-storage-e2e
Nov 9, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -108,6 +108,137 @@ var _ = SIGDescribe("LimitRange", func() { | |
|
||
}) | ||
|
||
var _ = framework.KubeDescribe("LimitRange", func() { | ||
f := framework.NewDefaultFramework("limitrange") | ||
|
||
BeforeEach(func() { | ||
// only run the tests when LocalStorageCapacityIsolation feature is enabled | ||
framework.SkipUnlessLocalEphemeralStorageEnabled() | ||
}) | ||
|
||
It("should create a LimitRange with default ephemeral storage and ensure pod has the default applied.", func() { | ||
By("Creating a LimitRange") | ||
|
||
min := getEphemeralStorageResourceList("100Mi") | ||
max := getEphemeralStorageResourceList("500Mi") | ||
defaultLimit := getEphemeralStorageResourceList("500Mi") | ||
defaultRequest := getEphemeralStorageResourceList("200Mi") | ||
maxLimitRequestRatio := v1.ResourceList{} | ||
limitRange := newLimitRange("limit-range", v1.LimitTypeContainer, | ||
min, max, | ||
defaultLimit, defaultRequest, | ||
maxLimitRequestRatio) | ||
limitRange, err := f.ClientSet.CoreV1().LimitRanges(f.Namespace.Name).Create(limitRange) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
defer func() { | ||
By("Removing limitrange") | ||
err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(limitRange.Name, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}() | ||
|
||
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} | ||
actual := v1.ResourceRequirements{Requests: limitRange.Spec.Limits[0].DefaultRequest, Limits: limitRange.Spec.Limits[0].Default} | ||
err = equalResourceRequirement(expected, actual) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Creating a Pod with no resource requirements") | ||
pod := f.NewTestPod("pod-no-resources", v1.ResourceList{}, v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
defer func() { | ||
By("Removing pod") | ||
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. maybe add pod.Name in the |
||
err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(pod.Name, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}() | ||
|
||
By("Ensuring Pod has resource requirements applied from LimitRange") | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(pod.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
for i := range pod.Spec.Containers { | ||
err = equalResourceRequirement(expected, pod.Spec.Containers[i].Resources) | ||
if err != nil { | ||
// Print the pod to help in debugging. | ||
framework.Logf("Pod %+v does not have the expected requirements", pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} | ||
} | ||
|
||
By("Creating a Pod with request") | ||
pod = f.NewTestPod("pod-partial-resources", getEphemeralStorageResourceList("150m"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
defer func() { | ||
By("Removing pod") | ||
err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(pod.Name, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}() | ||
|
||
By("Ensuring Pod has merged resource requirements applied from LimitRange") | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(pod.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
// If you specify a Request, and no Limit, the Limit will be set to default limit | ||
expected = v1.ResourceRequirements{Requests: getEphemeralStorageResourceList("150Mi"), Limits: defaultLimit} | ||
for i := range pod.Spec.Containers { | ||
err = equalResourceRequirement(expected, pod.Spec.Containers[i].Resources) | ||
if err != nil { | ||
// Print the pod to help in debugging. | ||
framework.Logf("Pod %+v does not have the expected requirements", pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} | ||
} | ||
|
||
By("Creating a Pod with limit") | ||
pod = f.NewTestPod("pod-partial-resources", v1.ResourceList{}, getEphemeralStorageResourceList("300m")) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
defer func() { | ||
By("Removing pod") | ||
err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(pod.Name, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}() | ||
|
||
By("Ensuring Pod has merged resource requirements applied from LimitRange") | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(pod.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
// If you specify a Limit, and no Request, the Limit will default to the Request | ||
// This means that the LimitRange.DefaultRequest will ONLY take affect if a container.resources.limit is not supplied | ||
expected = v1.ResourceRequirements{Requests: getEphemeralStorageResourceList("300Mi"), Limits: getEphemeralStorageResourceList("300Mi")} | ||
for i := range pod.Spec.Containers { | ||
err = equalResourceRequirement(expected, pod.Spec.Containers[i].Resources) | ||
if err != nil { | ||
// Print the pod to help in debugging. | ||
framework.Logf("Pod %+v does not have the expected requirements", pod) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} | ||
} | ||
|
||
By("Failing to create a Pod with less than min resources") | ||
pod = f.NewTestPod(podName, getEphemeralStorageResourceList("50Mi"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).To(HaveOccurred()) | ||
|
||
By("Failing to create a Pod with more than max resources") | ||
pod = f.NewTestPod(podName, getEphemeralStorageResourceList("600Mi"), v1.ResourceList{}) | ||
pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
||
}) | ||
|
||
func getEphemeralStorageResourceList(ephemeralStorage string) v1.ResourceList { | ||
res := v1.ResourceList{} | ||
if ephemeralStorage != "" { | ||
res[v1.ResourceEphemeralStorage] = resource.MustParse(ephemeralStorage) | ||
} | ||
return res | ||
} | ||
|
||
func equalResourceRequirement(expected v1.ResourceRequirements, actual v1.ResourceRequirements) error { | ||
framework.Logf("Verifying requests: expected %v with actual %v", expected.Requests, actual.Requests) | ||
err := equalResourceList(expected.Requests, actual.Requests) | ||
|
Oops, something went wrong.
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.
where is
env
used here?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.
yeah, seems not used, it is not added by me, i will delete it
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 still see
env
...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.
This comment appears to not have been addressed.
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.
Yeah, this is not introduced by me. I will look into that and send a separate pr to solve it