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


Golang meta.MultiRESTMapper函數代碼示例

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


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

示例1: 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

示例2: mergeGroupMeta

// mergeGroupMeta takes an lhs and an rhs GroupMeta, then builds a resulting GroupMeta that contains the
// merged information.  Order of merging matters: lhs wins.
func mergeGroupMeta(lhs, rhs apimachinery.GroupMeta) apimachinery.GroupMeta {
    merged := apimachinery.GroupMeta{}

    merged.GroupVersion = lhs.GroupVersion
    merged.SelfLinker = lhs.SelfLinker

    knownGVs := sets.String{}
    for _, lhsGV := range lhs.GroupVersions {
        knownGVs.Insert(lhsGV.String())
        merged.GroupVersions = append(merged.GroupVersions, lhsGV)
    }
    for _, rhsGV := range lhs.GroupVersions {
        if knownGVs.Has(rhsGV.String()) {
            continue
        }
        merged.GroupVersions = append(merged.GroupVersions, rhsGV)
    }

    merged.RESTMapper = meta.MultiRESTMapper(append([]meta.RESTMapper{}, lhs.RESTMapper, rhs.RESTMapper))

    merged.InterfacesFor = func(version unversioned.GroupVersion) (*meta.VersionInterfaces, error) {
        if ret, err := lhs.InterfacesFor(version); err == nil {
            return ret, nil
        }

        return rhs.InterfacesFor(version)
    }

    return merged
}
開發者ID:richm,項目名稱:origin,代碼行數:32,代碼來源:registered.go

示例3: 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

示例4: NewFactory

// NewFactory creates an object that holds common methods across all OpenShift commands
func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
    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))
    }
    mapper := ShortcutExpander{RESTMapper: kubectl.ShortcutExpander{RESTMapper: restMapper}}

    clients := &clientCache{
        clients: make(map[string]*client.Client),
        configs: make(map[string]*kclient.Config),
        loader:  clientConfig,
    }

    w := &Factory{
        Factory:               cmdutil.NewFactory(clientConfig),
        OpenShiftClientConfig: clientConfig,
        clients:               clients,
    }

    w.Object = func() (meta.RESTMapper, runtime.ObjectTyper) {
        // Output using whatever version was negotiated in the client cache. The
        // version we decode with may not be the same as what the server requires.
        if cfg, err := clients.ClientConfigForVersion(nil); err == nil {
            cmdApiVersion := unversioned.GroupVersion{}
            if cfg.GroupVersion != nil {
                cmdApiVersion = *cfg.GroupVersion
            }
            return kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}, api.Scheme
        }
        return mapper, api.Scheme
    }

    kClientForMapping := w.Factory.ClientForMapping
    w.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
        if latest.OriginKind(mapping.GroupVersionKind) {
            mappingVersion := mapping.GroupVersionKind.GroupVersion()
            client, err := clients.ClientForVersion(&mappingVersion)
            if err != nil {
                return nil, err
            }
            return client.RESTClient, nil
        }
        return kClientForMapping(mapping)
    }

    // Save original Describer function
    kDescriberFunc := w.Factory.Describer
    w.Describer = func(mapping *meta.RESTMapping) (kubectl.Describer, error) {
        if latest.OriginKind(mapping.GroupVersionKind) {
            oClient, kClient, err := w.Clients()
            if err != nil {
                return nil, fmt.Errorf("unable to create client %s: %v", mapping.GroupVersionKind.Kind, err)
            }

            mappingVersion := mapping.GroupVersionKind.GroupVersion()
            cfg, err := clients.ClientConfigForVersion(&mappingVersion)
            if err != nil {
                return nil, fmt.Errorf("unable to load a client %s: %v", mapping.GroupVersionKind.Kind, err)
            }

            describer, ok := describe.DescriberFor(mapping.GroupVersionKind.GroupKind(), oClient, kClient, cfg.Host)
            if !ok {
                return nil, fmt.Errorf("no description has been implemented for %q", mapping.GroupVersionKind.Kind)
            }
            return describer, nil
        }
        return kDescriberFunc(mapping)
    }
    kScalerFunc := w.Factory.Scaler
    w.Scaler = func(mapping *meta.RESTMapping) (kubectl.Scaler, error) {
        oc, kc, err := w.Clients()
        if err != nil {
            return nil, err
        }

        if mapping.GroupVersionKind.GroupKind() == deployapi.Kind("DeploymentConfig") {
            return deployscaler.NewDeploymentConfigScaler(oc, kc), nil
        }
        return kScalerFunc(mapping)
    }
    kReaperFunc := w.Factory.Reaper
    w.Reaper = func(mapping *meta.RESTMapping) (kubectl.Reaper, error) {
        oc, kc, err := w.Clients()
        if err != nil {
            return nil, err
        }

        switch mapping.GroupVersionKind.GroupKind() {
        case deployapi.Kind("DeploymentConfig"):
//.........這裏部分代碼省略.........
開發者ID:arilivigni,項目名稱:origin,代碼行數:101,代碼來源:factory.go

示例5: Create

func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {

    if err := rest.BeforeCreate(projectrequestregistry.Strategy, ctx, obj); err != nil {
        return nil, err
    }

    projectRequest := obj.(*projectapi.ProjectRequest)

    if _, err := r.openshiftClient.Projects().Get(projectRequest.Name); err == nil {
        return nil, kapierror.NewAlreadyExists(projectapi.Resource("project"), projectRequest.Name)
    }

    projectName := projectRequest.Name
    projectAdmin := ""
    projectRequester := ""
    if userInfo, exists := kapi.UserFrom(ctx); exists {
        projectAdmin = userInfo.GetName()
        projectRequester = userInfo.GetName()
    }

    template, err := r.getTemplate()
    if err != nil {
        return nil, err
    }

    for i := range template.Parameters {
        switch template.Parameters[i].Name {
        case ProjectAdminUserParam:
            template.Parameters[i].Value = projectAdmin
        case ProjectDescriptionParam:
            template.Parameters[i].Value = projectRequest.Description
        case ProjectDisplayNameParam:
            template.Parameters[i].Value = projectRequest.DisplayName
        case ProjectNameParam:
            template.Parameters[i].Value = projectName
        case ProjectRequesterParam:
            template.Parameters[i].Value = projectRequester
        }
    }

    list, err := r.openshiftClient.TemplateConfigs(kapi.NamespaceDefault).Create(template)
    if err != nil {
        return nil, err
    }
    if err := utilerrors.NewAggregate(runtime.DecodeList(list.Objects, kapi.Codecs.UniversalDecoder())); err != nil {
        return nil, kapierror.NewInternalError(err)
    }

    // one of the items in this list should be the project.  We are going to locate it, remove it from the list, create it separately
    var projectFromTemplate *projectapi.Project
    objectsToCreate := &kapi.List{}
    for i := range list.Objects {
        if templateProject, ok := list.Objects[i].(*projectapi.Project); ok {
            projectFromTemplate = templateProject

            if len(list.Objects) > (i + 1) {
                objectsToCreate.Items = append(objectsToCreate.Items, list.Objects[i+1:]...)
            }
            break
        }

        objectsToCreate.Items = append(objectsToCreate.Items, list.Objects[i])
    }
    if projectFromTemplate == nil {
        return nil, kapierror.NewInternalError(fmt.Errorf("the project template (%s/%s) is not correctly configured: must contain a project resource", r.templateNamespace, r.templateName))
    }

    // we split out project creation separately so that in a case of racers for the same project, only one will win and create the rest of their template objects
    if _, err := r.openshiftClient.Projects().Create(projectFromTemplate); err != nil {
        return nil, err
    }

    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))
    }

    bulk := configcmd.Bulk{
        Mapper: restMapper,
        Typer:  kapi.Scheme,
        RESTClientFactory: func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
            if latest.OriginKind(mapping.GroupVersionKind) {
                return r.openshiftClient, nil
            }
            return r.kubeClient, nil
        },
    }
    if err := utilerrors.NewAggregate(bulk.Create(objectsToCreate, projectName)); err != nil {
        return nil, kapierror.NewInternalError(err)
    }
//.........這裏部分代碼省略.........
開發者ID:richm,項目名稱:origin,代碼行數:101,代碼來源:delegated.go


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