util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 44 Imported by: 27

Documentation

Index

Constants

View Source
const (
	KubernetesSecret                    string = "KubernetesSecret"
	AWSSecretsManager                   string = "AWSSecretsManager"
	AWSSystemManager                    string = "AWSSystemManager"
	HashiCorpVault                      string = "HashiCorpVault"
	ESOGoogleSecretsManager             string = "ESO_GoogleSecretsManager"
	ESOAWSSecretsManager                string = "ESO_AWSSecretsManager"
	ESOAzureSecretsManager              string = "ESO_AzureSecretsManager"
	ESOHashiCorpVault                   string = "ESO_HashiCorpVault"
	KubernetesExternalSecret            string = "KubernetesExternalSecret"
	ConfigMapSecretUsageTypeEnvironment string = "environment"
	ConfigMapSecretUsageTypeVolume      string = "volume"
	YamlSeparator                       string = "---\n"
	NotSupportedErr                            = "This feature is not supported"
)
View Source
const (
	WorkflowAborted   = "Aborted"
	WorkflowFailed    = "Failed"
	WorkflowSucceeded = "Succeeded"
)
View Source
const (
	CpuRegex    = "(^\\d*\\.?\\d+e?\\d*)(m?)$"
	MemoryRegex = "(^\\d*\\.?\\d+e?\\d*)(Ei?|Pi?|Ti?|Gi?|Mi?|Ki?|$)$"
)
View Source
const (
	DEFAULT_TAG_VALUE = "latest"
)
View Source
const IsSuperAdminFlag = "isSuperAdmin"

Variables

View Source
var (
	CpuUnitChecker, _    = regexp.Compile(CpuRegex)
	MemoryUnitChecker, _ = regexp.Compile(MemoryRegex)
)
View Source
var (
	GitCommit            = ""
	BuildTime            = ""
	ServerMode           = ""
	SERVER_MODE_FULL     = "FULL"
	SERVER_MODE_HYPERION = "EA_ONLY"
)

Functions

func AppendErrorString

func AppendErrorString(errs []string, err error) []string

func AutoScale added in v0.2.37

func AutoScale(dat map[string]interface{}) (bool, error)

func BuildDeployedAppName added in v0.4.15

func BuildDeployedAppName(appName string, environmentName string) string

func BuildDevtronBomUrl added in v0.4.1

func BuildDevtronBomUrl(bomUrl string, version string) string

func CheckForMissingFiles added in v0.3.22

func CheckForMissingFiles(chartLocation string) error

func Close

func Close(c Closer, logger *zap.SugaredLogger)

func CompareLimitsRequests added in v0.2.37

func CompareLimitsRequests(dat map[string]interface{}, chartVersion string) (bool, error)

func ComputeHash

func ComputeHash(template *v1.PodTemplateSpec, collisionCount *int32) string

ComputeHash returns a hash value calculated from pod template and a collisionCount to avoid hash collision. The hash will be safe encoded to avoid bad words.

func Contains added in v0.6.29

func Contains[T any](input []T, check func(inp T) bool) bool

func ContainsString

func ContainsString(list []string, element string) bool

func ConvertStringSliceToMap added in v0.6.21

func ConvertStringSliceToMap(inputs []string) map[string]bool

func CpuToNumber added in v0.2.37

func CpuToNumber(cpu string) (int64, error)

func CreateFileWithData added in v0.7.2

func CreateFileWithData(folderPath, fileName, content string) (string, error)

func DeepHashObject

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.

func DeleteFile added in v0.7.2

func DeleteFile(filePath string) error

func DeleteFolder added in v0.7.2

func DeleteFolder(folderPath string) error

func ExtractChartVersion

func ExtractChartVersion(chartVersion string) (int, int, error)

func ExtractEcrImage added in v0.6.24

func ExtractEcrImage(registryId, region, repoName, tag string) string

func ExtractTarGz added in v0.3.22

func ExtractTarGz(gzipStream io.Reader, chartDir string) error

func Generate added in v0.2.8

func Generate(size int) string

Generates random string

func GenerateNewWorkflowName added in v0.7.0

func GenerateNewWorkflowName(name string) string

Generates random name format name-clone-xyts

func GetBeans added in v0.6.26

func GetBeans[T any](beans ...T) []T

func GetBeansPtr added in v0.6.26

func GetBeansPtr[T any](beans ...*T) []*T

func GetClientIP added in v0.4.11

func GetClientIP(r *http.Request) string

GetClientIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.

func GetCopyByValueObject added in v1.0.0

func GetCopyByValueObject[T any](input []T) []T

func GetDeReferencedArray added in v0.6.24

func GetDeReferencedArray[T any](ptrObjects []*T) []T

func GetDecodedAndEncodedData added in v0.6.26

func GetDecodedAndEncodedData(data json.RawMessage, transformer SecretTransformMode) ([]byte, error)

func GetErrorOrNil

func GetErrorOrNil(errs []string) error

func GetHTTPClientWithTLSConfig added in v0.7.2

func GetHTTPClientWithTLSConfig(tlsConfig *tls.Config) *http.Client

func GetHost added in v0.7.2

func GetHost(urlStr string) (string, error)

func GetIsSuperAdminFromContext added in v0.6.25

func GetIsSuperAdminFromContext(ctx context.Context) (bool, error)

func GetLIKEClauseQueryParam added in v1.0.0

func GetLIKEClauseQueryParam(s string) string

GetLIKEClauseQueryParam converts string "abc" into "%abc%". This is used for SQL queries and we have taken this approach instead of ex- .Where("name = %s%", "abc") because it will result into query : where name = %'abc'% since string params are added with quotes.

func GetMapValuesPtr added in v0.6.26

func GetMapValuesPtr[T any](valueMap map[string]*T) []*T

func GetRandomName added in v0.7.2

func GetRandomName() string

func GetRandomStringOfGivenLength added in v0.7.2

func GetRandomStringOfGivenLength(length int) string

func GetReferencedArray added in v0.6.24

func GetReferencedArray[T any](objects []T) []*T

func GetSchemaFromType added in v0.6.23

func GetSchemaFromType[T any](t T) (string, error)

func GetTlsConfig added in v0.7.2

func GetTlsConfig(TLSKey, TLSCert, CACert, folderPath string) (*tls.Config, error)

func HttpRequest added in v0.2.18

func HttpRequest(url string) (map[string]interface{}, error)

func Int

func Int() int

Int returns a non-negative pseudo-random int.

func Int63nRange

func Int63nRange(min, max int64) int64

IntnRange generates an int64 integer in range [min,max). By design this should panic if input is invalid, <= 0.

func InterfaceToFloat added in v0.6.15

func InterfaceToFloat(resp interface{}) float64

func InterfaceToMapAdapter added in v0.4.14

func InterfaceToMapAdapter(resp interface{}) map[string]interface{}

InterfaceToMapAdapter it will convert any golang struct into map

func InterfaceToString added in v0.6.15

func InterfaceToString(resp interface{}) string

func Intn

func Intn(max int) int

Intn generates an integer in range [0,max). By design this should panic if input is invalid, <= 0.

func IntnRange

func IntnRange(min, max int) int

IntnRange generates an integer in range [min,max). By design this should panic if input is invalid, <= 0.

func IsBaseStack added in v0.5.3

func IsBaseStack() bool

func IsFullStack added in v0.5.3

func IsFullStack() bool

func IsHelmApp added in v0.5.3

func IsHelmApp(appOfferingMode string) bool

func IsRunnerStatusFailed added in v0.7.1

func IsRunnerStatusFailed(status string) bool

func IsTerminalRunnerStatus added in v0.7.1

func IsTerminalRunnerStatus(status string) bool

func MatchRegexExpression added in v0.6.21

func MatchRegexExpression(exp string, text string) (bool, error)

func MemoryToNumber added in v0.2.37

func MemoryToNumber(memory string) (int64, error)

func MergeMaps added in v0.7.3

func MergeMaps(map1, map2 map[string][]string)

func ParseFloatNumber added in v0.6.13

func ParseFloatNumber(inputVal interface{}) (float64, error)

func Perm

func Perm(n int) []int

Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n) from the default Source.

func ReadFromUrlWithRetry added in v0.4.1

func ReadFromUrlWithRetry(url string) ([]byte, error)

func SafeEncodeString

func SafeEncodeString(s string) string

SafeEncodeString encodes s using the same characters as rand.String. This reduces the chances of bad words and ensures that strings generated from hash functions appear consistent throughout the API.

func Seed

func Seed(seed int64)

Seed seeds the rng with the provided seed.

func SetSuperAdminInContext added in v0.6.25

func SetSuperAdminInContext(ctx context.Context, isSuperAdmin bool) context.Context

func SplitCommaSeparatedIntValues added in v0.6.24

func SplitCommaSeparatedIntValues(input string) ([]int, error)

func String

func String(n int) string

String generates a random alphanumeric string, without vowels, which is n characters long. This will panic if n is less than zero. How the random string is created: - we generate random int63's - from each int63, we are extracting multiple random letters by bit-shifting and masking - if some index is out of range of alphanums we neglect it (unlikely to happen multiple times in a row)

func Tprintf added in v0.4.1

func Tprintf(tmpl string, data interface{}) (string, error)

Tprintf passed template string is formatted usign its operands and returns the resulting string. Spaces are added between operands when neither is a string.

func Transform added in v0.6.29

func Transform[T any, K any](input []T, transform func(inp T) K) []K

func TriggerCDMetrics added in v0.6.14

func TriggerCDMetrics(wfr CDMetrics, exposeCDMetrics bool)

func TriggerCIMetrics added in v0.6.15

func TriggerCIMetrics(Metrics CIMetrics, exposeCIMetrics bool, PipelineName string, AppName string)

func TriggerGitOpsMetrics added in v0.6.15

func TriggerGitOpsMetrics(operation string, method string, startTime time.Time, err error)

func TruncateFloat added in v0.6.29

func TruncateFloat(value float64, decimals int) float64

TruncateFloat truncates a float64 value to n decimal points using the math package.

func ValidateEncodedDataByDecoding added in v0.7.2

func ValidateEncodedDataByDecoding(dataMap map[string]string) error

Types

type CDMetrics added in v0.6.14

type CDMetrics struct {
	AppName         string
	DeploymentType  string
	Status          string
	EnvironmentName string
	Time            float64
}

type CIMetrics added in v0.6.15

type CIMetrics struct {
	CacheDownDuration  float64   `json:"cacheDownDuration"`
	PreCiDuration      float64   `json:"preCiDuration"`
	BuildDuration      float64   `json:"buildDuration"`
	PostCiDuration     float64   `json:"postCiDuration"`
	CacheUpDuration    float64   `json:"cacheUpDuration"`
	TotalDuration      float64   `json:"totalDuration"`
	CacheDownStartTime time.Time `json:"cacheDownStartTime"`
	PreCiStartTime     time.Time `json:"preCiStart"`
	BuildStartTime     time.Time `json:"buildStartTime"`
	PostCiStartTime    time.Time `json:"postCiStartTime"`
	CacheUpStartTime   time.Time `json:"cacheUpStartTime"`
	TotalStartTime     time.Time `json:"totalStartTime"`
}

type Closer

type Closer interface {
	Close() error
}

type CpuChecker added in v0.2.37

type CpuChecker struct{}

func (CpuChecker) IsFormat added in v0.2.37

func (f CpuChecker) IsFormat(input interface{}) bool

type CustomFormatCheckers added in v0.2.37

type CustomFormatCheckers struct {
}

func NewGoJsonSchemaCustomFormatChecker added in v0.2.37

func NewGoJsonSchemaCustomFormatChecker() *CustomFormatCheckers

func (CustomFormatCheckers) AddCheckers added in v0.2.37

func (c CustomFormatCheckers) AddCheckers()

type DeploymentServiceTypeConfig added in v0.7.0

type DeploymentServiceTypeConfig struct {
	ExternallyManagedDeploymentType bool `env:"IS_INTERNAL_USE" envDefault:"false"`
	HelmInstallASyncMode            bool `env:"RUN_HELM_INSTALL_IN_ASYNC_MODE_HELM_APPS" envDefault:"false"`
	UseDeploymentConfigData         bool `env:"USE_DEPLOYMENT_CONFIG_DATA" envDefault:"false"`
}

type DevtronSecretConfig added in v0.5.3

type DevtronSecretConfig struct {
	DevtronSecretName         string `env:"DEVTRON_SECRET_NAME" envDefault:"devtron-secret"`
	DevtronDexSecretNamespace string `env:"DEVTRON_DEX_SECRET_NAMESPACE" envDefault:"devtroncd"`
}

type EnvironmentVariables added in v0.7.0

type EnvironmentVariables struct {
	GlobalEnvVariables          *GlobalEnvVariables
	DevtronSecretConfig         *DevtronSecretConfig
	DeploymentServiceTypeConfig *DeploymentServiceTypeConfig
	TerminalEnvVariables        *TerminalEnvVariables
	GlobalClusterConfig         *GlobalClusterConfig
}

func GetEnvironmentVariables added in v0.7.0

func GetEnvironmentVariables() (*EnvironmentVariables, error)

type EvalIsNonPublishableErr added in v0.7.3

type EvalIsNonPublishableErr func(err error) bool

func AllPublishableError added in v0.7.3

func AllPublishableError() EvalIsNonPublishableErr

type GlobalClusterConfig added in v0.7.3

type GlobalClusterConfig struct {
	ClusterStatusCronTime int `env:"CLUSTER_STATUS_CRON_TIME" envDefault:"15"`
}

type GlobalEnvVariables added in v0.3.17

type GlobalEnvVariables struct {
	GitOpsRepoPrefix                     string `env:"GITOPS_REPO_PREFIX" envDefault:""`
	EnableAsyncHelmInstallDevtronChart   bool   `env:"ENABLE_ASYNC_INSTALL_DEVTRON_CHART" envDefault:"false"`
	EnableAsyncArgoCdInstallDevtronChart bool   `env:"ENABLE_ASYNC_ARGO_CD_INSTALL_DEVTRON_CHART" envDefault:"false"`
	ArgoGitCommitRetryCountOnConflict    int    `env:"ARGO_GIT_COMMIT_RETRY_COUNT_ON_CONFLICT" envDefault:"3"`
	ArgoGitCommitRetryDelayOnConflict    int    `env:"ARGO_GIT_COMMIT_RETRY_DELAY_ON_CONFLICT" envDefault:"1"`
	ExposeCiMetrics                      bool   `env:"EXPOSE_CI_METRICS" envDefault:"false"`
	ExecuteWireNilChecker                bool   `env:"EXECUTE_WIRE_NIL_CHECKER" envDefault:"false"`
}

type HpaResourceRequest added in v0.6.18

type HpaResourceRequest struct {
	ResourceName    string
	ReqReplicaCount float64
	ReqMaxReplicas  float64
	ReqMinReplicas  float64
	IsEnable        bool
	Group           string
	Version         string
	Kind            string
}

type ImageMetadata added in v1.0.0

type ImageMetadata struct {
	Repo   string
	Tag    string
	Digest string
}

func ExtractImageRepoAndTag added in v1.0.0

func ExtractImageRepoAndTag(imagePath string) (imageMetadata *ImageMetadata, err error)

type MemoryChecker added in v0.2.37

type MemoryChecker struct{}

func (MemoryChecker) IsFormat added in v0.2.37

func (f MemoryChecker) IsFormat(input interface{}) bool

type SecretTransformMode added in v0.6.26

type SecretTransformMode int
const (
	EncodeSecret SecretTransformMode = 1
	DecodeSecret SecretTransformMode = 2
)

type ServerVersion added in v0.3.9

type ServerVersion struct {
	GitCommit  string `json:"gitCommit"`
	BuildTime  string `json:"buildTime"`
	ServerMode string `json:"serverMode"`
}

func GetDevtronVersion added in v0.3.9

func GetDevtronVersion() *ServerVersion

type TerminalEnvVariables added in v0.7.1

type TerminalEnvVariables struct {
	RestrictTerminalAccessForNonSuperUser bool `env:"RESTRICT_TERMINAL_ACCESS_FOR_NON_SUPER_USER" envDefault:"false"`
}

Directories

Path Synopsis
mocks
rbac
Package mock_rbac is a generated GoMock package.
Package mock_rbac is a generated GoMock package.

Jump to

Keyboard shortcuts

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