Merge pull request #3195 from lavalamp/numericWire

Add numeric type into api
This commit is contained in:
Tim Hockin
2015-01-07 16:15:52 -08:00
35 changed files with 361 additions and 440 deletions

View File

@@ -17,7 +17,6 @@ limitations under the License.
package config
import (
"reflect"
"sort"
"testing"
@@ -65,13 +64,7 @@ func CreateValidPod(name, namespace, source string) api.BoundPod {
}
func CreatePodUpdate(op kubelet.PodOperation, source string, pods ...api.BoundPod) kubelet.PodUpdate {
// We deliberately return an empty slice instead of a nil pointer here
// because reflect.DeepEqual differentiates between the two and we need to
// pick one for consistency.
newPods := make([]api.BoundPod, len(pods))
if len(pods) == 0 {
return kubelet.PodUpdate{newPods, op, source}
}
for i := range pods {
newPods[i] = pods[i]
}
@@ -89,7 +82,7 @@ func expectPodUpdate(t *testing.T, ch <-chan kubelet.PodUpdate, expected ...kube
for i := range expected {
update := <-ch
sort.Sort(sortedPods(update.Pods))
if !reflect.DeepEqual(expected[i], update) {
if !api.Semantic.DeepEqual(expected[i], update) {
t.Fatalf("Expected %#v, Got %#v", expected[i], update)
}
}

View File

@@ -20,7 +20,6 @@ import (
"encoding/json"
"io/ioutil"
"os"
"reflect"
"sort"
"testing"
"time"
@@ -130,7 +129,7 @@ func TestReadFromFile(t *testing.T) {
Containers: []api.Container{{Image: "test/image", TerminationMessagePath: "/dev/termination-log"}},
},
})
if !reflect.DeepEqual(expected, update) {
if !api.Semantic.DeepEqual(expected, update) {
t.Fatalf("Expected %#v, Got %#v", expected, update)
}
@@ -171,7 +170,7 @@ func TestExtractFromValidDataFile(t *testing.T) {
}
update := (<-ch).(kubelet.PodUpdate)
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, expectedPod)
if !reflect.DeepEqual(expected, update) {
if !api.Semantic.DeepEqual(expected, update) {
t.Errorf("Expected %#v, Got %#v", expected, update)
}
}
@@ -192,7 +191,7 @@ func TestExtractFromEmptyDir(t *testing.T) {
update := (<-ch).(kubelet.PodUpdate)
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource)
if !reflect.DeepEqual(expected, update) {
if !api.Semantic.DeepEqual(expected, update) {
t.Errorf("Expected %#v, Got %#v", expected, update)
}
}
@@ -242,7 +241,7 @@ func TestExtractFromDir(t *testing.T) {
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, pods...)
sort.Sort(sortedPods(update.Pods))
sort.Sort(sortedPods(expected.Pods))
if !reflect.DeepEqual(expected, update) {
if !api.Semantic.DeepEqual(expected, update) {
t.Fatalf("Expected %#v, Got %#v", expected, update)
}
for i := range update.Pods {

View File

@@ -19,7 +19,6 @@ package config
import (
"encoding/json"
"net/http/httptest"
"reflect"
"testing"
"time"
@@ -193,7 +192,7 @@ func TestExtractFromHTTP(t *testing.T) {
continue
}
update := (<-ch).(kubelet.PodUpdate)
if !reflect.DeepEqual(testCase.expected, update) {
if !api.Semantic.DeepEqual(testCase.expected, update) {
t.Errorf("%s: Expected: %#v, Got: %#v", testCase.desc, testCase.expected, update)
}
for i := range update.Pods {

View File

@@ -398,7 +398,7 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m
return exposedPorts, portBindings
}
func milliCPUToShares(milliCPU int) int {
func milliCPUToShares(milliCPU int64) int64 {
if milliCPU == 0 {
// zero milliCPU means unset. Use kernel default.
return 0
@@ -537,8 +537,8 @@ func (kl *Kubelet) runContainer(pod *api.BoundPod, container *api.Container, pod
ExposedPorts: exposedPorts,
Hostname: pod.Name,
Image: container.Image,
Memory: int64(container.Memory),
CPUShares: int64(milliCPUToShares(container.CPU)),
Memory: container.Memory.Value(),
CPUShares: milliCPUToShares(container.CPU.MilliValue()),
WorkingDir: container.WorkingDir,
},
}