Documentation ¶
Index ¶
- Constants
- func AddOrUpdateAnnotations(item *unstructured.Unstructured, newAnnotations map[string]string)
- func BoolPtr(b bool) *bool
- func CidrTotalIPs(cidr string) (int, error)
- func CompareMapContains[T string | int](small, big map[string]T) bool
- func ConvertUnstructuredToYAML(obj *unstructured.Unstructured) (string, error)
- func DeepCopy[T any](src T) (T, error)
- func DetectType(value interface{}) (string, interface{})
- func FNV1(data []byte) uint32
- func FNV1_32(data []byte) uint32
- func FormatResource(q resource.Quantity) string
- func GetOrSetCache[T any](cache *ristretto.Cache[string, any], cacheKey string, ttl time.Duration, ...) (T, error)
- func Int32Ptr(i int32) *int32
- func Int64Ptr(i int64) *int64
- func IsTextFile(ob []byte) (bool, error)
- func MatchNodeSelectorRequirement(nodeLabels map[string]string, req v1.NodeSelectorRequirement) bool
- func NormalizeNewlines(input string) string
- func NormalizeToWindows(input string) string
- func ParseTime(value string) (time.Time, error)
- func RandNDigitInt(n int) int
- func RandNLengthString(n int) string
- func RemoveManagedFields(obj *unstructured.Unstructured)
- func SanitizeFileName(filename string) string
- func SortByCreationTime(items []unstructured.Unstructured) []unstructured.Unstructured
- func StringListToSQLIn(strList []string) string
- func ToInt(s string) int
- func ToInt64(str string) int64
- func ToInt64Slice(ids string) []int64
- func ToIntDefault(s string, i int) int
- func ToIntSlice(ids string) []int
- func ToJSON(v interface{}) string
- func ToUInt(s string) uint
- func TrimQuotes(str string) string
- func TruncateString(s string, length int) string
- func WaitUntil(f func() bool, interval time.Duration, timeout time.Duration) bool
- type LabelsManager
Constants ¶
const ( TypeNumber = "number" TypeTime = "time" TypeString = "string" TypeBoolean = "boolean" )
定义字符串的类型
Variables ¶
This section is empty.
Functions ¶
func AddOrUpdateAnnotations ¶ added in v0.1.16
func AddOrUpdateAnnotations(item *unstructured.Unstructured, newAnnotations map[string]string)
AddOrUpdateAnnotations 添加或更新 annotations
func CidrTotalIPs ¶ added in v0.1.13
func CompareMapContains ¶ added in v0.1.37
CompareMapContains compares two maps and returns true if the small map is contained in the big map small Map中的所有键值都存在于big map中,则返回true
func ConvertUnstructuredToYAML ¶ added in v0.0.4
func ConvertUnstructuredToYAML(obj *unstructured.Unstructured) (string, error)
ConvertUnstructuredToYAML 将 Unstructured 对象转换为 YAML 字符串
func DetectType ¶ added in v0.1.0
func DetectType(value interface{}) (string, interface{})
DetectType 探测字符串的类型(数字、时间、字符串)
func FormatResource ¶ added in v0.1.10
FormatResource 格式化 resource.Quantity 为人类可读的格式 Example: 示例:内存格式化 q1 := resource.MustParse("8127096Ki") fmt.Println("Formatted memory:", utils.FormatResource(q1))
// 示例:内存格式化(大于 Gi) q2 := resource.MustParse("256Gi") fmt.Println("Formatted memory:", utils.FormatResource(q2))
// 示例:CPU 格式化 q3 := resource.MustParse("500m") // CPU 百分之一核 fmt.Println("Formatted CPU:", q3.String()) // CPU 不需要转换,直接原格式即可
func GetOrSetCache ¶ added in v0.1.18
func IsTextFile ¶
func MatchNodeSelectorRequirement ¶ added in v0.1.37
func MatchNodeSelectorRequirement(nodeLabels map[string]string, req v1.NodeSelectorRequirement) bool
MatchNodeSelectorRequirement checks if a map satisfies the NodeSelectorRequirement.
func NormalizeNewlines ¶ added in v0.0.25
func NormalizeToWindows ¶ added in v0.0.25
func RandNDigitInt ¶
RandNDigitInt generates a random number with n digits
func RandNLengthString ¶
RandNLengthString generates a random string of specified length using the default charset
func RemoveManagedFields ¶ added in v0.0.4
func RemoveManagedFields(obj *unstructured.Unstructured)
RemoveManagedFields 删除 unstructured.Unstructured 对象中的 metadata.managedFields 字段
func SanitizeFileName ¶
SanitizeFileName 去除文件名中的非法字符,并替换为下划线 '_'
func SortByCreationTime ¶ added in v0.0.4
func SortByCreationTime(items []unstructured.Unstructured) []unstructured.Unstructured
func StringListToSQLIn ¶ added in v0.1.33
StringListToSQLIn 将字符串列表转换为 SQL IN 子句中使用的格式,例如 ('x', 'xx') 例如 ['x', 'xx'] 转换为 ('x', 'xx')
func ToInt64Slice ¶
func ToIntDefault ¶
func TrimQuotes ¶ added in v0.1.0
func TruncateString ¶
func WaitUntil ¶ added in v0.0.22
WaitUntil 传入一个函数 f,如果 f 返回 true 则停止等待,否则持续检查直到超时 Example: // 定义一个检查函数,模拟每 10 秒满足一次条件
checkCondition := func() bool { // 例如条件为当前秒数是 10 的倍数 return time.Now().Second()%10 == 0 } // 每 2 秒检查一次,超时设定为 30 秒 interval := 2 * time.Second timeout := 30 * time.Second if waitUntil(checkCondition, interval, timeout) { fmt.Println("Check succeeded, main process exiting.") } else { fmt.Println("Check failed due to timeout.") }
Types ¶
type LabelsManager ¶
LabelsManager 结构体,包含共享标签
func NewLabelsManager ¶
func NewLabelsManager(labels map[string]string) *LabelsManager
NewLabelsManager 构造函数,初始化并返回一个 LabelsManager
func (*LabelsManager) AddCustomLabel ¶
func (lm *LabelsManager) AddCustomLabel(meta *metav1.ObjectMeta, key, value string)
AddCustomLabel 动态添加用户指定的标签
func (*LabelsManager) AddLabels ¶
func (lm *LabelsManager) AddLabels(meta *metav1.ObjectMeta)
AddLabels 给任意 Kubernetes 资源对象添加共享标签