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


Golang registered.EnabledVersions函数代码示例

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


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

示例1: Complete

func (o *AppJSONOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
	version, _ := cmd.Flags().GetString("output-version")
	for _, v := range strings.Split(version, ",") {
		gv, err := unversioned.ParseGroupVersion(v)
		if err != nil {
			return fmt.Errorf("provided output-version %q is not valid: %v", v, err)
		}
		o.OutputVersions = append(o.OutputVersions, gv)
	}
	o.OutputVersions = append(o.OutputVersions, registered.EnabledVersions()...)

	o.Action.Bulk.Mapper = clientcmd.ResourceMapper(f)
	o.Action.Bulk.Op = configcmd.Create
	mapper, _ := f.Object(false)
	o.PrintObject = cmdutil.VersionedPrintObject(f.PrintObject, cmd, mapper, o.Action.Out)

	o.Generator, _ = cmd.Flags().GetString("generator")

	ns, _, err := f.DefaultNamespace()
	if err != nil {
		return err
	}
	o.Namespace = ns

	o.Client, _, err = f.Clients()
	return err
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:27,代码来源:appjson.go

示例2: defaultAPIGroupVersion

func (c *MasterConfig) defaultAPIGroupVersion() *apiserver.APIGroupVersion {
	var restMapper meta.MultiRESTMapper
	seenGroups := sets.String{}
	for _, gv := range registered.EnabledVersions() {
		if seenGroups.Has(gv.Group) {
			continue
		}
		seenGroups.Insert(gv.Group)

		groupMeta, err := registered.Group(gv.Group)
		if err != nil {
			continue
		}
		restMapper = meta.MultiRESTMapper(append(restMapper, groupMeta.RESTMapper))
	}

	statusMapper := meta.NewDefaultRESTMapper([]unversioned.GroupVersion{kubeapiv1.SchemeGroupVersion}, registered.GroupOrDie(kapi.GroupName).InterfacesFor)
	statusMapper.Add(kubeapiv1.SchemeGroupVersion.WithKind("Status"), meta.RESTScopeRoot)
	restMapper = meta.MultiRESTMapper(append(restMapper, statusMapper))

	return &apiserver.APIGroupVersion{
		Root: OpenShiftAPIPrefix,

		Mapper: restMapper,

		Creater:   kapi.Scheme,
		Typer:     kapi.Scheme,
		Convertor: kapi.Scheme,
		Linker:    registered.GroupOrDie("").SelfLinker,

		Admit:                       c.AdmissionControl,
		Context:                     c.getRequestContextMapper(),
		SubresourceGroupVersionKind: map[string]unversioned.GroupVersionKind{},
	}
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:35,代码来源:master.go

示例3: internalGroupVersions

func internalGroupVersions() []unversioned.GroupVersion {
	groupVersions := registered.EnabledVersions()
	groups := map[string]struct{}{}
	for _, gv := range groupVersions {
		groups[gv.Group] = struct{}{}
	}
	result := []unversioned.GroupVersion{}
	for group := range groups {
		result = append(result, unversioned.GroupVersion{Group: group, Version: runtime.APIVersionInternal})
	}
	return result
}
开发者ID:legionus,项目名称:origin,代码行数:12,代码来源:admission_test.go

示例4: updateResource

func updateResource(c *Client, target *resource.Info, currentObj runtime.Object, recreate bool) error {
	encoder := api.Codecs.LegacyCodec(registered.EnabledVersions()...)
	original, err := runtime.Encode(encoder, currentObj)
	if err != nil {
		return err
	}

	modified, err := runtime.Encode(encoder, target.Object)
	if err != nil {
		return err
	}

	if api.Semantic.DeepEqual(original, modified) {
		return ErrAlreadyExists{target.Name}
	}

	patch, err := strategicpatch.CreateTwoWayMergePatch(original, modified, currentObj)
	if err != nil {
		return err
	}

	// send patch to server
	helper := resource.NewHelper(target.Client, target.Mapping)
	_, err = helper.Patch(target.Namespace, target.Name, api.StrategicMergePatchType, patch)

	if err != nil {
		return err
	}

	if recreate {
		kind := target.Mapping.GroupVersionKind.Kind

		client, _ := c.ClientSet()
		switch kind {
		case "ReplicationController":
			rc := currentObj.(*v1.ReplicationController)
			err = recreatePods(client, target.Namespace, rc.Spec.Selector)
		case "DaemonSet":
			daemonSet := currentObj.(*v1beta1.DaemonSet)
			err = recreatePods(client, target.Namespace, daemonSet.Spec.Selector.MatchLabels)
		case "StatefulSet":
			petSet := currentObj.(*apps.StatefulSet)
			err = recreatePods(client, target.Namespace, petSet.Spec.Selector.MatchLabels)
		case "ReplicaSet":
			replicaSet := currentObj.(*v1beta1.ReplicaSet)
			err = recreatePods(client, target.Namespace, replicaSet.Spec.Selector.MatchLabels)
		}
	}

	return err
}
开发者ID:kubernetes,项目名称:helm,代码行数:51,代码来源:client.go

示例5: TestKnownAPIGroups

func TestKnownAPIGroups(t *testing.T) {
	unexposedGroups := sets.NewString("authorization.k8s.io", "componentconfig", "metrics", "policy", "federation", "authentication.k8s.io", "rbac.authorization.k8s.io")

	enabledGroups := sets.NewString()
	for _, enabledVersion := range registered.EnabledVersions() {
		enabledGroups.Insert(enabledVersion.Group)
	}

	if missingKnownGroups := KnownKubeAPIGroups.Difference(enabledGroups); len(missingKnownGroups) > 0 {
		t.Errorf("KnownKubeAPIGroups are missing from registered.EnabledVersions: %v", missingKnownGroups.List())
	}
	if unknownEnabledGroups := enabledGroups.Difference(KnownKubeAPIGroups).Difference(unexposedGroups); len(unknownEnabledGroups) > 0 {
		t.Errorf("KnownKubeAPIGroups is missing groups from registered.EnabledVersions: %v", unknownEnabledGroups.List())
	}
}
开发者ID:Xmagicer,项目名称:origin,代码行数:15,代码来源:types_test.go

示例6: getCurrentObject

func getCurrentObject(targetName string, infos []*resource.Info) (runtime.Object, error) {
	var curr *resource.Info
	for _, currInfo := range infos {
		if currInfo.Name == targetName {
			curr = currInfo
		}
	}

	if curr == nil {
		return nil, fmt.Errorf("No resource with the name %s found.", targetName)
	}

	encoder := api.Codecs.LegacyCodec(registered.EnabledVersions()...)
	defaultVersion := unversioned.GroupVersion{}
	return resource.AsVersionedObject([]*resource.Info{curr}, false, defaultVersion, encoder)
}
开发者ID:runseb,项目名称:helm,代码行数:16,代码来源:client.go

示例7: DefaultMultiRESTMapper

// DefaultMultiRESTMapper returns the multi REST mapper with all OpenShift and
// Kubernetes objects already registered.
func DefaultMultiRESTMapper() meta.MultiRESTMapper {
	var restMapper meta.MultiRESTMapper
	seenGroups := sets.String{}
	for _, gv := range registered.EnabledVersions() {
		if seenGroups.Has(gv.Group) {
			continue
		}
		seenGroups.Insert(gv.Group)
		groupMeta, err := registered.Group(gv.Group)
		if err != nil {
			continue
		}
		restMapper = meta.MultiRESTMapper(append(restMapper, groupMeta.RESTMapper))
	}
	return restMapper
}
开发者ID:RomainVabre,项目名称:origin,代码行数:18,代码来源:mapper.go

示例8: main

func main() {
	flag.Parse()
	if *kubeconfig == "" {
		log.Fatalf("Need to specify --kubeconfig")
	}
	cfg := read(*kubeconfig)
	secret := &api.Secret{
		ObjectMeta: api.ObjectMeta{
			Name:      *name,
			Namespace: *ns,
		},
		Data: map[string][]byte{
			"config": cfg,
		},
	}
	fmt.Printf(runtime.EncodeOrDie(api.Codecs.LegacyCodec(registered.EnabledVersions()...), secret))
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:17,代码来源:make_secret.go

示例9: main

func main() {
	flag.Parse()
	if *crt == "" || *key == "" {
		log.Fatalf("Need to specify -crt -key and -template")
	}
	tlsCrt := read(*crt)
	tlsKey := read(*key)
	secret := &api.Secret{
		ObjectMeta: api.ObjectMeta{
			Name: *name,
		},
		Data: map[string][]byte{
			api.TLSCertKey:       tlsCrt,
			api.TLSPrivateKeyKey: tlsKey,
		},
	}
	fmt.Printf(runtime.EncodeOrDie(api.Codecs.LegacyCodec(registered.EnabledVersions()...), secret))
}
开发者ID:spxtr,项目名称:contrib,代码行数:18,代码来源:make_secret.go

示例10: main

func main() {
	flag.Parse()
	if *crt == "" || *key == "" {
		log.Fatalf("Need to specify -crt -key and -template")
	}
	nginxCrt := read(*crt)
	nginxKey := read(*key)
	secret := &api.Secret{
		ObjectMeta: api.ObjectMeta{
			Name: "nginxsecret",
		},
		Data: map[string][]byte{
			"nginx.crt": nginxCrt,
			"nginx.key": nginxKey,
		},
	}
	fmt.Printf(runtime.EncodeOrDie(api.Codecs.LegacyCodec(registered.EnabledVersions()...), secret))
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:18,代码来源:make_secret.go

示例11: getFakeInfo

func getFakeInfo(podInfo *api.Pod) ([]*resource.Info, *VolumeOptions) {
	f := clientcmd.NewFactory(nil)
	fakeMapping := getFakeMapping()
	info := &resource.Info{
		Client:    fake.NewSimpleClientset().Core().RESTClient(),
		Mapping:   fakeMapping,
		Namespace: "default",
		Name:      "fakepod",
		Object:    podInfo,
	}
	infos := []*resource.Info{info}
	vOptions := &VolumeOptions{}
	vOptions.Name = "fake-mount"
	vOptions.Encoder = api.Codecs.LegacyCodec(registered.EnabledVersions()...)
	vOptions.Containers = "*"
	vOptions.UpdatePodSpecForObject = f.UpdatePodSpecForObject
	return infos, vOptions
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:18,代码来源:volume_test.go

示例12: updateResource

func updateResource(target *resource.Info, currentObj runtime.Object) error {

	encoder := api.Codecs.LegacyCodec(registered.EnabledVersions()...)
	originalSerialization, err := runtime.Encode(encoder, currentObj)
	if err != nil {
		return err
	}

	editedSerialization, err := runtime.Encode(encoder, target.Object)
	if err != nil {
		return err
	}

	originalJS, err := yaml.ToJSON(originalSerialization)
	if err != nil {
		return err
	}

	editedJS, err := yaml.ToJSON(editedSerialization)
	if err != nil {
		return err
	}

	if reflect.DeepEqual(originalJS, editedJS) {
		return ErrAlreadyExists{target.Name}
	}

	patch, err := strategicpatch.CreateStrategicMergePatch(originalJS, editedJS, currentObj)
	if err != nil {
		return err
	}

	// send patch to server
	helper := resource.NewHelper(target.Client, target.Mapping)
	if _, err = helper.Patch(target.Namespace, target.Name, api.StrategicMergePatchType, patch); err != nil {
		return err
	}

	return nil
}
开发者ID:runseb,项目名称:helm,代码行数:40,代码来源:client.go

示例13: getFakeInfo

func getFakeInfo(podInfo *api.Pod) ([]*resource.Info, *VolumeOptions) {
	ns := testapi.Default.NegotiatedSerializer()
	f := clientcmd.NewFactory(nil)
	client := &fake.RESTClient{
		NegotiatedSerializer: ns,
		Client:               fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { return nil, nil }),
	}
	fakeMapping := getFakeMapping()
	info := &resource.Info{
		Client:    client,
		Mapping:   fakeMapping,
		Namespace: "default",
		Name:      "fakepod",
		Object:    podInfo,
	}
	infos := []*resource.Info{info}
	vOptions := &VolumeOptions{}
	vOptions.Name = "fake-mount"
	vOptions.Encoder = api.Codecs.LegacyCodec(registered.EnabledVersions()...)
	vOptions.Containers = "*"
	vOptions.UpdatePodSpecForObject = f.UpdatePodSpecForObject
	return infos, vOptions
}
开发者ID:pweil-,项目名称:origin,代码行数:23,代码来源:volume_test.go

示例14: kubernetesAPIMessages

func (c *MasterConfig) kubernetesAPIMessages(kc *kubernetes.MasterConfig) []string {
	var messages []string

	// v1 has to be printed separately since it's served from different endpoint than groups
	if configapi.HasKubernetesAPIVersion(*c.Options.KubernetesMasterConfig, kubeapiv1.SchemeGroupVersion) {
		messages = append(messages, fmt.Sprintf("Started Kubernetes API at %%s%s", genericapiserver.DefaultLegacyAPIPrefix))
	}
	versions := registered.EnabledVersions()
	sort.Sort(sortedGroupVersions(versions))
	for _, ver := range versions {
		if ver.String() == "v1" {
			// skip legacy v1 as we handle that above
			continue
		}
		if configapi.HasKubernetesAPIVersion(*c.Options.KubernetesMasterConfig, ver) {
			messages = append(messages, fmt.Sprintf("Started Kubernetes API %s at %%s%s", ver.String(), genericapiserver.APIGroupPrefix))
		}
	}

	messages = append(messages, fmt.Sprintf("Started Swagger Schema API at %%s%s", kc.Master.GenericConfig.SwaggerConfig.ApiPath))
	messages = append(messages, fmt.Sprintf("Started OpenAPI Schema at %%s%s", openAPIServePath))

	return messages
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:24,代码来源:master.go

示例15: NewFactory


//.........这里部分代码省略.........
			default:
				if !registered.IsThirdPartyAPIGroupVersion(gvk.GroupVersion()) {
					return nil, fmt.Errorf("unknown api group/version: %s", gvk.String())
				}
				cfg, err := clientConfig.ClientConfig()
				if err != nil {
					return nil, err
				}
				gv := gvk.GroupVersion()
				cfg.GroupVersion = &gv
				cfg.APIPath = "/apis"
				cfg.Codec = thirdpartyresourcedata.NewCodec(c.ExtensionsClient.RESTClient.Codec(), gvk.Kind)
				return restclient.RESTClientFor(cfg)
			}
		},
		Describer: func(mapping *meta.RESTMapping) (kubectl.Describer, error) {
			mappingVersion := mapping.GroupVersionKind.GroupVersion()
			client, err := clients.ClientForVersion(&mappingVersion)
			if err != nil {
				return nil, err
			}
			if describer, ok := kubectl.DescriberFor(mapping.GroupVersionKind.GroupKind(), client); ok {
				return describer, nil
			}
			return nil, fmt.Errorf("no description has been implemented for %q", mapping.GroupVersionKind.Kind)
		},
		Decoder: func(toInternal bool) runtime.Decoder {
			if toInternal {
				return api.Codecs.UniversalDecoder()
			}
			return api.Codecs.UniversalDeserializer()
		},
		JSONEncoder: func() runtime.Encoder {
			return api.Codecs.LegacyCodec(registered.EnabledVersions()...)
		},
		Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, showLabels bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
			return kubectl.NewHumanReadablePrinter(noHeaders, withNamespace, wide, showAll, showLabels, absoluteTimestamps, columnLabels), nil
		},
		MapBasedSelectorForObject: func(object runtime.Object) (string, error) {
			// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
			switch t := object.(type) {
			case *api.ReplicationController:
				return kubectl.MakeLabels(t.Spec.Selector), nil
			case *api.Pod:
				if len(t.Labels) == 0 {
					return "", fmt.Errorf("the pod has no labels and cannot be exposed")
				}
				return kubectl.MakeLabels(t.Labels), nil
			case *api.Service:
				if t.Spec.Selector == nil {
					return "", fmt.Errorf("the service has no pod selector set")
				}
				return kubectl.MakeLabels(t.Spec.Selector), nil
			case *extensions.Deployment:
				// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
				// operator, DoubleEquals operator and In operator with only one element in the set.
				if len(t.Spec.Selector.MatchExpressions) > 0 {
					return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
				}
				return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
			case *extensions.ReplicaSet:
				// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
				// operator, DoubleEquals operator and In operator with only one element in the set.
				if len(t.Spec.Selector.MatchExpressions) > 0 {
					return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
				}
开发者ID:ZenoRewn,项目名称:origin,代码行数:67,代码来源:factory.go


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