core

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CompletePath func(prefix string, suffix string) string = controllers.CompletePath

CompletePath determines complete path of a file

View Source
var GetClient = func() (rc client.Client, err error) {
	var restConf *rest.Config
	restConf, err = GetConfig()
	if err != nil {
		return nil, err
	}

	var addKnownTypes = func(scheme *runtime.Scheme) error {

		metav1.AddToGroupVersion(scheme, iter8.GroupVersion)
		scheme.AddKnownTypes(iter8.GroupVersion, &Experiment{})

		gv := schema.GroupVersion{
			Group:   "",
			Version: "v1",
		}
		metav1.AddToGroupVersion(scheme, gv)
		scheme.AddKnownTypes(gv, &corev1.Secret{})

		return nil
	}

	var schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
	scheme := runtime.NewScheme()
	err = schemeBuilder.AddToScheme(scheme)

	if err == nil {
		rc, err = client.New(restConf, client.Options{
			Scheme: scheme,
		})
		if err == nil {
			return rc, nil
		}
	}
	return nil, errors.New("cannot get client using rest config")
}

GetClient constructs and returns a K8s client. The returned client has experiment.Experiment type registered.

View Source
var GetConfig = func() (*rest.Config, error) {
	return config.GetConfig()
}

GetConfig variable is useful for test mocks.

View Source
var NumAttempt = 10

NumAttempt is the number of times to attempt Get operation for a k8s resource

View Source
var Period = 18 * time.Second

Period is the time duration between between each attempt

Functions

func BoolPointer

func BoolPointer(b bool) *bool

BoolPointer takes a bool as input, creates a new variable with the input value, and returns a pointer to the variable

func FindVariableInVersionDetail

func FindVariableInVersionDetail(v *v2alpha2.VersionDetail, name string) (string, error)

FindVariableInVersionDetail scans the variables slice in the given version detail and returns the value of the given variable.

func Float32Pointer

func Float32Pointer(f float32) *float32

Float32Pointer takes an float32 as input, creates a new variable with the input value, and returns a pointer to the variable

func Float64Pointer

func Float64Pointer(f float64) *float64

Float64Pointer takes an float64 as input, creates a new variable with the input value, and returns a pointer to the variable

func GetJSONBytes

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

GetJSONBytes downloads JSON from URL and returns a byte slice

func GetLogger

func GetLogger() *logrus.Logger

GetLogger returns a logger, if needed after creating it.

func GetSecret

func GetSecret(namespacedname string) (*corev1.Secret, error)

GetSecret retrieves a secret from the kubernetes cluster

func GetTokenFromSecret

func GetTokenFromSecret(secret *corev1.Secret) (string, error)

GetTokenFromSecret gets token from k8s secret object can be used in notification, gitops and other tasks that use secret tokens

func GetTypedObject

func GetTypedObject(nn *client.ObjectKey, obj client.Object) error

GetTypedObject gets a typed object from the k8s cluster. Types of such objects include experiment, knative service, etc. This function attempts to get the object `numAttempts` times, with the interval between attempts equal to `period`.

func Int32Pointer

func Int32Pointer(i int32) *int32

Int32Pointer takes an int32 as input, creates a new variable with the input value, and returns a pointer to the variable

func IsARun

func IsARun(t *v2alpha2.TaskSpec) bool

IsARun determines if the given task spec is in fact a run spec.

func IsATask

func IsATask(t *v2alpha2.TaskSpec) bool

IsARun determines if the given task spec is in fact a task spec.

func Resource

func Resource(resource string) schema.GroupResource

Resource takes an unqualified resource and returns a Group qualified GroupResource

func SetLogLevel

func SetLogLevel(l logrus.Level)

SetLogLevel sets level for logging.

func StringPointer

func StringPointer(s string) *string

StringPointer takes a string as input, creates a new variable with the input value, and returns a pointer to the variable

func UpdateInClusterExperiment

func UpdateInClusterExperiment(e *Experiment) (err error)

UpdateInClusterExperiment updates the experiment within cluster.

func UpdateInClusterExperimentStatus

func UpdateInClusterExperimentStatus(e *Experiment) (err error)

UpdateInClusterExperimentStatus updates the experiment status within cluster.

func UpdateVariable

func UpdateVariable(v *v2alpha2.VersionDetail, name string, value string) error

UpdateVariable updates a variable within the given VersionDetail. If the variable is already present in the VersionDetail object, the pre-existing value takes precedence and is retained; if not, the new value is inserted.

func WaitTimeoutOrError

func WaitTimeoutOrError(wg *sync.WaitGroup, timeout time.Duration, errCh chan error) error

WaitTimeoutOrError waits for one of the following three events 1) all goroutines in the waitgroup to finish normally -- no error is returned 2) a timeout occurred before all go routines could finish normally -- an error is returned 3) an error in the errCh channel sent by one of the goroutines -- an error is returned See https://stackoverflow.com/questions/32840687/timeout-for-waitgroup-wait

Types

type Action

type Action []Task

Action is a slice of Tasks.

func (*Action) Run

func (a *Action) Run(ctx context.Context) error

Run the given action.

type Builder

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

Builder helps in construction of an experiment.

func (*Builder) Build

func (b *Builder) Build() (*Experiment, error)

Build returns the built experiment or error. Must call FromFile or FromCluster on b prior to invoking Build.

func (*Builder) FromCluster

func (b *Builder) FromCluster(nn *client.ObjectKey) *Builder

FromCluster fetches an experiment from k8s cluster.

func (*Builder) FromFile

func (b *Builder) FromFile(filePath string) *Builder

FromFile builds an experiment from a yaml file.

type ContextKey

type ContextKey string

ContextKey is the type of key that will be used to index into context.

type Experiment

type Experiment struct {
	v2alpha2.Experiment
}

Experiment is an enhancement of v2alpha2.Experiment struct with useful methods.

func GetExperimentFromContext

func GetExperimentFromContext(ctx context.Context) (*Experiment, error)

GetExperimentFromContext gets the experiment object from given context.

func (*Experiment) CandidateWon

func (exp *Experiment) CandidateWon() bool

CandidateWon returns true if candidate won in the experiment

func (*Experiment) GetActionSpec

func (e *Experiment) GetActionSpec(name string) (v2alpha2.Action, error)

GetActionSpec gets a named action spec from an experiment.

func (*Experiment) GetVersionDetail

func (e *Experiment) GetVersionDetail(versionName string) (*v2alpha2.VersionDetail, error)

GetVersionDetail from the experiment for a named version.

func (*Experiment) GetVersionRecommendedForPromotion

func (e *Experiment) GetVersionRecommendedForPromotion() (string, error)

GetVersionRecommendedForPromotion from the experiment.

func (*Experiment) Interpolate

func (exp *Experiment) Interpolate(inputArgs []string) ([]string, error)

Interpolate interpolates input arguments based on tags of the version recommended for promotion in the experiment. DEPRECATED. Use tags.Interpolate in base package instead

func (*Experiment) SetAggregatedBuiltinHists

func (e *Experiment) SetAggregatedBuiltinHists(fortioData v1.JSON)

SetAggregatedBuiltinHists sets the experiment status field corresponding to aggregated built in hists

func (*Experiment) ToMap

func (exp *Experiment) ToMap() (map[string]interface{}, error)

ToMap converts exp.Experiment to a map[string]interface{}

func (*Experiment) WinnerFound

func (exp *Experiment) WinnerFound() bool

WinnerFound returns true if Experiment found a winner

type HTTPMethod

type HTTPMethod string

HTTPMethod is either GET or POST

const (
	// GET method
	GET HTTPMethod = "GET"
	// POST method
	POST = "POST"
)

func HTTPMethodPointer

func HTTPMethodPointer(h HTTPMethod) *HTTPMethod

HTTPMethodPointer takes an HTTPMethod as input, creates a new variable with the input value, and returns a pointer to the variable

type Tags

type Tags struct {
	M map[string]interface{}
}

Tags supports string extrapolation using tags.

func GetDefaultTags

func GetDefaultTags(ctx context.Context) *Tags

GetDefaultTags creates interpolation.Tags from experiment referenced by context

func NewTags

func NewTags() Tags

NewTags creates an empty instance of Tags

func (*Tags) Interpolate

func (tags *Tags) Interpolate(str *string) (string, error)

Interpolate str using tags.

func (Tags) With

func (tags Tags) With(label string, obj interface{}) Tags

With adds obj to tags

func (Tags) WithRecommendedVersionForPromotion

func (tags Tags) WithRecommendedVersionForPromotion(exp *v2alpha2.Experiment, versions []VersionInfo) Tags

WithRecommendedVersionForPromotion adds variables from versionInfo for version recommended for promotion

func (Tags) WithRecommendedVersionForPromotionDeprecated

func (tags Tags) WithRecommendedVersionForPromotionDeprecated(exp *v2alpha2.Experiment) Tags

WithRecommendedVersionForPromotionDeprecated adds variables from versionDetail of version recommended for promotion

func (Tags) WithSecret

func (tags Tags) WithSecret(label string, secret *corev1.Secret) Tags

WithSecret adds the fields in secret to tags

type Task

type Task interface {
	Run(ctx context.Context) error
	GetIf() *string
}

Task defines common method signatures for every task.

type TaskMeta

type TaskMeta struct {
	Task *string `json:"task,omitempty" yaml:"task,omitempty"`
	Run  *string `json:"run,omitempty" yaml:"run,omitempty"`
	If   *string `json:"if,omitempty" yaml:"if,omitempty"`
}

TaskMeta is common to all Tasks

func (TaskMeta) GetIf added in v0.1.27

func (tm TaskMeta) GetIf() *string

GetIf returns any 'if' from TaskMeta

type VersionInfo

type VersionInfo struct {
	Variables []v2alpha2.NamedValue `json:"variables,omitempty" yaml:"variables,omitempty"`
}

VersionInfo contains name value pairs for each version.

Jump to

Keyboard shortcuts

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