utils

package
v0.5.15 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperatorURL = baseConfigURL + "manifests/default.yaml"
	BrokerURL   = baseConfigURL + "samples/meshery_v1alpha1_broker.yaml"
	MeshsyncURL = baseConfigURL + "samples/meshery_v1alpha1_meshsync.yaml"

	// Meshery Server Location
	EndpointProtocol = "http"
)

Variables

View Source
var (
	// ResetFlag indicates if a reset is required
	ResetFlag bool
	// SkipResetFlag indicates if fetching the updated manifest files is required
	SkipResetFlag bool
	// MesheryEndpoint is the default URL in which Meshery is exposed
	MesheryEndpoint = "http://localhost:9081"
	// MesheryFolder is the default relative location of the meshery config
	// related configuration files.
	MesheryFolder = ".meshery"
	// DockerComposeFile is the default location within the MesheryFolder
	// where the docker compose file is located.
	DockerComposeFile = "meshery.yaml"
	// AuthConfigFile is the location of the auth file for performing perf testing
	AuthConfigFile = "auth.json"
	// DefaultConfigPath is the detail path to mesheryctl config
	DefaultConfigPath = "config.yaml"
	// MesheryNamespace is the namespace to which Meshery is deployed in the Kubernetes cluster
	MesheryNamespace = "meshery"
	// MesheryDeployment is the name of a Kubernetes manifest file required to setup Meshery
	// check https://github.com/layer5io/meshery/tree/master/install/deployment_yamls/k8s
	MesheryDeployment = "meshery-deployment.yaml"
	// MesheryService is the name of a Kubernetes manifest file required to setup Meshery
	// check https://github.com/layer5io/meshery/tree/master/install/deployment_yamls/k8s
	MesheryService = "meshery-service.yaml"
	//MesheryOperator is the file for default Meshery operator
	//check https://github.com/layer5io/meshery-operator/blob/master/config/manifests/default.yaml
	MesheryOperator = "default.yaml"
	//MesheryOperatorBroker is the file for the Meshery broker
	//check https://github.com/layer5io/meshery-operator/blob/master/config/samples/meshery_v1alpha1_broker.yaml
	MesheryOperatorBroker = "meshery_v1alpha1_broker.yaml"
	//MesheryOperatorMeshsync is the file for the Meshery Meshsync Operator
	//check https://github.com/layer5io/meshery-operator/blob/master/config/samples/meshery_v1alpha1_meshsync.yaml
	MesheryOperatorMeshsync = "meshery_v1alpha1_meshsync.yaml"
	// ServiceAccount is the name of a Kubernetes manifest file required to setup Meshery
	// check https://github.com/layer5io/meshery/tree/master/install/deployment_yamls/k8s
	ServiceAccount = "service-account.yaml"
	// ViperCompose is an instance of viper for docker-compose
	ViperCompose = viper.New()
	// ViperDocker is an instance of viper for the meshconfig file when the platform is docker
	ViperDocker = viper.New()
	// ViperK8s is an instance of viper for the meshconfig file when the platform is kubernetes
	ViperK8s = viper.New()
	// SilentFlag skips waiting for user input and proceeds with default options
	SilentFlag bool
	// PlatformFlag sets the platform for the initial config file
	PlatformFlag string
)
View Source
var ListOfAdapters = []string{"meshery-istio", "meshery-linkerd", "meshery-consul", "meshery-nsm", "meshery-kuma", "meshery-cpx", "meshery-osm", "meshery-traefik-mesh"}

ListOfAdapters returns the list of adapters available

View Source
var (
	// ManifestsFolder is where the Kubernetes manifests are stored
	ManifestsFolder = "manifests"
)
View Source
var TemplateContext = config.Context{
	Endpoint: EndpointProtocol + "://localhost:9081",
	Token:    "Default",
	Platform: "docker",
	Adapters: ListOfAdapters,
	Channel:  "stable",
	Version:  "latest",
}

TemplateContext is the template context provided when creating a config file

View Source
var TemplateToken = config.Token{
	Name:     "Default",
	Location: AuthConfigFile,
}

TemplateToken is the template token provided when creating a config file

Functions

func AddAuthDetails

func AddAuthDetails(req *http.Request, filepath string) error

AddAuthDetails Adds authentication cookies to the request

func AddContextToConfig added in v0.5.1

func AddContextToConfig(contextName string, context config.Context, configPath string, set bool) error

AddContextToConfig adds context passed to it to mesheryctl config file

func AddTokenToConfig added in v0.5.2

func AddTokenToConfig(token config.Token, configPath string) error

AddTokenToConfig adds token passed to it to mesheryctl config file

func ApplyManifest added in v0.5.2

func ApplyManifest(manifest []byte, client *meshkitkube.Client, update bool, delete bool) error

ApplyManifest is a wrapper function for client.ApplyManifest

func ApplyManifestFiles added in v0.5.2

func ApplyManifestFiles(manifestArr []Manifest, requestedAdapters []string, client *meshkitkube.Client, update bool, delete bool) error

ApplyManifestFiles applies/updates/deletes all the required manifests into the Kubernetes cluster

func ApplyOperatorManifest added in v0.5.12

func ApplyOperatorManifest(client *meshkitkube.Client, update bool, delete bool) error

ApplyOperatorManifest applies/updates/deletes the operator manifest

func AskForConfirmation added in v0.5.1

func AskForConfirmation(s string) bool

AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user.

func AskForInput added in v0.5.15

func AskForInput(prompt string, allowed []string) string

AskForInput asks the user for an input and checks if it is in the available values

func ChangeConfigEndpoint added in v0.5.14

func ChangeConfigEndpoint(currCtx string, ctx config.Context) error

ChangeConfigEndpoint changes the endpoint of the current context in meshconfig, based on the platform

func ChangeManifestVersion added in v0.5.3

func ChangeManifestVersion(fileName string, version string, filePath string) error

ChangeManifestVersion changes the tag of the images in the manifest according to the pinned version

func CheckK8sVersion added in v0.5.3

func CheckK8sVersion(versionInfo *version.Info) error

func CheckKubectlVersion added in v0.5.3

func CheckKubectlVersion() error

CheckKubectlVersion validates whether the installed kubectl version is running a minimum kubectl version.

func CleanPodNames added in v0.5.13

func CleanPodNames(name string) string

CleanPodNames cleans the pod names in the MesheryNamespace to make it more readable

func ContentTypeIsHTML added in v0.3.18

func ContentTypeIsHTML(resp *http.Response) bool

ContentTypeIsHTML Checks if the response is an HTML resposnse

func CreateConfigFile added in v0.5.1

func CreateConfigFile() error

CreateConfigFile creates config file in Meshery Folder

func CreateManifestsFolder added in v0.5.13

func CreateManifestsFolder() error

CreateManifestsFolder creates a new folder (.meshery/manifests)

func DownloadDockerComposeFile added in v0.5.1

func DownloadDockerComposeFile(ctx config.Context, force bool) error

DownloadDockerComposeFile fetches docker-compose.yaml based on passed context if it does not exists. Use force to override download anyway

func DownloadFile

func DownloadFile(filepath string, url string) error

DownloadFile from url and save to configured file location

func DownloadManifests added in v0.5.1

func DownloadManifests(manifestArr []Manifest, rawManifestsURL string) error

DownloadManifests downloads all the Kubernetes manifest files

func DownloadOperatorManifest added in v0.5.13

func DownloadOperatorManifest() error

DownloadOperatorManifest downloads the operator manifest files

func GenerateConfigAKS added in v0.5.1

func GenerateConfigAKS(configPath, resourceGroup, clusterName string) error

GenerateConfigAKS generates kube config file in ~/.meshery/kubeconfig.yaml for a AKS cluster

func GenerateConfigEKS added in v0.5.1

func GenerateConfigEKS(configPath, region, cluster string) error

GenerateConfigEKS generates kube config file in .meshery/kubeconfig.yaml for an EKS cluster

func GenerateConfigGKE

func GenerateConfigGKE(configPath, SAName, namespc string) error

GenerateConfigGKE generates kube config file in ~/.meshery/kubeconfig.yaml for a GKE cluster

func GenerateConfigMinikube

func GenerateConfigMinikube(configPath string) error

GenerateConfigMinikube generates kube config file in ~/.meshery/kubeconfig.yaml for a Minikube cluster

func GetK8sVersionInfo added in v0.5.3

func GetK8sVersionInfo() (*version.Info, error)

GetK8sVersionInfo returns version.Info for the Kubernetes cluster.

func GetLatestStableReleaseTag added in v0.5.1

func GetLatestStableReleaseTag() (string, error)

GetLatestStableReleaseTag fetches and returns the latest release tag from GitHub

func GetManifestTreeURL added in v0.5.2

func GetManifestTreeURL(version string) (string, error)

GetManifestTreeURL returns the manifest tree url based on version

func GetManifestURL added in v0.5.1

func GetManifestURL(manifest Manifest, rawManifestsURL string) string

GetManifestURL returns the URLs for the manifest files

func GetPods added in v0.5.13

func GetPods(client *meshkitkube.Client, namespace string) (*v1core.PodList, error)

GetPods lists all the available pods in the MesheryNamespace

func GetRequiredPods added in v0.5.13

func GetRequiredPods(specifiedPods []string, availablePods []v1core.Pod) ([]string, error)

GetRequiredPods checks if the pods specified by the user is valid returns a list of the required pods

func InstallprereqDocker added in v0.5.12

func InstallprereqDocker() error

func IsAdapterValid added in v0.5.1

func IsAdapterValid(manifestArr []Manifest, adapterManifest string) bool

IsAdapterValid checks if the adapter mentioned by the user is a valid adapter

func IsMesheryRunning

func IsMesheryRunning(currPlatform string) (bool, error)

IsMesheryRunning checks if the meshery server containers are up and running

func IsPodRequired added in v0.5.13

func IsPodRequired(requiredPods []string, pod string) bool

IsPodRequired checks if a given pod is specified in the required pods

func IsValidSubcommand

func IsValidSubcommand(available []*cobra.Command, sub string) bool

IsValidSubcommand checks if the passed subcommand is supported by the parent command

func NavigateToBrowser(endpoint string) error

NavigateToBroswer naviagtes to the endpoint displaying Meshery UI in the broswer, based on the host operating system.

func PerfError

func PerfError(msg string) string

PerfError returns a formatted error message with a link to 'perf' command usage page at in addition to the error message

func PrintToTable added in v0.5.2

func PrintToTable(header []string, data [][]string)

PrintToTable prints the given data into a table format

func PrintToTableWithFooter added in v0.5.11

func PrintToTableWithFooter(header []string, data [][]string, footer []string)

PrintToTableWithFooter prints the given data into a table format but with a footer

func ReadToken added in v0.5.11

func ReadToken(filepath string) (map[string]string, error)

ReadToken returns a map of the token passed in

func RootError

func RootError(msg string) string

RootError returns a formatted error message with a link to 'root' command usage page at in addition to the error message

func SafeClose

func SafeClose(co io.Closer)

SafeClose is a helper function help to close the io

func SetFileLocation

func SetFileLocation() error

SetFileLocation to set absolute path

func Startdockerdaemon added in v0.5.12

func Startdockerdaemon(subcommand string) error

func StringContainedInSlice added in v0.5.13

func StringContainedInSlice(str string, slice []string) int

StringContainedInSlice returns the index in which a string is a substring in a list of strings

func StringInSlice added in v0.5.15

func StringInSlice(str string, slice []string) bool

StringInSlice checks if a string is present in a slice

func StringWithCharset

func StringWithCharset(length int) string

StringWithCharset generates a random string with a given length

func SystemError

func SystemError(msg string) string

SystemError returns a formatted error message with a link to 'system' command usage page in addition to the error message

func TruncateID added in v0.5.11

func TruncateID(id string) string

TruncateID shortens an id to 8 characters

func UpdateAuthDetails

func UpdateAuthDetails(filepath string) error

UpdateAuthDetails checks gets the token (old/refreshed) from meshery server and writes it back to the config file

func UpdateMesheryContainers added in v0.5.1

func UpdateMesheryContainers() error

UpdateMesheryContainers runs the update command for meshery client

func UploadFileWithParams

func UploadFileWithParams(uri string, params map[string]string, paramName, path string) (*http.Request, error)

UploadFileWithParams returns a request configured to upload files with other values

func ValidateURL added in v0.5.1

func ValidateURL(URL string) error

ValidateURL validates url provided for meshery backend to mesheryctl context

Types

type Containers added in v0.5.3

type Containers struct {
	Env       interface{}      `yaml:"env,omitempty"`
	Image     string           `yaml:"image,omitempty"`
	Name      string           `yaml:"name,omitempty"`
	Ports     []map[string]int `yaml:"ports,omitempty"`
	Resources interface{}      `yaml:"resources,omitempty"`
}

type DockerCompose added in v0.5.1

type DockerCompose struct {
	Version  string             `yaml:"version,omitempty"`
	Services map[string]Service `yaml:"services,omitempty"`
	Volumes  Volumes            `yaml:"volumes,omitempty"`
}

type K8sCompose added in v0.5.3

type K8sCompose struct {
	APIVersion interface{} `yaml:"apiVersion,omitempty"`
	Kind       string      `yaml:"kind,omitempty"`
	Metadata   interface{} `yaml:"metadata,omitempty"`
	Spec       Spec        `yaml:"spec,omitempty"`
	Status     interface{} `yaml:"status,omitempty"`
}

type Manifest added in v0.5.1

type Manifest struct {
	Path string      `json:"path,omitempty"`
	Mode string      `json:"mode,omitempty"`
	Typ  string      `json:"type,omitempty"`
	SHA  string      `json:"sha,omitempty"`
	Size json.Number `json:"size,omitempty"`
	URL  string      `json:"url,omitempty"`
}

func FetchManifests added in v0.5.2

func FetchManifests(version string) ([]Manifest, error)

FetchManifests is a wrapper function that identifies the required manifest files as downloads them

func ListManifests added in v0.5.1

func ListManifests(url string) ([]Manifest, error)

ListManifests lists the manifest files stored in GitHub

type ManifestList added in v0.5.1

type ManifestList struct {
	SHA       string     `json:"sha,omitempty"`
	URL       string     `json:"url,omitempty"`
	Tree      []Manifest `json:"tree,omitempty"`
	Truncated bool       `json:"truncated,omitempty"`
}

type OnlyStringFormatterForLogrus added in v0.5.1

type OnlyStringFormatterForLogrus struct{}

OnlyStringFormatterForLogrus is a custom logrus formatter that returns only string of message as output

func (OnlyStringFormatterForLogrus) Format added in v0.5.1

func (obj OnlyStringFormatterForLogrus) Format(entry *logrus.Entry) ([]byte, error)

Format defined the format of output for Logrus logs

type Service added in v0.5.1

type Service struct {
	Image       string   `yaml:"image,omitempty"`
	Labels      []string `yaml:"labels,omitempty"`
	Environment []string `yaml:"environment,omitempty"`
	Volumes     []string `yaml:"volumes,omitempty"`
	Ports       []string `yaml:"ports,omitempty"`
}

type Spec added in v0.5.3

type Spec struct {
	Replicas int         `yaml:"replicas,omitempty"`
	Selector interface{} `yaml:"selector,omitempty"`
	Strategy interface{} `yaml:"strategy,omitempty"`
	Template Template    `yaml:"template,omitempty"`
}

type Template added in v0.5.3

type Template struct {
	Metadata interface{}  `yaml:"metadata,omitempty"`
	Spec     TemplateSpec `yaml:"spec,omitempty"`
}

type TemplateSpec added in v0.5.3

type TemplateSpec struct {
	ServiceAccount string       `yaml:"serviceAccount,omitempty"`
	Containers     []Containers `yaml:"containers,omitempty"`
	RestartPolicy  string       `yaml:"restartPolicy,omitempty"`
}

type Volumes added in v0.5.1

type Volumes struct {
	MesheryConfig interface{} `yaml:"meshery-config,omitempty"`
}

Jump to

Keyboard shortcuts

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