gen

package
v0.0.0-...-9069b3a Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DotNet string = "dotnet"
	Go     string = "go"
	NodeJS string = "nodejs"
	Python string = "python"
)

Variables

This section is empty.

Functions

func AddMetadataRefs

func AddMetadataRefs(objectTypeSpecs map[string]pschema.ObjectTypeSpec, baseRefs []string)

AddMetadataRefs adds a `metadata?: meta/v1/ObjectMeta` field to each versioned CustomResourceArgs interface.

func AddPlaceholderMetadataSpec

func AddPlaceholderMetadataSpec(objectTypeSpecs map[string]pschema.ObjectTypeSpec)

AddPlaceholderMetadataSpec adds a placeholder `kubernetes:meta/v1:ObjectMeta` objectTypeSpec value. This is needed so that the Go codegen can properly import meta/v1:ObjectMeta.

func CombineSchemas

func CombineSchemas(combineRequired bool, schemas ...map[string]interface{}) map[string]interface{}

CombineSchemas combines the `properties` fields of the given sub-schemas into a single schema. Returns nil if no schemas are given. Returns the schema if only 1 schema is given. If combineRequired == true, then each sub-schema's `required` fields are also combined. In this case the combined schema's `required` field is of type []interface{}, not []string.

func GenericizeStringSlice

func GenericizeStringSlice(stringSlice []string) interface{}

GenericizeStringSlice converts a []string to []interface{}.

func IsValidLanguage

func IsValidLanguage(language string) bool

func NestedMapSlice

func NestedMapSlice(obj map[string]interface{}, fields ...string) ([]map[string]interface{}, bool, error)

NestedMapSlice returns a copy of []map[string]interface{} value of a nested field. Returns false if value is not found and an error if not a []interface{} or contains non-map items in the slice. If the value is found but not of type []interface{}, this still returns true.

func PrettyPrint

func PrettyPrint(v interface{}) (err error)

PrettyPrint properly formats and indents an unstructured value, and prints it to stdout.

func UnderscoreFields

func UnderscoreFields(schema map[string]interface{})

UnderscoreFields replaces the hyphens in the x-kubernetes-... fields with underscores

func UnmarshalYaml

func UnmarshalYaml(yamlFile []byte) (unstruct.Unstructured, error)

UnmarshalYaml decodes a yamlFile into a Unstructured type with a value of map[string]interface{}.

Types

type CustomResourceGenerator

type CustomResourceGenerator struct {
	// CustomResourceDefinition represents unmarshalled CRD YAML
	CustomResourceDefinition unstruct.Unstructured
	// Schemas represents a mapping from each version in the `spec.versions`
	// list to its corresponding `openAPIV3Schema` field in the CRD YAML
	Schemas map[string]map[string]interface{}
	// OutputDir represents the directory where generated code will output to
	OutputDir string
	// Language represents the target language to generate code
	Language string
	// ApiVersion represents the `apiVersion` field in the CRD YAML
	APIVersion string
	// Kind represents the `spec.names.kind` field in the CRD YAML
	Kind string
	// Plural represents the `spec.names.plural` field in the CRD YAML
	Plural string
	// Group represents the `spec.group` field in the CRD YAML
	Group string
}

func NewCustomResourceGenerator

func NewCustomResourceGenerator(language, yamlPath, outputDir string) (CustomResourceGenerator, error)

func (*CustomResourceGenerator) AddAPIVersionAndKindProperties

func (gen *CustomResourceGenerator) AddAPIVersionAndKindProperties(objectTypeSpecs map[string]pschema.ObjectTypeSpec, baseRefs []string)

AddAPIVersionAndKindProperties adds the `apiVersion` and `kind` properties to every version's schema

func (*CustomResourceGenerator) Generate

func (gen *CustomResourceGenerator) Generate(force bool) error

Generate outputs strongly-typed args for the CustomResourceGenerator's CRD in the target language and output folder

func (*CustomResourceGenerator) GetObjectTypeSpecs

func (gen *CustomResourceGenerator) GetObjectTypeSpecs() map[string]pschema.ObjectTypeSpec

GetObjectTypeSpecs generates types for each versioned schema. Returns a mapping from each type's name in the format of "{.spec.group}/{.spec.versions[*].name}:{.spec.names.kind}" to its proper pschema.ObjectTypeSpec.

func (*CustomResourceGenerator) Name

func (gen *CustomResourceGenerator) Name() string

func (*CustomResourceGenerator) VersionNames

func (gen *CustomResourceGenerator) VersionNames() []string

VersionNames returns a slice of the full names of each version, in the format <group>/<version>.

func (*CustomResourceGenerator) Versions

func (gen *CustomResourceGenerator) Versions() []string

Versions returns a slice of the versions supported by this CRD.

Jump to

Keyboard shortcuts

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