Documentation
¶
Index ¶
- func ApplyInlineFields(jsonData []byte, fields []InlineFieldMapping) ([]byte, error)
- func GetFieldOptions(field *protogen.Field, extTypes *protoregistry.Types) (*pboptions.Options, error)
- func GetPluginAndExtensions(data []byte, overrideGoPackageOpt bool) (*protogen.Plugin, *protoregistry.Types, error)
- func ReadRequest() []byte
- func RemoveInlineFields(typ reflect.Type, currentPath string, visited map[reflect.Type]bool, ...)
- func ReplaceImportPath(req *pluginpb.CodeGeneratorRequest)
- func SetPackageAlias(file *dst.File, pkgPath string, newAlias string)
- func ValidateWrapperContentField(baseCrdName, wrapperKind, wrapperName, path string, ...)
- func WriteResponse(resp *pluginpb.CodeGeneratorResponse)
- type GenericResolver
- type IndexFlag
- type IndexedField
- type IndexedSubField
- type InlineFieldMapping
- type MatchedResult
- type RevisionedIndex
- type Sidecar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyInlineFields ¶
func ApplyInlineFields(jsonData []byte, fields []InlineFieldMapping) ([]byte, error)
ApplyInlineFields processes JSON data to apply inline field mappings. It takes a JSON byte slice and a slice of InlineFieldMapping, and returns the modified JSON byte slice.
Parameters: - jsonData: A byte slice containing the JSON data to be processed. - fields: A slice of InlineFieldMapping structs that define the old and new paths for inline fields.
Returns: - A byte slice containing the modified JSON data. - An error if any issues occur during the processing.
func GetFieldOptions ¶
func GetFieldOptions(field *protogen.Field, extTypes *protoregistry.Types) (*pboptions.Options, error)
GetFieldOptions gets the field options for the given field
func GetPluginAndExtensions ¶
func GetPluginAndExtensions(data []byte, overrideGoPackageOpt bool) (*protogen.Plugin, *protoregistry.Types, error)
GetPluginAndExtensions generates protogen plugin and extensions given the data.
When overrideGoPackageOpt is set, it sets the go_package option to the protobuf package. This is useful when the caller is a protoc plugin that generates code for languages (e.g. yaml, sql) other than Go. We are using "google.golang.org/protobuf/compiler/protogen" to parse protobuf code. Since this library is a protobuf to Go compiler, it will fail if the go_package option is not set properly. However, when generating code for other languages, we shouldn't require the go_package option. So, we set the go_package option to the protobuf package, which is always a "valid" value for go_package, to make the library happy.
func ReadRequest ¶
func ReadRequest() []byte
ReadRequest reads the protoc request from stdin and returns it as a byte slice.
func RemoveInlineFields ¶
func RemoveInlineFields(typ reflect.Type, currentPath string, visited map[reflect.Type]bool, paths *[]InlineFieldMapping)
RemoveInlineFields identifies old and new JSON paths for inline fields.
Parameters: - typ: The reflect.Type of the struct to process. - currentPath: The current JSON path being processed. - visited: A map to track visited types and avoid infinite recursion. - paths: A slice to store the identified InlineFieldMapping structs.
func ReplaceImportPath ¶
func ReplaceImportPath(req *pluginpb.CodeGeneratorRequest)
ReplaceImportPath replaces the import path of GOGO_WELL_KNOW_TYPE_REMAPS modifiers in the CodeGeneratorRequest's parameter so that we can pass the golang's protobuf compiler's consistency check.
func SetPackageAlias ¶
SetPackageAlias modifies the alias of a package import and updates all its references
func ValidateWrapperContentField ¶
func ValidateWrapperContentField(baseCrdName, wrapperKind, wrapperName, path string, wrapperMsg *protogen.Message)
ValidateWrapperContentField walks a dotted path (e.g. "spec.content") against wrapperMsg's fields and panics unless every segment resolves to a real field and the leaf field is a google.protobuf.Any. This is the check that ties a revisioned_in wrapper kind's hardcoded content path back to the wrapper's actual proto schema, so a renamed/missing content field fails at codegen time instead of surfacing as a runtime failure when the storage layer reflects into the Any at that path.
func WriteResponse ¶
func WriteResponse(resp *pluginpb.CodeGeneratorResponse)
WriteResponse writes the CodeGeneratorResponse to stdout.
Types ¶
type GenericResolver ¶
type GenericResolver struct {
}
GenericResolver implements jsonpb.AnyResolver to support marshal/unmarshal generic protobuf types packed in Any. We implement this resovler as the defaultResolveAny in jsonpb https://github.com/gogo/protobuf/blob/master/jsonpb/jsonpb.go#L92 reports unknown message type error if the protobuf type does not register in the global registry (https://github.com/gogo/protobuf/blob/master/proto/properties.go#L545).
type IndexFlag ¶
type IndexFlag int
IndexFlag is used to describe properties of an IndexedField. Check the available flags below.
const ( // IndexFlagPrimitive is set if the Indexed field is a primitive type field, i.e. (string, int32, etc.). IndexFlagPrimitive IndexFlag = 1 << iota // IndexFlagCompositeKey is used to determine whether to generate composite or non-composite // index for a message field. IndexFlagCompositeKey // IndexFlagEnum is set if the indexed field is an enum field. IndexFlagEnum )
type IndexedField ¶
type IndexedField struct {
Key string
Flag IndexFlag
GoPaths []string
ProtoPath string
Type string
SubFields []IndexedSubField
}
IndexedField represents an indexed field in CRD that is annotated by the michelangelo.api.resource option. An indexed field can be either a primitive type field (IndexFlagPrimitive is set) or a message type field. For a message type field, SubFields represents the indexed subfields in the message type field. If the IndexFlagCompositeKey is set, the compiler will build composite key on all the subfields.
func ParseIndexedFields ¶
func ParseIndexedFields(crdRootMsg *protogen.Message, crdOptions *pboptions.Options) []IndexedField
ParseIndexedFields parses and validates the indexing fields in a CRD and returns a list of indexed fields for further code generation.
func (*IndexedField) HasFlag ¶
func (f *IndexedField) HasFlag(flag IndexFlag) bool
HasFlag checks if the field has the given flag.
type IndexedSubField ¶
IndexedSubField represents an indexed subfield in the indexed message field.
type InlineFieldMapping ¶
InlineFieldMapping holds old and new paths for inline fields.
type MatchedResult ¶
MatchedResult holds the path, value, and new path for a matched field.
type RevisionedIndex ¶
type RevisionedIndex struct {
// Kinds are the wrapper CRD kinds that mirror this index set, e.g.
// "revision", "draft". Each resolves to a wrapper CRD by convention
// (e.g. "revision" -> Revision, keyed on revision_uid).
Kinds []string
// Fields is the base CRD's full index set, resolved against the base
// message — which is exactly what each wrapper stores at spec.content.
Fields []IndexedField
}
RevisionedIndex describes a revisioned base CRD's index set and the wrapper kinds it is mirrored into. A base CRD that lists resource.revisioned_in has its full michelangelo.api.index set materialized into a "<base>_<kind>_unmarshaled" sidecar table for each listed kind, so List<Wrapper> can filter on the wrapped base resource's fields server-side. Every listed kind mirrors the same base index set, so Fields is shared across all Kinds rather than duplicated per kind.
func ParseRevisionedIndex ¶
func ParseRevisionedIndex(crdRootMsg *protogen.Message, crdOptions *pboptions.Options) *RevisionedIndex
ParseRevisionedIndex returns the base CRD's michelangelo.api.index set, with a synthesized "name" field (metadata.name) always prepended, together with the wrapper kinds listed in resource.revisioned_in that mirror it into "<base>_<kind>_unmarshaled" sidecar tables. Each index path resolves against the base CRD message itself, which is what each wrapper stores at spec.content, so every kind mirrors the same base index set. The base object's own SQL table always carries a "name" column regardless of michelangelo.api.index (see protoc-gen-sql's CRDMySQLMainTableColumn), so sidecar tables mirror that same guarantee rather than requiring every revisioned CRD to redeclare "metadata.name" explicitly.
Returns nil when the CRD is not revisioned (resource.revisioned_in is empty). Panics if revisioned_in is set but names an empty kind, is set on a CRD that declares no michelangelo.api.index fields to mirror, or if the CRD declares an index field with the reserved key "name" (which would collide with the synthesized metadata.name column).
type Sidecar ¶
Sidecar names the storage artifacts of one (base table, wrapper kind) pair: the "<base>_<kind>_unmarshaled" table and its "<kind>_uid" primary-key column. protoc-gen-sql emits the CREATE TABLE under these names and protoc-gen-kubeproto bakes them into the generated RevisionedIndexSpecs, so both generators MUST derive them from SidecarFor — the runtime queries whatever the spec says, and a divergence between the two would only surface as a missing table in production.
func SidecarFor ¶
SidecarFor derives the sidecar identity for a (base table, wrapper kind) pair, e.g. ("pipeline", "revision") -> {pipeline_revision_unmarshaled, revision_uid}.