当前位置: 首页>>代码示例>>Golang>>正文


Golang meta.KindToResource函数代码示例

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


在下文中一共展示了KindToResource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ValidateBytes

func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
	version, kind, err := runtime.UnstructuredJSONScheme.DataVersionAndKind(data)
	if err != nil {
		return err
	}
	gv, err := unversioned.ParseGroupVersion(version)
	if err != nil {
		return fmt.Errorf("unable to parse group/version from %q: %v", version, err)
	}
	if ok := registered.IsRegisteredAPIGroupVersion(gv); !ok {
		return fmt.Errorf("API version %q isn't supported, only supports API versions %q", version, registered.RegisteredGroupVersions)
	}
	resource, _ := meta.KindToResource(kind, false)
	gvk, err := c.mapper.KindFor(resource)
	if err != nil {
		return fmt.Errorf("could not find api group for %s: %v", kind, err)
	}
	if gvk.Group == "extensions" {
		if c.c.ExtensionsClient == nil {
			return errors.New("unable to validate: no experimental client")
		}
		return getSchemaAndValidate(c.c.ExtensionsClient.RESTClient, data, "apis/", version, c.cacheDir)
	}
	return getSchemaAndValidate(c.c.RESTClient, data, "api", version, c.cacheDir)
}
开发者ID:fwalker,项目名称:dashboard,代码行数:25,代码来源:factory.go

示例2: InstallThirdPartyResource

// InstallThirdPartyResource installs a third party resource specified by 'rsrc'.  When a resource is
// installed a corresponding RESTful resource is added as a valid path in the web service provided by
// the master.
//
// For example, if you install a resource ThirdPartyResource{ Name: "foo.company.com", Versions: {"v1"} }
// then the following RESTful resource is created on the server:
//   http://<host>/apis/company.com/v1/foos/...
func (m *Master) InstallThirdPartyResource(rsrc *extensions.ThirdPartyResource) error {
	kind, group, err := thirdpartyresourcedata.ExtractApiGroupAndKind(rsrc)
	if err != nil {
		return err
	}
	plural, _ := meta.KindToResource(unversioned.GroupVersionKind{
		Group:   group,
		Version: rsrc.Versions[0].Name,
		Kind:    kind,
	})

	thirdparty := m.thirdpartyapi(group, kind, rsrc.Versions[0].Name, plural.Resource)
	if err := thirdparty.InstallREST(m.HandlerContainer); err != nil {
		glog.Fatalf("Unable to setup thirdparty api: %v", err)
	}
	path := makeThirdPartyPath(group)
	groupVersion := unversioned.GroupVersionForDiscovery{
		GroupVersion: group + "/" + rsrc.Versions[0].Name,
		Version:      rsrc.Versions[0].Name,
	}
	apiGroup := unversioned.APIGroup{
		Name:             group,
		Versions:         []unversioned.GroupVersionForDiscovery{groupVersion},
		PreferredVersion: groupVersion,
	}
	apiserver.AddGroupWebService(api.Codecs, m.HandlerContainer, path, apiGroup)

	m.addThirdPartyResourceStorage(path, thirdparty.Storage[plural.Resource].(*thirdpartyresourcedataetcd.REST), apiGroup)
	apiserver.InstallServiceErrorHandler(api.Codecs, m.HandlerContainer, m.NewRequestInfoResolver(), []string{thirdparty.GroupVersion.String()})
	return nil
}
开发者ID:XbinZh,项目名称:kubernetes,代码行数:38,代码来源:master.go

示例3: ValidateBytes

func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
	version, kind, err := runtime.UnstructuredJSONScheme.DataVersionAndKind(data)
	if err != nil {
		return err
	}
	if ok := registered.IsRegisteredAPIVersion(version); !ok {
		return fmt.Errorf("API version %q isn't supported, only supports API versions %q", version, registered.RegisteredVersions)
	}
	resource, _ := meta.KindToResource(kind, false)
	group, err := c.mapper.GroupForResource(resource)
	if err != nil {
		return fmt.Errorf("could not find api group for %s: %v", kind, err)
	}
	if group == "experimental" {
		g, err := latest.Group(group)
		if err != nil {
			return err
		}
		if c.c.ExperimentalClient == nil {
			return errors.New("unable to validate: no experimental client")
		}
		return getSchemaAndValidate(c.c.ExperimentalClient.RESTClient, data, "apis/"+g.Group, version, c.cacheDir)
	}
	return getSchemaAndValidate(c.c.RESTClient, data, "api", version, c.cacheDir)
}
开发者ID:liuhewei,项目名称:kubernetes,代码行数:25,代码来源:factory.go

示例4: Get

// Get takes the reference to scale subresource and returns the subresource or error, if one occurs.
func (c *scales) Get(kind string, name string) (result *extensions.Scale, err error) {
	result = &extensions.Scale{}

	// TODO this method needs to take a proper unambiguous kind
	fullyQualifiedKind := unversioned.GroupVersionKind{Kind: kind}
	resource, _ := meta.KindToResource(fullyQualifiedKind)

	err = c.client.Get().Namespace(c.ns).Resource(resource.Resource).Name(name).SubResource("scale").Do().Into(result)
	return
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:11,代码来源:scale.go

示例5: Update

func (c *scales) Update(kind string, scale *experimental.Scale) (result *experimental.Scale, err error) {
	result = &experimental.Scale{}
	resource, _ := meta.KindToResource(kind, false)
	err = c.client.Put().
		Namespace(scale.Namespace).
		Resource(resource).
		Name(scale.Name).
		SubResource("scale").
		Body(scale).
		Do().
		Into(result)
	return
}
开发者ID:alena1108,项目名称:kubernetes,代码行数:13,代码来源:scale.go

示例6: Complete

// Complete calls the upstream Complete for the logs command and then resolves the
// resource a user requested to view its logs and creates the appropriate logOptions
// object for it.
func (o *OpenShiftLogsOptions) Complete(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
	if err := o.KubeLogOptions.Complete(f.Factory, out, cmd, args); err != nil {
		return err
	}
	namespace, _, err := f.DefaultNamespace()
	if err != nil {
		return err
	}

	podLogOptions := o.KubeLogOptions.Options.(*kapi.PodLogOptions)

	mapper, typer := f.Object()
	infos, err := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
		NamespaceParam(namespace).DefaultNamespace().
		ResourceNames("pods", args...).
		SingleResourceType().RequireObject(false).
		Do().Infos()
	if err != nil {
		return err
	}
	if len(infos) != 1 {
		return errors.New("expected a resource")
	}
	_, resource := meta.KindToResource(infos[0].Mapping.Kind, false)

	// TODO: podLogOptions should be included in our own logOptions objects.
	switch resource {
	case "build", "buildconfig":
		o.Options = &buildapi.BuildLogOptions{
			Follow:       podLogOptions.Follow,
			SinceSeconds: podLogOptions.SinceSeconds,
			SinceTime:    podLogOptions.SinceTime,
			Timestamps:   podLogOptions.Timestamps,
			TailLines:    podLogOptions.TailLines,
			LimitBytes:   podLogOptions.LimitBytes,
		}
	case "deploymentconfig":
		o.Options = &deployapi.DeploymentLogOptions{
			Follow:       podLogOptions.Follow,
			SinceSeconds: podLogOptions.SinceSeconds,
			SinceTime:    podLogOptions.SinceTime,
			Timestamps:   podLogOptions.Timestamps,
			TailLines:    podLogOptions.TailLines,
			LimitBytes:   podLogOptions.LimitBytes,
		}
	default:
		o.Options = nil
	}

	return nil
}
开发者ID:schen59,项目名称:origin,代码行数:54,代码来源:logs.go

示例7: Update

func (c *scales) Update(kind string, scale *v1beta1.Scale) (result *v1beta1.Scale, err error) {
	result = &v1beta1.Scale{}

	// TODO this method needs to take a proper unambiguous kind
	fullyQualifiedKind := schema.GroupVersionKind{Kind: kind}
	resource, _ := meta.KindToResource(fullyQualifiedKind)

	err = c.client.Put().
		Namespace(scale.Namespace).
		Resource(resource.Resource).
		Name(scale.Name).
		SubResource("scale").
		Body(scale).
		Do().
		Into(result)
	return
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:17,代码来源:scale_expansion.go

示例8: PrintObj

// PrintObj is an implementation of ResourcePrinter.PrintObj which decodes the object
// and print "resource/name" pair. If the object is a List, print all items in it.
func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
	objvalue := reflect.ValueOf(obj).Elem()
	kind := objvalue.FieldByName("Kind")
	if !kind.IsValid() {
		kind = reflect.ValueOf("<unknown>")
	}
	if kind.String() == "List" {
		items := objvalue.FieldByName("Items")
		if items.Type().String() == "[]runtime.RawExtension" {
			for i := 0; i < items.Len(); i++ {
				rawObj := items.Index(i).FieldByName("RawJSON").Interface().([]byte)
				scheme := api.Scheme
				version, kind, err := scheme.DataVersionAndKind(rawObj)
				if err != nil {
					return err
				}
				decodedObj, err := scheme.DecodeToVersion(rawObj, "")
				if err != nil {
					return err
				}
				tpmeta := api.TypeMeta{
					APIVersion: version,
					Kind:       kind,
				}
				s := reflect.ValueOf(decodedObj).Elem()
				s.FieldByName("TypeMeta").Set(reflect.ValueOf(tpmeta))
				p.PrintObj(decodedObj, w)
			}
		} else {
			return errors.New("the list object contains unrecognized items.")
		}
	} else {
		name := objvalue.FieldByName("Name")
		if !name.IsValid() {
			name = reflect.ValueOf("<unknown>")
		}
		_, resource := meta.KindToResource(kind.String(), false)

		fmt.Fprintf(w, "%s/%s\n", resource, name)
	}

	return nil
}
开发者ID:JTabel,项目名称:kubernetes,代码行数:45,代码来源:resource_printer.go

示例9: InstallThirdPartyResource

// InstallThirdPartyResource installs a third party resource specified by 'rsrc'.  When a resource is
// installed a corresponding RESTful resource is added as a valid path in the web service provided by
// the master.
//
// For example, if you install a resource ThirdPartyResource{ Name: "foo.company.com", Versions: {"v1"} }
// then the following RESTful resource is created on the server:
//   http://<host>/apis/company.com/v1/foos/...
func (m *ThirdPartyResourceServer) InstallThirdPartyResource(rsrc *extensions.ThirdPartyResource) error {
	kind, group, err := thirdpartyresourcedata.ExtractApiGroupAndKind(rsrc)
	if err != nil {
		return err
	}
	if len(rsrc.Versions) == 0 {
		return fmt.Errorf("ThirdPartyResource %s has no defined versions", rsrc.Name)
	}
	plural, _ := meta.KindToResource(unversioned.GroupVersionKind{
		Group:   group,
		Version: rsrc.Versions[0].Name,
		Kind:    kind,
	})
	path := extensionsrest.MakeThirdPartyPath(group)

	groupVersion := unversioned.GroupVersionForDiscovery{
		GroupVersion: group + "/" + rsrc.Versions[0].Name,
		Version:      rsrc.Versions[0].Name,
	}
	apiGroup := unversioned.APIGroup{
		Name:             group,
		Versions:         []unversioned.GroupVersionForDiscovery{groupVersion},
		PreferredVersion: groupVersion,
	}

	thirdparty := m.thirdpartyapi(group, kind, rsrc.Versions[0].Name, plural.Resource)

	// If storage exists, this group has already been added, just update
	// the group with the new API
	if m.hasThirdPartyGroupStorage(path) {
		m.addThirdPartyResourceStorage(path, plural.Resource, thirdparty.Storage[plural.Resource].(*thirdpartyresourcedataetcd.REST), apiGroup)
		return thirdparty.UpdateREST(m.genericAPIServer.HandlerContainer.Container)
	}

	if err := thirdparty.InstallREST(m.genericAPIServer.HandlerContainer.Container); err != nil {
		glog.Errorf("Unable to setup thirdparty api: %v", err)
	}
	m.genericAPIServer.HandlerContainer.Add(apiserver.NewGroupWebService(api.Codecs, path, apiGroup))

	m.addThirdPartyResourceStorage(path, plural.Resource, thirdparty.Storage[plural.Resource].(*thirdpartyresourcedataetcd.REST), apiGroup)
	return nil
}
开发者ID:Q-Lee,项目名称:kubernetes,代码行数:49,代码来源:thirdparty.go

示例10: HasThirdPartyResource

// HasThirdPartyResource returns true if a particular third party resource currently installed.
func (m *ThirdPartyResourceServer) HasThirdPartyResource(rsrc *extensions.ThirdPartyResource) (bool, error) {
	kind, group, err := thirdpartyresourcedata.ExtractApiGroupAndKind(rsrc)
	if err != nil {
		return false, err
	}
	path := extensionsrest.MakeThirdPartyPath(group)
	m.thirdPartyResourcesLock.Lock()
	defer m.thirdPartyResourcesLock.Unlock()
	entry := m.thirdPartyResources[path]
	if entry == nil {
		return false, nil
	}
	plural, _ := meta.KindToResource(unversioned.GroupVersionKind{
		Group:   group,
		Version: rsrc.Versions[0].Name,
		Kind:    kind,
	})
	_, found := entry.storage[plural.Resource]
	return found, nil
}
开发者ID:eljefedelrodeodeljefe,项目名称:kubernetes,代码行数:21,代码来源:thirdparty.go

示例11: TestInstallMultipleAPIs

func TestInstallMultipleAPIs(t *testing.T) {
	names := []string{"foo.company.com", "bar.company.com"}
	versions := []string{"v1", "v1"}

	_, etcdserver, server, assert := initThirdPartyMultiple(t, versions, names)
	defer server.Close()
	defer etcdserver.Terminate(t)
	for ix := range names {
		kind, group, err := thirdpartyresourcedata.ExtractApiGroupAndKind(
			&extensions.ThirdPartyResource{ObjectMeta: api.ObjectMeta{Name: names[ix]}})
		assert.NoError(err, "Failed to extract group & kind")

		plural, _ := meta.KindToResource(unversioned.GroupVersionKind{
			Group:   group,
			Version: versions[ix],
			Kind:    kind,
		})

		resp, err := http.Get(
			fmt.Sprintf("%s/apis/%s/%s/namespaces/default/%s", server.URL, group, versions[ix], plural.Resource))
		if !assert.NoError(err, "Failed to do HTTP GET") {
			return
		}
		defer resp.Body.Close()

		assert.Equal(http.StatusOK, resp.StatusCode)

		data, err := ioutil.ReadAll(resp.Body)
		assert.NoError(err)

		obj := map[string]interface{}{}
		if err = json.Unmarshal(data, &obj); err != nil {
			assert.NoError(err, fmt.Sprintf("unexpected error: %v", err))
		}
		kindOut, found := obj["kind"]
		if !found {
			t.Errorf("Missing 'kind' in %v", obj)
		}
		assert.Equal(kindOut, kind+"List")
	}
}
开发者ID:RyanBinfeng,项目名称:kubernetes,代码行数:41,代码来源:master_test.go

示例12: ResolveResource

// ResolveResource returns the resource type and name of the resourceString.
// If the resource string has no specified type, defaultResource will be returned.
func ResolveResource(defaultResource, resourceString string, mapper meta.RESTMapper) (string, string, error) {
	if mapper == nil {
		return "", "", errors.New("mapper cannot be nil")
	}

	var name string
	parts := strings.Split(resourceString, "/")
	switch len(parts) {
	case 1:
		name = parts[0]
	case 2:
		gvk, err := mapper.KindFor(unversioned.GroupVersionResource{Resource: parts[0]})
		if err != nil {
			return "", "", err
		}
		name = parts[1]
		resource, _ := meta.KindToResource(gvk, false)
		return resource.Resource, name, nil
	default:
		return "", "", fmt.Errorf("invalid resource format: %s", resourceString)
	}

	return defaultResource, name, nil
}
开发者ID:rrati,项目名称:origin,代码行数:26,代码来源:cmd.go

示例13: RunRollingUpdate


//.........这里部分代码省略.........
		newName := findNewName(args, oldRc)
		if newRc, err = kubectl.LoadExistingNextReplicationController(client, cmdNamespace, newName); err != nil {
			return err
		}

		if newRc == nil {
			return cmdutil.UsageError(cmd, "Could not find %s to rollback.\n", newName)
		}
	}

	if oldName == newRc.Name {
		return cmdutil.UsageError(cmd, "%s cannot have the same name as the existing ReplicationController %s",
			filename, oldName)
	}

	updater := kubectl.NewRollingUpdater(newRc.Namespace, client)

	// To successfully pull off a rolling update the new and old rc have to differ
	// by at least one selector. Every new pod should have the selector and every
	// old pod should not have the selector.
	var hasLabel bool
	for key, oldValue := range oldRc.Spec.Selector {
		if newValue, ok := newRc.Spec.Selector[key]; ok && newValue != oldValue {
			hasLabel = true
			break
		}
	}
	if !hasLabel {
		return cmdutil.UsageError(cmd, "%s must specify a matching key with non-equal value in Selector for %s",
			filename, oldName)
	}
	// TODO: handle scales during rolling update
	if replicasDefaulted {
		newRc.Spec.Replicas = oldRc.Spec.Replicas
	}
	if dryrun {
		oldRcData := &bytes.Buffer{}
		newRcData := &bytes.Buffer{}
		if outputFormat == "" {
			oldRcData.WriteString(oldRc.Name)
			newRcData.WriteString(newRc.Name)
		} else {
			if err := f.PrintObject(cmd, mapper, oldRc, oldRcData); err != nil {
				return err
			}
			if err := f.PrintObject(cmd, mapper, newRc, newRcData); err != nil {
				return err
			}
		}
		fmt.Fprintf(out, "Rolling from:\n%s\nTo:\n%s\n", string(oldRcData.Bytes()), string(newRcData.Bytes()))
		return nil
	}
	updateCleanupPolicy := kubectl.DeleteRollingUpdateCleanupPolicy
	if keepOldName {
		updateCleanupPolicy = kubectl.RenameRollingUpdateCleanupPolicy
	}
	config := &kubectl.RollingUpdaterConfig{
		Out:            out,
		OldRc:          oldRc,
		NewRc:          newRc,
		UpdatePeriod:   period,
		Interval:       interval,
		Timeout:        timeout,
		CleanupPolicy:  updateCleanupPolicy,
		MaxUnavailable: intstr.FromInt(0),
		MaxSurge:       intstr.FromInt(1),
	}
	if rollback {
		err = kubectl.AbortRollingUpdate(config)
		if err != nil {
			return err
		}
		client.ReplicationControllers(config.NewRc.Namespace).Update(config.NewRc)
	}
	err = updater.Update(config)
	if err != nil {
		return err
	}

	message := "rolling updated"
	if keepOldName {
		newRc.Name = oldName
	} else {
		message = fmt.Sprintf("rolling updated to %q", newRc.Name)
	}
	newRc, err = client.ReplicationControllers(cmdNamespace).Get(newRc.Name)
	if err != nil {
		return err
	}
	if outputFormat != "" {
		return f.PrintObject(cmd, mapper, newRc, out)
	}
	kind, err := api.Scheme.ObjectKind(newRc)
	if err != nil {
		return err
	}
	_, res := meta.KindToResource(kind)
	cmdutil.PrintSuccess(mapper, false, out, res.Resource, oldName, message)
	return nil
}
开发者ID:sgallagher,项目名称:origin,代码行数:101,代码来源:rollingupdate.go

示例14: RunRollingUpdate


//.........这里部分代码省略.........
			}
		}
		// Update the existing replication controller with pointers to the 'next' controller
		// and adding the <deploymentKey> label if necessary to distinguish it from the 'next' controller.
		oldHash, err := api.HashObject(oldRc, client.Codec)
		if err != nil {
			return err
		}
		oldRc, err = kubectl.UpdateExistingReplicationController(client, oldRc, cmdNamespace, newRc.Name, deploymentKey, oldHash, out)
		if err != nil {
			return err
		}
	}
	if oldName == newRc.Name {
		return cmdutil.UsageError(cmd, "%s cannot have the same name as the existing ReplicationController %s",
			filename, oldName)
	}

	updater := kubectl.NewRollingUpdater(newRc.Namespace, client)

	// To successfully pull off a rolling update the new and old rc have to differ
	// by at least one selector. Every new pod should have the selector and every
	// old pod should not have the selector.
	var hasLabel bool
	for key, oldValue := range oldRc.Spec.Selector {
		if newValue, ok := newRc.Spec.Selector[key]; ok && newValue != oldValue {
			hasLabel = true
			break
		}
	}
	if !hasLabel {
		return cmdutil.UsageError(cmd, "%s must specify a matching key with non-equal value in Selector for %s",
			filename, oldName)
	}
	// TODO: handle scales during rolling update
	if replicasDefaulted {
		newRc.Spec.Replicas = oldRc.Spec.Replicas
	}
	if dryrun {
		oldRcData := &bytes.Buffer{}
		newRcData := &bytes.Buffer{}
		if outputFormat == "" {
			oldRcData.WriteString(oldRc.Name)
			newRcData.WriteString(newRc.Name)
		} else {
			if err := f.PrintObject(cmd, oldRc, oldRcData); err != nil {
				return err
			}
			if err := f.PrintObject(cmd, newRc, newRcData); err != nil {
				return err
			}
		}
		fmt.Fprintf(out, "Rolling from:\n%s\nTo:\n%s\n", string(oldRcData.Bytes()), string(newRcData.Bytes()))
		return nil
	}
	updateCleanupPolicy := kubectl.DeleteRollingUpdateCleanupPolicy
	if keepOldName {
		updateCleanupPolicy = kubectl.RenameRollingUpdateCleanupPolicy
	}
	config := &kubectl.RollingUpdaterConfig{
		Out:            out,
		OldRc:          oldRc,
		NewRc:          newRc,
		UpdatePeriod:   period,
		Interval:       interval,
		Timeout:        timeout,
		CleanupPolicy:  updateCleanupPolicy,
		MaxUnavailable: util.NewIntOrStringFromInt(0),
		MaxSurge:       util.NewIntOrStringFromInt(1),
	}
	if cmdutil.GetFlagBool(cmd, "rollback") {
		kubectl.AbortRollingUpdate(config)
		client.ReplicationControllers(config.NewRc.Namespace).Update(config.NewRc)
	}
	err = updater.Update(config)
	if err != nil {
		return err
	}

	message := "rolling updated"
	if keepOldName {
		newRc.Name = oldName
	} else {
		message = fmt.Sprintf("rolling updated to %q", newRc.Name)
	}
	newRc, err = client.ReplicationControllers(cmdNamespace).Get(newRc.Name)
	if err != nil {
		return err
	}
	if outputFormat != "" {
		return f.PrintObject(cmd, newRc, out)
	}
	_, kind, err := api.Scheme.ObjectVersionAndKind(newRc)
	if err != nil {
		return err
	}
	_, res := meta.KindToResource(kind, false)
	cmdutil.PrintSuccess(mapper, false, out, res, oldName, message)
	return nil
}
开发者ID:neumino,项目名称:kubernetes,代码行数:101,代码来源:rollingupdate.go

示例15: getResource

func (t *thirdPartyResourceDataMapper) getResource() unversioned.GroupVersionResource {
	plural, _ := meta.KindToResource(t.getKind())

	return plural
}
开发者ID:RomainVabre,项目名称:origin,代码行数:5,代码来源:codec.go


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