Documentation ¶
Index ¶
- Constants
- Variables
- func AddDirToPath(dir string) error
- func AddKlogFlags(fs *pflag.FlagSet)
- func AppendErrIgnoreNotFound(allErrs *[]error, err error)
- func BuildAddonReleaseName(addon string) string
- func BuildClusterDefinitionRefLabel(prefix string, clusterDef []string) string
- func BuildComponentNameLabels(prefix string, names []string) string
- func BuildLabelSelectorByNames(selector string, names []string) string
- func BuildNodeAffinity(nodeLabels map[string]string) *corev1.NodeAffinity
- func BuildPodAntiAffinity(podAntiAffinityStrategy string, topologyKeys []string) *corev1.PodAntiAffinity
- func BuildTolerations(raw []string) ([]interface{}, error)
- func CheckEmpty(str string) string
- func CheckErr(err error)
- func CloneGitRepo(url, branch, path string) error
- func CloseQuietly(d io.Closer)
- func CombineLabels(labels map[string]string) string
- func CompGetFromTemplateWithLabels(template *string, f cmdutil.Factory, namespace string, cmd *cobra.Command, ...) []string
- func CompGetResourceWithLabels(f cmdutil.Factory, cmd *cobra.Command, resourceName string, labels []string, ...) []string
- func ConfigPath(name string) string
- func ConvertObjToUnstructured(obj any) (*unstructured.Unstructured, error)
- func CreateAndCleanFile(file string) (*os.File, error)
- func CreateResourceIfAbsent(dynamic dynamic.Interface, gvr schema.GroupVersionResource, namespace string, ...) error
- func DisplayDiffWithColor(out io.Writer, diffText string)
- func DoWithRetry(ctx context.Context, logger logr.Logger, operation func() error, ...) error
- func EnableLogToFile(fs *pflag.FlagSet) error
- func EnsureCloned(uri, destinationPath string) error
- func EnsureUpdated(uri, destinationPath string) error
- func ExecGitCommand(pwd string, args ...string) (string, error)
- func FileExists(fileName string) (bool, error)
- func GVRToString(gvr schema.GroupVersionResource) string
- func GetCliAddonDir() (string, error)
- func GetCliHomeDir() (string, error)
- func GetCliLogDir() (string, error)
- func GetComponentsFromClusterName(key client.ObjectKey, cli dynamic.Interface) ([]string, error)
- func GetComponentsFromResource(componentSpecs []appsv1alpha1.ClusterComponentSpec, ...) ([]string, error)
- func GetConfigTemplateList(clusterName string, namespace string, cli dynamic.Interface, ...) ([]appsv1alpha1.ComponentConfigSpec, error)
- func GetConfigTemplateListWithResource(cComponents []appsv1alpha1.ClusterComponentSpec, ...) ([]appsv1alpha1.ComponentConfigSpec, error)
- func GetCurrentBranch(destinationPath string) (string, error)
- func GetDataProtectionDeploy(client kubernetes.Interface) (*appsv1.Deployment, error)
- func GetDockerVersion() (*gv.Version, error)
- func GetEventObject(e *corev1.Event) string
- func GetEventTimeStr(e *corev1.Event) string
- func GetExposeAnnotations(provider K8sProvider, exposeType ExposeType) (map[string]string, error)
- func GetHelmChartRepoURL() string
- func GetHumanReadableDuration(startTime metav1.Time, endTime metav1.Time) string
- func GetIPLocation() (string, error)
- func GetK8sSemVer(version string) string
- func GetK8sVersion(discoveryClient discovery.DiscoveryInterface) (string, error)
- func GetKubeBlocksDeploy(client kubernetes.Interface) (*appsv1.Deployment, error)
- func GetKubeBlocksNamespace(client kubernetes.Interface) (string, error)
- func GetKubeBlocksNamespaceByDynamic(dynamic dynamic.Interface) (string, error)
- func GetKubeconfigDir() string
- func GetNodeByName(nodes []*corev1.Node, name string) *corev1.Node
- func GetPodStatus(pods []corev1.Pod) (running, waiting, succeeded, failed int)
- func GetPublicIP() (string, error)
- func GetResourceObjectFromGVR(gvr schema.GroupVersionResource, key client.ObjectKey, ...) error
- func GetUnifiedDiffString(original, edited string, from, to string, contextLine int) (string, error)
- func GitGetRemoteURL(dir string) (string, error)
- func IsGitCloned(gitPath string) (bool, error)
- func IsRepoLatest(destinationPath string) (bool, error)
- func IsSupportReconfigureParams(tpl appsv1alpha1.ComponentConfigSpec, values map[string]*string, ...) (bool, error)
- func IsWindows() bool
- func ListResourceByGVR(ctx context.Context, client dynamic.Interface, namespace string, ...) []*unstructured.UnstructuredList
- func MakeSSHKeyPair(pubKeyPath, privateKeyPath string) error
- func NewConfigFlagNoWarnings() *genericclioptions.ConfigFlags
- func NewFactory() cmdutil.Factory
- func NewOpsRequestForReconfiguring(opsName, namespace, clusterName string) *appsv1alpha1.OpsRequest
- func OpenBrowser(url string) error
- func PrintGoTemplate(wr io.Writer, tpl string, values interface{}) error
- func PrintObjYAML(obj *unstructured.Unstructured) error
- func RandRFC1123String(n int) string
- func RegisterClusterCompletionFunc(cmd *cobra.Command, f cmdutil.Factory)
- func RemoveConfig(name string) error
- func ResourceIsEmpty(res *resource.Quantity) bool
- func ResourceNameCompletionFunc(f cmdutil.Factory, gvr schema.GroupVersionResource) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective)
- func SetKubeConfig(cfg string) error
- func SortEventsByLastTimestamp(events *corev1.EventList, eventType string) *[]apiruntime.Object
- func TimeFormat(t *metav1.Time) string
- func TimeFormatWithDuration(t *metav1.Time, duration time.Duration) string
- func TimeParse(t string, precision time.Duration) (time.Time, error)
- func TimeTimeFormat(t time.Time) string
- func TimeTimeFormatWithDuration(t time.Time, precision time.Duration) string
- func TrimVersionPrefix(version string) string
- func UpdateAndCleanUntracked(destinationPath string) error
- func ValidateParametersModified(tpl *appsv1alpha1.ComponentConfigSpec, parameters sets.Set[string], ...) (err error)
- func ValidateParametersModified2(parameters sets.Set[string], cc appsv1alpha1.ConfigConstraintSpec) error
- func WritePogStreamingLog(ctx context.Context, client kubernetes.Interface, pod *corev1.Pod, ...) error
- type ExposeType
- type K8sProvider
- type RetryOptions
- type Version
Constants ¶
const ( ExposeToVPC ExposeType = "vpc" ExposeToInternet ExposeType = "internet" EnableValue string = "true" DisableValue string = "false" )
Variables ¶
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 AddDirToPath ¶
AddDirToPath add a dir to the PATH environment variable
func AddKlogFlags ¶
AddKlogFlags adds flags from k8s.io/klog marks the flags as hidden to avoid showing them in help
func AppendErrIgnoreNotFound ¶
func BuildAddonReleaseName ¶
BuildAddonReleaseName returns the release name of addon, its f
func BuildLabelSelectorByNames ¶
BuildLabelSelectorByNames builds the label selector by instance names, the label selector is like "instance-key in (name1, name2)"
func BuildNodeAffinity ¶
func BuildNodeAffinity(nodeLabels map[string]string) *corev1.NodeAffinity
BuildNodeAffinity build node affinity from node labels
func BuildPodAntiAffinity ¶
func BuildPodAntiAffinity(podAntiAffinityStrategy string, topologyKeys []string) *corev1.PodAntiAffinity
BuildPodAntiAffinity build pod anti affinity from topology keys
func BuildTolerations ¶
BuildTolerations toleration format: key=value:effect or key:effect,
func CheckEmpty ¶
CheckEmpty checks if string is empty, if yes, returns <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 ¶
CloneGitRepo clones git repo to local path
func CloseQuietly ¶
CloseQuietly closes `io.Closer` quietly. Very handy and helpful for code quality too.
func CombineLabels ¶
CombineLabels combines labels into a string
func CompGetFromTemplateWithLabels ¶
func CompGetFromTemplateWithLabels(template *string, f cmdutil.Factory, namespace string, cmd *cobra.Command, args []string, labels []string, toComplete string) []string
CompGetFromTemplateWithLabels executes a Get operation using the specified template and args and returns the results which begin with `toComplete` and have the specified labels. example: CompGetFromTemplateWithLabels(&template, f, "", cmd, []string{"pods"}, []string{"app=nginx"}, toComplete) will get the output of `kubectl get pods --template=template -l app=nginx`, and split the output by space and return
func CompGetResourceWithLabels ¶
func CompGetResourceWithLabels(f cmdutil.Factory, cmd *cobra.Command, resourceName string, labels []string, toComplete string) []string
CompGetResourceWithLabels gets the list of the resource specified which begin with `toComplete` and have the specified labels. example: CompGetResourceWithLabels(f, cmd, "pods", []string{"app=nginx"}, toComplete) gets the name of the pods which have the label `app=nginx` and begin with `toComplete`
func ConfigPath ¶
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 DisplayDiffWithColor ¶
func DoWithRetry ¶
func EnableLogToFile ¶
func EnsureCloned ¶
EnsureCloned clones into the destination path, otherwise returns no error.
func EnsureUpdated ¶
EnsureUpdated ensures the destination path exists and is up to date.
func ExecGitCommand ¶
ExecGitCommand executes a git command in the given directory.
func FileExists ¶
FileExists check if a file exists, and return an error otherwise
func GVRToString ¶
func GVRToString(gvr schema.GroupVersionResource) string
func GetCliAddonDir ¶
GetCliAddonDir returns kbcli addon index dir
func GetComponentsFromClusterName ¶
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 GetCurrentBranch ¶ added in v0.7.1
func GetDataProtectionDeploy ¶
func GetDataProtectionDeploy(client kubernetes.Interface) (*appsv1.Deployment, error)
GetDataProtectionDeploy gets DataProtection deployments, now one kubernetes cluster only support one DataProtection
func GetDockerVersion ¶
GetDockerVersion get Docker Version
func GetEventObject ¶
func GetEventTimeStr ¶
func GetExposeAnnotations ¶
func GetExposeAnnotations(provider K8sProvider, exposeType ExposeType) (map[string]string, error)
func GetHelmChartRepoURL ¶
func GetHelmChartRepoURL() string
GetHelmChartRepoURL gets helm chart repo, chooses one from GitHub and GitLab based on the IP location
func GetHumanReadableDuration ¶
GetHumanReadableDuration returns a succinct representation of the provided startTime and endTime with limited precision for consumption by humans.
func GetIPLocation ¶
func GetK8sSemVer ¶
func GetK8sVersion ¶
func GetK8sVersion(discoveryClient discovery.DiscoveryInterface) (string, error)
GetK8sVersion gets 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 GetKubeBlocksNamespaceByDynamic ¶
GetKubeBlocksNamespaceByDynamic gets namespace of KubeBlocks installation, infer namespace from helm secrets
func GetKubeconfigDir ¶
func GetKubeconfigDir() string
GetKubeconfigDir returns the kubeconfig directory.
func GetNodeByName ¶
GetNodeByName chooses node by name from a node array
func GetPodStatus ¶
func GetPublicIP ¶
func GetResourceObjectFromGVR ¶
func GetResourceObjectFromGVR(gvr schema.GroupVersionResource, key client.ObjectKey, client dynamic.Interface, k8sObj interface{}) error
GetResourceObjectFromGVR queries the resource object using GVR.
func GetUnifiedDiffString ¶
func GitGetRemoteURL ¶
func IsGitCloned ¶
IsGitCloned tests if the path is a git dir.
func IsRepoLatest ¶
func IsSupportReconfigureParams ¶
func IsSupportReconfigureParams(tpl appsv1alpha1.ComponentConfigSpec, values map[string]*string, cli dynamic.Interface) (bool, error)
IsSupportReconfigureParams checks whether all updated parameters belong to config template parameters.
func IsWindows ¶
func IsWindows() bool
IsWindows returns true if the kbcli runtime situation is windows
func ListResourceByGVR ¶
func ListResourceByGVR(ctx context.Context, client dynamic.Interface, namespace string, gvrs []schema.GroupVersionResource, selector []metav1.ListOptions, allErrs *[]error) []*unstructured.UnstructuredList
func MakeSSHKeyPair ¶
MakeSSHKeyPair makes 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 NewOpsRequestForReconfiguring ¶
func NewOpsRequestForReconfiguring(opsName, namespace, clusterName string) *appsv1alpha1.OpsRequest
NewOpsRequestForReconfiguring returns a new common OpsRequest for Reconfiguring operation
func OpenBrowser ¶
OpenBrowser opens browser with url in different OS system
func PrintObjYAML ¶
func PrintObjYAML(obj *unstructured.Unstructured) error
func RandRFC1123String ¶
RandRFC1123String generate a random string with length n, which fulfills RFC1123
func RemoveConfig ¶
func ResourceIsEmpty ¶
ResourceIsEmpty checks if resource is empty or not
func SortEventsByLastTimestamp ¶
func SortEventsByLastTimestamp(events *corev1.EventList, eventType string) *[]apiruntime.Object
SortEventsByLastTimestamp sorts events by lastTimestamp
func TimeFormat ¶
func TimeFormatWithDuration ¶
TimeFormatWithDuration formats time with specified precision
func TimeTimeFormat ¶
func TrimVersionPrefix ¶ added in v0.7.2
func UpdateAndCleanUntracked ¶
UpdateAndCleanUntracked fetches origin and sets HEAD to origin/HEAD and also creates a pristine working directory by removing untracked files and directories.
func ValidateParametersModified ¶
func ValidateParametersModified(tpl *appsv1alpha1.ComponentConfigSpec, parameters sets.Set[string], cli dynamic.Interface) (err error)
func ValidateParametersModified2 ¶
func ValidateParametersModified2(parameters sets.Set[string], cc appsv1alpha1.ConfigConstraintSpec) error
func WritePogStreamingLog ¶
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 gets k8s provider from field GitVersion in cluster server version
func (K8sProvider) IsCloud ¶
func (p K8sProvider) IsCloud() bool