Documentation ¶
Overview ¶
Package converter provides utilities for converting between various types. For example, one should expect to see the following conversions:
TextProto <-> Protos JSON <-> Protos YAML <-> Protos
Index ¶
- Variables
- func CloneBundle(b *bpb.ClusterBundle) *bpb.ClusterBundle
- func CloneComponentPackage(b *bpb.ComponentPackage) *bpb.ComponentPackage
- func CloneFile(b *bpb.File) *bpb.File
- func CloneStruct(b *structpb.Struct) *structpb.Struct
- func ObjectMetaFromStruct(obj *structpb.Struct) (*bpb.ObjectMeta, error)
- func ProtoToJSON(b proto.Message) ([]byte, error)
- func ProtoToYAML(b proto.Message) ([]byte, error)
- func SanitizeName(name string) string
- func ToBundle(msg proto.Message) *bpb.ClusterBundle
- func ToComponentPackage(msg proto.Message) *bpb.ComponentPackage
- func ToNodeConfig(msg proto.Message) *bextpb.NodeConfig
- func ToObjectMeta(msg proto.Message) *bpb.ObjectMeta
- func ToStruct(msg proto.Message) *structpb.Struct
- type BundleReaderWriter
- type Converter
- func (b *Converter) JSONToProto(contents []byte) (proto.Message, error)
- func (b *Converter) ProtoToJSON(bun proto.Message) ([]byte, error)
- func (b *Converter) ProtoToTextProto(msg proto.Message) ([]byte, error)
- func (b *Converter) ProtoToYAML(bun proto.Message) ([]byte, error)
- func (b *Converter) TextProtoToProto(textpb []byte) (proto.Message, error)
- func (b *Converter) YAMLToProto(contents []byte) (proto.Message, error)
- type KubeConverter
- type ObjectExporter
Constants ¶
This section is empty.
Variables ¶
var ( // Bundle is a converter for ClusterBundles Bundle = &Converter{&bpb.ClusterBundle{}} // ComponentPackage is a converter for ComponentPackage protos. ComponentPackage = &Converter{&bpb.ComponentPackage{}} // NodeConfig is a converter for NodeConfig protos. NodeConfig = &Converter{&bextpb.NodeConfig{}} // ObjectMeta is a converter for NodeConfig protos. ObjectMeta = &Converter{&bpb.ObjectMeta{}} // Struct is a converter for Struct protos. Struct = &Converter{&structpb.Struct{}} )
Functions ¶
func CloneBundle ¶
func CloneBundle(b *bpb.ClusterBundle) *bpb.ClusterBundle
CloneBundle creates a copy of a cluster bundle proto.
func CloneComponentPackage ¶ added in v0.4.0
func CloneComponentPackage(b *bpb.ComponentPackage) *bpb.ComponentPackage
CloneComponentPackage creates a copy of a object collection proto.
func CloneStruct ¶
CloneStruct creates a copy of a struct proto.
func ObjectMetaFromStruct ¶
func ObjectMetaFromStruct(obj *structpb.Struct) (*bpb.ObjectMeta, error)
ObjectMetaFromStruct converts to the ObjectMeta proto from a structpb's ObjectMeta.
func ProtoToJSON ¶
ProtoToJSON converts a proto into a JSON encoded proto.
func ProtoToYAML ¶
ProtoToYAML converts a proto into a YAML encoded proto.
func SanitizeName ¶ added in v0.4.1
SanitizeName sanitizes a metadata.name field, replacing unsafe characters with _ and truncating if it's longer than 253 characters.
func ToBundle ¶
func ToBundle(msg proto.Message) *bpb.ClusterBundle
ToBundle is a type converter for converting to and from a Bundle.
func ToComponentPackage ¶ added in v0.4.0
func ToComponentPackage(msg proto.Message) *bpb.ComponentPackage
ToComponentPackage is a type converter for converting to and from a ComponentPackage.
func ToNodeConfig ¶
func ToNodeConfig(msg proto.Message) *bextpb.NodeConfig
ToNodeConfig is a type converter for converting to and from a NodeConfig.
func ToObjectMeta ¶
func ToObjectMeta(msg proto.Message) *bpb.ObjectMeta
ToObjectMeta is a type converter for converting a proto to an ObjectMeta.
Types ¶
type BundleReaderWriter ¶
type BundleReaderWriter struct { // RW is a FileReaderWriter instance. RW files.FileReaderWriter }
BundleReaderWriter uses a file reader writer to read, write. and convert bundles.
func NewFileSystemBundleReaderWriter ¶
func NewFileSystemBundleReaderWriter() *BundleReaderWriter
func (*BundleReaderWriter) ReadBundleFile ¶
func (r *BundleReaderWriter) ReadBundleFile(ctx context.Context, path string) (*bpb.ClusterBundle, error)
ReadBundleFile reads in a ClusterBundle from a yaml file found at the given path.
func (*BundleReaderWriter) WriteBundleFile ¶
func (r *BundleReaderWriter) WriteBundleFile(ctx context.Context, path string, bundle *bpb.ClusterBundle, permissions os.FileMode) error
WriteBundleFile writes a given ClusterBundle proto to a yaml file at the specified path with given permissions.
type Converter ¶
Converter is a generic struct that knows how to convert between textpb, proto, and yamls, for a specific proto message.
func (*Converter) JSONToProto ¶
JSONToProto converts a json encoded bundle into a proto.
func (*Converter) ProtoToJSON ¶
ProtoToJSON converts a bundle into a JSON encoded proto.
func (*Converter) ProtoToTextProto ¶
ProtoToTextProto converts a proto to a textformat proto.
func (*Converter) ProtoToYAML ¶
ProtoToYAML converts a proto into a YAML encoded proto.
func (*Converter) TextProtoToProto ¶
TextProtoToProto converts a textformat proto to a proto.
type KubeConverter ¶
type KubeConverter struct {
// contains filtered or unexported fields
}
KubeConverter converts structs to Kubernetes objects.
func FromStruct ¶
func FromStruct(s *structpb.Struct) *KubeConverter
FromStruct creates a new KubeConverter.
func (*KubeConverter) ToConfigMap ¶ added in v0.4.1
func (k *KubeConverter) ToConfigMap() (*corev1.ConfigMap, error)
ToNodeConfig converts from a struct to a NodeConfig.
func (*KubeConverter) ToNodeConfig ¶ added in v0.4.0
func (k *KubeConverter) ToNodeConfig() (*bextpb.NodeConfig, error)
ToNodeConfig converts from a struct to a NodeConfig.
type ObjectExporter ¶
ObjectExporter exports cluster objects
func (*ObjectExporter) ExportAsMultiYAML ¶
func (e *ObjectExporter) ExportAsMultiYAML() ([]string, error)
ExportAsMultiYAML converts cluster objects into multiple YAML files.
func (*ObjectExporter) ExportAsYAML ¶
func (e *ObjectExporter) ExportAsYAML() (string, error)
ExportAsYAML converts cluster objects into single YAML file.