utils

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 35 Imported by: 8

Documentation

Index

Constants

View Source
const TypeGitee = "gitee"

TypeGitee represents gitee

View Source
const TypeGithub = "github"

TypeGithub represents github

View Source
const TypeGitlab = "gitlab"

TypeGitlab represents gitlab

View Source
const TypeLocal = "local"

TypeLocal represents github

View Source
const TypeOss = "oss"

TypeOss represent oss

View Source
const TypeUnknown = "unknown"

TypeUnknown represents parse failed

Variables

This section is empty.

Functions

func AutoSetSelfImpersonationInConfig added in v1.4.0

func AutoSetSelfImpersonationInConfig(cfg *rest.Config)

AutoSetSelfImpersonationInConfig set impersonate username and group to the identity in the original rest config

func ByteCountIEC added in v1.3.0

func ByteCountIEC(b int64) string

ByteCountIEC convert number of bytes into readable string borrowed from https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/

func CreateNamespace added in v1.2.0

func CreateNamespace(ctx context.Context, kubeClient client.Client, name string, options ...MutateOption) error

CreateNamespace will create a namespace with mutate option

func CreateOrUpdate added in v1.4.0

func CreateOrUpdate(ctx context.Context, cli client.Client, obj client.Object) (controllerutil.OperationResult, error)

CreateOrUpdate create or update a kubernetes object

func CreateOrUpdateNamespace added in v1.2.0

func CreateOrUpdateNamespace(ctx context.Context, kubeClient client.Client, name string, options ...MutateOption) error

CreateOrUpdateNamespace will create a namespace if not exist, it will also update a namespace if exists It will report an error if the labels conflict while it will override the annotations

func DumpJSON

func DumpJSON(o interface{}) string

DumpJSON returns the JSON encoding

func EqualSlice added in v1.3.0

func EqualSlice(a, b []string) bool

EqualSlice checks if two slice are equal

func GetBoxDrawingString added in v1.3.1

func GetBoxDrawingString(up bool, down bool, left bool, right bool, padLeft int, padRight int) string

GetBoxDrawingString get line drawing string, see https://en.wikipedia.org/wiki/Box-drawing_character nolint:gocyclo

func GetCertificateCommonNameAndOrganizationsFromConfig added in v1.4.0

func GetCertificateCommonNameAndOrganizationsFromConfig(cfg *rest.Config) (string, []string)

GetCertificateCommonNameAndOrganizationsFromConfig extract CommonName and Organizations from Certificate

func GetCertificateSubject added in v1.4.0

func GetCertificateSubject(certificate []byte) (*pkix.Name, error)

GetCertificateSubject extract Subject from Certificate

func GetNamespace added in v1.4.0

func GetNamespace(ctx context.Context, kubeClient client.Client, name string) (*corev1.Namespace, error)

GetNamespace will return a namespace with mutate option

func GetServiceAccountSubjectFromConfig added in v1.4.0

func GetServiceAccountSubjectFromConfig(cfg *rest.Config) string

GetServiceAccountSubjectFromConfig extract ServiceAccountName subject from token

func GetTokenSubject added in v1.4.0

func GetTokenSubject(token string) (string, error)

GetTokenSubject extract the subject field from the jwt token

func GetUserInfoFromConfig added in v1.4.0

func GetUserInfoFromConfig(cfg *rest.Config) *authv1.UserInfo

GetUserInfoFromConfig extract UserInfo from KubeConfig

func IsJSONOrYAMLFile added in v1.4.0

func IsJSONOrYAMLFile(path string) bool

IsJSONOrYAMLFile check if the path is a json or yaml file

func IsValidURL added in v1.2.3

func IsValidURL(strURL string) bool

IsValidURL checks whether the given string is a valid URL or not

func JoinURL added in v1.4.0

func JoinURL(baseURL, subPath string) (string, error)

JoinURL join baseURL and subPath to be new URL

func MapKey2Array added in v1.3.0

func MapKey2Array(source map[string]string) []string

MapKey2Array convery map keys to array

func ParseAPIServerEndpoint added in v1.1.9

func ParseAPIServerEndpoint(server string) (string, error)

ParseAPIServerEndpoint automatically construct the full url of APIServer It will patch port and scheme if not exists

func RandomString added in v1.1.1

func RandomString(n int) string

RandomString generate random string.

func Sanitize added in v1.2.0

func Sanitize(s string) string

Sanitize the inputs by removing line endings

func SliceIncludeSlice added in v1.3.0

func SliceIncludeSlice(a, b []string) bool

SliceIncludeSlice the a slice include the b slice

func StrictUnmarshal added in v1.3.0

func StrictUnmarshal(bs []byte, dest interface{}) error

StrictUnmarshal unmarshal target structure and disallow unknown fields

func StringsContain added in v1.2.0

func StringsContain(items []string, source string) bool

StringsContain strings contain

func ThreeWaySliceCompare added in v1.3.0

func ThreeWaySliceCompare(a []string, b []string) ([]string, []string, []string)

ThreeWaySliceCompare will compare two string slice, with the three return values: [both in A and B], [only in A], [only in B]

func TryCancelRequest added in v1.3.0

func TryCancelRequest(rt http.RoundTripper, req *http.Request)

TryCancelRequest tries to cancel the request by traversing round trippers

func UpdateNamespace added in v1.2.0

func UpdateNamespace(ctx context.Context, kubeClient client.Client, name string, options ...MutateOption) error

UpdateNamespace will update a namespace with mutate option

Types

type Content added in v1.2.0

Content contains different type of content needed when building Registry

func Parse added in v1.2.0

func Parse(addr string) (string, *Content, error)

Parse will parse config from address

func ParseGitlab added in v1.4.0

func ParseGitlab(addr, repo string) (string, *Content, error)

ParseGitlab will parse gitlab config from address

type FileData added in v1.4.0

type FileData struct {
	Path string
	Data []byte
}

FileData data of a file at the path

func LoadDataFromPath added in v1.4.0

func LoadDataFromPath(ctx context.Context, path string, pathFilter func(string) bool) ([]FileData, error)

LoadDataFromPath load FileData from path If path is an url, fetch the data from the url If path is a file, fetch the data from the file If path is a dir, fetch the data from all the files inside the dir that passes the pathFilter

type GiteeContent added in v1.3.0

type GiteeContent struct {
	Owner string `json:"gitee_owner"`
	Repo  string `json:"gitee_repo"`
	Path  string `json:"gitee_path"`
	Ref   string `json:"gitee_ref"`
}

GiteeContent for cap center

type GithubContent added in v1.2.0

type GithubContent struct {
	Owner string `json:"owner"`
	Repo  string `json:"repo"`
	Path  string `json:"path"`
	Ref   string `json:"ref"`
}

GithubContent for cap center

type GitlabContent added in v1.4.0

type GitlabContent struct {
	Host  string `json:"gitlab_host"`
	Owner string `json:"gitlab_owner"`
	Repo  string `json:"gitlab_repo"`
	Path  string `json:"gitlab_path"`
	Ref   string `json:"gitlab_ref"`
	PId   int    `json:"gitlab_pid"`
}

GitlabContent for cap center

type LocalContent added in v1.2.0

type LocalContent struct {
	AbsDir string `json:"abs_dir"`
}

LocalContent for local registry

type MutateOption added in v1.2.0

type MutateOption func(object metav1.Object) error

MutateOption defines the function pattern for mutate

func MergeNoConflictLabels added in v1.2.0

func MergeNoConflictLabels(labels map[string]string) MutateOption

MergeNoConflictLabels will merge the existing labels with the labels passed in, it will report conflicts if exists

func MergeOverrideAnnotations added in v1.2.0

func MergeOverrideAnnotations(annotations map[string]string) MutateOption

MergeOverrideAnnotations will merge the existing annotations and override by the annotations passed in

func MergeOverrideLabels added in v1.2.0

func MergeOverrideLabels(labels map[string]string) MutateOption

MergeOverrideLabels will merge the existing labels and override by the labels passed in

type OssContent added in v1.2.0

type OssContent struct {
	EndPoint string `json:"bucket_url"`
	Bucket   string `json:"bucket"`
}

OssContent for oss registry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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