util

package
v0.5.2-beta.5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: AGPL-3.0 Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExposeToVPC      ExposeType = "vpc"
	ExposeToInternet ExposeType = "internet"

	EnableValue  string = "true"
	DisableValue string = "false"
)

Variables

View Source
var ProviderExposeAnnotations = map[K8sProvider]map[ExposeType]map[string]string{
	EKSProvider: {
		ExposeToVPC: map[string]string{
			"service.beta.kubernetes.io/aws-load-balancer-type":     "nlb",
			"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
		},
		ExposeToInternet: map[string]string{
			"service.beta.kubernetes.io/aws-load-balancer-type":     "nlb",
			"service.beta.kubernetes.io/aws-load-balancer-internal": "false",
		},
	},
	GKEProvider: {
		ExposeToVPC: map[string]string{
			"networking.gke.io/load-balancer-type": "Internal",
		},
		ExposeToInternet: map[string]string{},
	},
	AKSProvider: {
		ExposeToVPC: map[string]string{
			"service.beta.kubernetes.io/azure-load-balancer-internal": "true",
		},
		ExposeToInternet: map[string]string{
			"service.beta.kubernetes.io/azure-load-balancer-internal": "false",
		},
	},
	ACKProvider: {
		ExposeToVPC: map[string]string{
			"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type": "intranet",
		},
		ExposeToInternet: map[string]string{
			"service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type": "internet",
		},
	},

	TKEProvider: {
		ExposeToInternet: map[string]string{},
	},
}

Functions

func AddKlogFlags

func AddKlogFlags(fs *pflag.FlagSet)

AddKlogFlags adds flags from k8s.io/klog marks the flags as hidden to avoid showing them in help

func BuildAddonReleaseName

func BuildAddonReleaseName(addon string) string

BuildAddonReleaseName returns the release name of addon, its f

func BuildComponentNameLabels

func BuildComponentNameLabels(prefix string, names []string) string

func BuildLabelSelectorByNames

func BuildLabelSelectorByNames(selector string, names []string) string

BuildLabelSelectorByNames build the label selector by instance names, the label selector is like "instance-key in (name1, name2)"

func CheckEmpty

func CheckEmpty(str string) string

CheckEmpty check if string is empty, if yes, return <none> for displaying

func CheckErr

func CheckErr(err error)

CheckErr prints a user-friendly error to STDERR and exits with a non-zero exit code.

func CloneGitRepo

func CloneGitRepo(url, branch, path string) error

CloneGitRepo clone git repo to local path

func CloseQuietly

func CloseQuietly(d io.Closer)

CloseQuietly closes `io.Closer` quietly. Very handy and helpful for code quality too.

func CombineLabels

func CombineLabels(labels map[string]string) string

CombineLabels combines labels into a string

func ConfigPath

func ConfigPath(name string) string

func ConvertObjToUnstructured

func ConvertObjToUnstructured(obj any) (*unstructured.Unstructured, error)

func CreateResourceIfAbsent

func CreateResourceIfAbsent(
	dynamic dynamic.Interface,
	gvr schema.GroupVersionResource,
	namespace string,
	unstructuredObj *unstructured.Unstructured) error

func DoWithRetry

func DoWithRetry(ctx context.Context, logger logr.Logger, operation func() error, options *RetryOptions) error

func EnableLogToFile

func EnableLogToFile(fs *pflag.FlagSet) error

func GVRToString

func GVRToString(gvr schema.GroupVersionResource) string

func GetCliHomeDir

func GetCliHomeDir() (string, error)

GetCliHomeDir return kbcli home dir

func GetComponentsFromClusterName

func GetComponentsFromClusterName(key client.ObjectKey, cli dynamic.Interface) ([]string, error)

GetComponentsFromClusterName returns name of component.

func GetComponentsFromResource

func GetComponentsFromResource(componentSpecs []appsv1alpha1.ClusterComponentSpec, clusterDefObj *appsv1alpha1.ClusterDefinition) ([]string, error)

GetComponentsFromResource returns name of component.

func GetConfigTemplateList

func GetConfigTemplateList(clusterName string, namespace string, cli dynamic.Interface, componentName string, reloadTpl bool) ([]appsv1alpha1.ComponentConfigSpec, error)

GetConfigTemplateList returns ConfigTemplate list used by the component.

func GetConfigTemplateListWithResource

func GetConfigTemplateListWithResource(cComponents []appsv1alpha1.ClusterComponentSpec,
	dComponents []appsv1alpha1.ClusterComponentDefinition,
	vComponents []appsv1alpha1.ClusterComponentVersion,
	componentName string,
	reloadTpl bool) ([]appsv1alpha1.ComponentConfigSpec, error)

func GetEventObject

func GetEventObject(e *corev1.Event) string

func GetEventTimeStr

func GetEventTimeStr(e *corev1.Event) string

func GetExposeAnnotations

func GetExposeAnnotations(provider K8sProvider, exposeType ExposeType) (map[string]string, error)

func GetHelmChartRepoURL

func GetHelmChartRepoURL() string

GetHelmChartRepoURL get helm chart repo, we will choose one from GitHub and GitLab based on the IP location

func GetHumanReadableDuration

func GetHumanReadableDuration(startTime metav1.Time, endTime metav1.Time) string

GetHumanReadableDuration returns a succinct representation of the provided startTime and endTime with limited precision for consumption by humans.

func GetK8sSemVer

func GetK8sSemVer(version string) string

func GetK8sVersion

func GetK8sVersion(discoveryClient discovery.DiscoveryInterface) (string, error)

GetK8sVersion get k8s server version

func GetKubeBlocksDeploy

func GetKubeBlocksDeploy(client kubernetes.Interface) (*appsv1.Deployment, error)

GetKubeBlocksDeploy gets KubeBlocks deployments, now one kubernetes cluster only support one KubeBlocks

func GetKubeBlocksNamespace

func GetKubeBlocksNamespace(client kubernetes.Interface) (string, error)

GetKubeBlocksNamespace gets namespace of KubeBlocks installation, infer namespace from helm secrets

func GetKubeconfigDir

func GetKubeconfigDir() string

GetKubeconfigDir returns the kubeconfig directory.

func GetNodeByName

func GetNodeByName(nodes []*corev1.Node, name string) *corev1.Node

GetNodeByName choose node by name from a node array

func GetPodStatus

func GetPodStatus(pods []*corev1.Pod) (running, waiting, succeeded, failed int)

func GetPublicIP

func GetPublicIP() (string, error)

func GetResourceObjectFromGVR

func GetResourceObjectFromGVR(gvr schema.GroupVersionResource, key client.ObjectKey, client dynamic.Interface, k8sObj interface{}) error

GetResourceObjectFromGVR query the resource object using GVR.

func IsSupportReconfigureParams

func IsSupportReconfigureParams(tpl appsv1alpha1.ComponentConfigSpec, values map[string]string, cli dynamic.Interface) (bool, error)

IsSupportReconfigureParams check whether all updated parameters belong to config template parameters.

func IsWindows added in v0.5.2

func IsWindows() bool

IsWindows return true if the kbcli runtime situation is windows

func MakeSSHKeyPair

func MakeSSHKeyPair(pubKeyPath, privateKeyPath string) error

MakeSSHKeyPair make a pair of public and private keys for SSH access. Public key is encoded in the format for inclusion in an OpenSSH authorized_keys file. Private Key generated is PEM encoded

func NewConfigFlagNoWarnings

func NewConfigFlagNoWarnings() *genericclioptions.ConfigFlags

NewConfigFlagNoWarnings returns a ConfigFlags that disables warnings.

func NewFactory

func NewFactory() cmdutil.Factory

func NewOpsRequestForReconfiguring

func NewOpsRequestForReconfiguring(opsName, namespace, clusterName string) *appsv1alpha1.OpsRequest

NewOpsRequestForReconfiguring returns a new common OpsRequest for Reconfiguring operation

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser will open browser by url in different OS system

func PrintGoTemplate

func PrintGoTemplate(wr io.Writer, tpl string, values interface{}) error

func PrintObjYAML

func PrintObjYAML(obj *unstructured.Unstructured) error

func RemoveConfig

func RemoveConfig(name string) error

func ResourceIsEmpty

func ResourceIsEmpty(res *resource.Quantity) bool

ResourceIsEmpty check if resource is empty or not

func SetKubeConfig

func SetKubeConfig(cfg string) error

SetKubeConfig set KUBECONFIG environment

func SortEventsByLastTimestamp

func SortEventsByLastTimestamp(events *corev1.EventList, eventType string) *[]apiruntime.Object

SortEventsByLastTimestamp sorts events by lastTimestamp

func TimeFormat

func TimeFormat(t *metav1.Time) string

func TimeFormatWithDuration

func TimeFormatWithDuration(t *metav1.Time, duration time.Duration) string

TimeFormatWithDuration format time with specified precision

func TimeParse

func TimeParse(t string, precision time.Duration) (time.Time, error)

func TimeTimeFormat

func TimeTimeFormat(t time.Time) string

func TimeTimeFormatWithDuration

func TimeTimeFormatWithDuration(t time.Time, precision time.Duration) string

Types

type ExposeType

type ExposeType string

type K8sProvider

type K8sProvider string
const (
	EKSProvider     K8sProvider = "EKS"
	GKEProvider     K8sProvider = "GKE"
	AKSProvider     K8sProvider = "AKS"
	ACKProvider     K8sProvider = "ACK"
	TKEProvider     K8sProvider = "TKE"
	UnknownProvider K8sProvider = "unknown"
)

func GetK8sProvider

func GetK8sProvider(version string, client kubernetes.Interface) (K8sProvider, error)

GetK8sProvider returns the k8s provider

func GetK8sProviderFromNodes

func GetK8sProviderFromNodes(nodes *corev1.NodeList) K8sProvider

GetK8sProviderFromNodes get k8s provider from node.spec.providerID

func GetK8sProviderFromVersion

func GetK8sProviderFromVersion(version string) K8sProvider

GetK8sProviderFromVersion get k8s provider from field GitVersion in cluster server version

func (K8sProvider) IsCloud

func (p K8sProvider) IsCloud() bool

type RetryOptions

type RetryOptions struct {
	MaxRetry int
	Delay    time.Duration
}

type Version

type Version struct {
	KubeBlocks string
	Kubernetes string
	Cli        string
}

func GetVersionInfo

func GetVersionInfo(client kubernetes.Interface) (Version, error)

GetVersionInfo get version include KubeBlocks, CLI and kubernetes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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