experiment

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: Apache-2.0 Imports: 22 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{})

		var gvk schema.GroupVersionKind
		var gv schema.GroupVersion

		gvk = schema.GroupVersionKind{
			Group:   "",
			Version: "v1",
			Kind:    "Secret",
		}

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

		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 *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 GetSecret added in v0.1.18

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

GetSecret retrieves a secret from the kubernetes cluster

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 UpdateInClusterExperimentStatus added in v0.1.16

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.

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 {
	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) 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) (*iter8.VersionDetail, error)

GetVersionDetail from the experiment for a named version.

func (*Experiment) GetVersionRecommendedForPromotion added in v0.1.13

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

GetVersionRecommendedForPromotion from the experiment.

func (*Experiment) Interpolate added in v0.1.10

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 added in v0.1.16

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

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

func (*Experiment) ToMap added in v0.1.18

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

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

Jump to

Keyboard shortcuts

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