template

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIsTemplate = `` /* 1216-byte string literal not displayed */
View Source
var InstallAPITemplate = `` /* 649-byte string literal not displayed */
View Source
var UnversionedAPITemplate = `` /* 7772-byte string literal not displayed */
View Source
var VersionedAPITemplate = `
func addKnownTypes(scheme *runtime.Scheme) error {
	// TODO this will get cleaned up with the scheme types are fixed
	scheme.AddKnownTypes(SchemeGroupVersion,
{{ range $api := .Resources -}}
		&{{ $api.Kind }}{},
		&{{ $api.Kind }}List{},
  {{ range $subresource := $api.Subresources -}}
		&{{ $subresource.Kind }}{},
  {{ end -}}
{{ end -}}
	)
	return nil
}

var (
	ApiVersion = builders.NewApiVersion("{{.Group}}.{{.Domain}}", "{{.Version}}").WithResources(
		{{ range $api := .Resources -}}
		{{$api.Group}}.{{$api.Group|public}}{{$api.Kind}}Storage,
		{{ if $api.REST }}{{ else -}}
		builders.NewApiResource( // Resource status endpoint
			{{ $api.Group }}.Internal{{ $api.Kind }}Status,
			func() runtime.Object { return &{{ $api.Kind }}{} },     // Register versioned resource
			func() runtime.Object { return &{{ $api.Kind }}List{} }, // Register versioned resource list
			&{{ $api.Group }}.{{ $api.StatusStrategy }}{DefaultStatusStorageStrategy: builders.StatusStorageStrategySingleton},
		),{{ end -}}

		{{ range $subresource := $api.Subresources -}}
		builders.NewApiResourceWithStorage(
			{{ $api.Group }}.Internal{{ $subresource.Kind }}REST,
			func() runtime.Object { return &{{ $subresource.Request }}{} }, // Register versioned resource
			nil,
            {{ if $subresource.REST }}{{ $api.Group }}.New{{ $subresource.REST }}{{ else -}}
			func(generic.RESTOptionsGetter) rest.Storage { return &{{ $api.Group }}.{{ $subresource.Kind }}REST{Registry: {{$api.Group}}.New{{$api.Kind}}Registry({{$api.Group}}.{{$api.Group|public}}{{$api.Kind}}Storage) } },
			{{ end -}}
		),
		{{ end -}}
		{{ end -}}
	)

	// Required by code generated by go2idl
	AddToScheme = (&runtime.SchemeBuilder{
		ApiVersion.SchemeBuilder.AddToScheme, 
		RegisterDefaults, 
		RegisterConversions,
		addKnownTypes,
		func(scheme *runtime.Scheme) error {
			metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
			return nil
		},
	}).AddToScheme

	SchemeBuilder = ApiVersion.SchemeBuilder
	localSchemeBuilder = SchemeBuilder
	SchemeGroupVersion = ApiVersion.GroupVersion
)

// Required by code generated by go2idl
// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
	return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Required by code generated by go2idl
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
	return SchemeGroupVersion.WithResource(resource).GroupResource()
}

{{ range $api := .Resources -}}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type {{$api.Kind}}List struct {
	metav1.TypeMeta ` + "`json:\",inline\"`" + `
	metav1.ListMeta ` + "`json:\"metadata,omitempty\"`" + `
	Items           []{{$api.Kind}} ` + "`json:\"items\"`" + `
}

{{ range $subresource := $api.Subresources -}}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type {{$subresource.Request}}List struct {
	metav1.TypeMeta ` + "`json:\",inline\"`" + `
	metav1.ListMeta ` + "`json:\"metadata,omitempty\"`" + `
	Items           []{{$subresource.Request}} ` + "`json:\"items\"`" + `
}
{{ end }}{{ end -}}
`

Functions

func CreateApisGenerator

func CreateApisGenerator(apis *APIs, filename string) generator.Generator

func CreateInstallGenerator

func CreateInstallGenerator(apigroup *APIGroup, filename string) generator.Generator

func CreateUnversionedGenerator

func CreateUnversionedGenerator(apigroup *APIGroup, filename string) generator.Generator

func CreateVersionedGenerator

func CreateVersionedGenerator(apiversion *APIVersion, apigroup *APIGroup, filename string) generator.Generator

func GetGroup

func GetGroup(t *types.Type) string

func GetGroupPackage

func GetGroupPackage(t *types.Type) string

func GetKind

func GetKind(t *types.Type, group string) string

func GetVersion

func GetVersion(t *types.Type, group string) string

func HasSubresource

func HasSubresource(t *types.Type) bool

HasSubresource returns true if t is an APIResource with one or more Subresources

func IsAPIResource

func IsAPIResource(t *types.Type) bool

IsAPIResource returns true if t has a +resource comment tag

func IsAPISubresource

func IsAPISubresource(t *types.Type) bool

IsAPISubresource returns true if t has a +subresource-request comment tag

func IsApisDir

func IsApisDir(dir string) bool

IsApisDir returns true if a directory path is a Kubernetes api directory

func IsNonNamespaced

func IsNonNamespaced(t *types.Type) bool

IsNonNamespaced returns true if t has a +nonNamespaced comment tag

func IsUnversioned

func IsUnversioned(t *types.Type, group string) bool

func IsVersioned

func IsVersioned(t *types.Type, group string) bool

Types

type APIGroup

type APIGroup struct {
	// Package is the name of the go package the api group is under - e.g. github.com/pwittrock/apiserver-helloworld/apis
	Package string
	// Domain is the domain portion of the group - e.g. k8s.io
	Domain string
	// Group is the short name of the group - e.g. mushroomkingdom
	Group      string
	GroupTitle string
	// Versions is the list of all versions for this group keyed by name
	Versions map[string]*APIVersion

	UnversionedResources map[string]*APIResource

	// Structs is a list of unversioned definitions that must be generated
	Structs []*Struct
	Aliases map[string]*Alias
	Pkg     *types.Package
	PkgPath string
}

func (*APIGroup) DoType

func (apigroup *APIGroup) DoType(t *types.Type) (*Struct, []*types.Type)

type APIResource

type APIResource struct {
	// Domain is the group domain - e.g. k8s.io
	Domain string
	// Group is the group name - e.g. mushroomkingdom
	Group string
	// Version is the api version - e.g. v1beta1
	Version string
	// Kind is the resource name - e.g. PeachesCastle
	Kind string
	// Resource is the resource name - e.g. peachescastles
	Resource string
	// ShortName is the resource short name - e.g. pc
	ShortName string
	// REST is the rest.Storage implementation used to handle requests
	// This field is optional. The standard REST implementation will be used
	// by default.
	REST string
	// Subresources is a map of subresources keyed by name
	Subresources map[string]*APISubresource
	// Type is the Type object from code-gen
	Type *types.Type
	// Strategy is name of the struct to use for the strategy
	Strategy string
	// Strategy is name of the struct to use for the strategy
	StatusStrategy string
	// NonNamespaced indicates that the resource kind is non namespaced
	NonNamespaced bool
}

type APISubresource

type APISubresource struct {
	// Domain is the group domain - e.g. k8s.io
	Domain string
	// Group is the group name - e.g. mushroomkingdom
	Group string
	// Version is the api version - e.g. v1beta1
	Version string
	// Kind is the resource name - e.g. PeachesCastle
	Kind string
	// Resource is the resource name - e.g. peachescastles
	Resource string
	// Request is the subresource request type - e.g. ScaleCastle
	Request string
	// REST is the rest.Storage implementation used to handle requests
	REST string
	// Path is the subresource path - e.g. scale
	Path string

	// ImportPackage is the import statement that must appear for the Request
	ImportPackage string

	// RequestType is the type of the request
	RequestType *types.Type

	// RESTType is the type of the request handler
	RESTType *types.Type
}

type APIVersion

type APIVersion struct {
	// Domain is the group domain - e.g. k8s.io
	Domain string
	// Group is the group name - e.g. mushroomkingdom
	Group string
	// Version is the api version - e.g. v1beta1
	Version string
	// Resources is a list of resources appearing in the API version keyed by name
	Resources map[string]*APIResource
	// Pkg is the Package object from code-gen
	Pkg *types.Package
}

type APIs

type APIs struct {
	// Domain is the domain portion of the group - e.g. k8s.io
	Domain string
	// Package is the name of the go package the api group is under - e.g. github.com/pwittrock/apiserver-helloworld/apis
	Package string
	Pkg     *types.Package
	// Groups is a list of API groups
	Groups map[string]*APIGroup
}

type APIsBuilder

type APIsBuilder struct {
	Domain          string
	VersionedPkgs   sets.String
	UnversionedPkgs sets.String
	APIsPkg         string
	APIsPkgRaw      *types.Package
	GroupNames      sets.String

	APIs *APIs

	ByGroupKindVersion    map[string]map[string]map[string]*APIResource
	ByGroupVersionKind    map[string]map[string]map[string]*APIResource
	SubByGroupVersionKind map[string]map[string]map[string]*types.Type
	Groups                map[string]types.Package
	// contains filtered or unexported fields
}

func NewAPIsBuilder

func NewAPIsBuilder(context *generator.Context, arguments *args.GeneratorArgs) *APIsBuilder

func (*APIsBuilder) GenClient

func (b *APIsBuilder) GenClient(c *types.Type) bool

func (*APIsBuilder) GenDeepCopy

func (b *APIsBuilder) GenDeepCopy(c *types.Type) bool

func (*APIsBuilder) GetControllerTag

func (b *APIsBuilder) GetControllerTag(c *types.Type) string

func (*APIsBuilder) GetNameAndImport

func (b *APIsBuilder) GetNameAndImport(tags SubresourceTags) (string, string)

GetNameAndImport converts

func (*APIsBuilder) GetResourceTag

func (b *APIsBuilder) GetResourceTag(c *types.Type) string

GetResourceTag returns the value of the "+resource=" comment tag

func (*APIsBuilder) GetSubresourceTags

func (b *APIsBuilder) GetSubresourceTags(c *types.Type) []string

func (*APIsBuilder) GetSubresources

func (b *APIsBuilder) GetSubresources(c *APIResource) map[string]*APISubresource

func (*APIsBuilder) IsInPackage

func (b *APIsBuilder) IsInPackage(tags SubresourceTags) bool

Returns true if the subresource Request type is in the same package as the resource type

func (*APIsBuilder) ParseAPIs

func (b *APIsBuilder) ParseAPIs()

func (*APIsBuilder) ParseDomain

func (b *APIsBuilder) ParseDomain()

ParseDomain parses the domain from the apis/doc.go file comment "// +domain=YOUR_DOMAIN".

func (*APIsBuilder) ParseGroupNames

func (b *APIsBuilder) ParseGroupNames()

ParseGroupNames initializes b.GroupNames with the set of all groups

func (*APIsBuilder) ParseIndex

func (b *APIsBuilder) ParseIndex()

ParseIndex indexes all types with the comment "// +resource=RESOURCE" by GroupVersionKind and GroupKindVersion

func (*APIsBuilder) ParsePackages

func (b *APIsBuilder) ParsePackages()

ParsePackages parses out the sets of Versioned, Unversioned packages and identifies the root Apis package.

func (*APIsBuilder) ParseStructsAndAliases

func (b *APIsBuilder) ParseStructsAndAliases(apigroup *APIGroup)

type Alias

type Alias struct {
	Name               string
	UnderlyingTypeName string
}

type Comments

type Comments []string

Comments is a structure for using comment tags on go structs and fields

func (Comments) GetTag

func (c Comments) GetTag(name, sep string) string

GetTags returns the value for the first comment with a prefix matching "+name=" e.g. "+name=foo\n+name=bar" would return "foo"

func (Comments) GetTags

func (c Comments) GetTags(name, sep string) []string

GetTags returns the value for all comments with a prefix and separator. E.g. for "name" and "=" "+name=foo\n+name=bar" would return []string{"foo", "bar"}

func (Comments) HasTag

func (c Comments) HasTag(name string) bool

type CustomArgs

type CustomArgs struct{}

CustomArgs is used tby the go2idl framework to pass args specific to this generator.

type Field

type Field struct {
	// Name is the name of the field
	Name string
	// For versioned Kubernetes types, this is the versioned package
	VersionedPackage string
	// For versioned Kubernetes types, this is the unversioned package
	UnversionedImport string
	UnversionedType   string
}

type Gen

type Gen struct {
	// contains filtered or unexported fields
}

func (*Gen) DefaultNameSystem

func (g *Gen) DefaultNameSystem() string

DefaultNameSystem returns the default name system for ordering the types to be processed by the generators in this package.

func (*Gen) Execute

func (g *Gen) Execute(arguments *args.GeneratorArgs) error

func (*Gen) NameSystems

func (g *Gen) NameSystems() namer.NameSystems

NameSystems returns the name system used by the generators in this package.

func (*Gen) Packages

func (g *Gen) Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages

func (*Gen) ParsePackages

func (g *Gen) ParsePackages(context *generator.Context, arguments *args.GeneratorArgs) (sets.String, sets.String, string, string)

type GenUnversionedType

type GenUnversionedType struct {
	Type     *types.Type
	Resource *APIResource
}

type ResourceTags

type ResourceTags struct {
	Resource  string
	REST      string
	Strategy  string
	ShortName string
}

ResourceTags contains the tags present in a "+resource=" comment

func ParseResourceTag

func ParseResourceTag(tag string) ResourceTags

ParseResourceTag parses the tags in a "+resource=" comment into a ResourceTags struct

type Struct

type Struct struct {
	// Name is the name of the type
	Name string
	// GenClient
	GenClient     bool
	GenDeepCopy   bool
	NonNamespaced bool

	GenUnversioned bool
	// Fields is the list of fields appearing in the struct
	Fields []*Field
}

type SubresourceTags

type SubresourceTags struct {
	Path        string
	Kind        string
	RequestKind string
	REST        string
}

SubresourceTags contains the tags present in a "+subresource=" comment

func ParseSubresourceTag

func ParseSubresourceTag(c *APIResource, tag string) SubresourceTags

ParseSubresourceTag parses the tags in a "+subresource=" comment into a SubresourceTags struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL