Skip to content

Commit

Permalink
Merge pull request #335 from zinuzoid/limitsset-support-new-format
Browse files Browse the repository at this point in the history
feat(limits-cmd): accept new limits:set value type
  • Loading branch information
Vaughn Dice authored Jan 11, 2017
2 parents ba0d452 + 70797cb commit 0384b09
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"

"strings"
)

// TODO (bacongobbler): inspect kubectl for limits being applied to manifest
Expand Down Expand Up @@ -60,17 +62,83 @@ var _ = Describe("deis limits", func() {
Eventually(sess).Should(Exit(0))

// Check that --memory also works
// 128M
sess, err = cmd.Start("deis limits:set --memory cmd=128M -a %s", &user, app.Name)
Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("--- Memory\ncmd 128M"))
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(0))

// Check Kubernetes pods manifest
sess, err = cmd.Start("HOME=%s kubectl get --all-namespaces pods -l app=%s --sort-by='.status.startTime' -o jsonpath={.items[*].spec.containers[0].resources}", nil, settings.ActualHome, app.Name)
Eventually(sess).Should(Exit(0))
Expect(err).NotTo(HaveOccurred())
resource := string(sess.Out.Contents())
// try to get test latest pod, in case cmd still see terminated pod.
// Also as per bug in https://github.com/kubernetes/kubernetes/issues/16707
if strings.Contains(resource, "] map[") {
resource = resource[strings.Index(resource, "] map[")+len("] "):]
}
Expect(resource).Should(SatisfyAny(
Equal("map[requests:map[memory:128Mi] limits:map[memory:128Mi]]"),
Equal("map[limits:map[memory:128Mi] requests:map[memory:128Mi]]")))

// 0/100M
sess, err = cmd.Start("deis limits:set cmd=0/100M -a %s", &user, app.Name)
Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("--- Memory\ncmd 0/100M"))
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(0))

// Check Kubernetes pods manifest
sess, err = cmd.Start("HOME=%s kubectl get --all-namespaces pods -l app=%s --sort-by='.status.startTime' -o jsonpath={.items[*].spec.containers[0].resources}", nil, settings.ActualHome, app.Name)
Eventually(sess).Should(Exit(0))
Expect(err).NotTo(HaveOccurred())
resource = string(sess.Out.Contents())
// try to get test latest pod, in case cmd still see terminated pod.
if strings.Contains(resource, "] map[") {
resource = resource[strings.Index(resource, "] map[")+len("] "):]
}
Expect(resource).Should(SatisfyAny(
Equal("map[requests:map[memory:0] limits:map[memory:100Mi]]"),
Equal("map[limits:map[memory:100Mi] requests:map[memory:0]]")))

// 50/100MB
sess, err = cmd.Start("deis limits:set cmd=50M/100MB -a %s", &user, app.Name)
Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("--- Memory\ncmd 50M/100M"))
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(0))

// Check Kubernetes pods manifest
sess, err = cmd.Start("HOME=%s kubectl get --all-namespaces pods -l app=%s --sort-by='.status.startTime' -o jsonpath={.items[*].spec.containers[0].resources}", nil, settings.ActualHome, app.Name)
Eventually(sess).Should(Exit(0))
Expect(err).NotTo(HaveOccurred())
resource = string(sess.Out.Contents())
// try to get test latest pod, in case cmd still see terminated pod.
if strings.Contains(resource, "] map[") {
resource = resource[strings.Index(resource, "] map[")+len("] "):]
}
Expect(resource).Should(SatisfyAny(
Equal("map[requests:map[memory:50Mi] limits:map[memory:100Mi]]"),
Equal("map[limits:map[memory:100Mi] requests:map[memory:50Mi]]")))
})

Specify("that user can set a CPU limit on that application", func() {
sess, err := cmd.Start("deis limits:set --cpu cmd=500m -a %s", &user, app.Name)
Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("--- CPU\ncmd 500m"))
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(0))

// Check Kubernetes pods manifest
sess, err = cmd.Start("HOME=%s kubectl get --all-namespaces pods -l app=%s --sort-by='.status.startTime' -o jsonpath={.items[*].spec.containers[0].resources}", nil, settings.ActualHome, app.Name)
Eventually(sess).Should(Exit(0))
Expect(err).NotTo(HaveOccurred())
resource := string(sess.Out.Contents())
// try to get test latest pod, in case cmd still see terminated pod.
if strings.Contains(resource, "] map[") {
resource = resource[strings.Index(resource, "] map[")+len("] "):]
}
Expect(resource).Should(SatisfyAny(
Equal("map[requests:map[cpu:500m] limits:map[cpu:500m]]"),
Equal("map[limits:map[cpu:500m] requests:map[cpu:500m]]")))
})

Specify("that user can unset a memory limit on that application", func() {
Expand All @@ -88,6 +156,13 @@ var _ = Describe("deis limits", func() {
Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("--- Memory\nUnlimited"))
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(0))

// Check Kubernetes pods manifest
sess, err = cmd.Start("HOME=%s kubectl get --all-namespaces pods -l app=%s -o jsonpath={.items[*].spec.containers[0].resources}", nil, settings.ActualHome, app.Name)
Eventually(sess).Should(Exit(0))
Expect(err).NotTo(HaveOccurred())
// At least 1 pod have empty resources
Expect(string(sess.Out.Contents())).Should(ContainSubstring("map[]"))
})

Specify("that user can unset a CPU limit on that application", func() {
Expand Down

0 comments on commit 0384b09

Please sign in to comment.