util

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TraitPrefixKey is prefix of trait name
	TraitPrefixKey = "trait"

	// Dummy used for dummy definition
	Dummy = "dummy"

	// DummyTraitMessage is a message for trait which don't have definition found
	DummyTraitMessage = "No valid TraitDefinition found, all framework capabilities will work as default or disabled"

	// DefinitionNamespaceEnv is env key for specifying a namespace to fetch definition
	DefinitionNamespaceEnv = "DEFINITION_NAMESPACE"
)
View Source
const (
	// ErrUpdateStatus is the error while applying status.
	ErrUpdateStatus = "cannot apply status"
	// ErrLocateAppConfig is the error while locating parent application.
	ErrLocateAppConfig = "cannot locate the parent application configuration to emit event to"
	// ErrLocateWorkload is the error while locate the workload
	ErrLocateWorkload = "cannot find the workload that the trait is referencing to"
	// ErrFetchChildResources is the error while fetching workload child resources
	ErrFetchChildResources = "failed to fetch workload child resources"
)

Variables

View Source
var (
	// KindDeployment is the k8s Deployment kind.
	KindDeployment = reflect.TypeOf(appsv1.Deployment{}).Name()

	// KindService is the k8s Service kind.
	KindService = reflect.TypeOf(corev1.Service{}).Name()

	// KindStatefulSet is the k8s StatefulSet kind
	KindStatefulSet = reflect.TypeOf(appsv1.StatefulSet{}).Name()
	// KindVolumeTrait is the k8s VolumeTrait kind
	KindVolumeTrait = reflect.TypeOf(v1alpha2.VolumeTrait{}).Name()

	// KindPersistentVolumeClaim is the k8s PersistentVolumeClaim kind
	KindPersistentVolumeClaim = reflect.TypeOf(corev1.PersistentVolumeClaim{}).Name()

	// KindPersistentVolume is the k8s PersistentVolume kind
	KindPersistentVolume = reflect.TypeOf(corev1.PersistentVolume{}).Name()

	// ReconcileWaitResult is the time to wait between reconciliation.
	ReconcileWaitResult = reconcile.Result{RequeueAfter: 30 * time.Second}

	// KindConfigMap is the k8s Deployment kind.
	KindConfigMap = reflect.TypeOf(corev1.ConfigMap{}).Name()

	// LabelKeyChildResource us containerized workload child resource
	LabelKeyChildResource = "app.oam.dev/childResource"

	// LabelAppID istio app must has this label key
	LabelAppID = "oam.runtime.app.id"

	// LabelComponentID launcher.app must has it
	LabelComponentID = "oam.runtime.component.id"
)

Functions

func AddAnnotations

func AddAnnotations(o *unstructured.Unstructured, annos map[string]string)

AddAnnotations will merge annotations with existing ones. If any conflict keys, use new value to override existing value.

func AddLabels

func AddLabels(o *unstructured.Unstructured, labels map[string]string)

AddLabels will merge labels with existing labels. If any conflict keys, use new value to override existing value.

func BeEquivalentToError

func BeEquivalentToError(expected error) types.GomegaMatcher

BeEquivalentToError matches the error to take care of nil.

func ComputeHash

func ComputeHash(trait *v1alpha2.ComponentTrait) string

ComputeHash returns a hash value calculated from pod template and a collisionCount to avoid hash collision. The hash will be safe encoded to avoid bad words.

func DeepHashObject

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.

func FetchScopeDefinition

FetchScopeDefinition fetch corresponding scopeDefinition given a scope

func FetchTraitDefinition

FetchTraitDefinition fetch corresponding traitDefinition given a trait

func FetchWorkload

func FetchWorkload(ctx context.Context, c client.Client, oamTrait oam.Trait) (*unstructured.Unstructured, error)

FetchWorkload fetch the workload that a trait refers to

func FetchWorkloadChildResources

func FetchWorkloadChildResources(ctx context.Context, r client.Reader,
	dm discoverymapper.DiscoveryMapper, workload *unstructured.Unstructured) ([]*unstructured.Unstructured, error)

FetchWorkloadChildResources fetch corresponding child resources given a workload

func FetchWorkloadDefinition

FetchWorkloadDefinition fetch corresponding workloadDefinition given a workload

func GenNamespacedDefinitionName

func GenNamespacedDefinitionName(dn string) types.NamespacedName

GenNamespacedDefinitionName generate definition name with customized namespace

func GenTraitName

func GenTraitName(componentName string, ct *v1alpha2.ComponentTrait, traitType string) string

GenTraitName generate trait name

func GetComponent

GetComponent will get Component and RevisionName by AppConfigComponent

func GetDefinitionName

func GetDefinitionName(dm discoverymapper.DiscoveryMapper, u *unstructured.Unstructured, typeLabel string) (string, error)

GetDefinitionName return the Definition name of any resources the format of the definition of a resource is <kind plurals>.<group> Now the definition name of a resource could also be defined as `definition.oam.dev/name` in `metadata.annotations` typeLabel specified which Definition it is, if specified, will directly get definition from label.

func GetDummyTraitDefinition

func GetDummyTraitDefinition(u *unstructured.Unstructured) *v1alpha2.TraitDefinition

GetDummyTraitDefinition will generate a dummy TraitDefinition for CustomResource that won't block app from running. OAM runtime will report warning if they got this dummy definition.

func GetDummyWorkloadDefinition

func GetDummyWorkloadDefinition(u *unstructured.Unstructured) *v1alpha2.WorkloadDefinition

GetDummyWorkloadDefinition will generate a dummy WorkloadDefinition for CustomResource that won't block app from running. OAM runtime will report warning if they got this dummy definition.

func GetGVKFromDefinition

func GetGVKFromDefinition(dm discoverymapper.DiscoveryMapper, definitionRef v1alpha2.DefinitionReference) (schema.GroupVersionKind, error)

GetGVKFromDefinition help get Group Version Kind from DefinitionReference

func JSONMarshal

func JSONMarshal(o interface{}) []byte

JSONMarshal returns the JSON encoding

func LocateParentAppConfig

func LocateParentAppConfig(ctx context.Context, client client.Client, oamObject oam.Object) (oam.Object, error)

LocateParentAppConfig locate the parent application configuration object

func MergeMapOverrideWithDst

func MergeMapOverrideWithDst(src, dst map[string]string) map[string]string

MergeMapOverrideWithDst merges two could be nil maps. If any conflicts, override src with dst.

func Object2Map

func Object2Map(obj interface{}) (map[string]interface{}, error)

Object2Map turn the Object to a map

func Object2Unstructured

func Object2Unstructured(obj interface{}) (*unstructured.Unstructured, error)

Object2Unstructured convert an object to an unstructured struct

func PassLabel

func PassLabel(parentObj oam.Object, childObj labelAnnotationObject)

PassLabel passes through labels from the parent to the child object

func PassLabelAndAnnotation

func PassLabelAndAnnotation(parentObj oam.Object, childObj labelAnnotationObject)

PassLabelAndAnnotation passes through labels and annotation objectMeta from the parent to the child object

func PatchCondition

func PatchCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, condition ...cpv1alpha1.Condition) error

PatchCondition condition for a conditioned object

func UnpackRevisionData

func UnpackRevisionData(rev *appsv1.ControllerRevision) (*v1alpha2.Component, error)

UnpackRevisionData will unpack revision.Data to Component

Types

type AlreadyExistMatcher

type AlreadyExistMatcher struct {
}

AlreadyExistMatcher matches the error to be already exist

func (AlreadyExistMatcher) FailureMessage

func (matcher AlreadyExistMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage builds an error message.

func (AlreadyExistMatcher) Match

func (matcher AlreadyExistMatcher) Match(actual interface{}) (success bool, err error)

Match matches error.

func (AlreadyExistMatcher) NegatedFailureMessage

func (matcher AlreadyExistMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage builds an error message.

type ConditionedObject

type ConditionedObject interface {
	oam.Object

	oam.Conditioned
}

A ConditionedObject is an Object type with condition field

type ErrorMatcher

type ErrorMatcher struct {
	ExpectedError error
}

ErrorMatcher matches errors.

func (ErrorMatcher) FailureMessage

func (matcher ErrorMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage builds an error message.

func (ErrorMatcher) Match

func (matcher ErrorMatcher) Match(actual interface{}) (success bool, err error)

Match matches an error.

func (ErrorMatcher) NegatedFailureMessage

func (matcher ErrorMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage builds an error message.

type NotFoundMatcher

type NotFoundMatcher struct {
}

NotFoundMatcher matches the error to be not found.

func (NotFoundMatcher) FailureMessage

func (matcher NotFoundMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage builds an error message.

func (NotFoundMatcher) Match

func (matcher NotFoundMatcher) Match(actual interface{}) (success bool, err error)

Match matches the api error.

func (NotFoundMatcher) NegatedFailureMessage

func (matcher NotFoundMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage builds an error message.

Jump to

Keyboard shortcuts

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