kubernetes

package
v3.24.42 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	URLObject = decls.NewObjectType("kubernetes.URL")

	URLType = cel.ObjectType("kubernetes.URL")
)
View Source
var FindAllRegexOptimization = &interpreter.RegexOptimization{
	Function:   "findAll",
	RegexIndex: 1,
	Factory: func(call interpreter.InterpretableCall, regexPattern string) (interpreter.InterpretableCall, error) {
		compiledRegex, err := regexp.Compile(regexPattern)
		if err != nil {
			return nil, err
		}
		return interpreter.NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), func(args ...ref.Val) ref.Val {
			argn := len(args)
			if argn < 2 || argn > 3 {
				return types.NoSuchOverloadErr()
			}
			str, ok := args[0].Value().(string)
			if !ok {
				return types.MaybeNoSuchOverloadErr(args[0])
			}
			n := int64(-1)
			if argn == 3 {
				n, ok = args[2].Value().(int64)
				if !ok {
					return types.MaybeNoSuchOverloadErr(args[2])
				}
			}

			result := compiledRegex.FindAllString(str, int(n))
			return types.NewStringList(types.DefaultTypeAdapter, result)
		}), nil
	},
}

FindAllRegexOptimization optimizes the 'findAll' function by compiling the regex pattern and reporting any compilation errors at program creation time, and using the compiled regex pattern for all function call invocations.

View Source
var FindRegexOptimization = &interpreter.RegexOptimization{
	Function:   "find",
	RegexIndex: 1,
	Factory: func(call interpreter.InterpretableCall, regexPattern string) (interpreter.InterpretableCall, error) {
		compiledRegex, err := regexp.Compile(regexPattern)
		if err != nil {
			return nil, err
		}
		return interpreter.NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), func(args ...ref.Val) ref.Val {
			if len(args) != 2 {
				return types.NoSuchOverloadErr()
			}
			in, ok := args[0].Value().(string)
			if !ok {
				return types.MaybeNoSuchOverloadErr(args[0])
			}
			return types.String(compiledRegex.FindString(in))
		}), nil
	},
}

FindRegexOptimization optimizes the 'find' function by compiling the regex pattern and reporting any compilation errors at program creation time, and using the compiled regex pattern for all function call invocations.

View Source
var MatchRegexOptimization = &interpreter.RegexOptimization{
	Function:   "match",
	RegexIndex: 1,
	Factory: func(call interpreter.InterpretableCall, regexPattern string) (interpreter.InterpretableCall, error) {
		compiledRegex, err := regexp.Compile(regexPattern)
		if err != nil {
			return nil, err
		}
		return interpreter.NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), func(args ...ref.Val) ref.Val {
			if len(args) != 2 {
				return types.NoSuchOverloadErr()
			}
			in, ok := args[0].Value().(string)
			if !ok {
				return types.MaybeNoSuchOverloadErr(args[0])
			}
			return types.Bool(compiledRegex.Match([]byte(in)))
		}), nil
	},
}
View Source
var ReplaceAllRegexOptimization = &interpreter.RegexOptimization{
	Function:   "replaceAll",
	RegexIndex: 1,
	Factory: func(call interpreter.InterpretableCall, regexPattern string) (interpreter.InterpretableCall, error) {
		compiledRegex, err := regexp.Compile(regexPattern)
		if err != nil {
			return nil, err
		}
		return interpreter.NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), func(args ...ref.Val) ref.Val {
			if len(args) != 3 {
				return types.NoSuchOverloadErr()
			}
			in, ok := args[0].Value().(string)
			if !ok {
				return types.MaybeNoSuchOverloadErr(args[0])
			}
			with, ok := args[2].Value().(string)
			if !ok {
				return types.MaybeNoSuchOverloadErr(args[2])
			}
			return types.String(compiledRegex.ReplaceAllString(in, with))
		}), nil
	},
}
View Source
var TestDegradedCertificate = `` /* 1018-byte string literal not displayed */
View Source
var TestHealthyCertificate = `` /* 979-byte string literal not displayed */
View Source
var TestHealthySvc = `` /* 481-byte string literal not displayed */
View Source
var TestLuaStatus = `` /* 737-byte string literal not displayed */
View Source
var TestLuaStatusUnstructured = GetUnstructured(TestLuaStatus)
View Source
var TestPVJsonRaw = `` /* 1209-byte string literal not displayed */
View Source
var TestPVYAMLRaw = `` /* 668-byte string literal not displayed */
View Source
var TestPodNeat = `` /* 720-byte string literal not displayed */
View Source
var TestPodRaw = `` /* 3446-byte string literal not displayed */
View Source
var TestProgressing = `` /* 357-byte string literal not displayed */
View Source
var TestProgressingUnstructured = GetUnstructured(TestProgressing)
View Source
var TestServiceNeat = `` /* 254-byte string literal not displayed */
View Source
var TestServiceRaw = `` /* 574-byte string literal not displayed */
View Source
var TestUnhealthy = `` /* 2449-byte string literal not displayed */
View Source
var TestUnhealthyUnstructured = GetUnstructured(TestUnhealthy)
View Source
var TesthealthyUnstructured = GetUnstructured(TestHealthySvc)

Functions

func GetStatus added in v3.20.19

func GetStatus(in interface{}) string

func GetUnstructured added in v3.20.19

func GetUnstructured(in interface{}) *unstructured.Unstructured

func GetUnstructuredMap added in v3.20.19

func GetUnstructuredMap(in interface{}) []byte

func IsHealthy added in v3.20.19

func IsHealthy(in interface{}) bool

func IsReady added in v3.24.7

func IsReady(in any) bool

func Library added in v3.20.19

func Library() []cel.EnvOption

func Lists

func Lists() cel.EnvOption

Lists provides a CEL function library extension of list utility functions.

isSorted

Returns true if the provided list of comparable elements is sorted, else returns false.

<list<T>>.isSorted() <bool>, T must be a comparable type

Examples:

[1, 2, 3].isSorted()  // return true
['a', 'b', 'b', 'c'].isSorted()  // return true
[2.0, 1.0].isSorted()  // return false
[1].isSorted()  // return true
[].isSorted()  // return true

sum

Returns the sum of the elements of the provided list. Supports CEL number (int, uint, double) and duration types.

<list<T>>.sum() <T>, T must be a numeric type or a duration

Examples:

[1, 3].sum() // returns 4
[1.0, 3.0].sum() // returns 4.0
['1m', '1s'].sum() // returns '1m1s'
emptyIntList.sum() // returns 0
emptyDoubleList.sum() // returns 0.0
[].sum() // returns 0

min / max

Returns the minimum/maximum valued element of the provided list. Supports all comparable types. If the list is empty, an error is returned.

<list<T>>.min() <T>, T must be a comparable type
<list<T>>.max() <T>, T must be a comparable type

Examples:

[1, 3].min() // returns 1
[1, 3].max() // returns 3
[].min() // error
[1].min() // returns 1
([0] + emptyList).min() // returns 0

indexOf / lastIndexOf

Returns either the first or last positional index of the provided element in the list. If the element is not found, -1 is returned. Supports all equatable types.

<list<T>>.indexOf(<T>) <int>, T must be an equatable type
<list<T>>.lastIndexOf(<T>) <int>, T must be an equatable type

Examples:

[1, 2, 2, 3].indexOf(2) // returns 1
['a', 'b', 'b', 'c'].lastIndexOf('b') // returns 2
[1.0].indexOf(1.1) // returns -1
[].indexOf('string') // returns -1

func Neat added in v3.23.0

func Neat(in, outputFormat string) (string, error)

func NodeComponentProperties added in v3.21.0

func NodeComponentProperties(input any) []map[string]any

func PodComponentProperties added in v3.21.0

func PodComponentProperties(input any) []map[string]any

func Regex

func Regex() cel.EnvOption

Regex provides a CEL function library extension of regex utility functions.

find / findAll

Returns substrings that match the provided regular expression. find returns the first match. findAll may optionally be provided a limit. If the limit is set and >= 0, no more than the limit number of matches are returned.

<string>.find(<string>) <string>
<string>.findAll(<string>) <list <string>>
<string>.findAll(<string>, <int>) <list <string>>

Examples:

"abc 123".find('[0-9]*') // returns '123'
"abc 123".find('xyz') // returns ''
"123 abc 456".findAll('[0-9]*') // returns ['123', '456']
"123 abc 456".findAll('[0-9]*', 1) // returns ['123']
"123 abc 456".findAll('xyz') // returns []

func URLs

func URLs() cel.EnvOption

URLs provides a CEL function library extension of URL parsing functions.

url

Converts a string to a URL or results in an error if the string is not a valid URL. The URL must be an absolute URI or an absolute path.

url(<string>) <URL>

Examples:

url('https://user:pass@example.com:80/path?query=val#fragment') // returns a URL
url('/absolute-path') // returns a URL
url('https://a:b:c/') // error
url('../relative-path') // error

isURL

Returns true if a string is a valid URL. The URL must be an absolute URI or an absolute path.

isURL( <string>) <bool>

Examples:

isURL('https://user:pass@example.com:80/path?query=val#fragment') // returns true
isURL('/absolute-path') // returns true
isURL('https://a:b:c/') // returns false
isURL('../relative-path') // returns false

getScheme / getHost / getHostname / getPort / getEscapedPath / getQuery

Return the parsed components of a URL.

  • getScheme: If absent in the URL, returns an empty string.

  • getHostname: IPv6 addresses are returned without braces, e.g. "::1". If absent in the URL, returns an empty string.

  • getHost: IPv6 addresses are returned with braces, e.g. "[::1]". If absent in the URL, returns an empty string.

  • getEscapedPath: The string returned by getEscapedPath is URL escaped, e.g. "with space" becomes "with%20space". If absent in the URL, returns an empty string.

  • getPort: If absent in the URL, returns an empty string.

  • getQuery: Returns the query parameters in "matrix" form where a repeated query key is interpreted to mean that there are multiple values for that key. The keys and values are returned unescaped. If absent in the URL, returns an empty map.

    <URL>.getScheme() <string> <URL>.getHost() <string> <URL>.getHostname() <string> <URL>.getPort() <string> <URL>.getEscapedPath() <string> <URL>.getQuery() <map <string>, <list <string>>

Examples:

url('/path').getScheme() // returns ''
url('https://example.com/').getScheme() // returns 'https'
url('https://example.com:80/').getHost() // returns 'example.com:80'
url('https://example.com/').getHost() // returns 'example.com'
url('https://[::1]:80/').getHost() // returns '[::1]:80'
url('https://[::1]/').getHost() // returns '[::1]'
url('/path').getHost() // returns ''
url('https://example.com:80/').getHostname() // returns 'example.com'
url('https://127.0.0.1:80/').getHostname() // returns '127.0.0.1'
url('https://[::1]:80/').getHostname() // returns '::1'
url('/path').getHostname() // returns ''
url('https://example.com:80/').getPort() // returns '80'
url('https://example.com/').getPort() // returns ''
url('/path').getPort() // returns ''
url('https://example.com/path').getEscapedPath() // returns '/path'
url('https://example.com/path with spaces/').getEscapedPath() // returns '/path%20with%20spaces/'
url('https://example.com').getEscapedPath() // returns ''
url('https://example.com/path?k1=a&k2=b&k2=c').getQuery() // returns { 'k1': ['a'], 'k2': ['b', 'c']}
url('https://example.com/path?key with spaces=value with spaces').getQuery() // returns { 'key with spaces': ['value with spaces']}
url('https://example.com/path?').getQuery() // returns {}
url('https://example.com/path').getQuery() // returns {}

Types

type HealthStatus added in v3.20.19

type HealthStatus struct {
	Status  string `json:"status"`
	Message string `json:"message"`
	Health  string `json:"health"`
	Ready   bool   `json:"ready"`

	// Deprecated: Use Health.
	OK bool `json:"ok"`
}

func GetHealth added in v3.20.19

func GetHealth(in interface{}) HealthStatus

type URL

type URL struct {
	*url.URL
}

URL provides a CEL representation of a URL.

func (URL) ConvertToNative

func (d URL) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (URL) ConvertToType

func (d URL) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (URL) Equal

func (d URL) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (URL) Type

func (d URL) Type() ref.Type

Type implements ref.Val.Type.

func (URL) Value

func (d URL) Value() interface{}

Value implements ref.Val.Value.

Jump to

Keyboard shortcuts

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