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


Golang rest.GetterWithOptions函數代碼示例

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


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

示例1: resourceLocationHelper

func resourceLocationHelper(BuildPhase api.BuildPhase, podPhase string, ctx kapi.Context) (string, error) {
	expectedBuild := mockBuild(BuildPhase, podPhase)
	internal := &test.BuildStorage{Build: expectedBuild}

	storage := &REST{
		Getter:         internal,
		PodGetter:      &testPodGetter{},
		ConnectionInfo: &kclient.HTTPKubeletClient{Config: &kclient.KubeletConfig{EnableHttps: true, Port: 12345}, Client: &http.Client{}},
		Timeout:        defaultTimeout,
	}
	getter := rest.GetterWithOptions(storage)
	obj, err := getter.Get(ctx, "foo-build", &api.BuildLogOptions{NoWait: true})
	if err != nil {
		return "", err
	}
	streamer, ok := obj.(*genericrest.LocationStreamer)
	if !ok {
		return "", fmt.Errorf("Result of get not LocationStreamer")
	}
	if streamer.Location != nil {
		return streamer.Location.String(), nil
	}
	return "", nil

}
開發者ID:johnmccawley,項目名稱:origin,代碼行數:25,代碼來源:rest_test.go

示例2: TestPreviousBuildLogs

func TestPreviousBuildLogs(t *testing.T) {
	ctx := kapi.NewDefaultContext()
	first := mockBuild(api.BuildPhaseComplete, "bc-1", 1)
	second := mockBuild(api.BuildPhaseComplete, "bc-2", 2)
	third := mockBuild(api.BuildPhaseComplete, "bc-3", 3)
	internal := &test.BuildStorage{Builds: &api.BuildList{Items: []api.Build{*first, *second, *third}}}

	storage := &REST{
		Getter:         internal,
		PodGetter:      &anotherTestPodGetter{},
		ConnectionInfo: &fakeConnectionInfoGetter{},
		Timeout:        defaultTimeout,
	}
	getter := rest.GetterWithOptions(storage)
	// Will expect the previous from bc-3 aka bc-2
	obj, err := getter.Get(ctx, "bc-3", &api.BuildLogOptions{NoWait: true, Previous: true})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	streamer, ok := obj.(*genericrest.LocationStreamer)
	if !ok {
		t.Fatalf("unexpected object: %#v", obj)
	}

	expected := &url.URL{
		Scheme: "https",
		Host:   "foo-host:12345",
		Path:   "/containerLogs/default/bc-2-build/foo-container",
	}

	if exp, got := expected.String(), streamer.Location.String(); exp != got {
		t.Fatalf("expected location:\n\t%s\ngot location:\n\t%s\n", exp, got)
	}
}
開發者ID:xgwang-zte,項目名稱:origin,代碼行數:35,代碼來源:rest_test.go

示例3: resourceLocationHelper

func resourceLocationHelper(BuildPhase api.BuildPhase, podPhase string, ctx kapi.Context, version int) (string, error) {
	expectedBuild := mockBuild(BuildPhase, podPhase, version)
	internal := &test.BuildStorage{Build: expectedBuild}

	storage := &REST{
		Getter:         internal,
		PodGetter:      &testPodGetter{},
		ConnectionInfo: &fakeConnectionInfoGetter{},
		Timeout:        defaultTimeout,
	}
	getter := rest.GetterWithOptions(storage)
	obj, err := getter.Get(ctx, "foo-build", &api.BuildLogOptions{NoWait: true})
	if err != nil {
		return "", err
	}
	streamer, ok := obj.(*genericrest.LocationStreamer)
	if !ok {
		return "", fmt.Errorf("Result of get not LocationStreamer")
	}
	if streamer.Location != nil {
		return streamer.Location.String(), nil
	}
	return "", nil

}
開發者ID:xgwang-zte,項目名稱:origin,代碼行數:25,代碼來源:rest_test.go

示例4: Update

	return &api.Pod{}
}

// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
	return r.store.Update(ctx, obj)
}

// LogREST implements the log endpoint for a Pod
type LogREST struct {
	store       *etcdgeneric.Etcd
	kubeletConn client.ConnectionInfoGetter
}

// LogREST implements GetterWithOptions
var _ = rest.GetterWithOptions(&LogREST{})

// New creates a new Pod log options object
func (r *LogREST) New() runtime.Object {
	// TODO - return a resource that represents a log
	return &api.Pod{}
}

// Get retrieves a runtime.Object that will stream the contents of the pod log
func (r *LogREST) Get(ctx api.Context, name string, opts runtime.Object) (runtime.Object, error) {
	logOpts, ok := opts.(*api.PodLogOptions)
	if !ok {
		return nil, fmt.Errorf("Invalid options object: %#v", opts)
	}
	location, transport, err := pod.LogLocation(r.store, r.kubeletConn, ctx, name, logOpts)
	if err != nil {
開發者ID:vmturbo,項目名稱:kubernetes,代碼行數:31,代碼來源:etcd.go


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