本文整理汇总了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")
}
}
示例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)
}
示例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
}
示例4: init
func init() {
if api.PreV1Beta3(testapi.Version()) {
nodeResourceName = "minions"
} else {
nodeResourceName = "nodes"
}
}
示例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)
}
示例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
}
示例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()
}
示例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)
}
}
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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
}