utils

package
v0.0.0-...-b25b198 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package utils adding package comment to satisfy linters

Index

Constants

View Source
const (
	KubePublicNamespace       = "kube-public"
	PinnipedInfoConfigMapName = "pinniped-info"
)
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 CompareVersions

func CompareVersions(v1, cmpSign, v2 string) bool

CompareVersions compares version v1 against version v2.

func ContainsString

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

ContainsString checks the string contains in string array

func Convert

func Convert(in string) interface{}

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 Get

Get returns the condition with the given type, if the condition does not exist, it returns nil.

func GetClusterInfoFromCluster

func GetClusterInfoFromCluster(clusterAPIServerURL, configmapName 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 GetMessage

func GetMessage(from Getter, t clusterv1alpha3.ConditionType) string

GetMessage returns a nil safe string of Message.

func GetPinnipedInfoFromCluster

func GetPinnipedInfoFromCluster(clusterInfo *clientcmdapi.Cluster, discoveryPort *int) (*pinnipedinfo.PinnipedInfo, error)

GetPinnipedInfoFromCluster gets the Pinniped Info by accessing the pinniped-info configMap in kube-public namespace 'discoveryPort' is used to optionally override the port used for discovery. This may be needed on setups that expose discovery information to unauthenticated users on a different port (for instance, to avoid the need to anonymous auth on the apiserver). By default, the endpoint from the cluster-info is used.

func GetReason

func GetReason(from Getter, t clusterv1alpha3.ConditionType) string

GetReason returns a nil safe string of Reason for the condition with the given type.

func GetSeverity

GetSeverity returns the condition Severity or nil if the condition does not exist (is nil).

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 Has

Has returns true if a condition with the given type exists.

func IsAviInputEmpty

func IsAviInputEmpty(input interface{}) bool

IsAviFieldInputEmpty check if the input is empty or not

func IsFalse

func IsFalse(from Getter, t clusterv1alpha3.ConditionType) bool

IsFalse is true if the condition with the given type is False, otherwise it return false if the condition is not False or if the condition does not exist (is nil).

func IsOnWindows

func IsOnWindows() bool

IsOnWindows returns true if running on a Windows machine.

func IsTrue

func IsTrue(from Getter, t clusterv1alpha3.ConditionType) bool

IsTrue is true if the condition with the given type is True, otherwise it return false if the condition is not True or if the condition does not exist (is nil).

func IsUnknown

func IsUnknown(from Getter, t clusterv1alpha3.ConditionType) bool

IsUnknown is true if the condition with the given type is Unknown or if the condition does not exist (is nil).

func IsValidURL

func IsValidURL(s string) bool

IsValidURL validates urls

func PathExists

func PathExists(dir string) bool

PathExists returns true if file/directory exists otherwise returns false

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 SHA256FromFile

func SHA256FromFile(filePath string) (string, error)

SHA256FromFile returns SHA256 sum of a file

func SaveFile

func SaveFile(filePath string, data []byte) error

SaveFile saves the file to the provided path Also creates missing directories if any

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 Getter

type Getter interface {
	crtclient.Object
	GetConditions() clusterv1alpha3.Conditions
}

Getter interface defines methods that a Cluster API object should implement in order to use the conditions package for getting conditions.

Directories

Path Synopsis
Package net provides helpers to work with network addresses.
Package net provides helpers to work with network addresses.

Jump to

Keyboard shortcuts

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