utils

package
v0.0.0-...-c8bc4d7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 29 Imported by: 3

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

This section is empty.

Variables

View Source
var (
	ErrUnmarshalCode                 = "11043"
	ErrUnmarshalInvalidCode          = "11044"
	ErrUnmarshalSyntaxCode           = "11045"
	ErrUnmarshalTypeCode             = "11046"
	ErrUnmarshalUnsupportedTypeCode  = "11047"
	ErrUnmarshalUnsupportedValueCode = "11048"
	ErrMarshalCode                   = "11049"
	ErrGetBoolCode                   = "11050"
	ErrInvalidProtocolCode           = "11051"
	ErrRemoteFileNotFoundCode        = "11052"
	ErrReadingRemoteFileCode         = "11053"
	ErrReadingLocalFileCode          = "11054"
	ErrGettingLatestReleaseTagCode   = "11055"
	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              = "11076"
	ErrExpectedTypeMismatchCode      = "11079"
	ErrJsonToCueCode                 = "11085"
	ErrYamlToCueCode                 = "11086"
	ErrJsonSchemaToCueCode           = "11087"
	ErrCueLookupCode                 = "11089"
)

Functions

func Contains

func Contains[G []K, K comparable](slice G, ele K) bool

func CreateFile

func CreateFile(contents []byte, filename string, location string) error

CreateFile creates a file with the given content on the given location with the given filename

func DownloadFile

func DownloadFile(filepath string, url string) error

func ErrCueLookup

func ErrCueLookup(err error) error

func ErrExpectedTypeMismatch

func ErrExpectedTypeMismatch(err error, expectedType string) error

func ErrGetBool

func ErrGetBool(key string, err error) error

func ErrGettingLatestReleaseTag

func ErrGettingLatestReleaseTag(err error) error

func ErrJsonSchemaToCue

func ErrJsonSchemaToCue(err error) error

func ErrJsonToCue

func ErrJsonToCue(err error) error

func ErrMarshal

func ErrMarshal(err error) error

func ErrMissingField

func ErrMissingField(err error, missingFieldName string) error

func ErrReadingLocalFile

func ErrReadingLocalFile(err error) error

func ErrReadingRemoteFile

func ErrReadingRemoteFile(err error) error

func ErrRemoteFileNotFound

func ErrRemoteFileNotFound(url string) error

func ErrUnmarshal

func ErrUnmarshal(err error) error

func ErrUnmarshalInvalid

func ErrUnmarshalInvalid(err error, typ reflect.Type) error

func ErrUnmarshalSyntax

func ErrUnmarshalSyntax(err error, offset int64) error

func ErrUnmarshalType

func ErrUnmarshalType(err error, value string) error

func ErrUnmarshalUnsupportedType

func ErrUnmarshalUnsupportedType(err error, typ reflect.Type) error

func ErrUnmarshalUnsupportedValue

func ErrUnmarshalUnsupportedValue(err error, value reflect.Value) error

func ErrYamlToCue

func ErrYamlToCue(err error) error

func Filepath

func Filepath() string

func GetBool

func GetBool(key string) (bool, error)

getBool function returns the boolean config data

func GetHome

func GetHome() string

GetHome returns the home path

func GetLatestReleaseTagsSorted

func GetLatestReleaseTagsSorted(org string, repo string) ([]string, error)

Gets the latest stable release tags from github for a given org name and repo name(in that org) in sorted order

func GetNonConcreteFields

func GetNonConcreteFields(val cue.Value) []string

func Git

func Git() (version, commitHead string)

git method which allows fetch the git HEAD tag version and commit number

func JsonSchemaToCue

func JsonSchemaToCue(value string) (cue.Value, error)

func JsonToCue

func JsonToCue(value []byte) (cue.Value, error)

func Lookup

func Lookup(rootVal cue.Value, path string) (cue.Value, error)

func Marshal

func Marshal(obj interface{}) (string, error)

func MergeToTemplate

func MergeToTemplate(tpl []byte, data interface{}) ([]byte, error)

MergeToTemplate merges data into the template tpl and returns the result.

func NewUUID

func NewUUID() (string, error)

func ReadFileSource

func ReadFileSource(uri string) (string, error)

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

func ReadLocalFile(location string) (string, error)

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

func ReadRemoteFile(url string) (string, error)

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 SortDottedStringsByDigits

func SortDottedStringsByDigits(s []string) []string

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 StrConcat

func StrConcat(s ...string) string

func TcpCheck

func TcpCheck(hp *HostPort, mock *MockOptions) bool

func TransformMapKeys

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 Unmarshal

func Unmarshal(obj string, result interface{}) error

unmarshal returns parses the JSON config data and stores the value in the reference to result

func Validate

func Validate(schema cue.Value, value cue.Value) (bool, []errors.Error)

func YamlToCue

func YamlToCue(value string) (cue.Value, error)

Types

type Endpoint

type Endpoint struct {
	Name     string
	Internal *HostPort
	External *HostPort
}

Endpoint represents the structure for an endpoint

type HostPort

type HostPort struct {
	Address string
	Port    int32
}

type MockOptions

type MockOptions struct {
	DesiredEndpoint string
}

Directories

Path Synopsis
Package broadcast implements multi-listener broadcast channels.
Package broadcast implements multi-listener broadcast channels.

Jump to

Keyboard shortcuts

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