@@ -14,6 +14,8 @@ import (
14
14
. "github.com/onsi/gomega"
15
15
. "github.com/onsi/gomega/gbytes"
16
16
. "github.com/onsi/gomega/gexec"
17
+
18
+ "strings"
17
19
)
18
20
19
21
// TODO (bacongobbler): inspect kubectl for limits being applied to manifest
@@ -60,17 +62,83 @@ var _ = Describe("deis limits", func() {
60
62
Eventually (sess ).Should (Exit (0 ))
61
63
62
64
// Check that --memory also works
65
+ // 128M
63
66
sess , err = cmd .Start ("deis limits:set --memory cmd=128M -a %s" , & user , app .Name )
64
67
Eventually (sess , settings .MaxEventuallyTimeout ).Should (Say ("--- Memory\n cmd 128M" ))
65
68
Expect (err ).NotTo (HaveOccurred ())
66
69
Eventually (sess ).Should (Exit (0 ))
70
+
71
+ // Check Kubernetes pods manifest
72
+ 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 )
73
+ Eventually (sess ).Should (Exit (0 ))
74
+ Expect (err ).NotTo (HaveOccurred ())
75
+ resource := string (sess .Out .Contents ())
76
+ // try to get test latest pod, in case cmd still see terminated pod.
77
+ // Also as per bug in https://github.com/kubernetes/kubernetes/issues/16707
78
+ if strings .Contains (resource , "] map[" ) {
79
+ resource = resource [strings .Index (resource , "] map[" )+ len ("] " ):]
80
+ }
81
+ Expect (resource ).Should (SatisfyAny (
82
+ Equal ("map[requests:map[memory:128Mi] limits:map[memory:128Mi]]" ),
83
+ Equal ("map[limits:map[memory:128Mi] requests:map[memory:128Mi]]" )))
84
+
85
+ // 0/100M
86
+ sess , err = cmd .Start ("deis limits:set cmd=0/100M -a %s" , & user , app .Name )
87
+ Eventually (sess , settings .MaxEventuallyTimeout ).Should (Say ("--- Memory\n cmd 0/100M" ))
88
+ Expect (err ).NotTo (HaveOccurred ())
89
+ Eventually (sess ).Should (Exit (0 ))
90
+
91
+ // Check Kubernetes pods manifest
92
+ 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 )
93
+ Eventually (sess ).Should (Exit (0 ))
94
+ Expect (err ).NotTo (HaveOccurred ())
95
+ resource = string (sess .Out .Contents ())
96
+ // try to get test latest pod, in case cmd still see terminated pod.
97
+ if strings .Contains (resource , "] map[" ) {
98
+ resource = resource [strings .Index (resource , "] map[" )+ len ("] " ):]
99
+ }
100
+ Expect (resource ).Should (SatisfyAny (
101
+ Equal ("map[requests:map[memory:0] limits:map[memory:100Mi]]" ),
102
+ Equal ("map[limits:map[memory:100Mi] requests:map[memory:0]]" )))
103
+
104
+ // 50/100MB
105
+ sess , err = cmd .Start ("deis limits:set cmd=50M/100MB -a %s" , & user , app .Name )
106
+ Eventually (sess , settings .MaxEventuallyTimeout ).Should (Say ("--- Memory\n cmd 50M/100M" ))
107
+ Expect (err ).NotTo (HaveOccurred ())
108
+ Eventually (sess ).Should (Exit (0 ))
109
+
110
+ // Check Kubernetes pods manifest
111
+ 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 )
112
+ Eventually (sess ).Should (Exit (0 ))
113
+ Expect (err ).NotTo (HaveOccurred ())
114
+ resource = string (sess .Out .Contents ())
115
+ // try to get test latest pod, in case cmd still see terminated pod.
116
+ if strings .Contains (resource , "] map[" ) {
117
+ resource = resource [strings .Index (resource , "] map[" )+ len ("] " ):]
118
+ }
119
+ Expect (resource ).Should (SatisfyAny (
120
+ Equal ("map[requests:map[memory:50Mi] limits:map[memory:100Mi]]" ),
121
+ Equal ("map[limits:map[memory:100Mi] requests:map[memory:50Mi]]" )))
67
122
})
68
123
69
124
Specify ("that user can set a CPU limit on that application" , func () {
70
125
sess , err := cmd .Start ("deis limits:set --cpu cmd=500m -a %s" , & user , app .Name )
71
126
Eventually (sess , settings .MaxEventuallyTimeout ).Should (Say ("--- CPU\n cmd 500m" ))
72
127
Expect (err ).NotTo (HaveOccurred ())
73
128
Eventually (sess ).Should (Exit (0 ))
129
+
130
+ // Check Kubernetes pods manifest
131
+ 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 )
132
+ Eventually (sess ).Should (Exit (0 ))
133
+ Expect (err ).NotTo (HaveOccurred ())
134
+ resource := string (sess .Out .Contents ())
135
+ // try to get test latest pod, in case cmd still see terminated pod.
136
+ if strings .Contains (resource , "] map[" ) {
137
+ resource = resource [strings .Index (resource , "] map[" )+ len ("] " ):]
138
+ }
139
+ Expect (resource ).Should (SatisfyAny (
140
+ Equal ("map[requests:map[cpu:500m] limits:map[cpu:500m]]" ),
141
+ Equal ("map[limits:map[cpu:500m] requests:map[cpu:500m]]" )))
74
142
})
75
143
76
144
Specify ("that user can unset a memory limit on that application" , func () {
@@ -88,6 +156,13 @@ var _ = Describe("deis limits", func() {
88
156
Eventually (sess , settings .MaxEventuallyTimeout ).Should (Say ("--- Memory\n Unlimited" ))
89
157
Expect (err ).NotTo (HaveOccurred ())
90
158
Eventually (sess ).Should (Exit (0 ))
159
+
160
+ // Check Kubernetes pods manifest
161
+ 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 )
162
+ Eventually (sess ).Should (Exit (0 ))
163
+ Expect (err ).NotTo (HaveOccurred ())
164
+ // At least 1 pod have empty resources
165
+ Expect (string (sess .Out .Contents ())).Should (ContainSubstring ("map[]" ))
91
166
})
92
167
93
168
Specify ("that user can unset a CPU limit on that application" , func () {
0 commit comments