當前位置: 首頁>>代碼示例>>Golang>>正文


Golang api.PreV1Beta3函數代碼示例

本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.PreV1Beta3函數的典型用法代碼示例。如果您正苦於以下問題:Golang PreV1Beta3函數的具體用法?Golang PreV1Beta3怎麽用?Golang PreV1Beta3使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PreV1Beta3函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestReadManifestFromFileWithDefaults

func TestReadManifestFromFileWithDefaults(t *testing.T) {
	if !api.PreV1Beta3(testapi.Version()) {
		return
	}
	file := writeTestFile(t, os.TempDir(), "test_pod_config",
		fmt.Sprintf(`{
			"version": "%s",
			"id": "test",
			"containers": [{ "name": "image", "image": "test/image" }]
		}`, testapi.Version()))
	defer os.Remove(file.Name())

	ch := make(chan interface{})
	NewSourceFile(file.Name(), "localhost", time.Millisecond, ch)
	select {
	case got := <-ch:
		update := got.(kubelet.PodUpdate)
		if update.Pods[0].UID == "" {
			t.Errorf("Unexpected UID: %s", update.Pods[0].UID)
		}

	case <-time.After(time.Second):
		t.Errorf("Expected update, timeout instead")
	}
}
開發者ID:SivagnanamCiena,項目名稱:calico-kubernetes,代碼行數:25,代碼來源:file_test.go

示例2: TestPodTemplateList

func TestPodTemplateList(t *testing.T) {
	if api.PreV1Beta3(testapi.Version()) {
		return
	}

	ns := api.NamespaceDefault
	podTemplateList := &api.PodTemplateList{
		Items: []api.PodTemplate{
			{
				ObjectMeta: api.ObjectMeta{
					Name:      "foo",
					Namespace: ns,
				},
			},
		},
	}
	c := &testClient{
		Request: testRequest{
			Method: "GET",
			Path:   testapi.ResourcePath(getPodTemplatesResoureName(), ns, ""),
			Query:  buildQueryValues(ns, nil),
			Body:   nil,
		},
		Response: Response{StatusCode: 200, Body: podTemplateList},
	}
	response, err := c.Setup().PodTemplates(ns).List(labels.Everything(), fields.Everything())
	c.Validate(t, response, err)
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:28,代碼來源:pod_templates_test.go

示例3: makeTestServer

func makeTestServer(t *testing.T, namespace, name string, podResponse, controllerResponse, updateResponse serverResponse) (*httptest.Server, *util.FakeHandler) {
	fakePodHandler := util.FakeHandler{
		StatusCode:   podResponse.statusCode,
		ResponseBody: runtime.EncodeOrDie(testapi.Codec(), podResponse.obj.(runtime.Object)),
	}
	fakeControllerHandler := util.FakeHandler{
		StatusCode:   controllerResponse.statusCode,
		ResponseBody: runtime.EncodeOrDie(testapi.Codec(), controllerResponse.obj.(runtime.Object)),
	}
	fakeUpdateHandler := util.FakeHandler{
		StatusCode:   updateResponse.statusCode,
		ResponseBody: runtime.EncodeOrDie(testapi.Codec(), updateResponse.obj.(runtime.Object)),
	}
	mux := http.NewServeMux()
	mux.Handle(testapi.ResourcePath("pods", namespace, ""), &fakePodHandler)
	mux.Handle(testapi.ResourcePath(replicationControllerResourceName(), "", ""), &fakeControllerHandler)
	if !api.PreV1Beta3(testapi.Version()) && namespace != "" {
		mux.Handle(testapi.ResourcePath(replicationControllerResourceName(), namespace, ""), &fakeControllerHandler)
	}
	if name != "" {
		mux.Handle(testapi.ResourcePath(replicationControllerResourceName(), namespace, name), &fakeUpdateHandler)
	}
	mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
		t.Errorf("unexpected request: %v", req.RequestURI)
		res.WriteHeader(http.StatusNotFound)
	})
	return httptest.NewServer(mux), &fakeUpdateHandler
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:28,代碼來源:replication_controller_test.go

示例4: init

func init() {
	if api.PreV1Beta3(testapi.Version()) {
		nodeResourceName = "minions"
	} else {
		nodeResourceName = "nodes"
	}
}
開發者ID:chenzhen411,項目名稱:kubernetes,代碼行數:7,代碼來源:auth_test.go

示例5: TestPodTemplateGet

func TestPodTemplateGet(t *testing.T) {
	if api.PreV1Beta3(testapi.Version()) {
		return
	}

	ns := api.NamespaceDefault
	podTemplate := &api.PodTemplate{
		ObjectMeta: api.ObjectMeta{
			Name:      "abc",
			Namespace: ns,
		},
		Template: api.PodTemplateSpec{},
	}
	c := &testClient{
		Request: testRequest{
			Method: "GET",
			Path:   testapi.ResourcePath(getPodTemplatesResoureName(), ns, "abc"),
			Query:  buildQueryValues(ns, nil),
			Body:   nil,
		},
		Response: Response{StatusCode: 200, Body: podTemplate},
	}

	response, err := c.Setup().PodTemplates(ns).Get("abc")
	c.Validate(t, response, err)
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:26,代碼來源:pod_templates_test.go

示例6: ResourcePathWithPrefixAndNamespaceQuery

func ResourcePathWithPrefixAndNamespaceQuery(prefix, resource, namespace, name string) string {
	path := ResourcePathWithPrefix(prefix, resource, namespace, name)
	// Add namespace as query param for pre v1beta3.
	if api.PreV1Beta3(Version()) && namespace != "" {
		path = path + "?namespace=" + namespace
	}
	return path
}
開發者ID:mikedanese,項目名稱:heapster,代碼行數:8,代碼來源:testapi.go

示例7: Delete

// Delete deletes an existing service.
func (c *services) Delete(name string) error {
	// v1beta3 does not allow DELETE without a namespace.
	needNamespace := !api.PreV1Beta3(c.r.APIVersion())
	namespace := c.ns
	if needNamespace && len(namespace) == 0 {
		namespace = api.NamespaceDefault
	}
	return c.r.Delete().Namespace(c.ns).Resource("services").Name(name).Do().Error()
}
開發者ID:DreadPirateShawn,項目名稱:heapster,代碼行數:10,代碼來源:services.go

示例8: TestExtractFromDir

func TestExtractFromDir(t *testing.T) {
	if !api.PreV1Beta3(testapi.Version()) {
		return
	}
	manifest, expectedPod := exampleManifestAndPod("1")
	manifest2, expectedPod2 := exampleManifestAndPod("2")

	manifests := []v1beta1.ContainerManifest{manifest, manifest2}
	pods := []*api.Pod{expectedPod, expectedPod2}
	files := make([]*os.File, len(manifests))

	dirName, err := ioutil.TempDir("", "foo")
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}

	for i, manifest := range manifests {
		data, err := json.Marshal(manifest)
		if err != nil {
			t.Errorf("Unexpected error: %v", err)
			continue
		}
		file, err := ioutil.TempFile(dirName, manifest.ID)
		if err != nil {
			t.Errorf("Unexpected error: %v", err)
			continue
		}
		name := file.Name()
		if err := file.Close(); err != nil {
			t.Errorf("Unexpected error: %v", err)
			continue
		}
		ioutil.WriteFile(name, data, 0755)
		files[i] = file
	}

	ch := make(chan interface{}, 1)
	c := sourceFile{dirName, "an-example-host", ch}
	err = c.extractFromPath()
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}

	update := (<-ch).(kubelet.PodUpdate)
	expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, pods...)
	sort.Sort(sortedPods(update.Pods))
	sort.Sort(sortedPods(expected.Pods))
	if !api.Semantic.DeepDerivative(expected, update) {
		t.Fatalf("Expected %#v, Got %#v", expected, update)
	}
	for _, pod := range update.Pods {
		if errs := validation.ValidatePod(pod); len(errs) != 0 {
			t.Errorf("Expected no validation errors on %#v, Got %q", pod, errs)
		}
	}
}
開發者ID:SivagnanamCiena,項目名稱:calico-kubernetes,代碼行數:56,代碼來源:file_test.go

示例9: Create

// Create creates a new service.
func (c *services) Create(svc *api.Service) (result *api.Service, err error) {
	result = &api.Service{}
	// v1beta3 does not allow POST without a namespace.
	needNamespace := !api.PreV1Beta3(c.r.APIVersion())
	namespace := c.ns
	if needNamespace && len(namespace) == 0 {
		namespace = api.NamespaceDefault
	}
	err = c.r.Post().Namespace(namespace).Resource("services").Body(svc).Do().Into(result)
	return
}
開發者ID:DreadPirateShawn,項目名稱:heapster,代碼行數:12,代碼來源:services.go

示例10: getSelfLink

func getSelfLink(name, namespace string) string {
	var selfLink string
	if api.PreV1Beta3(latest.Version) {
		selfLink = fmt.Sprintf("/api/"+latest.Version+"/pods/%s?namespace=%s", name, namespace)
	} else {
		if len(namespace) == 0 {
			namespace = api.NamespaceDefault
		}
		selfLink = fmt.Sprintf("/api/"+latest.Version+"/pods/namespaces/%s/%s", name, namespace)
	}
	return selfLink
}
開發者ID:mbforbes,項目名稱:kubernetes,代碼行數:12,代碼來源:common.go

示例11: TestPodTemplateDelete

func TestPodTemplateDelete(t *testing.T) {
	if api.PreV1Beta3(testapi.Version()) {
		return
	}

	ns := api.NamespaceDefault
	c := &testClient{
		Request:  testRequest{Method: "DELETE", Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, "foo"), Query: buildQueryValues(ns, nil)},
		Response: Response{StatusCode: 200},
	}
	err := c.Setup().PodTemplates(ns).Delete("foo", nil)
	c.Validate(t, nil, err)
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:13,代碼來源:pod_templates_test.go

示例12: parseResourceVersion

func parseResourceVersion(response []byte) (string, float64, error) {
	var resultBodyMap map[string]interface{}
	err := json.Unmarshal(response, &resultBodyMap)
	if err != nil {
		return "", 0, fmt.Errorf("unexpected error unmarshaling resultBody: %v", err)
	}
	apiVersion, ok := resultBodyMap["apiVersion"].(string)
	if !ok {
		return "", 0, fmt.Errorf("unexpected error, apiVersion not found in JSON response: %v", string(response))
	}
	if api.PreV1Beta3(apiVersion) {
		return parsePreV1Beta3ResourceVersion(resultBodyMap, response)
	}
	return parseV1Beta3ResourceVersion(resultBodyMap, response)
}
開發者ID:SivagnanamCiena,項目名稱:calico-kubernetes,代碼行數:15,代碼來源:auth_test.go

示例13: TestPodTemplateWatch

func TestPodTemplateWatch(t *testing.T) {
	if api.PreV1Beta3(testapi.Version()) {
		return
	}

	c := &testClient{
		Request: testRequest{
			Method: "GET",
			Path:   "/api/" + testapi.Version() + "/watch/" + getPodTemplatesResoureName(),
			Query:  url.Values{"resourceVersion": []string{}}},
		Response: Response{StatusCode: 200},
	}
	_, err := c.Setup().PodTemplates(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
	c.Validate(t, nil, err)
}
開發者ID:cjnygard,項目名稱:origin,代碼行數:15,代碼來源:pod_templates_test.go

示例14: Update

// Update updates an existing service.
func (c *services) Update(svc *api.Service) (result *api.Service, err error) {
	result = &api.Service{}
	if len(svc.ResourceVersion) == 0 {
		err = fmt.Errorf("invalid update object, missing resource version: %v", svc)
		return
	}
	// v1beta3 does not allow PUT without a namespace.
	needNamespace := !api.PreV1Beta3(c.r.APIVersion())
	namespace := c.ns
	if needNamespace && len(namespace) == 0 {
		namespace = api.NamespaceDefault
	}
	err = c.r.Put().Namespace(namespace).Resource("services").Name(svc.Name).Body(svc).Do().Into(result)
	return
}
開發者ID:DreadPirateShawn,項目名稱:heapster,代碼行數:16,代碼來源:services.go

示例15: buildQueryValues

// buildQueryValues is a convenience function for knowing if a namespace should be in a query param or not
func buildQueryValues(namespace string, query url.Values) url.Values {
	v := url.Values{}
	if query != nil {
		for key, values := range query {
			for _, value := range values {
				v.Add(key, value)
			}
		}
	}
	if len(namespace) > 0 {
		if api.PreV1Beta3(testapi.Version()) {
			v.Set("namespace", namespace)
		}
	}
	return v
}
開發者ID:eghobo,項目名稱:kubedash,代碼行數:17,代碼來源:client_test.go


注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/api.PreV1Beta3函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。