common

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DisableLocalExecutionFlag is the name of the flag that tells us whether to use allow execution of executables locally
	DisableLocalExecutionFlag = "disable-local-execution"
	// FailOnEmptyPlan is the name of the flag that lets the user fail when the plan is empty (zero services, zero default transformers).
	FailOnEmptyPlan = "fail-on-empty-plan"
)
View Source
const (
	// DefaultProjectName represents the short app name
	DefaultProjectName = "myproject"
	// VolumePrefix defines the prefix to be used for volumes
	VolumePrefix = "vol"
	// DefaultDirectoryPermission defines the default permission used when a directory is created
	DefaultDirectoryPermission os.FileMode = 0755
	// DefaultExecutablePermission defines the default permission used when an executable file is created
	DefaultExecutablePermission os.FileMode = 0744
	// DefaultFilePermission defines the default permission used when a non-executable file is created
	DefaultFilePermission os.FileMode = 0644
	// QACacheFile defines the location of the QA cache file
	QACacheFile = types.AppNameShort + "qacache.yaml"
	// ConfigFile defines the location of the config file
	ConfigFile = types.AppNameShort + "config.yaml"
	// IgnoreFilename is the name of the file containing the ignore rules and exceptions
	IgnoreFilename = "." + types.AppNameShort + "ignore"
	// WindowsAnnotation tag is used tag a service to run on windows nodes
	WindowsAnnotation = types.GroupName + "/containertype.windows"
	// AnnotationLabelValue represents the value when an annotation is valid
	AnnotationLabelValue = "true"
	// DefaultServicePort is the default port that will be added to a service.
	DefaultServicePort int32 = 8080
	// TODOAnnotation is used to annotate with TODO tasks
	TODOAnnotation = types.GroupName + "/todo."
	// ShExt is the extension of sh file
	ShExt = ".sh"
	// BatExt is the extension of bat file
	BatExt = ".bat"
	// RemoteSourcesFolder stores remote sources
	RemoteSourcesFolder = "m2ksources"
	// RemoteCustomizationsFolder stores remote customizations
	RemoteCustomizationsFolder = "m2kcustomizations"
	// RemoteOutputsFolder stores remote outputs
	RemoteOutputsFolder = "m2koutputs"
)
View Source
const (
	// Delim is the delimiter used to separate key segments
	Delim = "."
	// Special is the special case indicator of the multi-select problems
	Special = "[]"
	// MatchAll is used to set the default for a set of keys. Example: move2kube.services.*.ports=[8080]
	MatchAll = "*"

	// BaseKey is the prefix for every key
	BaseKey = types.AppName
	//TransformerSelectorKey represents transformers selector Key
	TransformerSelectorKey = BaseKey + d + "transformerselector"
	//ConfigServicesKey represents Services Key
	ConfigServicesKey = BaseKey + d + "services"
	//ConfigStoragesKey represents Storages Key
	ConfigStoragesKey = BaseKey + d + "storages"
	//ConfigMinReplicasKey represents Ingress host Key
	ConfigMinReplicasKey = BaseKey + d + "minreplicas"
	//ConfigDeploymentTypeKey represents which type of Deployment should be generated
	ConfigDeploymentTypeKey = "deployment"
	//ConfigPortsForServiceKeySegment represents the ports used for service
	ConfigPortsForServiceKeySegment = "ports"
	//ConfigPortForServiceKeySegment represents the port used for service
	ConfigPortForServiceKeySegment = "port"
	//ConfigMainPythonFileForServiceKeySegment represents the main file used for service
	ConfigMainPythonFileForServiceKeySegment = "pythonmainfile"
	//ConfigStartingPythonFileForServiceKeySegment represents the starting python file used for service
	ConfigStartingPythonFileForServiceKeySegment = "pythonstartingfile"
	//ConfigCsprojFileForServiceKeySegment represents the csproj file used for service
	ConfigCsprojFileForServiceKeySegment = "csprojfile"
	//ConfigPublishProfileForServiceKeySegment represents the publish profile used for service
	ConfigPublishProfileForServiceKeySegment = "publishprofile"
	//ConfigContainerizationOptionServiceKeySegment represents containerization option to use
	ConfigContainerizationOptionServiceKeySegment = "containerizationoption"
	//ConfigApacheConfFileForServiceKeySegment represents the conf file used for service
	ConfigApacheConfFileForServiceKeySegment = "apacheconfig"
	//ConfigSpawnContainersKey represents spwan containers option Key
	ConfigSpawnContainersKey = BaseKey + d + "spawncontainers"
	//ConfigTransformersKey represents transformers Key
	ConfigTransformersKey = BaseKey + d + "transformers"
	//ConfigTargetKey represents Target Key
	ConfigTargetKey = BaseKey + d + "target"
	//ConfigRepoKey represents Repo Key
	ConfigRepoKey = BaseKey + d + "repo"
	//ConfigContainerizationKeySegment represents Containerization Key segment
	ConfigContainerizationKeySegment = BaseKey + d + "containerization"
	//ConfigRepoKeysKey represents Repo Key
	ConfigRepoKeysKey = ConfigRepoKey + d + "keys"
	//ConfigRepoPubKey represents allow load of public key of repos Key
	ConfigRepoPubKey = ConfigRepoKeysKey + d + "pub"
	//ConfigRepoLoadPubDomainsKey represents allow load of public key per domain of repos Key
	ConfigRepoLoadPubDomainsKey = ConfigRepoPubKey + d + "domain"
	//ConfigRepoLoadPubKey represents allow load of public key of repos Key
	ConfigRepoLoadPubKey = ConfigRepoPubKey + d + "load"
	//ConfigRepoPrivKey represents allow load of private key of repos Key
	ConfigRepoPrivKey = ConfigRepoKeysKey + d + "priv"
	//ConfigRepoLoadPrivKey represents allow load of private key of repos Key
	ConfigRepoLoadPrivKey = ConfigRepoKeysKey + d + "load"
	//ConfigRepoKeyPathsKey represents paths of keyfiles
	ConfigRepoKeyPathsKey = ConfigRepoKeysKey + d + "paths"
	//ConfigTransformerTypesKey represents Transformers type Key
	ConfigTransformerTypesKey = ConfigTransformersKey + d + "types"
	//VolQaPrefixKey represents the storage QA
	VolQaPrefixKey = BaseKey + d + "storage.type"
	//IngressKey represents ingress keyword
	IngressKey = "ingress"
	// ConfigIngressClassNameKeySuffix represents the ingress class name
	ConfigIngressClassNameKeySuffix = IngressKey + d + "ingressclassname"
	//ConfigIngressHostKeySuffix represents Ingress host Key
	ConfigIngressHostKeySuffix = IngressKey + d + "host"
	//ConfigIngressTLSKeySuffix represents ingress tls Key
	ConfigIngressTLSKeySuffix = IngressKey + d + "tls"
	//RouteKey represents route keyword
	RouteKey = "route"
	//TLSKey represents TLS keyword
	TLSKey = "tls"
	//ConfigRouteTLSTerminationPolicy represents the Route's TLS Termination Policy
	ConfigRouteTLSTerminationPolicy = RouteKey + d + TLSKey + d + "terminationpolicy"
	//ConfigRouteTLSKeyKey represents the Route's TLS Key
	ConfigRouteTLSKeyKey = RouteKey + d + TLSKey + d + "key"
	//ConfigRouteTLSCertificateKey represents the Route's TLS Certificate
	ConfigRouteTLSCertificateKey = RouteKey + d + TLSKey + d + "certificate"
	//ConfigTargetClusterTypeKey represents target cluster type key
	ConfigTargetClusterTypeKey = ConfigTargetKey + d + "clustertype"
	//ConfigImageRegistryKey represents image registry Key
	ConfigImageRegistryKey = ConfigTargetKey + d + "imageregistry"
	// ConfigCICDKey is for CICD related questions
	ConfigCICDKey = ConfigTargetKey + d + "cicd"
	// ConfigCICDTektonKey is for CICD Tekton pipelines
	ConfigCICDTektonKey = ConfigCICDKey + d + "tekton"
	// ConfigCICDTektonGitRepoSSHSecretNameKey is for Tekton git-clone ssh
	ConfigCICDTektonGitRepoSSHSecretNameKey = ConfigCICDTektonKey + d + "gitreposshsecret"
	// ConfigCICDTektonGitRepoBasicAuthSecretNameKey is for Tekton git-clone basic auth
	ConfigCICDTektonGitRepoBasicAuthSecretNameKey = ConfigCICDTektonKey + d + "gitrepobasicauthsecret"
	// ConfigCICDTektonRegistryPushSecretNameKey is for Tekton push image to registry credentials
	ConfigCICDTektonRegistryPushSecretNameKey = ConfigCICDTektonKey + d + "registrypushsecret"
	//ConfigTargetExistingVersionUpdate represents key which how to update versions
	ConfigTargetExistingVersionUpdate = ConfigTargetKey + d + "existingversionupdate"
	//ConfigImageRegistryURLKey represents image registry url Key
	ConfigImageRegistryURLKey = ConfigImageRegistryKey + d + "url"
	//ConfigImageRegistryNamespaceKey represents image registry namespace Key
	ConfigImageRegistryNamespaceKey = ConfigImageRegistryKey + d + "namespace"
	//ConfigImageRegistryLoginTypeKey represents image registry login type Key
	ConfigImageRegistryLoginTypeKey = ConfigImageRegistryKey + d + "%s" + d + "logintype"
	//ConfigImageRegistryPullSecretKey represents image registry pull secret Key
	ConfigImageRegistryPullSecretKey = ConfigImageRegistryKey + d + "%s" + d + "pullsecret"
	//ConfigImageRegistryUserNameKey represents image registry login Username Key
	ConfigImageRegistryUserNameKey = ConfigImageRegistryKey + d + "%s" + d + "username"
	//ConfigImageRegistryPasswordKey represents image registry login Password Key
	ConfigImageRegistryPasswordKey = ConfigImageRegistryKey + d + "%s" + d + "password"
	//ConfigStoragesPVCForHostPathKey represents key for PVC for Host Path
	ConfigStoragesPVCForHostPathKey = ConfigStoragesKey + d + "pvcforhostpath"
	//ConfigStoragesPerClaimStorageClassKey represents key for having different storage class for claim
	ConfigStoragesPerClaimStorageClassKey = ConfigStoragesKey + d + "perclaimstorageclass"
	//ConfigServicesNamesKey is true if a detected service is enabled for transformation
	ConfigServicesNamesKey = ConfigServicesKey + d + Special + d + "enable"
	//ConfigContainerizationTypesKey represents source type Key
	ConfigContainerizationTypesKey = ConfigContainerizationKeySegment + d + "types"
	//ConfigServicesExposeKey represents Services Expose Key
	ConfigServicesExposeKey = ConfigServicesKey + d + Special + d + "expose"
	// ConfigActiveMavenProfilesForServiceKeySegment represents the maven profiles used for service
	ConfigActiveMavenProfilesForServiceKeySegment = "activemavenprofiles"
	// ConfigActiveSpringBootProfilesForServiceKeySegment represent the springboot profiles used for service
	ConfigActiveSpringBootProfilesForServiceKeySegment = "activespringbootprofiles"
	// ConfigServicesChildModulesNamesKey is true if a detected child module/sub-project of a service is enabled for transformation
	ConfigServicesChildModulesNamesKey = ConfigServicesKey + d + "%s" + d + "childModules" + d + Special + d + "enable"
	// ConfigServicesDotNetChildProjectsNamesKey is true if a detected child-project of a dot net service is enabled for transformation
	ConfigServicesDotNetChildProjectsNamesKey = ConfigServicesKey + d + "%s" + d + "childProjects" + d + Special + d + "enable"
	// ConfigServicesChildModulesSpringProfilesKey is the list of spring profiles for this child module. 1st arg is service name and 2nd is child module name.
	ConfigServicesChildModulesSpringProfilesKey = ConfigServicesKey + d + "%s" + d + "childModules" + d + "%s" + d + "springBootProfiles"
	// ConfigTransformersKubernetesArgoCDNamespaceKey represents namespace key for argocd transformer
	ConfigTransformersKubernetesArgoCDNamespaceKey = ConfigTransformersKey + d + "kubernetes" + d + "argocd" + d + "namespace"
	// ConfigArgoRolloutTypeKey represents the type of Rollout that should be generated.
	ConfigArgoRolloutTypeKey = "argorollout"
	//VCSKey represents version control system key
	VCSKey = BaseKey + d + "vcs"
	//GitKey represents git qa key
	GitKey = VCSKey + d + "git"
)
View Source
const (
	// DefaultDockerfileName refers to the default Dockerfile name
	DefaultDockerfileName = "Dockerfile"
	// VcapServiceEnvName refers to the VCAP_SERVICES environment variable DefaultDockerfileName
	VcapServiceEnvName = "VCAP_SERVICES"
	// VcapApplicationEnvName refers to the VCAP_APPLICATION environment variable DefaultDockerfileName
	VcapApplicationEnvName = "VCAP_APPLICATION"
	// VcapSpringBootSecretSuffix refers to VCAP springboot secret suffix
	VcapSpringBootSecretSuffix = "-vcapasspringbootproperties"
	// VcapCfSecretSuffix refers to VCAP secret suffix
	VcapCfSecretSuffix = "-vcapasenv"
)
View Source
const (
	// ProjectNameTemplatizedStringKey is the key for denoting project name in a templatized string
	ProjectNameTemplatizedStringKey = "ProjectName"
	// ArtifactNameTemplatizedStringKey is the key for denoting artifact name in a templatized string
	ArtifactNameTemplatizedStringKey = "ArtifactName"
	// ServiceNameTemplatizedStringKey is the key for denoting service name in a templatized string
	ServiceNameTemplatizedStringKey = "ServiceName"
	// ArtifactTypeTemplatizedStringKey is the key for denoting artifact type in a templatized string
	ArtifactTypeTemplatizedStringKey = "ArtifactType"
)
View Source
const (
	// ServiceKind defines Service Kind
	ServiceKind = "Service"
	// DeploymentKind defines Deployment Kind
	DeploymentKind = "Deployment"
	// IngressKind defines Ingress Kind
	IngressKind = "Ingress"
)
View Source
const (
	// DefaultPlanFile is the default name for the plan file
	DefaultPlanFile = types.AppNameShort + ".plan"
	// DefaultConfigFilePath is the default config file path
	DefaultConfigFilePath = types.AppNameShort + "-default-config.yaml"
	// DefaultCustomizationDir is the default path for the customization directory
	DefaultCustomizationDir = types.AppNameShort + "-default-customizations"
	// TempDirPrefix defines the prefix of the temp directory
	TempDirPrefix = types.AppNameShort + "-"
	// AssetsDir defines the dir of the assets temp directory
	AssetsDir = types.AppNameShort + "assets"

	// ScriptsDir defines the directory where the output scripts are placed
	ScriptsDir = "scripts"
	// DefaultSourceDir defines the directory where the source files and folders are placed along with build scripts for each individual image
	DefaultSourceDir = "source"
	// DeployDir defines the directory where the deployment artifacts are placed
	DeployDir = "deploy"
	// CICDDir defines the directory where the deployment artifacts are placed
	CICDDir = "cicd"
	// HelmDir defines the directory where the helm charts are placed
	HelmDir = "helm-charts"
	// OCTemplatesDir defines the directory where the openshift templates are placed
	OCTemplatesDir = "openshift-templates"
)

Variables

View Source
var (
	// DefaultPVCSize stores the default PVC size
	DefaultPVCSize, _ = resource.ParseQuantity("100Mi")
	// IgnoreEnvironment indicates whether to ignore the current environment or not
	IgnoreEnvironment = false
	// DisableLocalExecution indicates whether to allow execution of local executables
	DisableLocalExecution = false
	// DefaultIgnoreDirRegexps specifies directory name regexes that would be ignored
	DefaultIgnoreDirRegexps = []*regexp.Regexp{regexp.MustCompile("^[.].*")}
	// DisabledCategories is a list of QA categories that are disabled
	DisabledCategories = []string{}
	// QACategoryMap maps category names to problem IDs
	QACategoryMap = map[string][]string{}
)
View Source
var (
	// TempPath defines where all app data get stored during execution
	TempPath = TempDirPrefix + "temp"
	// AssetsPath defines where all assets get stored during execution
	AssetsPath = filepath.Join(TempPath, AssetsDir)
	// RemoteTempPath defines where all remote sources data get stored during execution
	RemoteTempPath = TempDirPrefix + "remote-temp"
)
View Source
var PlanProgressNumBaseDetectTransformers = 0

PlanProgressNumBaseDetectTransformers keeps track of the number of transformers that finished base directory detect during planning

View Source
var PlanProgressNumDirectories = 0

PlanProgressNumDirectories keeps track of the number of files/folders analyzed during planning

View Source
var (
	// ProjectName stores the project name during an execution
	ProjectName = DefaultProjectName
)

Functions

func AppendIfNotPresent added in v0.3.3

func AppendIfNotPresent[C comparable](list []C, values ...C) []C

AppendIfNotPresent checks if a value is present in a slice and if not appends it to the slice

func CleanAndFindCommonDirectory

func CleanAndFindCommonDirectory(paths []string) string

CleanAndFindCommonDirectory finds the common ancestor directory among a list of absolute paths. Cleans the paths you give it before finding the directory. Also see FindCommonDirectory

func ConvertInterfaceToSliceOfStrings

func ConvertInterfaceToSliceOfStrings(xI interface{}) ([]string, error)

ConvertInterfaceToSliceOfStrings converts an interface{} to a []string type. It can handle []interface{} as long as all the values are strings.

func ConvertStringSelectorsToSelectors

func ConvertStringSelectorsToSelectors(transformerSelector string) (labels.Selector, error)

ConvertStringSelectorsToSelectors converts selector string to selector object

func ConvertUtf8AndUtf16ToUtf8 added in v0.3.5

func ConvertUtf8AndUtf16ToUtf8(original []byte) ([]byte, error)

ConvertUtf8AndUtf16ToUtf8 converts UTF-8 and UTF-16 encoded text (with or without a BOM) into UTF-8 encoded text (without a BOM)

func CopyEmbedFSToDir

func CopyEmbedFSToDir(embedFS embed.FS, source, dest string, permissions map[string]int) (err error)

CopyEmbedFSToDir converts a string into a directory

func CopyFile

func CopyFile(dst, src string) error

CopyFile copies a file from src to dst. The dst file will be truncated if it exists. Returns an error if it failed to copy all the bytes.

func CreateAssetsData

func CreateAssetsData(assetsFS embed.FS, permissions map[string]int) (assetsPath string, tempPath string, remoteTempPath string, err error)

CreateAssetsData creates an assets directory and dumps the assets data into it

func CreateTarArchiveGZipStringWrapper added in v0.3.5

func CreateTarArchiveGZipStringWrapper(srcPath string) string

CreateTarArchiveGZipStringWrapper can be used to archive a set of files and compression using gzip and return tar archive string

func CreateTarArchiveNoCompressionStringWrapper added in v0.3.5

func CreateTarArchiveNoCompressionStringWrapper(srcPath string) string

CreateTarArchiveNoCompressionStringWrapper can be used to archive a set of files and compression without compression and return tar archive string

func EncryptAesCbcWithPbkdfWrapper added in v0.3.5

func EncryptAesCbcWithPbkdfWrapper(key string, data string) string

EncryptAesCbcWithPbkdfWrapper can be used to encrypt the data using AES 256 CBC mode with Pbkdf key derivation

func EncryptRsaCertWrapper added in v0.3.5

func EncryptRsaCertWrapper(certificate string, data string) string

EncryptRsaCertWrapper can be used to encrypt the data using RSA PKCS1v15 algorithm with certificate as key

func Filter added in v0.3.3

func Filter[T comparable](vs []T, condition func(T) bool) []T

Filter returns the elements that satisfy the condition. It returns nil if none of the elements satisfy the condition.

func FindCommonDirectory

func FindCommonDirectory(paths []string) string

FindCommonDirectory finds the common ancestor directory among a list of cleaned absolute paths. Will not clean the paths you give it before trying to find the directory. Also see CleanAndFindCommonDirectory

func FindIndex added in v0.3.3

func FindIndex[T interface{}](vs []T, condition func(T) bool) int

FindIndex returns the index of the first element that satisfies the condition. It returns -1 if none of the elements satisfy the condition.

func GatherGitInfo

func GatherGitInfo(path string) (repoName, repoDir, repoHostName, repoURL, repoBranch string, err error)

GatherGitInfo tries to find the git repo for the path if one exists.

func GetClosestMatchingString

func GetClosestMatchingString(options []string, searchstring string) string

GetClosestMatchingString returns the closest matching string for a given search string

func GetDefaultContainerRuntime added in v0.3.13

func GetDefaultContainerRuntime() string

GetDefaultContainerRuntime returns the preferred container runtime of the host

func GetFilesByExt

func GetFilesByExt(inputPath string, exts []string) ([]string, error)

GetFilesByExt returns files by extension

func GetFilesByExtInCurrDir

func GetFilesByExtInCurrDir(dir string, exts []string) ([]string, error)

GetFilesByExtInCurrDir returns the files present in current directory which have one of the specified extensions

func GetFilesByName

func GetFilesByName(inputPath string, names []string, nameRegexes []string) ([]string, error)

GetFilesByName returns files by name

func GetFilesInCurrentDirectory

func GetFilesInCurrentDirectory(path string, fileNames, fileNameRegexes []string) (matchedFilePaths []string, err error)

GetFilesInCurrentDirectory returns the name of the file present in the current directory which matches the pattern

func GetImageNameAndTag

func GetImageNameAndTag(image string) (string, string)

GetImageNameAndTag splits an image full name and returns the image name and tag

func GetMapInterfaceFromObj

func GetMapInterfaceFromObj(obj interface{}) (mapobj interface{}, err error)

GetMapInterfaceFromObj converts a struct to map[string]interface{} using yaml marshaller

func GetObjFromInterface

func GetObjFromInterface(obj interface{}, loadinto interface{}) error

GetObjFromInterface loads from map[string]interface{} to struct

func GetRandomString

func GetRandomString() string

GetRandomString generates a random string

func GetRuntimeObjectMetadata

func GetRuntimeObjectMetadata(obj runtime.Object) metav1.ObjectMeta

GetRuntimeObjectMetadata returns the metadata field from a k8s object.

func GetSHA256Hash

func GetSHA256Hash(s string) string

GetSHA256Hash returns the SHA256 hash of the string. The hash is 256 bits/32 bytes and encoded as a 64 char hexadecimal string.

func GetStringFromTemplate

func GetStringFromTemplate(tpl string, config interface{}) (string, error)

GetStringFromTemplate returns string for a template

func GetTypesMap

func GetTypesMap(typeInstances interface{}) (typesMap map[string]reflect.Type)

GetTypesMap returns a type registry for the types in the array

func GetUnixPath

func GetUnixPath(path string) string

GetUnixPath return Unix Path for any path

func GetWindowsPath

func GetWindowsPath(path string) string

GetWindowsPath return Windows Path for any path

func GetYamlsWithTypeMeta added in v0.3.2

func GetYamlsWithTypeMeta(inputPath string, kindFilter string) ([]string, error)

GetYamlsWithTypeMeta returns files by yaml kind

func Interrupt

func Interrupt() error

Interrupt creates SIGINT signal

func IsHTTPURL added in v0.3.9

func IsHTTPURL(str string) bool

IsHTTPURL checks if a string represents an HTTP or HTTPS URL using regular expressions.

func IsParent

func IsParent(child, parent string) bool

IsParent can be used to check if a path is one of the parent directories of another path. Also returns true if the paths are the same.

func IsPresent added in v0.3.3

func IsPresent[C comparable](list []C, value C) bool

IsPresent checks if a value is present in a slice

func IsSameRuntimeObject

func IsSameRuntimeObject(obj1, obj2 runtime.Object) bool

IsSameRuntimeObject returns true if the 2 k8s resources are same. 2 resources are the same if they have the same group, version, kind, namespace and name. Also prints an error if the 2 objects have the same kind, namespace and name but different group versions.

func IsStringPresent

func IsStringPresent(list []string, value string) bool

IsStringPresent is like IsPresent but does case-insensitive comparison of strings

func JoinQASubKeys added in v0.3.3

func JoinQASubKeys(xs ...string) string

JoinQASubKeys joins sub keys into a valid QA key using the proper delimiter

func JsonifyMapValues added in v0.3.8

func JsonifyMapValues(inputMap map[string]interface{}) map[string]interface{}

JsonifyMapValues converts the map values to json

func LookupEnv added in v0.3.6

func LookupEnv(envNameToLookup string, envList []core.EnvVar) (core.EnvVar, bool)

LookupEnv looks for a environment variable in a list of environment variables

func MakeFileNameCompliant

func MakeFileNameCompliant(name string) string

MakeFileNameCompliant returns a DNS-1123 standard string Motivated by https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set Also see page 1 "ASSUMPTIONS" heading of https://tools.ietf.org/html/rfc952 Also see page 13 of https://tools.ietf.org/html/rfc1123#page-13

func MakeStringContainerImageNameCompliant

func MakeStringContainerImageNameCompliant(s string) string

MakeStringContainerImageNameCompliant makes the string into a valid image name.

func MakeStringDNSLabelNameCompliant

func MakeStringDNSLabelNameCompliant(s string) string

MakeStringDNSLabelNameCompliant makes the string a valid DNS label name. See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names 1. contain at most 63 characters 2. contain only lowercase alphanumeric characters or '-' 3. start with an alphanumeric character 4. end with an alphanumeric character

func MakeStringDNSNameCompliant

func MakeStringDNSNameCompliant(s string) string

MakeStringDNSNameCompliant makes the string into a valid DNS name.

func MakeStringDNSNameCompliantWithoutDots added in v0.3.4

func MakeStringDNSNameCompliantWithoutDots(s string) string

MakeStringDNSNameCompliantWithoutDots makes the string into a valid DNS name without dots.

func MakeStringDNSSubdomainNameCompliant

func MakeStringDNSSubdomainNameCompliant(s string) string

MakeStringDNSSubdomainNameCompliant makes the string a valid DNS subdomain name. See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names 1. contain no more than 253 characters 2. contain only lowercase alphanumeric characters, '-' or '.' 3. start with an alphanumeric character 4. end with an alphanumeric character

func MakeStringEnvNameCompliant

func MakeStringEnvNameCompliant(s string) string

MakeStringEnvNameCompliant makes the string into a valid Environment variable name.

func MakeStringK8sServiceNameCompliant added in v0.3.4

func MakeStringK8sServiceNameCompliant(s string) string

MakeStringK8sServiceNameCompliant makes the string a valid K8s service name. See https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names 1. contain at most 63 characters 2. contain only lowercase alphanumeric characters or '-' 3. start with an alphabetic character 4. end with an alphanumeric character

func Map added in v0.3.3

func Map[T1 interface{}, T2 interface{}](vs []T1, f func(T1) T2) []T2

Map applies the given function over all the elements and returns a new slice with the results.

func MarshalObjToYaml

func MarshalObjToYaml(obj runtime.Object) ([]byte, error)

MarshalObjToYaml marshals an object to yaml

func MergeSlices added in v0.3.3

func MergeSlices[C comparable](slice1 []C, slice2 []C) []C

MergeSlices merges two slices

func MergeStringMaps

func MergeStringMaps(map1 map[string]string, map2 map[string]string) map[string]string

MergeStringMaps merges two string maps

func MergeStringSliceMaps

func MergeStringSliceMaps(map1 map[string][]string, map2 map[string][]string) map[string][]string

MergeStringSliceMaps merges two string slice maps

func NormalizeForEnvironmentVariableName

func NormalizeForEnvironmentVariableName(envName string) string

NormalizeForEnvironmentVariableName converts the string to be compatible for environment variable name convention specified below: https://pubs.opengroup.org/onlinepubs/9699919799/

func NormalizeForFilename

func NormalizeForFilename(name string) string

NormalizeForFilename normalizes a string to only filename valid characters

func NormalizeForMetadataName

func NormalizeForMetadataName(metadataName string) string

NormalizeForMetadataName converts the string to be compatible for service name

func ObjectToYamlBytes

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

ObjectToYamlBytes encodes an object to yaml

func ReadFilesAsTar added in v0.3.5

func ReadFilesAsTar(srcPath, basePath string, compressionType CompressionType) io.ReadCloser

ReadFilesAsTar creates the Tar with given compression format and return ReadCloser interface

func ReadJSON

func ReadJSON(path string, data interface{}) error

ReadJSON reads an json into an object

func ReadMove2KubeYaml

func ReadMove2KubeYaml(path string, out interface{}) error

ReadMove2KubeYaml reads move2kube specific yaml files (like m2k.plan) into an struct. It checks if apiVersion to see if the group is move2kube and also reports if the version is different from the expected version.

func ReadMove2KubeYamlStrict

func ReadMove2KubeYamlStrict(path string, out interface{}, kind string) error

ReadMove2KubeYamlStrict is like ReadMove2KubeYaml but returns an error when it finds unknown fields in the yaml

func ReadXML

func ReadXML(file string, data interface{}) error

ReadXML reads an json into an object

func ReadYaml

func ReadYaml(file string, data interface{}) error

ReadYaml reads an yaml into an object

func ReplaceStartingTerminatingHyphens

func ReplaceStartingTerminatingHyphens(str, startReplaceStr, endReplaceStr string) string

ReplaceStartingTerminatingHyphens replaces the first and last characters of a string if they are hyphens

func ReverseInPlace

func ReverseInPlace[T interface{}](xs []T)

ReverseInPlace reverses a slice in place.

func SplitOnDotExpectInsideQuotes

func SplitOnDotExpectInsideQuotes(s string) []string

SplitOnDotExpectInsideQuotes splits a string on dot. Stuff inside double or single quotes will not be split.

func SplitYAML

func SplitYAML(rawYAML []byte) ([][]byte, error)

SplitYAML splits a file into multiple YAML documents.

func StringToK8sQuantityHookFunc added in v0.3.6

func StringToK8sQuantityHookFunc() mapstructure.DecodeHookFunc

StringToK8sQuantityHookFunc returns a DecodeHookFunc that converts strings to a Kubernetes resource limits quantity.

func StripQuotes

func StripQuotes(s string) string

StripQuotes strips a single layer of double or single quotes from the left and right ends Example: "github.com" -> github.com Example: 'github.com' -> github.com Example: "'github.com'" -> 'github.com'

func UniqueStrings

func UniqueStrings(xs []string) []string

UniqueStrings returns a new slice with only the unique strings from the input slice.

func WriteJSON

func WriteJSON(outputPath string, data interface{}) error

WriteJSON writes an json to disk

func WriteYaml

func WriteYaml(outputPath string, data interface{}) error

WriteYaml writes encodes object as yaml and writes it to a file

func YamlAttrPresent

func YamlAttrPresent(path string, attr string) (bool, interface{})

YamlAttrPresent returns YAML attributes

Types

type CleanupHook

type CleanupHook struct {
	// contains filtered or unexported fields
}

CleanupHook calls the cleanup functions on fatal and panic errors

func NewCleanupHook

func NewCleanupHook(ctxContextFn context.CancelFunc) *CleanupHook

NewCleanupHook creates a cleanup hook

func (*CleanupHook) Fire

func (hook *CleanupHook) Fire(entry *logrus.Entry) error

Fire calls the clean up

func (*CleanupHook) Levels

func (hook *CleanupHook) Levels() []logrus.Level

Levels returns the levels on which the cleanup hook gets called

type CompressionType added in v0.3.5

type CompressionType = string

CompressionType refers to the compression type

const (
	// GZipCompression allows archival using gzip compression format
	GZipCompression CompressionType = "GZip"
	// NoCompression allows archival without compression
	NoCompression CompressionType = "None"
)

type Sortable added in v0.3.13

type Sortable[T any] struct {
	Xs []T
	Ys []int
}

Sortable is an implementation of the sort.Interface interface. This is useful when you want to sort one slice using another slice.

func (*Sortable[T]) Len added in v0.3.13

func (s *Sortable[T]) Len() int

Len is the number of elements in the collection.

func (*Sortable[T]) Less added in v0.3.13

func (s *Sortable[T]) Less(i, j int) bool

Less reports whether the element with index i must sort before the element with index j.

func (*Sortable[T]) Swap added in v0.3.13

func (s *Sortable[T]) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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