Skip to content

Commit

Permalink
Merge pull request kubernetes#23023 from caesarxuchao/minor-fix-aliases
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Mar 16, 2016
2 parents 41c85d1 + 51886c3 commit c412dcb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/api/meta/restmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type DefaultRESTMapper struct {
pluralToSingular map[unversioned.GroupVersionResource]unversioned.GroupVersionResource

interfacesFunc VersionInterfacesFunc

// aliasToResource is used for mapping aliases to resources
aliasToResource map[string][]string
}

func (m *DefaultRESTMapper) String() string {
Expand All @@ -103,6 +106,7 @@ func NewDefaultRESTMapper(defaultGroupVersions []unversioned.GroupVersion, f Ver
kindToScope := make(map[unversioned.GroupVersionKind]RESTScope)
singularToPlural := make(map[unversioned.GroupVersionResource]unversioned.GroupVersionResource)
pluralToSingular := make(map[unversioned.GroupVersionResource]unversioned.GroupVersionResource)
aliasToResource := make(map[string][]string)
// TODO: verify name mappings work correctly when versions differ

return &DefaultRESTMapper{
Expand All @@ -112,6 +116,7 @@ func NewDefaultRESTMapper(defaultGroupVersions []unversioned.GroupVersion, f Ver
defaultGroupVersions: defaultGroupVersions,
singularToPlural: singularToPlural,
pluralToSingular: pluralToSingular,
aliasToResource: aliasToResource,
interfacesFunc: f,
}
}
Expand Down Expand Up @@ -488,20 +493,17 @@ func (m *DefaultRESTMapper) RESTMapping(gk unversioned.GroupKind, versions ...st
return retVal, nil
}

// aliasToResource is used for mapping aliases to resources
var aliasToResource = map[string][]string{}

// AddResourceAlias maps aliases to resources
func (m *DefaultRESTMapper) AddResourceAlias(alias string, resources ...string) {
if len(resources) == 0 {
return
}
aliasToResource[alias] = resources
m.aliasToResource[alias] = resources
}

// AliasesForResource returns whether a resource has an alias or not
func (m *DefaultRESTMapper) AliasesForResource(alias string) ([]string, bool) {
if res, ok := aliasToResource[alias]; ok {
if res, ok := m.aliasToResource[alias]; ok {
return res, true
}
return nil, false
Expand Down

0 comments on commit c412dcb

Please sign in to comment.