utils

package
v4.20.7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: AGPL-3.0 Imports: 62 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusUnknown  string = "unknown"
	StatusPending  string = "pending"
	StatusDeployed string = "deployed"
	StatusFailed   string = "failed"
)

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 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 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 MD5 added in v4.19.7

func MD5(data string) string

MD5 md5

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 PackageChart

func PackageChart(path string, destDir string) (string, error)

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 RandomString

func RandomString(length int) string

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

func ReleaseStatus

func ReleaseStatus(releaseName, namespace string) types.Deploy

func Rollback

func Rollback(releaseName, namespace string, wait bool, log contracts.LogFn, dryRun bool) error

func SplitManifests

func SplitManifests(manifest string) []string

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

func UninstallRelease

func UninstallRelease(releaseName, namespace string, log contracts.LogFn) error

func UpgradeOrInstall

func UpgradeOrInstall(ctx context.Context, releaseName, namespace string, ch *chart.Chart, valueOpts *values.Options, fn contracts.WrapLogFn, wait bool, timeoutSeconds int64, dryRun bool, podSelectors []string, desc string) (*release.Release, error)

UpgradeOrInstall 不会自动回滚

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 ListReleaseItem

type ListReleaseItem struct {
	Release *release.Release
	Status  string
}

type ReleaseList

type ReleaseList map[string]ListReleaseItem

func (ReleaseList) Add

func (l ReleaseList) Add(r *release.Release)

func (ReleaseList) GetStatus

func (l ReleaseList) GetStatus(namespace, name string) string

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