mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
[client-gen] Support Read-Only APIs
This commit adds support for read-only APIs to client-gen. If the tag `// +readonly=true` is used, only the {Get,List,Watch} client methods will be generated.
This commit is contained in:
parent
392b8da1d0
commit
1cbc825fb9
@ -149,6 +149,8 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
||||
|
||||
noMethods := extractBoolTagOrDie("noMethods", t.SecondClosestCommentLines) == true
|
||||
|
||||
readonly := extractBoolTagOrDie("readonly", t.SecondClosestCommentLines) == true
|
||||
|
||||
if namespaced {
|
||||
sw.Do(structNamespaced, m)
|
||||
} else {
|
||||
@ -158,6 +160,9 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
||||
if !noMethods {
|
||||
sw.Do(resource, m)
|
||||
sw.Do(kind, m)
|
||||
}
|
||||
|
||||
if !noMethods && !readonly {
|
||||
sw.Do(createTemplate, m)
|
||||
sw.Do(updateTemplate, m)
|
||||
// Generate the UpdateStatus method if the type has a status
|
||||
@ -166,6 +171,9 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
||||
}
|
||||
sw.Do(deleteTemplate, m)
|
||||
sw.Do(deleteCollectionTemplate, m)
|
||||
}
|
||||
|
||||
if !noMethods {
|
||||
sw.Do(getTemplate, m)
|
||||
if hasObjectMeta(t) {
|
||||
sw.Do(listUsingOptionsTemplate, m)
|
||||
@ -173,6 +181,9 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
||||
sw.Do(listTemplate, m)
|
||||
}
|
||||
sw.Do(watchTemplate, m)
|
||||
}
|
||||
|
||||
if !noMethods && !readonly {
|
||||
sw.Do(patchTemplate, m)
|
||||
}
|
||||
|
||||
|
@ -102,14 +102,20 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
||||
}
|
||||
noMethods := extractBoolTagOrDie("noMethods", t.SecondClosestCommentLines) == true
|
||||
|
||||
readonly := extractBoolTagOrDie("readonly", t.SecondClosestCommentLines) == true
|
||||
|
||||
sw.Do(interfaceTemplate1, m)
|
||||
if !noMethods {
|
||||
sw.Do(interfaceTemplate2, m)
|
||||
// Include the UpdateStatus method if the type has a status
|
||||
if genStatus(t) {
|
||||
sw.Do(interfaceUpdateStatusTemplate, m)
|
||||
if readonly {
|
||||
sw.Do(interfaceTemplateReadonly, m)
|
||||
} else {
|
||||
sw.Do(interfaceTemplate2, m)
|
||||
// Include the UpdateStatus method if the type has a status
|
||||
if genStatus(t) {
|
||||
sw.Do(interfaceUpdateStatusTemplate, m)
|
||||
}
|
||||
sw.Do(interfaceTemplate3, m)
|
||||
}
|
||||
sw.Do(interfaceTemplate3, m)
|
||||
}
|
||||
sw.Do(interfaceTemplate4, m)
|
||||
|
||||
@ -121,7 +127,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
||||
sw.Do(newStructNonNamespaced, m)
|
||||
}
|
||||
|
||||
if !noMethods {
|
||||
if !noMethods && !readonly {
|
||||
sw.Do(createTemplate, m)
|
||||
sw.Do(updateTemplate, m)
|
||||
// Generate the UpdateStatus method if the type has a status
|
||||
@ -130,9 +136,15 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
||||
}
|
||||
sw.Do(deleteTemplate, m)
|
||||
sw.Do(deleteCollectionTemplate, m)
|
||||
}
|
||||
|
||||
if !noMethods {
|
||||
sw.Do(getTemplate, m)
|
||||
sw.Do(listTemplate, m)
|
||||
sw.Do(watchTemplate, m)
|
||||
}
|
||||
|
||||
if !noMethods && !readonly {
|
||||
sw.Do(patchTemplate, m)
|
||||
}
|
||||
|
||||
@ -177,6 +189,11 @@ var interfaceTemplate3 = `
|
||||
Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error)
|
||||
Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.type|raw$, err error)`
|
||||
|
||||
var interfaceTemplateReadonly = `
|
||||
Get(name string, options $.GetOptions|raw$) (*$.type|raw$, error)
|
||||
List(opts $.ListOptions|raw$) (*$.type|raw$List, error)
|
||||
Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error)`
|
||||
|
||||
var interfaceTemplate4 = `
|
||||
$.type|public$Expansion
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user