utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package utils adding package comment to satisfy linters

Index

Constants

View Source
const (
	// DefaultLockTimeout is the default time waiting on the filelock
	DefaultLockTimeout = 10 * time.Minute
)

Variables

This section is empty.

Functions

func CheckKubernetesUpgradeCompatibility

func CheckKubernetesUpgradeCompatibility(fromVersion, toVersion string) bool

CheckKubernetesUpgradeCompatibility checks if a tkg cluster with a k8s version can be upgraded to another version. Updrading operations is not supported if the gap between the minor versions is larger than 1. For example upgrading from v1.17.9 to v1.19.1 is not supported. The behavior of this function may be changed in the future, if the upstream supports upgrading between versions with larger gaps.

func CompareMajorMinorPatchVersion

func CompareMajorMinorPatchVersion(version1, version2 string) bool

CompareMajorMinorPatchVersion returns true if major/minor/patch parts of the versions match, else false

func CompareVMwareVersionStrings

func CompareVMwareVersionStrings(v1, v2 string) (int, error)

CompareVMwareVersionStrings compares vmware aware versions

func ContainsString

func ContainsString(arr []string, str string) bool

ContainsString checks the string contains in string array

func CopyFile

func CopyFile(sourceFile, destFile string) error

CopyFile copies source file to dest file

func CopyToTempFile

func CopyToTempFile(sourceFile, tempFilePrefix string) (string, error)

CopyToTempFile creates temp file and copies the sourcefile to created temp file

func CreateTempFile

func CreateTempFile(dir, prefix string) (string, error)

CreateTempFile creates temporary file

func DeleteFile

func DeleteFile(filePath string) error

DeleteFile deletes the file from given location

func DivideVPCCidr

func DivideVPCCidr(cidrStr string, extendedBits, numSubnets int) ([]string, error)

DivideVPCCidr divide VPC cidr as per extendedBits and number of subnets needed

func FixKubeConfigForMacEnvironment

func FixKubeConfigForMacEnvironment(dockerContext context.Context, cli *client.Client, kubeconfigBytes []byte) ([]byte, error)

FixKubeConfigForMacEnvironment fix api server endpoint

func GenerateRandomID

func GenerateRandomID(length int, excludeCapitalLetters bool) string

GenerateRandomID generates random string

func GetClusterInfoFromCluster

func GetClusterInfoFromCluster(clusterAPIServerURL string) (*clientcmdapi.Cluster, error)

GetClusterInfoFromCluster gets the cluster Info by accessing the cluster-info configMap in kube-public namespace

func GetClusterNameFromKubeconfigAndContext

func GetClusterNameFromKubeconfigAndContext(kubeConfigPath, context string) (string, error)

GetClusterNameFromKubeconfigAndContext gets name of the cluster from kubeconfig file and kube-context

func GetClusterServerFromKubeconfigAndContext

func GetClusterServerFromKubeconfigAndContext(kubeConfigPath, context string) (string, error)

GetClusterServerFromKubeconfigAndContext gets apiserver URL of the cluster from kubeconfig file and kube-context

func GetFileLockWithTimeOut

func GetFileLockWithTimeOut(lockPath string, lockDuration time.Duration) (*fslock.Lock, error)

GetFileLockWithTimeOut returns a file lock with timeout

func GetTKGBoMTagFromFileName

func GetTKGBoMTagFromFileName(fileName string) string

GetTKGBoMTagFromFileName gets BOM Tag from filename

func GetTKRVersionFromTKRName

func GetTKRVersionFromTKRName(tkrName string) string

GetTKRVersionFromTKRName gets TKr version from TKr name

func GetTkrNameFromTkrVersion

func GetTkrNameFromTkrVersion(tkrVersion string) string

GetTkrNameFromTkrVersion gets TKr name from TKr version

func IsOnWindows

func IsOnWindows() bool

IsOnWindows returns true if running on a Windows machine.

func IsValidURL

func IsValidURL(s string) bool

IsValidURL validates urls

func ReplaceSpecialChars

func ReplaceSpecialChars(str string) string

ReplaceSpecialChars replaces special character in string

func ReplaceVersionInDockerImage

func ReplaceVersionInDockerImage(image, newVersion string) (string, error)

ReplaceVersionInDockerImage replaces version in existing docker image with a new version. This simply replaces the tag in REGISTRY[:PORT]/REPO/MORE/PATH/ELEMENTS/IMAGE[:TAG]

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts string to SnakeCase with all upper case letters

func WriteToFile

func WriteToFile(sourceFile string, data []byte) error

WriteToFile writes byte data to file

Types

type PinnipedConfigMapInfo

type PinnipedConfigMapInfo struct {
	Kind    string `json:"kind" yaml:"kind"`
	Version string `json:"apiVersion" yaml:"apiVersion"`
	Data    struct {
		ClusterName    string `json:"cluster_name" yaml:"cluster_name"`
		Issuer         string `json:"issuer" yaml:"issuer"`
		IssuerCABundle string `json:"issuer_ca_bundle_data" yaml:"issuer_ca_bundle_data"`
	}
}

PinnipedConfigMapInfo defines the fields of pinniped-info configMap

func GetPinnipedInfoFromCluster

func GetPinnipedInfoFromCluster(clusterInfo *clientcmdapi.Cluster) (*PinnipedConfigMapInfo, error)

GetPinnipedInfoFromCluster gets the Pinniped Info by accessing the pinniped-info configMap in kube-public namespace

Jump to

Keyboard shortcuts

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