utils

package
v4.25.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidSeparator = errors.New("error invalid separator")
)

Functions

func BranchPass

func BranchPass(mars *mars.Config, name string) bool

func CreateDockerSecrets

func CreateDockerSecrets(client kubernetes.Interface, namespace string, auths config.DockerAuths) (*v1.Secret, error)

func DownloadFiles

func DownloadFiles(pid any, commit string, files []string) (string, func(), error)

func DownloadFilesToDir

func DownloadFilesToDir(pid any, commit string, files []string, dir string) (string, func(), error)

func FileExists

func FileExists(path string) bool

func Filter

func Filter[T any](items []T, fn func(item T, index int) bool) []T

func GetCpuAndMemory

func GetCpuAndMemory(list []v1beta1.PodMetrics) (string, string)

func GetCpuAndMemoryInNamespace

func GetCpuAndMemoryInNamespace(namespace string) (string, string)

func GetCpuAndMemoryQuantity

func GetCpuAndMemoryQuantity(pod v1beta1.PodMetrics) (cpu *resource.Quantity, memory *resource.Quantity)

func GetMarsNamespace

func GetMarsNamespace(ns string) string

GetMarsNamespace prefix `devops-` namespace output dev devops-dev devops-dev devops-dev

func GetPodSelectorsByManifest added in v4.23.14

func GetPodSelectorsByManifest(manifests []string) []string

GetPodSelectorsByManifest 参考 https://github.com/kubernetes/client-go/issues/193#issuecomment-363240636 参考源码

func GetPreOccupiedLenByValuesYaml

func GetPreOccupiedLenByValuesYaml(values string) int

func GetProjectMarsConfig

func GetProjectMarsConfig(projectId any, branch string) (*mars.Config, error)

func GetProjectName

func GetProjectName[T ~int | ~int64 | ~string](projectID T, marsC *mars.Config) string

func GetSlugName

func GetSlugName[T int64 | int](namespaceId T, name string) string

func Hash added in v4.23.18

func Hash(data string) string

func IsPodRunning

func IsPodRunning(namespace, podName string) (running bool, notRunningReason string)

func IsRemoteChart

func IsRemoteChart(mars *mars.Config) bool

func IsRemoteConfigFile

func IsRemoteConfigFile(mars *mars.Config) bool

IsRemoteConfigFile 如果是这个格式意味着是远程项目, "pid|branch|filename"

func NewCloser

func NewCloser(fn func() error) io.Closer

func NewCustomErrorContext

func NewCustomErrorContext() (context.Context, func(error))

func NewDefaultArchiver

func NewDefaultArchiver() contracts.Archiver

func NewFileCopier

func NewFileCopier(executor contracts.RemoteExecutor, archiver contracts.Archiver) contracts.PodFileCopier

func ParseInputConfig

func ParseInputConfig(mars *mars.Config, input string) (string, error)
values.yaml:
 ```
 command:
   command:
     - sleep 3600
 ```

 config_field: command

 input:
 ```
 command:
  - app
 ```

 wants:
 ```
  command:
    command:
    - app
 ```

------------------------------------

   values.yaml:
   command:
   - sleep 3600

   config_field: command

   input:
   ```
   command:
	- app
   ```

   wants:
   ```
	command:
    - app
   ```

func PrettyMarshal added in v4.23.6

func PrettyMarshal(v any) ([]byte, error)

PrettyMarshal 这里想用 LiteralStyle, 不然前端显示的时候是一坨

func RandomString

func RandomString(length int) string

RandomString [0-9a-zA-Z]*

func SplitManifests

func SplitManifests(manifest string) []string

SplitManifests 因为有些 secret 自带 --- 的值,导致 spilt "---" 解析异常

func WriteConfigYamlToTmpFile

func WriteConfigYamlToTmpFile(data []byte) (string, io.Closer, error)

func YamlDeepSetKey

func YamlDeepSetKey(field string, data any) ([]byte, error)

YamlDeepSetKey 把 'user->name: duc' 设置成

user:
  name: duc

Types

type Closeable

type Closeable struct {
	// contains filtered or unexported fields
}

func (*Closeable) Close

func (c *Closeable) Close() bool

func (*Closeable) IsClosed

func (c *Closeable) IsClosed() bool

type ClusterStatus

type ClusterStatus = string
const (
	StatusBad     ClusterStatus = "bad"
	StatusNotGood ClusterStatus = "not good"
	StatusHealth  ClusterStatus = "health"
)

type CustomErrorContext

type CustomErrorContext struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*CustomErrorContext) Deadline

func (m *CustomErrorContext) Deadline() (deadline time.Time, ok bool)

func (*CustomErrorContext) Done

func (m *CustomErrorContext) Done() <-chan struct{}

func (*CustomErrorContext) Err

func (m *CustomErrorContext) Err() error

func (*CustomErrorContext) Value

func (m *CustomErrorContext) Value(key any) any

type DockerConfig

type DockerConfig map[string]DockerConfigEntry

type DockerConfigEntry

type DockerConfigEntry struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Email    string `json:"email,omitempty"`
	Auth     string `json:"auth,omitempty"`
}

type DockerConfigJSON

type DockerConfigJSON struct {
	Auths       DockerConfig      `json:"auths"`
	HttpHeaders map[string]string `json:"HttpHeaders,omitempty"`
}

func DecodeDockerConfigJSON

func DecodeDockerConfigJSON(data []byte) (res DockerConfigJSON, err error)

type Endpoint

type Endpoint = types.ServiceEndpoint

type EndpointMapping

type EndpointMapping map[string][]*Endpoint

func GetIngressMappingByProjects

func GetIngressMappingByProjects(namespace string, projects ...models.Project) EndpointMapping

func GetLoadBalancerMappingByProjects

func GetLoadBalancerMappingByProjects(namespace string, projects ...models.Project) EndpointMapping

func GetNodePortMappingByProjects

func GetNodePortMappingByProjects(namespace string, projects ...models.Project) EndpointMapping

func (EndpointMapping) AllEndpoints

func (e EndpointMapping) AllEndpoints() []*Endpoint

func (EndpointMapping) Get

func (e EndpointMapping) Get(projName string) []*Endpoint

func (EndpointMapping) Sort

func (e EndpointMapping) Sort()

type InfoResponse

type InfoResponse struct {
	// 健康状况
	Status ClusterStatus `json:"status"`

	// 可用内存
	FreeMemory string `json:"free_memory"`
	// 可用 cpu
	FreeCpu string `json:"free_cpu"`

	// 可分配内存
	FreeRequestMemory string `json:"free_request_memory"`
	// 可分配 cpu
	FreeRequestCpu string `json:"free_request_cpu"`

	// 总共的可调度的内存
	TotalMemory string `json:"total_memory"`
	// 总共的可调度的 cpu
	TotalCpu string `json:"total_cpu"`

	// 内存使用率
	UsageMemoryRate string `json:"usage_memory_rate"`
	// cpu 使用率
	UsageCpuRate string `json:"usage_cpu_rate"`

	// 内存分配率
	RequestMemoryRate string `json:"request_memory_rate"`
	// cpu 分配率
	RequestCpuRate string `json:"request_cpu_rate"`
}

func ClusterInfo

func ClusterInfo() *InfoResponse

type RuntimeObjectList

type RuntimeObjectList []runtime.Object

func FilterRuntimeObjectFromManifests

func FilterRuntimeObjectFromManifests[T runtime.Object](manifests []string) RuntimeObjectList

func (RuntimeObjectList) Has

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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