Documentation ¶
Index ¶
- Constants
- Variables
- func AddType(schema map[string]any, name string, types map[string]pschema.ComplexTypeSpec)
- func CombineSchemas(combineRequired bool, schemas ...map[string]any) map[string]any
- func Generate(cs *CodegenSettings, yamls []io.ReadCloser) error
- func GenerateDotNet(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error)
- func GenerateFromFiles(cs *CodegenSettings, yamlPaths []string) error
- func GenerateGo(pg *PackageGenerator, name string) (buffers map[string]*bytes.Buffer, err error)
- func GenerateJava(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error)
- func GenerateNodeJS(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error)
- func GeneratePython(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error)
- func GetTypeSpec(schema map[string]any, name string, types map[string]pschema.ComplexTypeSpec) pschema.TypeSpec
- type CodegenSettings
- type CustomResourceGenerator
- type GenerateFunc
- type PackageGenerator
Constants ¶
const ( Boolean string = "boolean" Integer string = "integer" Number string = "number" String string = "string" Array string = "array" Object string = "object" )
const DefaultName = "crds"
DefaultName specifies the default value for the package name
const DotNet string = "dotnet"
const Go string = "go"
const Java string = "java"
const (
KubernetesProviderVersion string = "4.18.0"
)
const NodeJS string = "nodejs"
const PulumiToolName = "crd2pulumi"
PulumiToolName is a symbol that identifies to Pulumi the name of this program.
const Python string = "python"
Variables ¶
var UnneededGoFiles = codegen.NewStringSet(
"doc.go",
"init.go",
"provider.go",
"meta/v1/pulumiTypes.go",
"utilities/pulumiUtilities.go",
"utilities/pulumiVersion.go",
)
Functions ¶
func AddType ¶
AddType converts the given OpenAPI `schema` to a ObjectTypeSpec and adds it to the `types` map under the given `name`. Recursively converts and adds all nested schemas as well.
func CombineSchemas ¶
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 []any, not []string.
func Generate ¶
func Generate(cs *CodegenSettings, yamls []io.ReadCloser) error
Generate performs the entire CRD codegen process, reading YAML content from the given readers.
func GenerateDotNet ¶
func GenerateFromFiles ¶
func GenerateFromFiles(cs *CodegenSettings, yamlPaths []string) error
GenerateFromFiles performs the entire CRD codegen process. The yamlPaths argument can contain both file paths and URLs.
func GenerateGo ¶
func GenerateJava ¶ added in v1.4.0
func GenerateNodeJS ¶
func GeneratePython ¶
func GetTypeSpec ¶
func GetTypeSpec(schema map[string]any, name string, types map[string]pschema.ComplexTypeSpec) pschema.TypeSpec
GetTypeSpec returns the corresponding pschema.TypeSpec for a OpenAPI v3 schema. Handles nested pschema.TypeSpecs in case the schema type is an array, object, or "combined schema" (oneOf, allOf, anyOf). Also recursively converts and adds all schemas of type object to the types map.
Types ¶
type CodegenSettings ¶
type CodegenSettings struct { Language string OutputDir string PackageName string PackageVersion string Overwrite bool ShouldGenerate bool }
func (*CodegenSettings) Path ¶
func (cs *CodegenSettings) Path() string
type CustomResourceGenerator ¶
type CustomResourceGenerator struct { // CustomResourceDefinition contains the unmarshalled CRD YAML CustomResourceDefinition extensionv1.CustomResourceDefinition // Schemas represents a mapping from each version in the `spec.versions` // list to its corresponding `openAPIV3Schema` field in the CRD YAML Schemas map[string]spec.Swagger // 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 // Versions is a slice of names of each version supported by this CRD Versions []string // GroupVersions is a slice of names of each version, in the format // <group>/<version>. GroupVersions []string // ResourceTokens is a slice of the token types of every versioned // CustomResource ResourceTokens []string }
CustomResourceGenerator generates a Pulumi schema for a single CustomResource
func NewCustomResourceGenerator ¶
func NewCustomResourceGenerator(crd extensionv1.CustomResourceDefinition) (CustomResourceGenerator, error)
func (*CustomResourceGenerator) HasSchemas ¶
func (crg *CustomResourceGenerator) HasSchemas() bool
HasSchemas returns true if the CustomResource specifies at least some schema, and false otherwise.
type GenerateFunc ¶
type GenerateFunc func(pg *PackageGenerator, name string) (mapFileNameToData map[string]*bytes.Buffer, err error)
GenerateFunc is the function that is called by the generator to generate the code. It returns a mapping of filename to the contents of said file and any error that may have occurred.
type PackageGenerator ¶
type PackageGenerator struct { // CustomResourceGenerators contains a slice of all CustomResourceGenerators CustomResourceGenerators []CustomResourceGenerator // ResourceTokens is a slice of the token types of every CustomResource ResourceTokens []string // GroupVersions is a slice of the names of every CustomResource's versions, // in the format <group>/<version> GroupVersions []string // Types is a mapping from every type's token name to its ComplexTypeSpec Types map[string]pschema.ComplexTypeSpec // Version is the semver that will be stamped into the generated package Version string // contains filtered or unexported fields }
PackageGenerator generates code for multiple CustomResources
func ReadPackagesFromSource ¶
func ReadPackagesFromSource(version string, yamlSources []io.ReadCloser) (*PackageGenerator, error)
ReadPackagesFromSource reads one or more documents and returns a PackageGenerator that can be used to generate Pulumi code. Calling this function will fully read and close each document.
func (*PackageGenerator) HasSchemas ¶
func (pg *PackageGenerator) HasSchemas() bool
HasSchemas returns true if there exists at least one CustomResource with a schema in this package.
func (*PackageGenerator) ModuleToPackage ¶
func (pg *PackageGenerator) ModuleToPackage() (map[string]string, error)
Returns language-specific 'ModuleToPackage' map. Creates a mapping from every groupVersion string <group>/<version> to <groupPrefix>/<version>.
func (*PackageGenerator) SchemaPackage ¶
func (pg *PackageGenerator) SchemaPackage() *pschema.Package
SchemaPackage returns the Pulumi schema package with no ObjectMeta type. This is only necessary for NodeJS and Python.
func (*PackageGenerator) SchemaPackageWithObjectMetaType ¶
func (pg *PackageGenerator) SchemaPackageWithObjectMetaType() *pschema.Package
SchemaPackageWithObjectMetaType returns the Pulumi schema package with an ObjectMeta type. This is only necessary for Go and .NET.