• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang api.PreV1Beta3函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.PreV1Beta3函数的典型用法代码示例。如果您正苦于以下问题:Golang PreV1Beta3函数的具体用法?Golang PreV1Beta3怎么用?Golang PreV1Beta3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PreV1Beta3函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: getFakeClient

func getFakeClient(t *testing.T, validURLs []string) (ClientPosterFunc, *httptest.Server) {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) {
		for _, u := range validURLs {
			if u == r.RequestURI {
				return
			}
		}
		t.Errorf("Unexpected HTTP request: %s, expected %v", r.RequestURI, validURLs)
	}
	server := httptest.NewServer(http.HandlerFunc(handlerFunc))
	return func(mapping *meta.RESTMapping) (RESTClientPoster, error) {
		fakeCodec := testapi.Codec()
		fakeUri, _ := url.Parse(server.URL + "/api/" + testapi.Version())
		legacyBehavior := api.PreV1Beta3(testapi.Version())
		return client.NewRESTClient(fakeUri, testapi.Version(), fakeCodec, legacyBehavior, 5, 10), nil
	}, server
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:17,代码来源:config_test.go


示例17: ResourcePathWithPrefix

// Returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/watch/pods/pod0 for v1beta1 and
// /api/v1beta3/watch/namespaces/foo/pods/pod0 for v1beta3.
func ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
	path := "/api/" + Version()
	if prefix != "" {
		path = path + "/" + prefix
	}
	if !api.PreV1Beta3(Version()) {
		if namespace != "" {
			path = path + "/namespaces/" + namespace
		}
		// Resource names in v1beta3 are lower case.
		resource = strings.ToLower(resource)
	}
	if resource != "" {
		path = path + "/" + resource
	}
	if name != "" {
		path = path + "/" + name
	}
	return path
}
开发者ID:mikedanese,项目名称:heapster,代码行数:24,代码来源:testapi.go


示例18: WebHookURL

// WebHookURL returns the URL for the provided build config name and trigger policy, or ErrTriggerIsNotAWebHook
// if the trigger is not a webhook type.
func (c *buildConfigs) WebHookURL(name string, trigger *buildapi.BuildTriggerPolicy) (*url.URL, error) {
	if kapi.PreV1Beta3(c.r.APIVersion()) {
		switch {
		case trigger.GenericWebHook != nil:
			return c.r.Get().Namespace(c.ns).Resource("buildConfigHooks").Name(name).Suffix(trigger.GenericWebHook.Secret, "generic").URL(), nil
		case trigger.GitHubWebHook != nil:
			return c.r.Get().Namespace(c.ns).Resource("buildConfigHooks").Name(name).Suffix(trigger.GitHubWebHook.Secret, "github").URL(), nil
		default:
			return nil, ErrTriggerIsNotAWebHook
		}
	}
	switch {
	case trigger.GenericWebHook != nil:
		return c.r.Get().Namespace(c.ns).Resource("buildConfigs").Name(name).SubResource("webhooks").Suffix(trigger.GenericWebHook.Secret, "generic").URL(), nil
	case trigger.GitHubWebHook != nil:
		return c.r.Get().Namespace(c.ns).Resource("buildConfigs").Name(name).SubResource("webhooks").Suffix(trigger.GitHubWebHook.Secret, "github").URL(), nil
	default:
		return nil, ErrTriggerIsNotAWebHook
	}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:22,代码来源:buildconfigs.go


示例19: getSCCResoureName

func getSCCResoureName() string {
	if api.PreV1Beta3(testapi.Version()) {
		return "securityContextConstraints"
	}
	return "securitycontextconstraints"
}
开发者ID:cjnygard,项目名称:origin,代码行数:6,代码来源:securitycontextconstraints_test.go


示例20: getPersistentVolumeClaimsResoureName

func getPersistentVolumeClaimsResoureName() string {
	if api.PreV1Beta3(testapi.Version()) {
		return "persistentVolumeClaims"
	}
	return "persistentvolumeclaims"
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:6,代码来源:persistentvolumeclaim_test.go



注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/api.PreV1Beta3函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang api.Protocol函数代码示例发布时间:2022-05-23
下一篇:
Golang api.ObjectMetaFor函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap