Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c59e211a
Commit
c59e211a
authored
Jul 19, 2017
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow exceptions to be specified to handle conflicting group and resourc enames
parent
3660ff46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
3 deletions
+48
-3
client_generator.go
...io/kube-gen/cmd/client-gen/generators/client_generator.go
+47
-2
generator_fake_for_type.go
...cmd/client-gen/generators/fake/generator_fake_for_type.go
+1
-1
No files found.
staging/src/k8s.io/kube-gen/cmd/client-gen/generators/client_generator.go
View file @
c59e211a
...
@@ -41,9 +41,36 @@ func NameSystems() namer.NameSystems {
...
@@ -41,9 +41,36 @@ func NameSystems() namer.NameSystems {
"Endpoints"
:
"Endpoints"
,
"Endpoints"
:
"Endpoints"
,
}
}
lowercaseNamer
:=
namer
.
NewAllLowercasePluralNamer
(
pluralExceptions
)
lowercaseNamer
:=
namer
.
NewAllLowercasePluralNamer
(
pluralExceptions
)
publicNamer
:=
&
ExceptionNamer
{
Exceptions
:
map
[
string
]
string
{
// these exceptions are used to deconflict the generated code
// you can put your fully qualified package like
// to generate a name that doesn't conflict with your group.
// "k8s.io/apis/events/v1alpha1.Event": "EventResource"
},
KeyFunc
:
func
(
t
*
types
.
Type
)
string
{
return
t
.
Name
.
Package
+
"."
+
t
.
Name
.
Name
},
Delegate
:
namer
.
NewPublicNamer
(
0
),
}
privateNamer
:=
&
ExceptionNamer
{
Exceptions
:
map
[
string
]
string
{
// these exceptions are used to deconflict the generated code
// you can put your fully qualified package like
// to generate a name that doesn't conflict with your group.
// "k8s.io/apis/events/v1alpha1.Event": "eventResource"
},
KeyFunc
:
func
(
t
*
types
.
Type
)
string
{
return
t
.
Name
.
Package
+
"."
+
t
.
Name
.
Name
},
Delegate
:
namer
.
NewPrivateNamer
(
0
),
}
return
namer
.
NameSystems
{
return
namer
.
NameSystems
{
"public"
:
namer
.
NewPublicNamer
(
0
),
"singularKind"
:
namer
.
NewPublicNamer
(
0
),
"private"
:
namer
.
NewPrivateNamer
(
0
),
"public"
:
publicNamer
,
"private"
:
privateNamer
,
"raw"
:
namer
.
NewRawNamer
(
""
,
nil
),
"raw"
:
namer
.
NewRawNamer
(
""
,
nil
),
"publicPlural"
:
namer
.
NewPublicPluralNamer
(
pluralExceptions
),
"publicPlural"
:
namer
.
NewPublicPluralNamer
(
pluralExceptions
),
"privatePlural"
:
namer
.
NewPrivatePluralNamer
(
pluralExceptions
),
"privatePlural"
:
namer
.
NewPrivatePluralNamer
(
pluralExceptions
),
...
@@ -52,6 +79,24 @@ func NameSystems() namer.NameSystems {
...
@@ -52,6 +79,24 @@ func NameSystems() namer.NameSystems {
}
}
}
}
// ExceptionNamer allows you specify exceptional cases with exact names. This allows you to have control
// for handling various conflicts, like group and resource names for instance.
type
ExceptionNamer
struct
{
Exceptions
map
[
string
]
string
KeyFunc
func
(
*
types
.
Type
)
string
Delegate
namer
.
Namer
}
// Name provides the requested name for a type.
func
(
n
*
ExceptionNamer
)
Name
(
t
*
types
.
Type
)
string
{
key
:=
n
.
KeyFunc
(
t
)
if
exception
,
ok
:=
n
.
Exceptions
[
key
];
ok
{
return
exception
}
return
n
.
Delegate
.
Name
(
t
)
}
// DefaultNameSystem returns the default name system for ordering the types to be
// DefaultNameSystem returns the default name system for ordering the types to be
// processed by the generators in this package.
// processed by the generators in this package.
func
DefaultNameSystem
()
string
{
func
DefaultNameSystem
()
string
{
...
...
staging/src/k8s.io/kube-gen/cmd/client-gen/generators/fake/generator_fake_for_type.go
View file @
c59e211a
...
@@ -213,7 +213,7 @@ var $.type|allLowercasePlural$Resource = $.GroupVersionResource|raw${Group: "$.g
...
@@ -213,7 +213,7 @@ var $.type|allLowercasePlural$Resource = $.GroupVersionResource|raw${Group: "$.g
`
`
var
kind
=
`
var
kind
=
`
var $.type|allLowercasePlural$Kind = $.GroupVersionKind|raw${Group: "$.groupName$", Version: "$.version$", Kind: "$.type|
public
$"}
var $.type|allLowercasePlural$Kind = $.GroupVersionKind|raw${Group: "$.groupName$", Version: "$.version$", Kind: "$.type|
singularKind
$"}
`
`
var
listTemplate
=
`
var
listTemplate
=
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment