experiment

package
v0.1.5-pre Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package experiment enables construction of an experiment object with handler/task lists within it.

Index

Constants

This section is empty.

Variables

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{})

		ksvc := &servingv1.Service{}
		gvk := ksvc.GetGroupVersionKind()
		gv := schema.GroupVersion{
			Group:   gvk.Group,
			Version: gvk.Version,
		}
		metav1.AddToGroupVersion(scheme, gv)

		scheme.AddKnownTypes(gv, ksvc)
		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 FindVariableInVersionDetail

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

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

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 Resource

func Resource(resource string) schema.GroupResource

Resource takes an unqualified resource and returns a Group qualified GroupResource

func UpdateInClusterExperiment

func UpdateInClusterExperiment(e *Experiment) (err error)

UpdateInClusterExperiment updates the experiment within cluster.

func UpdateVariable

func UpdateVariable(v *v2alpha1.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.

Types

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 Experiment

type Experiment struct {
	v2alpha1.Experiment
}

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

func GetExperimentFromContext

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

GetExperimentFromContext gets the experiment object from given context.

func (*Experiment) Extrapolate

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

Extrapolate extrapolates input arguments based on tags of the recommended baseline in the experiment.

func (*Experiment) GetActionSpec

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

GetActionSpec gets a named action spec from an experiment.

func (*Experiment) GetRecommendedBaseline

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

GetRecommendedBaseline from the experiment.

func (*Experiment) GetVersionDetail

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

GetVersionDetail from the experiment for a named version.

Jump to

Keyboard shortcuts

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