本文整理汇总了Golang中k8s/io/kubernetes/pkg/api/unversioned.Date函数的典型用法代码示例。如果您正苦于以下问题:Golang Date函数的具体用法?Golang Date怎么用?Golang Date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestCloudProviderNoRateLimit
// TestCloudProviderNoRateLimit tests that monitorNodes() immediately deletes
// pods and the node when kubelet has not reported, and the cloudprovider says
// the node is gone.
func TestCloudProviderNoRateLimit(t *testing.T) {
fnh := &FakeNodeHandler{
Existing: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionUnknown,
LastHeartbeatTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
},
},
},
},
Clientset: fake.NewSimpleClientset(&api.PodList{Items: []api.Pod{*newPod("pod0", "node0"), *newPod("pod1", "node0")}}),
deleteWaitChan: make(chan struct{}),
}
nodeController, _ := NewNodeController(nil, fnh, 10*time.Minute,
testRateLimiterQPS,
testNodeMonitorGracePeriod, testNodeStartupGracePeriod,
testNodeMonitorPeriod, nil, nil, 0, false)
nodeController.cloud = &fakecloud.FakeCloud{}
nodeController.now = func() unversioned.Time { return unversioned.Date(2016, 1, 1, 12, 0, 0, 0, time.UTC) }
nodeController.nodeExistsInCloudProvider = func(nodeName string) (bool, error) {
return false, nil
}
// monitorNodeStatus should allow this node to be immediately deleted
if err := nodeController.monitorNodeStatus(); err != nil {
t.Errorf("unexpected error: %v", err)
}
select {
case <-fnh.deleteWaitChan:
case <-time.After(wait.ForeverTestTimeout):
t.Errorf("Timed out waiting %v for node to be deleted", wait.ForeverTestTimeout)
}
if len(fnh.DeletedNodes) != 1 || fnh.DeletedNodes[0].Name != "node0" {
t.Errorf("Node was not deleted")
}
if nodeOnQueue := nodeController.zonePodEvictor[""].Remove("node0"); nodeOnQueue {
t.Errorf("Node was queued for eviction. Should have been immediately deleted.")
}
}
开发者ID:RyanBinfeng,项目名称:kubernetes,代码行数:51,代码来源:nodecontroller_test.go
示例2: TestSortStatusTags
func TestSortStatusTags(t *testing.T) {
tests := []struct {
name string
tags map[string]TagEventList
expected []string
}{
{
name: "all timestamps here",
tags: map[string]TagEventList{
"other": {
Items: []TagEvent{
{
DockerImageReference: "other-ref",
Created: unversioned.Date(2015, 9, 4, 13, 52, 0, 0, time.UTC),
Image: "other-image",
},
},
},
"latest": {
Items: []TagEvent{
{
DockerImageReference: "latest-ref",
Created: unversioned.Date(2015, 9, 4, 13, 53, 0, 0, time.UTC),
Image: "latest-image",
},
},
},
"third": {
Items: []TagEvent{
{
DockerImageReference: "third-ref",
Created: unversioned.Date(2015, 9, 4, 13, 54, 0, 0, time.UTC),
Image: "third-image",
},
},
},
},
expected: []string{"third", "latest", "other"},
},
}
for _, test := range tests {
got := SortStatusTags(test.tags)
if !reflect.DeepEqual(test.expected, got) {
t.Errorf("%s: tags mismatch: expected %v, got %v", test.name, test.expected, got)
}
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:48,代码来源:sort_test.go
示例3: TestOverlappingRCs
func TestOverlappingRCs(t *testing.T) {
c := clientset.NewForConfigOrDie(&restclient.Config{Host: "", ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
for i := 0; i < 5; i++ {
manager := NewReplicationManagerFromClient(c, controller.NoResyncPeriodFunc, 10, 0)
manager.podStoreSynced = alwaysReady
// Create 10 rcs, shuffled them randomly and insert them into the rc manager's store
var controllers []*api.ReplicationController
for j := 1; j < 10; j++ {
controllerSpec := newReplicationController(1)
controllerSpec.CreationTimestamp = unversioned.Date(2014, time.December, j, 0, 0, 0, 0, time.Local)
controllerSpec.Name = string(util.NewUUID())
controllers = append(controllers, controllerSpec)
}
shuffledControllers := shuffle(controllers)
for j := range shuffledControllers {
manager.rcStore.Store.Add(shuffledControllers[j])
}
// Add a pod and make sure only the oldest rc is synced
pods := newPodList(nil, 1, api.PodPending, controllers[0], "pod")
rcKey := getKey(controllers[0], t)
manager.addPod(&pods.Items[0])
queueRC, _ := manager.queue.Get()
if queueRC != rcKey {
t.Fatalf("Expected to find key %v in queue, found %v", rcKey, queueRC)
}
}
}
开发者ID:freedev,项目名称:kubernetes,代码行数:30,代码来源:replication_controller_test.go
示例4: TestLimitedLogAndRetryFinish
func TestLimitedLogAndRetryFinish(t *testing.T) {
updater := &buildUpdater{}
err := errors.New("funky error")
now := unversioned.Now()
retry := controller.Retry{
Count: 0,
StartTimestamp: unversioned.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-31, now.Second(), now.Nanosecond(), now.Location()),
}
if limitedLogAndRetry(updater, 30*time.Minute)(&buildapi.Build{Status: buildapi.BuildStatus{Phase: buildapi.BuildPhaseNew}}, err, retry) {
t.Error("Expected no more retries after reaching timeout!")
}
if updater.Build == nil {
t.Fatal("BuildUpdater wasn't called!")
}
if updater.Build.Status.Phase != buildapi.BuildPhaseFailed {
t.Errorf("Expected status %s, got %s!", buildapi.BuildPhaseFailed, updater.Build.Status.Phase)
}
if !strings.Contains(updater.Build.Status.Message, err.Error()) {
t.Errorf("Expected message to contain %v, got %s!", err.Error(), updater.Build.Status.Message)
}
if updater.Build.Status.CompletionTimestamp == nil {
t.Error("Expected CompletionTimestamp to be set!")
}
}
开发者ID:kcbabo,项目名称:origin,代码行数:25,代码来源:factory_test.go
示例5: newPodList
func newPodList(count, isUnready, isUnhealthy int, labels map[string]string) *api.PodList {
pods := []api.Pod{}
for i := 0; i < count; i++ {
newPod := api.Pod{
ObjectMeta: api.ObjectMeta{
Name: fmt.Sprintf("pod-%d", i+1),
Namespace: api.NamespaceDefault,
CreationTimestamp: unversioned.Date(2016, time.April, 1, 1, 0, i, 0, time.UTC),
Labels: labels,
},
Status: api.PodStatus{
Conditions: []api.PodCondition{
{
Status: api.ConditionTrue,
Type: api.PodReady,
},
},
},
}
pods = append(pods, newPod)
}
if isUnready > -1 && isUnready < count {
pods[isUnready].Status.Conditions[0].Status = api.ConditionFalse
}
if isUnhealthy > -1 && isUnhealthy < count {
pods[isUnhealthy].Status.ContainerStatuses = []api.ContainerStatus{{RestartCount: 5}}
}
return &api.PodList{
Items: pods,
}
}
开发者ID:ravihansa3000,项目名称:kubernetes,代码行数:31,代码来源:factory_test.go
示例6: TestOverlappingRSs
func TestOverlappingRSs(t *testing.T) {
client := clientset.NewForConfigOrDie(&restclient.Config{Host: "", ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
labelMap := map[string]string{"foo": "bar"}
for i := 0; i < 5; i++ {
manager := NewReplicaSetControllerFromClient(client, controller.NoResyncPeriodFunc, 10, 0)
manager.podStoreSynced = alwaysReady
// Create 10 ReplicaSets, shuffled them randomly and insert them into the ReplicaSet controller's store
var controllers []*extensions.ReplicaSet
for j := 1; j < 10; j++ {
rsSpec := newReplicaSet(1, labelMap)
rsSpec.CreationTimestamp = unversioned.Date(2014, time.December, j, 0, 0, 0, 0, time.Local)
rsSpec.Name = string(uuid.NewUUID())
controllers = append(controllers, rsSpec)
}
shuffledControllers := shuffle(controllers)
for j := range shuffledControllers {
manager.rsStore.Store.Add(shuffledControllers[j])
}
// Add a pod and make sure only the oldest ReplicaSet is synced
pods := newPodList(nil, 1, api.PodPending, labelMap, controllers[0], "pod")
rsKey := getKey(controllers[0], t)
manager.addPod(&pods.Items[0])
queueRS, _ := manager.queue.Get()
if queueRS != rsKey {
t.Fatalf("Expected to find key %v in queue, found %v", rsKey, queueRS)
}
}
}
开发者ID:simonswine,项目名称:kubernetes,代码行数:31,代码来源:replica_set_test.go
示例7: TestUnstructuredSetters
func TestUnstructuredSetters(t *testing.T) {
unstruct := runtime.Unstructured{}
want := runtime.Unstructured{
Object: map[string]interface{}{
"kind": "test_kind",
"apiVersion": "test_version",
"metadata": map[string]interface{}{
"name": "test_name",
"namespace": "test_namespace",
"generateName": "test_generateName",
"uid": "test_uid",
"resourceVersion": "test_resourceVersion",
"selfLink": "test_selfLink",
"creationTimestamp": "2009-11-10T23:00:00Z",
"deletionTimestamp": "2010-11-10T23:00:00Z",
"labels": map[string]interface{}{
"test_label": "test_value",
},
"annotations": map[string]interface{}{
"test_annotation": "test_value",
},
},
},
}
unstruct.SetAPIVersion("test_version")
unstruct.SetKind("test_kind")
unstruct.SetNamespace("test_namespace")
unstruct.SetName("test_name")
unstruct.SetGenerateName("test_generateName")
unstruct.SetUID(types.UID("test_uid"))
unstruct.SetResourceVersion("test_resourceVersion")
unstruct.SetSelfLink("test_selfLink")
unstruct.SetCreationTimestamp(unversioned.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC))
date := unversioned.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC)
unstruct.SetDeletionTimestamp(&date)
unstruct.SetLabels(map[string]string{"test_label": "test_value"})
unstruct.SetAnnotations(map[string]string{"test_annotation": "test_value"})
if !reflect.DeepEqual(unstruct, want) {
t.Errorf("Wanted: \n%s\n Got:\n%s", unstruct, want)
}
}
开发者ID:timstclair,项目名称:kube-contrib,代码行数:44,代码来源:unstructured_test.go
示例8: TestGetImageStreamTagDIR
func TestGetImageStreamTagDIR(t *testing.T) {
expDockerImageReference := "foo/bar/baz:latest"
image := &api.Image{ObjectMeta: kapi.ObjectMeta{Name: "10"}, DockerImageReference: "foo/bar/baz:different"}
repo := &api.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Namespace: "default",
Name: "test",
},
Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {
Items: []api.TagEvent{
{
Created: unversioned.Date(2015, 3, 24, 9, 38, 0, 0, time.UTC),
DockerImageReference: expDockerImageReference,
Image: "10",
},
},
},
},
},
}
fakeEtcdClient, _, storage := setup(t)
fakeEtcdClient.Data[etcdtest.AddPrefix("/images/"+image.Name)] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(latest.Codec, image),
ModifiedIndex: 1,
},
},
}
fakeEtcdClient.Data[etcdtest.AddPrefix("/imagestreams/default/test")] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(latest.Codec, repo),
ModifiedIndex: 1,
},
},
}
obj, err := storage.Get(kapi.NewDefaultContext(), "test:latest")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
actual := obj.(*api.ImageStreamTag)
if actual.Image.DockerImageReference != expDockerImageReference {
t.Errorf("Different DockerImageReference: expected %s, got %s", expDockerImageReference, actual.Image.DockerImageReference)
}
}
开发者ID:johnmccawley,项目名称:origin,代码行数:48,代码来源:rest_test.go
示例9: TestLimitedLogAndRetryProcessing
func TestLimitedLogAndRetryProcessing(t *testing.T) {
updater := &buildUpdater{}
err := errors.New("funky error")
now := unversioned.Now()
retry := controller.Retry{
Count: 0,
StartTimestamp: unversioned.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-10, now.Second(), now.Nanosecond(), now.Location()),
}
if !limitedLogAndRetry(updater, 30*time.Minute)(&buildapi.Build{Status: buildapi.BuildStatus{Phase: buildapi.BuildPhaseNew}}, err, retry) {
t.Error("Expected more retries!")
}
if updater.Build != nil {
t.Fatal("BuildUpdater shouldn't be called!")
}
}
开发者ID:kcbabo,项目名称:origin,代码行数:16,代码来源:factory_test.go
示例10: TestGetImageStreamTagDIR
func TestGetImageStreamTagDIR(t *testing.T) {
expDockerImageReference := "foo/bar/baz:latest"
image := &api.Image{ObjectMeta: kapi.ObjectMeta{Name: "10"}, DockerImageReference: "foo/bar/baz:different"}
repo := &api.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Namespace: "default",
Name: "test",
},
Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {
Items: []api.TagEvent{
{
Created: unversioned.Date(2015, 3, 24, 9, 38, 0, 0, time.UTC),
DockerImageReference: expDockerImageReference,
Image: "10",
},
},
},
},
},
}
client, server, storage := setup(t)
defer server.Terminate(t)
client.Create(
context.TODO(),
etcdtest.AddPrefix("/images/"+image.Name),
runtime.EncodeOrDie(kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), image),
)
client.Create(
context.TODO(),
etcdtest.AddPrefix("/imagestreams/default/test"),
runtime.EncodeOrDie(kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), repo),
)
obj, err := storage.Get(kapi.NewDefaultContext(), "test:latest")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
actual := obj.(*api.ImageStreamTag)
if actual.Image.DockerImageReference != expDockerImageReference {
t.Errorf("Different DockerImageReference: expected %s, got %s", expDockerImageReference, actual.Image.DockerImageReference)
}
}
开发者ID:Xmagicer,项目名称:origin,代码行数:44,代码来源:rest_test.go
示例11: TestOverlappingRCs
func TestOverlappingRCs(t *testing.T) {
// Setup a fake server to listen for requests, and run the rc manager in steady state
fakeResponse := serverResponse{
statusCode: 200,
obj: &api.ReplicationController{},
}
testServer, _ := makeTestServer(t, api.NamespaceDefault, api.TenantDefault, fakeResponse)
defer testServer.Close()
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Default.Version()})
for i := 0; i < 5; i++ {
manager := NewReplicationManager(client, controller.NoResyncPeriodFunc, 10)
manager.podStoreSynced = alwaysReady
// Create 10 rcs, shuffled them randomly and insert them into the rc manager's store
var controllers []*api.ReplicationController
for j := 1; j < 10; j++ {
controllerSpec := newReplicationController(1)
controllerSpec.CreationTimestamp = unversioned.Date(2014, time.December, j, 0, 0, 0, 0, time.Local)
controllerSpec.Name = string(util.NewUUID())
controllers = append(controllers, controllerSpec)
}
shuffledControllers := shuffle(controllers)
for j := range shuffledControllers {
manager.rcStore.Store.Add(shuffledControllers[j])
}
// Add a pod and make sure only the oldest rc is synced
pods := newPodList(nil, 1, api.PodPending, controllers[0])
rcKey := getKey(controllers[0], t)
manager.addPod(&pods.Items[0])
queueRC, _ := manager.queue.Get()
if queueRC != rcKey {
t.Fatalf("Expected to find key %v in queue, found %v", rcKey, queueRC)
}
}
}
开发者ID:kuenzaa,项目名称:hypernetes,代码行数:37,代码来源:replication_controller_test.go
示例12: TestUpdateExistingNodeStatus
func TestUpdateExistingNodeStatus(t *testing.T) {
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
kubelet := testKubelet.kubelet
kubeClient := testKubelet.fakeKubeClient
kubeClient.ReactionChain = fake.NewSimpleClientset(&api.NodeList{Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: testKubeletHostname},
Spec: api.NodeSpec{},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeOutOfDisk,
Status: api.ConditionTrue,
Reason: "KubeletOutOfDisk",
Message: "out of disk space",
LastHeartbeatTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
{
Type: api.NodeMemoryPressure,
Status: api.ConditionFalse,
Reason: "KubeletHasSufficientMemory",
Message: fmt.Sprintf("kubelet has sufficient memory available"),
LastHeartbeatTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
{
Type: api.NodeDiskPressure,
Status: api.ConditionFalse,
Reason: "KubeletHasSufficientDisk",
Message: fmt.Sprintf("kubelet has sufficient disk space available"),
LastHeartbeatTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
{
Type: api.NodeReady,
Status: api.ConditionTrue,
Reason: "KubeletReady",
Message: fmt.Sprintf("kubelet is posting ready status"),
LastHeartbeatTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
},
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(3000, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(20E9, resource.BinarySI),
api.ResourcePods: *resource.NewQuantity(0, resource.DecimalSI),
},
Allocatable: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(2800, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(19900E6, resource.BinarySI),
api.ResourcePods: *resource.NewQuantity(0, resource.DecimalSI),
},
},
},
}}).ReactionChain
mockCadvisor := testKubelet.fakeCadvisor
mockCadvisor.On("Start").Return(nil)
machineInfo := &cadvisorapi.MachineInfo{
MachineID: "123",
SystemUUID: "abc",
BootID: "1b3",
NumCores: 2,
MemoryCapacity: 20E9,
}
mockCadvisor.On("MachineInfo").Return(machineInfo, nil)
versionInfo := &cadvisorapi.VersionInfo{
KernelVersion: "3.16.0-0.bpo.4-amd64",
ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)",
}
mockCadvisor.On("VersionInfo").Return(versionInfo, nil)
// Make kubelet report that it is out of disk space.
if err := updateDiskSpacePolicy(kubelet, mockCadvisor, 500, 500, 50, 50, 100, 100); err != nil {
t.Fatalf("can't update disk space manager: %v", err)
}
expectedNode := &api.Node{
ObjectMeta: api.ObjectMeta{Name: testKubeletHostname},
Spec: api.NodeSpec{},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeOutOfDisk,
Status: api.ConditionTrue,
Reason: "KubeletOutOfDisk",
Message: "out of disk space",
LastHeartbeatTime: unversioned.Time{}, // placeholder
LastTransitionTime: unversioned.Time{}, // placeholder
},
{
Type: api.NodeMemoryPressure,
Status: api.ConditionFalse,
Reason: "KubeletHasSufficientMemory",
Message: fmt.Sprintf("kubelet has sufficient memory available"),
LastHeartbeatTime: unversioned.Time{},
LastTransitionTime: unversioned.Time{},
},
{
Type: api.NodeDiskPressure,
//.........这里部分代码省略.........
开发者ID:eljefedelrodeodeljefe,项目名称:kubernetes,代码行数:101,代码来源:kubelet_node_status_test.go
示例13: TestGetImageStreamTag
func TestGetImageStreamTag(t *testing.T) {
tests := map[string]struct {
image *api.Image
repo *api.ImageStream
expectError bool
errorTargetKind string
errorTargetID string
}{
"happy path": {
image: &api.Image{ObjectMeta: kapi.ObjectMeta{Name: "10"}, DockerImageReference: "foo/bar/baz"},
repo: &api.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Namespace: "default",
Name: "test",
},
Spec: api.ImageStreamSpec{
Tags: map[string]api.TagReference{
"latest": {
Annotations: map[string]string{
"color": "blue",
"size": "large",
},
},
},
},
Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {
Items: []api.TagEvent{
{
Created: unversioned.Date(2015, 3, 24, 9, 38, 0, 0, time.UTC),
DockerImageReference: "test",
Image: "10",
},
},
},
},
},
},
},
"image = ''": {
repo: &api.ImageStream{
ObjectMeta: kapi.ObjectMeta{Name: "test"},
Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {Items: []api.TagEvent{{DockerImageReference: "test", Image: ""}}},
},
}},
expectError: true,
errorTargetKind: "imagestreamtags",
errorTargetID: "test:latest",
},
"missing image": {
repo: &api.ImageStream{Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {Items: []api.TagEvent{{DockerImageReference: "test", Image: "10"}}},
},
}},
expectError: true,
errorTargetKind: "images",
errorTargetID: "10",
},
"missing repo": {
expectError: true,
errorTargetKind: "imagestreams",
errorTargetID: "test",
},
"missing tag": {
image: &api.Image{ObjectMeta: kapi.ObjectMeta{Name: "10"}, DockerImageReference: "foo/bar/baz"},
repo: &api.ImageStream{
ObjectMeta: kapi.ObjectMeta{Name: "test"},
Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"other": {Items: []api.TagEvent{{DockerImageReference: "test", Image: "10"}}},
},
}},
expectError: true,
errorTargetKind: "imagestreamtags",
errorTargetID: "test:latest",
},
}
for name, testCase := range tests {
client, server, storage := setup(t)
defer server.Terminate(t)
if testCase.image != nil {
client.Create(
context.TODO(),
etcdtest.AddPrefix("/images/"+testCase.image.Name),
runtime.EncodeOrDie(kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), testCase.image),
)
}
if testCase.repo != nil {
client.Create(
context.TODO(),
etcdtest.AddPrefix("/imagestreams/default/test"),
runtime.EncodeOrDie(kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), testCase.repo),
)
}
//.........这里部分代码省略.........
开发者ID:Xmagicer,项目名称:origin,代码行数:101,代码来源:rest_test.go
示例14: TestScale
func TestScale(t *testing.T) {
newTimestamp := unversioned.Date(2016, 5, 20, 2, 0, 0, 0, time.UTC)
oldTimestamp := unversioned.Date(2016, 5, 20, 1, 0, 0, 0, time.UTC)
olderTimestamp := unversioned.Date(2016, 5, 20, 0, 0, 0, 0, time.UTC)
tests := []struct {
name string
deployment *exp.Deployment
oldDeployment *exp.Deployment
newRS *exp.ReplicaSet
oldRSs []*exp.ReplicaSet
expectedNew *exp.ReplicaSet
expectedOld []*exp.ReplicaSet
desiredReplicasAnnotations map[string]int32
}{
{
name: "normal scaling event: 10 -> 12",
deployment: newDeployment(12, nil),
oldDeployment: newDeployment(10, nil),
newRS: rs("foo-v1", 10, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{},
expectedNew: rs("foo-v1", 12, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{},
},
{
name: "normal scaling event: 10 -> 5",
deployment: newDeployment(5, nil),
oldDeployment: newDeployment(10, nil),
newRS: rs("foo-v1", 10, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{},
expectedNew: rs("foo-v1", 5, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{},
},
{
name: "proportional scaling: 5 -> 10",
deployment: newDeployment(10, nil),
oldDeployment: newDeployment(5, nil),
newRS: rs("foo-v2", 2, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{rs("foo-v1", 3, nil, oldTimestamp)},
expectedNew: rs("foo-v2", 4, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{rs("foo-v1", 6, nil, oldTimestamp)},
},
{
name: "proportional scaling: 5 -> 3",
deployment: newDeployment(3, nil),
oldDeployment: newDeployment(5, nil),
newRS: rs("foo-v2", 2, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{rs("foo-v1", 3, nil, oldTimestamp)},
expectedNew: rs("foo-v2", 1, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{rs("foo-v1", 2, nil, oldTimestamp)},
},
{
name: "proportional scaling: 9 -> 4",
deployment: newDeployment(4, nil),
oldDeployment: newDeployment(9, nil),
newRS: rs("foo-v2", 8, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{rs("foo-v1", 1, nil, oldTimestamp)},
expectedNew: rs("foo-v2", 4, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{rs("foo-v1", 0, nil, oldTimestamp)},
},
{
name: "proportional scaling: 7 -> 10",
deployment: newDeployment(10, nil),
oldDeployment: newDeployment(7, nil),
newRS: rs("foo-v3", 2, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{rs("foo-v2", 3, nil, oldTimestamp), rs("foo-v1", 2, nil, olderTimestamp)},
expectedNew: rs("foo-v3", 3, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{rs("foo-v2", 4, nil, oldTimestamp), rs("foo-v1", 3, nil, olderTimestamp)},
},
{
name: "proportional scaling: 13 -> 8",
deployment: newDeployment(8, nil),
oldDeployment: newDeployment(13, nil),
newRS: rs("foo-v3", 2, nil, newTimestamp),
oldRSs: []*exp.ReplicaSet{rs("foo-v2", 8, nil, oldTimestamp), rs("foo-v1", 3, nil, olderTimestamp)},
expectedNew: rs("foo-v3", 1, nil, newTimestamp),
expectedOld: []*exp.ReplicaSet{rs("foo-v2", 5, nil, oldTimestamp), rs("foo-v1", 2, nil, olderTimestamp)},
},
// Scales up the new replica set.
{
name: "leftover distribution: 3 -> 4",
deployment: newDeployment(4, nil),
oldDeployment: newDeployment(3, nil),
//.........这里部分代码省略.........
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:101,代码来源:sync_test.go
示例15: TestUnstructuredSetters
func TestUnstructuredSetters(t *testing.T) {
unstruct := runtime.Unstructured{}
trueVar := true
want := runtime.Unstructured{
Object: map[string]interface{}{
"kind": "test_kind",
"apiVersion": "test_version",
"metadata": map[string]interface{}{
"name": "test_name",
"namespace": "test_namespace",
"generateName": "test_generateName",
"uid": "test_uid",
"resourceVersion": "test_resourceVersion",
"selfLink": "test_selfLink",
"creationTimestamp": "2009-11-10T23:00:00Z",
"deletionTimestamp": "2010-11-10T23:00:00Z",
"labels": map[string]interface{}{
"test_label": "test_value",
},
"annotations": map[string]interface{}{
"test_annotation": "test_value",
},
"ownerReferences": []map[string]interface{}{
{
"kind": "Pod",
"name": "poda",
"apiVersion": "v1",
"uid": "1",
"controller": (*bool)(nil),
},
{
"kind": "Pod",
"name": "podb",
"apiVersion": "v1",
"uid": "2",
"controller": &trueVar,
},
},
"finalizers": []interface{}{
"finalizer.1",
"finalizer.2",
},
"clusterName": "cluster123",
},
},
}
unstruct.SetAPIVersion("test_version")
unstruct.SetKind("test_kind")
unstruct.SetNamespace("test_namespace")
unstruct.SetName("test_name")
unstruct.SetGenerateName("test_generateName")
unstruct.SetUID(types.UID("test_uid"))
unstruct.SetResourceVersion("test_resourceVersion")
unstruct.SetSelfLink("test_selfLink")
unstruct.SetCreationTimestamp(unversioned.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC))
date := unversioned.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC)
unstruct.SetDeletionTimestamp(&date)
unstruct.SetLabels(map[string]string{"test_label": "test_value"})
unstruct.SetAnnotations(map[string]string{"test_annotation": "test_value"})
newOwnerReferences := []metatypes.OwnerReference{
{
Kind: "Pod",
Name: "poda",
APIVersion: "v1",
UID: "1",
},
{
Kind: "Pod",
Name: "podb",
APIVersion: "v1",
UID: "2",
Controller: &trueVar,
},
}
unstruct.SetOwnerReferences(newOwnerReferences)
unstruct.SetFinalizers([]string{"finalizer.1", "finalizer.2"})
unstruct.SetClusterName("cluster123")
if !reflect.DeepEqual(unstruct, want) {
t.Errorf("Wanted: \n%s\n Got:\n%s", want, unstruct)
}
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:84,代码来源:unstructured_test.go
示例16: TestMonitorNodeStatusUpdateStatus
func TestMonitorNodeStatusUpdateStatus(t *testing.T) {
fakeNow := unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC)
table := []struct {
fakeNodeHandler *FakeNodeHandler
timeToPass time.Duration
newNodeStatus api.NodeStatus
expectedEvictPods bool
expectedRequestCount int
expectedNodes []*api.Node
}{
// Node created long time ago, without status:
// Expect Unknown status posted from node controller.
{
fakeNodeHandler: &FakeNodeHandler{
Existing: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
},
},
Clientset: fake.NewSimpleClientset(&api.PodList{Items: []api.Pod{*newPod("pod0", "node0")}}),
},
expectedRequestCount: 2, // List+Update
expectedNodes: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionUnknown,
Reason: "NodeStatusNeverUpdated",
Message: "Kubelet never posted node status.",
LastHeartbeatTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
LastTransitionTime: fakeNow,
},
{
Type: api.NodeOutOfDisk,
Status: api.ConditionUnknown,
Reason: "NodeStatusNeverUpdated",
Message: "Kubelet never posted node status.",
LastHeartbeatTime: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
LastTransitionTime: fakeNow,
},
},
},
},
},
},
// Node created recently, without status.
// Expect no action from node controller (within startup grace period).
{
fakeNodeHandler: &FakeNodeHandler{
Existing: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: fakeNow,
},
},
},
Clientset: fake.NewSimpleClientset(&api.PodList{Items: []api.Pod{*newPod("pod0", "node0")}}),
},
expectedRequestCount: 1, // List
expectedNodes: nil,
},
// Node created long time ago, with status updated by kubelet exceeds grace period.
// Expect Unknown status posted from node controller.
{
fakeNodeHandler: &FakeNodeHandler{
Existing: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionTrue,
// Node status hasn't been updated for 1hr.
LastHeartbeatTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
{
Type: api.NodeOutOfDisk,
Status: api.ConditionFalse,
// Node status hasn't been updated for 1hr.
LastHeartbeatTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
},
Capacity: api.ResourceList{
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
//.........这里部分代码省略.........
开发者ID:richm,项目名称:origin,代码行数:101,代码来源:nodecontroller_test.go
示例17: TestNodeDeletion
func TestNodeDeletion(t *testing.T) {
fakeNow := unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC)
fakeNodeHandler := &FakeNodeHandler{
Existing: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionTrue,
// Node status has just been updated.
LastHeartbeatTime: fakeNow,
LastTransitionTime: fakeNow,
},
},
Capacity: api.ResourceList{
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
},
},
Spec: api.NodeSpec{
ExternalID: "node0",
},
},
{
ObjectMeta: api.ObjectMeta{
Name: "node1",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionTrue,
// Node status has just been updated.
LastHeartbeatTime: fakeNow,
LastTransitionTime: fakeNow,
},
},
Capacity: api.ResourceList{
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
},
},
Spec: api.NodeSpec{
ExternalID: "node0",
},
},
},
Clientset: fake.NewSimpleClientset(&api.PodList{Items: []api.Pod{*newPod("pod0", "node0"), *newPod("pod1", "node1")}}),
}
nodeController := NewNodeController(nil, fakeNodeHandler, 5*time.Minute, util.NewFakeAlwaysRateLimiter(), util.NewFakeAlwaysRateLimiter(),
testNodeMonitorGracePeriod, testNodeStartupGracePeriod, testNodeMonitorPeriod, nil, false)
nodeController.now = func() unversioned.Time { return fakeNow }
if err := nodeController.monitorNodeStatus(); err != nil {
t.Errorf("unexpected error: %v", err)
}
fakeNodeHandler.Delete("node1", nil)
if err := nodeController.monitorNodeStatus(); err != nil {
t.Errorf("unexpected error: %v", err)
}
nodeController.podEvictor.Try(func(value TimedValue) (bool, time.Duration) {
nodeController.deletePods(value.Value)
return true, 0
})
podEvicted := false
for _, action := range fakeNodeHandler.Actions() {
if action.GetVerb() == "delete" && action.GetResource() == "pods" {
podEvicted = true
}
}
if !podEvicted {
t.Error("expected pods to be evicted from the deleted node")
}
}
开发者ID:richm,项目名称:origin,代码行数:80,代码来源:nodecontroller_test.go
示例18: TestMonitorNodeStatusEvictPods
func TestMonitorNodeStatusEvictPods(t *testing.T) {
fakeNow := unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC)
evictionTimeout := 10 * time.Minute
// Because of the logic that prevents NC from evicting anything when all Nodes are NotReady
// we need second healthy node in tests. Because of how the tests are written we need to update
// the status of this Node.
healthyNodeNewStatus := api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionTrue,
// Node status has just been updated, and is NotReady for 10min.
LastHeartbeatTime: unversioned.Date(2015, 1, 1, 12, 9, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
},
}
table := []struct {
fakeNodeHandler *FakeNodeHandler
daemonSets []extensions.DaemonSet
timeToPass time.Duration
newNodeStatus api.NodeStatus
secondNodeNewStatus api.NodeStatus
expectedEvictPods bool
description string
}{
// Node created recently, with no status (happens only at cluster startup).
{
fakeNodeHandler: &FakeNodeHandler{
Existing: []*api.Node{
{
ObjectMeta: api.ObjectMeta{
Name: "node0",
CreationTimestamp: fakeNow,
Labels: map[string]string{
unversioned.LabelZoneRegion: "region1",
unversioned.LabelZoneFailureDomain: "zone1",
},
},
},
{
ObjectMeta: api.ObjectMeta{
Name: "node1",
CreationTimestamp: unversioned.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
Labels: map[string]string{
unversioned.LabelZoneRegion: "region1",
unversioned.LabelZoneFailureDomain: "zone1",
},
},
Status: api.NodeStatus{
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionTrue,
LastHeartbeatTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
LastTransitionTime: unversioned.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
},
},
},
},
Clientset: fake.NewSimpleClientset(&api.PodList{Items: []api.Pod{*newPod("pod0", "node0")}}),
},
daemonSets: nil,
timeToPass: 0,
newNodeStatus: api.NodeStatus{},
secondNodeNewStatus: heal
|
请发表评论