Documentation
¶
Index ¶
- Constants
- Variables
- func AnyPositiveInSliceInt64(numbers []int64) bool
- func ApplyRedactorChange(loggerInstance logger.Logger, callback func(*nucliozap.Redactor))
- func ByteSliceToString(b []byte) string
- func CatchAndLogPanicWithOptions(ctx context.Context, loggerInstance logger.Logger, actionName string, ...) error
- func CompareTwoStrings(stringOne, stringTwo string) float32
- func CompileImageName(registryURL string, imageName string) string
- func CompileListFunctionPodsLabelSelector(functionName string) string
- func CompileStalePodsFieldSelector() string
- func DownloadFile(url string, out *os.File, headers http.Header) error
- func EnsureDirExists(ctx context.Context, loggerInstance logger.Logger, dir string) error
- func EnvInSlice(env v1.EnvVar, slice []v1.EnvVar) bool
- func ErrorFromRecoveredError(recoveredError interface{}) error
- func FileExists(path string) bool
- func FilterInvalidLabels(labels map[string]string) map[string]string
- func FixEscapeChars(s string) string
- func GenerateRandomString(length int, letters []rune) string
- func GenerateStringMatchVerifier(str string) func(string) bool
- func GetAttributeRecursivelyFromMapStringInterface(mapStringInterface map[string]interface{}, attributes []string) map[string]interface{}
- func GetClientConfig(kubeconfigPath string) (*rest.Config, error)
- func GetDurationOrInfinite(timeout *time.Duration) time.Duration
- func GetEnvOrDefaultBool(key string, defaultValue bool) bool
- func GetEnvOrDefaultInt(key string, defaultValue int) int
- func GetEnvOrDefaultString(key string, defaultValue string) string
- func GetFunctionName(function interface{}) string
- func GetKubeConfigClientCmdByKubeconfigPath(kubeconfigPath string) (*clientcmdapi.Config, error)
- func GetKubeconfigPath(kubeconfigPath string) string
- func GetLoggersFromInstance(loggerInstance logger.Logger) []logger.Logger
- func GetPathFromLocalFileURL(s string) string
- func GetRedactorInstance(output io.Writer) *nucliozap.Redactor
- func GetRuntimeNameAndVersion(runtime string) (string, string)
- func GetSourceDir() string
- func GetStringToStringMapOrEmpty(m map[string]string) map[string]string
- func GetZipFileContents(zf *zip.File) (string, error)
- func IsDir(path string) bool
- func IsFile(path string) bool
- func IsInKubernetesCluster() bool
- func IsJavaProjectDir(dirPath string) bool
- func IsLocalFileURL(s string) bool
- func IsURL(s string) bool
- func LabelsMapMatchByLabelSelector(labelSelector string, labelsMap map[string]string) (bool, error)
- func LogPanic(ctx context.Context, loggerInstance logger.Logger, actionName string, ...)
- func MapInterfaceInterfaceToMapStringInterface(mapInterfaceInterface map[interface{}]interface{}) map[string]interface{}
- func MapStringInterfaceGetOrDefault(mapStringInterface map[string]interface{}, key string, ...) interface{}
- func MapStringStringToMapStringBytesArray(m map[string]string) map[string][]byte
- func MapToSlice(m map[string]interface{}) []interface{}
- func MatchStringPatterns(patterns []string, s string) bool
- func MergeEnvSlices(primaryEnv []v1.EnvVar, secondaryEnv []v1.EnvVar) []v1.EnvVar
- func MergeNodeSelector(...) map[string]string
- func NormalizeURLPath(p string) string
- func ParseQuantityOrDefault(value string, defaultValue string, loggerInstance logger.Logger) apiresource.Quantity
- func PopulateFieldsFromValues[T string | bool | int](fieldsToValues map[*T]T)
- func PrependStringToStringSlice(slice []string, str string) []string
- func PrependStringsToStringSlice(slice []string, strs ...string) []string
- func Quote(s string) string
- func RemoveANSIColorsFromString(s string) string
- func RemoveDuplicatesFromSliceString(slice []string) []string
- func RemoveEmptyLines(input string) string
- func RemoveEnvFromSlice(env v1.EnvVar, slice []v1.EnvVar) []v1.EnvVar
- func RemoveStringSliceItemsFromStringSlice(slice []string, itemsToRemove []string) []string
- func RemoveWindowsCarriage(b []byte) []byte
- func RenderTemplate(text string, data map[string]interface{}) (string, error)
- func RenderTemplateWithCustomDelimiters(text string, data map[string]interface{}, leftDelimiter string, ...) (string, error)
- func ResolveDefaultNamespace(namespace string) string
- func ResolveErrorStatusCodeOrDefault(err error, defaultStatusCode int) int
- func ResolveNamespace(namespaceArgument string, defaultEnvVarKey string) string
- func RetryUntilSuccessful(duration time.Duration, interval time.Duration, callback func() bool) error
- func RetryUntilSuccessfulOnErrorPatterns(duration time.Duration, interval time.Duration, errorRegexPatterns []string, ...) error
- func RunningContainerHostname() (string, error)
- func RunningInContainer() bool
- func SanitizeResponseData(data []byte, headers http.Header) []byte
- func SendHTTPRequest(httpClient *http.Client, method string, requestURL string, body []byte, ...) ([]byte, *http.Response, error)
- func SendHTTPRequestWithContext(ctx context.Context, httpClient *http.Client, method string, requestURL string, ...) ([]byte, *http.Response, error)
- func SetLoggerRedactionMode(loggerInstance logger.Logger, enabled bool)
- func SetVersionFromEnv()
- func StringInSlice(a string, list []string) bool
- func StringMapToString(source map[string]string) string
- func StringSliceContainsString(slice []string, str string) bool
- func StringSliceContainsStringCaseInsensitive(slice []string, str string) bool
- func StringSliceContainsStringPrefix(prefixes []string, str string) bool
- func StringSliceToIntSlice(stringSlice []string) ([]int, error)
- func StringToStringMap(source string, separator string) map[string]string
- func StripPrefixes(input string, prefixes []string) string
- func StripSuffixes(input string, suffixes []string) string
- func StructureToMap(input interface{}) map[string]interface{}
- func ValidateLabels(labels map[string]string) error
- func ValidateURLPath(path string) bool
- type AbstractS3Client
- type AbstractScrubber
- func (s *AbstractScrubber) CreateOrUpdateObjectSecret(ctx context.Context, encodedSecretsMap map[string]string, secretName string, ...) error
- func (s *AbstractScrubber) CreateOrUpdateSecret(ctx context.Context, namespace string, secretConfig *v1.Secret) error
- func (s *AbstractScrubber) DecodeSecretData(secretData map[string][]byte) (map[string]string, error)
- func (s *AbstractScrubber) DecodeSecretKey(secretKey string) (string, error)
- func (s *AbstractScrubber) DecodeSecretsMapContent(secretsMapContent string) (map[string]string, error)
- func (s *AbstractScrubber) EncodeSecretKey(fieldPath string) string
- func (s *AbstractScrubber) EncodeSecretsMap(secretsMap map[string]string) (map[string]string, error)
- func (s *AbstractScrubber) GetObjectSecret(ctx context.Context, name, namespace string) (*v1.Secret, error)
- func (s *AbstractScrubber) GetObjectSecretMap(ctx context.Context, name, namespace string) (map[string]string, string, error)
- func (s *AbstractScrubber) GetObjectSecretName(ctx context.Context, name, namespace string) (string, error)
- func (s *AbstractScrubber) GetObjectSecrets(ctx context.Context, name, namespace string) ([]v1.Secret, error)
- func (s *AbstractScrubber) HasScrubbedConfig(object interface{}, sensitiveFields []*regexp.Regexp) (bool, error)
- func (s *AbstractScrubber) Restore(scrubbedObject interface{}, secretsMap map[string]string) (interface{}, error)
- func (s *AbstractScrubber) Scrub(ctx context.Context, objectConfig interface{}, name, namespace string) (interface{}, string, map[string]string, error)
- type CatchAndLogPanicOptions
- type ChannelWithRecover
- type ExportFunctionOptions
- type FunctionStateMessage
- type KubernetesClientWarningHandler
- type MockS3Client
- type ReusedMessage
- type S3Client
- type Scrubber
Constants ¶
const ( AutoPlatformName = "auto" KubePlatformName = "kube" LocalPlatformName = "local" )
const ( ReferencePrefix = "$ref:" ReferenceToEnvVarPrefix = "NUCLIO_B64_" SecretContentKey = "content" )
const ( HTTPPrefix = "http://" HTTPSPrefix = "https://" LocalFilePrefix = "file://" )
const DefaultIngressHostTemplate = "@nuclio.fromDefault"
const FunctionConfigFileName = "function.yaml"
const FunctionTagLatest = "latest"
const KubernetesDomainLevelMaxLength = 63
KubernetesDomainLevelMaxLength DNS domain level limitation is 63 chars https://en.wikipedia.org/wiki/Subdomain#Overview
const NuclioLabelKeyApp = "nuclio.io/app"
const NuclioLabelKeyClass = "nuclio.io/class"
const NuclioLabelKeyComponent = "nuclio.io/component"
const NuclioLabelKeyFunctionCronJobPod = "nuclio.io/function-cron-job-pod"
const NuclioLabelKeyFunctionCronTriggerName = "nuclio.io/function-cron-trigger-name"
const NuclioLabelKeyFunctionVersion = "nuclio.io/function-version"
const NuclioResourceLabelKeyApiGatewayName = "nuclio.io/apigateway-name"
const NuclioResourceLabelKeyFunctionName = "nuclio.io/function-name"
const NuclioResourceLabelKeyProjectName = "nuclio.io/project-name"
const NuclioResourceLabelKeyVolumeName = "nuclio.io/volume-name"
const RestoreConfigFromSecretEnvVar = "NUCLIO_RESTORE_FUNCTION_CONFIG_FROM_SECRET"
Variables ¶
var LettersAndNumbers = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
var SmallLettersAndNumbers = []rune("abcdefghijklmnopqrstuvwxyz1234567890")
var URLPathRegexpCompiled = regexp.MustCompile(urlPathRegex)
Functions ¶
func AnyPositiveInSliceInt64 ¶
func ApplyRedactorChange ¶
func ByteSliceToString ¶
func CompareTwoStrings ¶
CompareTwoStrings uses Sørensen–Dice coefficient to check similarity
func CompileImageName ¶
func CompileStalePodsFieldSelector ¶
func CompileStalePodsFieldSelector() string
CompileStalePodsFieldSelector creates a field selector(string) for stale pods
func EnsureDirExists ¶
EnsureDirExists checks if the directory exists, creates it if it doesn't
func ErrorFromRecoveredError ¶
func ErrorFromRecoveredError(recoveredError interface{}) error
func FileExists ¶
FileExists returns true if the file @ path exists
func FilterInvalidLabels ¶
FilterInvalidLabels filters out invalid kubernetes labels from a map of labels
func FixEscapeChars ¶
func GenerateRandomString ¶
func GenerateStringMatchVerifier ¶
GenerateStringMatchVerifier generates a function that returns whether a given string matches the specified string
func GetAttributeRecursivelyFromMapStringInterface ¶
func GetAttributeRecursivelyFromMapStringInterface(mapStringInterface map[string]interface{}, attributes []string) map[string]interface{}
GetAttributeRecursivelyFromMapStringInterface iterates over the attributes slice and recursively searches the map, returning the last attribute in the slice
func GetEnvOrDefaultBool ¶
func GetEnvOrDefaultInt ¶
func GetEnvOrDefaultString ¶
func GetFunctionName ¶
func GetFunctionName(function interface{}) string
GetFunctionName returns the actual name of a function variable
func GetKubeConfigClientCmdByKubeconfigPath ¶
func GetKubeConfigClientCmdByKubeconfigPath(kubeconfigPath string) (*clientcmdapi.Config, error)
func GetKubeconfigPath ¶
func GetLoggersFromInstance ¶
func GetPathFromLocalFileURL ¶
GetPathFromLocalFileURL extracts absolute path to file from local file URL example: "file://path/to/file" -> "/path/to/file"
func GetRuntimeNameAndVersion ¶
GetRuntimeNameAndVersion return runtime name and version. e.g. go:1.8 -> go, 1.8
func GetSourceDir ¶
func GetSourceDir() string
func GetStringToStringMapOrEmpty ¶
GetStringToStringMapOrEmpty returns string to string map if it's not nil. otherwise, return an empty one
func IsInKubernetesCluster ¶
func IsInKubernetesCluster() bool
func IsJavaProjectDir ¶
IsJavaProjectDir Checks if the given @dirPath is in a java project structure for example if the following dir existed "/my-project/src/main/java" then IsJavaProjectDir("/my-project") -> true
func IsLocalFileURL ¶
func LabelsMapMatchByLabelSelector ¶
LabelsMapMatchByLabelSelector returns whether a labelsMap is matched by an encoded label selector corresponding to https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
Example:
labelsMap: a: b c: d encodedLabelSelector: a=b
returns true
func MapInterfaceInterfaceToMapStringInterface ¶
func MapInterfaceInterfaceToMapStringInterface(mapInterfaceInterface map[interface{}]interface{}) map[string]interface{}
MapInterfaceInterfaceToMapStringInterface recursively converts map[interface{}]interface{} to map[string]interface{}
func MapStringInterfaceGetOrDefault ¶
func MapStringInterfaceGetOrDefault(mapStringInterface map[string]interface{}, key string, defaultValue interface{}) interface{}
MapStringInterfaceGetOrDefault will return the key as an integer or return a default
func MapStringStringToMapStringBytesArray ¶
MapStringStringToMapStringBytesArray converts the string values of a map to byte arrays Example: {"a": "b"} -> {"a": []byte("b")}
func MapToSlice ¶
func MapToSlice(m map[string]interface{}) []interface{}
MapToSlice converts {key1: val1, key2: val2 ...} to [key1, val1, key2, val2 ...]
func MatchStringPatterns ¶
func MergeEnvSlices ¶
MergeEnvSlices merges two lists of environment variables, giving priority to variables from the primary list
func MergeNodeSelector ¶
func MergeNodeSelector(functionNodeSelector, projectNodeSelector, platformNodeSelector map[string]string) map[string]string
MergeNodeSelector merges function, project and platform NodeSelectors where function values take precedence over project values, and project values take precedence over platform values
func NormalizeURLPath ¶
NormalizeURLPath normalizes URL Path examples: "" -> "/" "a" -> "/a/" "//a//b/c/" -> "/a/b/c/"
func ParseQuantityOrDefault ¶
func PopulateFieldsFromValues ¶
PopulateFieldsFromValues populates empty fields with values if the value is not zero. the fieldsToValues argument is a map of pointers to fields to populate and values.
func PrependStringToStringSlice ¶
PrependStringToStringSlice prepends a string to a string slice
func PrependStringsToStringSlice ¶
PrependStringsToStringSlice prepends multiple strings to a string slice
func Quote ¶
Quote returns a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line.
func RemoveANSIColorsFromString ¶
RemoveANSIColorsFromString strips out ANSI Colors chars from string example: "\u001b[31mHelloWorld" -> "HelloWorld"
func RemoveEmptyLines ¶
RemoveEmptyLines removes all empty lines from a string
func RemoveWindowsCarriage ¶
RemoveWindowsCarriage removes windows carriage character '\r' when it follows by '\n'
func ResolveDefaultNamespace ¶
ResolveDefaultNamespace returns the proper default resource namespace, given the current default namespace
func ResolveNamespace ¶
ResolveNamespace returns the namespace by the following order: 1. If namespace is passed as an argument, use that 2. If namespace is passed as an environment variable, use that 3. Alternatively, use "this" namespace (where the pod is running)
func RetryUntilSuccessful ¶
func RetryUntilSuccessful(duration time.Duration, interval time.Duration, callback func() bool) error
RetryUntilSuccessful calls callback every interval for duration until it returns true
func RetryUntilSuccessfulOnErrorPatterns ¶
func RetryUntilSuccessfulOnErrorPatterns( duration time.Duration, interval time.Duration, errorRegexPatterns []string, callback func(retryCounter int) (string, error)) error
RetryUntilSuccessfulOnErrorPatterns calls callback every interval for duration as long as error pattern is matched the callback argument retryCounter is the number of times the callback was called
func RunningContainerHostname ¶
RunningContainerHostname returns the hostname (aka container id) of the running container
func RunningInContainer ¶
func RunningInContainer() bool
RunningInContainer returns true if currently running in a container, false otherwise
func SanitizeResponseData ¶
SanitizeResponseData tries to parse byte data as html. if it succeeds, it is returned sanitized, otherwise the original data is returned. func SanitizeResponseData(data []byte) []byte {
func SendHTTPRequest ¶
func SendHTTPRequest(httpClient *http.Client, method string, requestURL string, body []byte, headers map[string]string, cookies []*http.Cookie, expectedStatusCode int) ([]byte, *http.Response, error)
SendHTTPRequest Sends an HTTP request using custom http client ignore expectedStatusCode by setting it to 0
func SendHTTPRequestWithContext ¶
func SendHTTPRequestWithContext(ctx context.Context, httpClient *http.Client, method string, requestURL string, body []byte, headers map[string]string, cookies []*http.Cookie, expectedStatusCode int) ([]byte, *http.Response, error)
SendHTTPRequestWithContext is like SendHTTPRequest but with context
func SetLoggerRedactionMode ¶
func SetVersionFromEnv ¶
func SetVersionFromEnv()
SetVersionFromEnv is being used by tests to override linker injected values
func StringInSlice ¶
func StringMapToString ¶
StringMapToString converts a map of a: x, b: y to a string in the form of "a=x,b=y"
func StringSliceContainsString ¶
StringSliceContainsString returns whether the input str is in the slice
func StringSliceContainsStringCaseInsensitive ¶
StringSliceContainsStringCaseInsensitive returns whether the input str is in the slice case-insensitive
func StringSliceContainsStringPrefix ¶
StringSliceContainsStringPrefix returns whether the input str has prefix
func StringSliceToIntSlice ¶
StringSliceToIntSlice converts slices of strings to slices of int. e.g. ["1", "3"] -> [1, 3]
func StringToStringMap ¶
StringToStringMap converts a string in the form of a{separator}x,b{separator}y to a map of a: x, b: y, inputs source-string & string-separator
func StripPrefixes ¶
func StripSuffixes ¶
func StructureToMap ¶
func StructureToMap(input interface{}) map[string]interface{}
StructureToMap converts a strcuture to a map, flattening all members
func ValidateLabels ¶
ValidateLabels validates the given labels according to k8s label constraints
func ValidateURLPath ¶
ValidateURLPath validates only path of url (without host)
Types ¶
type AbstractS3Client ¶
type AbstractS3Client struct {
S3Client
}
func (*AbstractS3Client) DownloadWithinEC2Instance ¶
func (asc *AbstractS3Client) DownloadWithinEC2Instance(file *os.File, bucket, itemKey string) error
type AbstractScrubber ¶
type AbstractScrubber struct { SensitiveFields []*regexp.Regexp KubeClientSet kubernetes.Interface ReferencePrefix string Scrubber Scrubber ResourceLabelKeyObjectName string SecretType v1.SecretType Logger logger.Logger // contains filtered or unexported fields }
AbstractScrubber is an object that implements abstract scrubbing functionality
func NewAbstractScrubber ¶
func NewAbstractScrubber(parentLogger logger.Logger, sensitiveFields []*regexp.Regexp, kubeClientSet kubernetes.Interface, referencePrefix, resourceLabelKeyObjectName string, secretType v1.SecretType, secretFilterName func(secret v1.Secret) bool) *AbstractScrubber
NewAbstractScrubber returns a new AbstractScrubber
func (*AbstractScrubber) CreateOrUpdateObjectSecret ¶
func (*AbstractScrubber) CreateOrUpdateSecret ¶
func (*AbstractScrubber) DecodeSecretData ¶
func (s *AbstractScrubber) DecodeSecretData(secretData map[string][]byte) (map[string]string, error)
DecodeSecretData decodes the keys of a secrets map
func (*AbstractScrubber) DecodeSecretKey ¶
func (s *AbstractScrubber) DecodeSecretKey(secretKey string) (string, error)
DecodeSecretKey decodes a secret key and returns the original field
func (*AbstractScrubber) DecodeSecretsMapContent ¶
func (s *AbstractScrubber) DecodeSecretsMapContent(secretsMapContent string) (map[string]string, error)
DecodeSecretsMapContent decodes the secrets map content
func (*AbstractScrubber) EncodeSecretKey ¶
func (s *AbstractScrubber) EncodeSecretKey(fieldPath string) string
EncodeSecretKey encodes a secret key
func (*AbstractScrubber) EncodeSecretsMap ¶
func (s *AbstractScrubber) EncodeSecretsMap(secretsMap map[string]string) (map[string]string, error)
EncodeSecretsMap encodes the keys of a secrets map
func (*AbstractScrubber) GetObjectSecret ¶
func (s *AbstractScrubber) GetObjectSecret(ctx context.Context, name, namespace string) (*v1.Secret, error)
GetObjectSecret returns the object's secret data
func (*AbstractScrubber) GetObjectSecretMap ¶
func (*AbstractScrubber) GetObjectSecretName ¶
func (*AbstractScrubber) GetObjectSecrets ¶
func (*AbstractScrubber) HasScrubbedConfig ¶
func (s *AbstractScrubber) HasScrubbedConfig(object interface{}, sensitiveFields []*regexp.Regexp) (bool, error)
HasScrubbedConfig checks if a object has scrubbed data, using the scrub object
type CatchAndLogPanicOptions ¶
type CatchAndLogPanicOptions struct { Args []interface{} CustomHandler func(error) }
type ChannelWithRecover ¶
ChannelWithRecover wraps a context.Context and a Channel, providing a safe way to write data to the Channel with panic recovery
func (*ChannelWithRecover) Write ¶
func (c *ChannelWithRecover) Write(logger logger.Logger, objectToWrite interface{})
Write writes the specified object to the Channel, handling any panics that may occur during the operation and logging them using the provided logger. If the associated context is canceled (via `Done()`), the write operation is aborted. Otherwise, the objectToWrite is sent to the Channel. This method is designed to recover from panics during the write operation
type ExportFunctionOptions ¶
type FunctionStateMessage ¶
type FunctionStateMessage string
const (
FunctionStateMessageUnhealthy FunctionStateMessage = "Function is not healthy"
)
type KubernetesClientWarningHandler ¶
type KubernetesClientWarningHandler struct {
// contains filtered or unexported fields
}
func NewKubernetesClientWarningHandler ¶
func NewKubernetesClientWarningHandler(logger logger.Logger) *KubernetesClientWarningHandler
func (*KubernetesClientWarningHandler) HandleWarningHeader ¶
func (kcl *KubernetesClientWarningHandler) HandleWarningHeader(code int, agent string, message string)
HandleWarningHeader handles miscellaneous warning messages yielded by Kubernetes api server e.g.: "autoscaling/v2beta1 HorizontalPodAutoscaler is deprecated in v1.22+, unavailable in v1.25+; use autoscaling/v2beta2 HorizontalPodAutoscaler" Note: code is determined by the Kubernetes server
type MockS3Client ¶
func (*MockS3Client) Download ¶
func (msc *MockS3Client) Download(file *os.File, bucket, itemKey, region, accessKeyID, secretAccessKey, sessionToken string) error
func (*MockS3Client) DownloadWithinEC2Instance ¶
func (msc *MockS3Client) DownloadWithinEC2Instance(file *os.File, bucket, itemKey string) error
type ReusedMessage ¶
type ReusedMessage string
const ( UnexpectedTerminationChildProcess ReusedMessage = "Unexpected termination of child process" WorkDirectoryDoesNotExist ReusedMessage = "Work directory does not exist" WorkDirectoryExpectedBeString ReusedMessage = "Work directory is expected to be string" FailedReadFromEventConnection ReusedMessage = "Failed to read from event connection" FailedReadFromControlConnection ReusedMessage = "Failed to read from control connection" FailedReadControlMessage ReusedMessage = "Failed to read control message" )
type Scrubber ¶
type Scrubber interface { // Scrub scrubs sensitive data from an object Scrub(ctx context.Context, objectConfig interface{}, name, namespace string) (interface{}, string, map[string]string, error) // Restore restores sensitive data in an object from a secrets map Restore(scrubbedObject interface{}, secretsMap map[string]string) (interface{}, error) // ValidateReference validates references in a scrubbed object ValidateReference(objectToScrub interface{}, existingSecretMap map[string]string, fieldPath, secretKey, stringValue string) error // ConvertMapToConfig converts map back to an object entity ConvertMapToConfig(mapConfig interface{}) (interface{}, error) }