README
¶
The Utils Package
The Utils Package is the Central component of Meshkit. This package encompases different packages that offers a simplified and tailored experience for developers working with Kubernetes and Helm. Developers can easily interact with Kubernetes and Helm without relying on the command line versions by utilizing higher-level functions from the utils package. Here is a brief description of some of the packages embedded in Utils:
Broadcast
The BroadCast package provides a simple and concurrent way to implement a broadcast channel, where messages can be submitted and multiple subscribers can register to receive those messages. It allows for decoupling the provider and subscribers and facilitates pubsub communication between components in a system.
Component
The Component Package genarates a component definition struct which may contain various fields that provide information about the component, such as the component kind, API version, display name, schema, and metadata based on a custom CRD. The Component package also Extracts the JSON schema of the CRD using the provided CUE path configuration.
Kuberentes
The kubernetes package provides functionality for working with Kubernetes clusters .The package defines a Client
that encapsulates the necessary components for interacting with the Kubernetes API server.
This package contains certain packages such as describe, expose, Kompose, manifests and walker for interacting with the kubernetes Api Server.
Below are descriptions of each package:
Describe Package is a comprehensive and user-friendly solution for describing Kubernetes objects through the Kubernetes API. With its rich set of functionalities, it contains components for creating and initiaizing a meshclient, allowing users to retrieve information about various Kubernetes resources such as pods, deployments, jobs, services, and more to interact with the kubernetes Api.
Overall, the describe package provides a convenient way to retrieve detailed information about Kubernetes resources in a standardized format.
The Expose Package provides functionality for exposing Kubernetes resources as services.
- The package imports various packages from the standard library and external dependencies.
- It contains fields for specifying the service type, load balancer IP, cluster IP, namespace, session affinity, name, annotations, and a logger.
- The
Expose()
is the main function of the package this takes a Kubernetes clientset, REST config, Config object, and a list of resources to expose. - It uses a Traverser to iterate over the resources and generate the corresponding services. Overall, this package provides a way to expose Kubernetes resources as services with customizable configurations.
Kompose Package provides functionality for working with Docker Compose files and converting them to Kubernetes manifests. It provides the following features:
- Validation: The package can validate a Docker Compose file against a provided JSON schema. It ensures that the file adheres to the specified structure and format.
- Conversion: The package can convert a validated Docker Compose file into Kubernetes manifests. It transforms the services, volumes, and other components defined in the Compose file into their equivalent representations in the Kubernetes ecosystem.
- Compatibility Check: The package checks the compatibility of the Docker Compose file version with the "kompose" tool. It verifies if the version exceeds a certain limit and throws an error if it does.
- Formatting: The package performs formatting operations on the Docker Compose and converted Kubernetes manifest files to ensure compatibility and consistency. Overall, the kompose package aims to simplify the process of migrating from Docker Compose to Kubernetes by providing validation, conversion, and compatibility checking capabilities.
Documentation
¶
Index ¶
- Constants
- Variables
- func Cast[K any](val interface{}) (K, error)
- func CombineErrors(errs []error, sep string) error
- func Compress(src string, buf io.Writer) error
- func Contains[G []K, K comparable](slice G, ele K) bool
- func ConvertMapInterfaceMapString(v interface{}) interface{}
- func ConvertToJSONCompatible(data interface{}) interface{}
- func ConvertoCue(reader io.Reader) (cue.Value, error)
- func CreateDirectory(path string) error
- func CreateFile(contents []byte, filename string, location string) error
- func DownloadFile(filepath string, url string) error
- func ErrCloseFile(err error) error
- func ErrCompressToTarGZ(err error, path string) error
- func ErrConvertToByte(err error) error
- func ErrCopyFile(err error) error
- func ErrCreateDir(err error, filepath string) error
- func ErrCreateFile(err error, filepath string) error
- func ErrCueLookup(err error) error
- func ErrDecodeYaml(err error) error
- func ErrExpectedTypeMismatch(err error, expectedType string) error
- func ErrExtractTarXZ(err error, path string) error
- func ErrExtractZip(err error, path string) error
- func ErrFileWalkDir(err error, path string) error
- func ErrGetBool(key string, err error) error
- func ErrGettingLatestReleaseTag(err error) error
- func ErrGoogleJwtInvalid(err error) error
- func ErrGoogleSheetSRV(err error) error
- func ErrInvalidConstructSchemaVersion(contruct string, version string, supportedVersion string) error
- func ErrJsonSchemaToCue(err error) error
- func ErrJsonToCue(err error) error
- func ErrMarshal(err error) error
- func ErrMissingField(err error, missingFieldName string) error
- func ErrOpenFile(file string) error
- func ErrReadDir(err error, dirPath string) error
- func ErrReadFile(err error, filepath string) error
- func ErrReadingLocalFile(err error) error
- func ErrReadingRemoteFile(err error) error
- func ErrRelPath(err error, path string) error
- func ErrRemoteFileNotFound(url string) error
- func ErrTypeCast(err error) error
- func ErrUnmarshal(err error) error
- func ErrUnmarshalInvalid(err error, typ reflect.Type) error
- func ErrUnmarshalSyntax(err error, offset int64) error
- func ErrUnmarshalType(err error, value string) error
- func ErrUnmarshalUnsupportedType(err error, typ reflect.Type) error
- func ErrUnmarshalUnsupportedValue(err error, value reflect.Value) error
- func ErrWriteFile(err error, filepath string) error
- func ErrWritingIntoFile(err error, obj string) error
- func ErrYamlToCue(err error) error
- func ExtractDomainFromURL(location string) string
- func ExtractFile(filePath string, destDir string) error
- func ExtractTarGz(path, downloadfilePath string) error
- func ExtractZip(path, artifactPath string) error
- func Filepath() string
- func FindEntityType(content []byte) (entity.EntityType, error)
- func FindIndexInSlice(key string, col []string) int
- func FormatName(input string) string
- func GetAllVersionDirsSortedDesc(modelVersionsDirPath string) ([]string, error)
- func GetBool(key string) (bool, error)
- func GetHome() string
- func GetLatestReleaseTagsSorted(org string, repo string) ([]string, error)
- func GetNonConcreteFields(val cue.Value) []string
- func GetRandomAlphabetsOfDigit(length int) (s string)
- func Git() (version, commitHead string)
- func IsClosed[K any](ch chan K) bool
- func IsDirectoryNonEmpty(dirPath string) bool
- func IsErrKubeStatusErr(err error) bool
- func IsInterfaceNil(val interface{}) bool
- func IsSchemaEmpty(schema string) (valid bool)
- func IsTarGz(name string) bool
- func IsYaml(name string) bool
- func IsZip(name string) bool
- func JsonSchemaToCue(value string) (cue.Value, error)
- func JsonToCue(value []byte) (cue.Value, error)
- func Lookup(rootVal cue.Value, path string) (cue.Value, error)
- func Marshal(obj interface{}) (string, error)
- func MarshalAndUnmarshal[fromType any, toType any](val fromType) (unmarshalledvalue toType, err error)
- func MergeMaps(mergeInto, toMerge map[string]interface{}) map[string]interface{}
- func MergeToTemplate(tpl []byte, data interface{}) ([]byte, error)
- func NewSheetSRV(cred string) (*sheets.Service, error)
- func NewUUID() (string, error)
- func ParseKubeStatusErr(err *kubeerror.StatusError) (shortDescription, longDescription, probableCause, remedy []string)
- func ProcessContent(filePath string, f func(path string) error) error
- func ReadFileSource(uri string) (string, error)
- func ReadLocalFile(location string) (string, error)
- func ReadRemoteFile(url string) (string, error)
- func ReadSVGData(baseDir, path string) (string, error)
- func RecursiveCastMapStringInterfaceToMapStringInterface(in map[string]interface{}) map[string]interface{}
- func ReplaceSpacesAndConvertToLowercase(s string) string
- func ReplaceSpacesWithHyphenAndConvertToLowercase(s string) string
- func SortDottedStringsByDigits(s []string) []string
- func StrConcat(s ...string) string
- func TcpCheck(hp *HostPort, mock *MockOptions) bool
- func TrackTime(logger logger.Handler, start time.Time, name string)
- func TransformMapKeys(input map[string]interface{}, transformFunc func(string) string) map[string]interface{}
- func Unmarshal(obj string, result interface{}) errordeprecated
- func UpdateSVGString(svgStr string, width, height int, skipHeader bool) (string, error)
- func Validate(schema cue.Value, value cue.Value) (bool, []errors.Error)
- func WriteJSONToFile[K any](outputPath string, data K) error
- func WriteToFile(path string, content string) error
- func WriteYamlToFile[K any](outputPath string, data K) error
- func YAMLToJSON(content []byte) ([]byte, error)
- func YamlToCue(value string) (cue.Value, error)
- type Endpoint
- type HostPort
- type MockOptions
- type TarWriter
Constants ¶
const XMLTAG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg>"
Variables ¶
var ( ErrUnmarshalCode = "meshkit-11159" ErrUnmarshalInvalidCode = "meshkit-11160" ErrUnmarshalSyntaxCode = "meshkit-11161" ErrUnmarshalTypeCode = "meshkit-11162" ErrUnmarshalUnsupportedTypeCode = "meshkit-11163" ErrUnmarshalUnsupportedValueCode = "meshkit-11164" ErrMarshalCode = "meshkit-11165" ErrGetBoolCode = "meshkit-11166" ErrInvalidProtocolCode = "meshkit-11167" ErrRemoteFileNotFoundCode = "meshkit-11168" ErrReadingRemoteFileCode = "meshkit-11169" ErrReadingLocalFileCode = "meshkit-11170" ErrReadFileCode = "meshkit-11171" ErrWriteFileCode = "meshkit-11172" ErrGettingLatestReleaseTagCode = "meshkit-11173" ErrInvalidProtocol = errors.New(ErrInvalidProtocolCode, errors.Alert, []string{"invalid protocol: only http, https and file are valid protocols"}, []string{}, []string{"Network protocol is incorrect"}, []string{"Make sure to specify the right network protocol"}) ErrMissingFieldCode = "meshkit-11174" ErrExpectedTypeMismatchCode = "meshkit-11175" ErrJsonToCueCode = "meshkit-11176" ErrYamlToCueCode = "meshkit-11177" ErrJsonSchemaToCueCode = "meshkit-11178" ErrCueLookupCode = "meshkit-11179" ErrTypeCastCode = "meshkit-11180" ErrCreateFileCode = "meshkit-11181" ErrCreateDirCode = "meshkit-11182" // ErrDecodeYamlCode represents the error which is generated when yaml // decode process fails ErrDecodeYamlCode = "meshkit-11183" ErrExtractTarXZCode = "meshkit-11184" ErrExtractZipCode = "meshkit-11185" ErrReadDirCode = "meshkit-11186" ErrInvalidSchemaVersionCode = "meshkit-11273" ErrFileWalkDirCode = "meshkit-11274" ErrRelPathCode = "meshkit-11275" ErrCopyFileCode = "meshkit-11276" ErrCloseFileCode = "meshkit-11277" ErrCompressToTarGZCode = "meshkit-11248" ErrConvertToByteCode = "meshkit-11187" ErrOpenFileCode = "meshkit-11278" // Google Sheets Service Errors ErrGoogleJwtInvalidCode = "meshkit-11279" ErrGoogleSheetSRVCode = "meshkit-11280" ErrWritingIntoFileCode = "meshkit-11281" )
var ( ErrExtractType = errors.New( ErrUnmarshalTypeCode, errors.Alert, []string{"Invalid extraction type"}, []string{"The file type to be extracted is neither `tar.gz` nor `zip`."}, []string{"Invalid object format. The file is not of type `zip` or `tar.gz`."}, []string{"Make sure to check that the file type is `zip` or `tar.gz`."}, ) ErrInvalidSchemaVersion = errors.New( ErrInvalidSchemaVersionCode, errors.Alert, []string{"Invalid schema version"}, []string{"The `schemaVersion` key is either empty or has an incorrect value."}, []string{"The schema is not of type 'relationship', 'component', 'model' , 'policy'."}, []string{"Verify that `schemaVersion` key should be either `relationships.meshery.io`, `component.meshery.io`, `model.meshery.io` or `policy.meshery.io`."}, ) )
var (
GoogleSpreadSheetURL = "https://docs.google.com/spreadsheets/d/"
)
Functions ¶
func CombineErrors ¶ added in v0.7.12
combineErrors merges a slice of error into one error separated by the given separator
func Contains ¶ added in v0.6.56
func Contains[G []K, K comparable](slice G, ele K) bool
func ConvertMapInterfaceMapString ¶ added in v0.7.68
func ConvertMapInterfaceMapString(v interface{}) interface{}
ConvertMapInterfaceMapString converts map[interface{}]interface{} => map[string]interface{}
It will also convert []interface{} => []string
func ConvertToJSONCompatible ¶ added in v0.7.75
func ConvertToJSONCompatible(data interface{}) interface{}
func CreateDirectory ¶ added in v0.7.12
func CreateFile ¶ added in v0.1.22
CreateFile creates a file with the given content on the given location with the given filename
func DownloadFile ¶
func ErrCloseFile ¶ added in v0.7.47
func ErrCompressToTarGZ ¶ added in v0.7.30
ErrCompressTar is the error for zipping a file into targz
func ErrConvertToByte ¶ added in v0.7.77
func ErrCopyFile ¶ added in v0.7.47
func ErrCreateDir ¶ added in v0.7.12
func ErrCreateFile ¶ added in v0.7.12
func ErrCueLookup ¶ added in v0.5.38
func ErrDecodeYaml ¶ added in v0.7.12
ErrDecodeYaml is the error when the yaml unmarshal fails
func ErrExpectedTypeMismatch ¶ added in v0.5.22
func ErrExtractTarXZ ¶ added in v0.7.12
ErrExtractTarXVZ is the error for unzipping the targz file
func ErrExtractZip ¶ added in v0.7.12
ErrExtractZip is the error for unzipping the zip file
func ErrFileWalkDir ¶ added in v0.7.47
func ErrGetBool ¶
func ErrGettingLatestReleaseTag ¶ added in v0.2.35
func ErrGoogleJwtInvalid ¶ added in v0.8.6
func ErrGoogleSheetSRV ¶ added in v0.8.6
func ErrInvalidConstructSchemaVersion ¶ added in v0.8.17
func ErrJsonSchemaToCue ¶ added in v0.5.33
func ErrJsonToCue ¶ added in v0.5.29
func ErrMarshal ¶
func ErrMissingField ¶ added in v0.5.22
func ErrOpenFile ¶ added in v0.7.75
func ErrReadDir ¶ added in v0.7.12
func ErrReadFile ¶ added in v0.7.3
func ErrReadingLocalFile ¶ added in v0.1.31
func ErrReadingRemoteFile ¶ added in v0.1.31
func ErrRelPath ¶ added in v0.7.47
func ErrRemoteFileNotFound ¶ added in v0.1.31
func ErrTypeCast ¶ added in v0.6.88
func ErrUnmarshal ¶
func ErrUnmarshalInvalid ¶ added in v0.1.25
func ErrUnmarshalSyntax ¶ added in v0.1.25
func ErrUnmarshalType ¶ added in v0.1.25
func ErrUnmarshalUnsupportedType ¶ added in v0.1.25
func ErrUnmarshalUnsupportedValue ¶ added in v0.1.25
func ErrWriteFile ¶ added in v0.7.12
func ErrWritingIntoFile ¶ added in v0.8.9
func ErrYamlToCue ¶ added in v0.5.29
func ExtractDomainFromURL ¶ added in v0.7.15
func ExtractFile ¶ added in v0.7.75
func ExtractTarGz ¶ added in v0.7.12
func ExtractZip ¶ added in v0.7.12
func FindEntityType ¶ added in v0.7.47
func FindEntityType(content []byte) (entity.EntityType, error)
func FindIndexInSlice ¶ added in v0.8.19
func FormatName ¶ added in v0.7.10
FormatName formats the given string to by replacing " " with "-"
func GetAllVersionDirsSortedDesc ¶ added in v0.7.80
Function to get all version directories sorted in descending order
func GetLatestReleaseTagsSorted ¶ added in v0.2.36
Gets the latest stable release tags from github for a given org name and repo name(in that org) in sorted order
func GetNonConcreteFields ¶ added in v0.5.35
func GetRandomAlphabetsOfDigit ¶ added in v0.7.12
func Git ¶
func Git() (version, commitHead string)
git method which allows fetch the git HEAD tag version and commit number
func IsDirectoryNonEmpty ¶ added in v0.7.80
isDirectoryNonEmpty checks if a directory exists and is non-empty
func IsErrKubeStatusErr ¶ added in v0.8.5
checks if the error is of type kubeerror.StatusError
func IsInterfaceNil ¶ added in v0.7.18
func IsInterfaceNil(val interface{}) bool
func IsSchemaEmpty ¶ added in v0.7.26
func MarshalAndUnmarshal ¶ added in v0.6.88
func MergeToTemplate ¶ added in v0.1.28
MergeToTemplate merges data into the template tpl and returns the result.
func NewSheetSRV ¶ added in v0.7.10
func ParseKubeStatusErr ¶ added in v0.8.5
func ParseKubeStatusErr(err *kubeerror.StatusError) (shortDescription, longDescription, probableCause, remedy []string)
ParseKubeStatusErr converts Kubernetes API errors into user-friendly messages
func ProcessContent ¶ added in v0.7.12
func ReadFileSource ¶ added in v0.1.31
ReadFileSource supports "http", "https" and "file" protocols. it takes in the location as a uri and returns the contents of file as a string.
func ReadLocalFile ¶ added in v0.1.31
ReadLocalFile takes in the location of a local file in the format `file://location/of/file` and returns the content of the file if the path is valid and no error occurs
func ReadRemoteFile ¶ added in v0.1.24
ReadRemoteFile takes in the location of a remote file in the format 'http://location/of/file' or 'https://location/file' and returns the content of the file if the location is valid and no error occurs
func ReadSVGData ¶ added in v0.7.75
Convert path to svg Data
func RecursiveCastMapStringInterfaceToMapStringInterface ¶ added in v0.7.68
func RecursiveCastMapStringInterfaceToMapStringInterface(in map[string]interface{}) map[string]interface{}
RecursiveCastMapStringInterfaceToMapStringInterface will convert a map[string]interface{} recursively => map[string]interface{}
func ReplaceSpacesAndConvertToLowercase ¶ added in v0.7.14
func ReplaceSpacesWithHyphenAndConvertToLowercase ¶ added in v0.7.80
func SortDottedStringsByDigits ¶ added in v0.2.36
SortDottedStringsByDigits takes version-like dot separated digits in string format and returns them in sorted normalized form. Takes [v1.4.3,0.9.3,v0.0.0]=> returns [v0.0.0,0.9.3,v1.4.3] This function ignores all letters except for: - numeric digits - alpha, beta, rc, stable For the same version, stable is preferred over edge
func TcpCheck ¶
func TcpCheck(hp *HostPort, mock *MockOptions) bool
func TransformMapKeys ¶ added in v0.5.36
func TransformMapKeys(input map[string]interface{}, transformFunc func(string) string) map[string]interface{}
transforms the keys of a Map recursively with the given transform function
func UpdateSVGString ¶ added in v0.7.13
UpdateSVGString updates the width and height attributes of an SVG file and returns the modified SVG as a string.
func WriteJSONToFile ¶ added in v0.7.12
func WriteToFile ¶ added in v0.7.10
WriteToFile writes the given content to the given file path
func WriteYamlToFile ¶ added in v0.7.44
func YAMLToJSON ¶ added in v0.7.75
Types ¶
type MockOptions ¶ added in v0.2.7
type MockOptions struct {
DesiredEndpoint string
}
type TarWriter ¶ added in v0.7.30
func NewTarWriter ¶ added in v0.7.30
func NewTarWriter() *TarWriter