Documentation ¶
Index ¶
- Constants
- Variables
- func Abs(a int) int
- func AddAnnotations(o labelAnnotationObject, annos map[string]string)
- func AddLabels(o labelAnnotationObject, labels map[string]string)
- func AsController(r *corev1.ObjectReference) metav1.OwnerReference
- func AsOwner(r *corev1.ObjectReference) metav1.OwnerReference
- func BeEquivalentToError(expected error) types.GomegaMatcher
- func CheckAppRevision(revs []v1beta1.ApplicationRevision, collection []int) (bool, error)
- func ComputeHash(trait *v1alpha2.ComponentTrait) string
- func ConvertComponentDef2WorkloadDef(dm discoverymapper.DiscoveryMapper, componentDef *v1beta1.ComponentDefinition, ...) error
- func ConvertDefinitionRevName(definitionName string) (string, error)
- func ConvertWorkloadGVK2Definition(dm discoverymapper.DiscoveryMapper, def common.WorkloadGVK) (common.DefinitionReference, error)
- func DeepHashObject(hasher hash.Hash, objectToWrite interface{})
- func EndReconcileWithNegativeCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, ...) error
- func EndReconcileWithPositiveCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, ...) error
- func ExtractComponentName(revisionName string) string
- func ExtractRevisionNum(appRevision string, delimiter string) (int, error)
- func FetchScopeDefinition(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, ...) (*v1alpha2.ScopeDefinition, error)
- func FetchTraitDefinition(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, ...) (*v1alpha2.TraitDefinition, error)
- func FetchWorkload(ctx context.Context, c client.Client, oamTrait oam.Trait) (*unstructured.Unstructured, error)
- func FetchWorkloadChildResources(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, ...) ([]*unstructured.Unstructured, error)
- func FetchWorkloadDefinition(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, ...) (*v1alpha2.WorkloadDefinition, error)
- func GenTraitName(componentName string, ct *v1alpha2.ComponentTrait, traitType string) string
- func GenTraitNameCompatible(componentName string, trait *unstructured.Unstructured, traitType string) string
- func GetCapabilityDefinition(ctx context.Context, cli client.Reader, definition client.Object, ...) error
- func GetComponent(ctx context.Context, client client.Reader, ...) (*v1alpha2.Component, string, error)
- func GetDefinition(ctx context.Context, cli client.Reader, definition client.Object, ...) error
- func GetDefinitionName(dm discoverymapper.DiscoveryMapper, u *unstructured.Unstructured, ...) (string, error)
- func GetDefinitionNamespaceWithCtx(ctx context.Context) string
- func GetDummyTraitDefinition(u *unstructured.Unstructured) *v1alpha2.TraitDefinition
- func GetDummyWorkloadDefinition(u *unstructured.Unstructured) *v1alpha2.WorkloadDefinition
- func GetGVKFromDefinition(dm discoverymapper.DiscoveryMapper, definitionRef common.DefinitionReference) (metav1.GroupVersionKind, error)
- func GetObjectGivenGVKAndName(ctx context.Context, client client.Reader, gvk schema.GroupVersionKind, ...) (*unstructured.Unstructured, error)
- func GetObjectsGivenGVKAndLabels(ctx context.Context, cli client.Reader, gvk schema.GroupVersionKind, ...) (*unstructured.UnstructuredList, error)
- func IsConditionChanged(newCondition []condition.Condition, workload ConditionedObject) bool
- func JSONMarshal(o interface{}) []byte
- func LocateParentAppConfig(ctx context.Context, client client.Client, oamObject oam.Object) (oam.Object, error)
- func Max(a, b int) int
- func MergeMapOverrideWithDst(src, dst map[string]string) map[string]string
- func Min(a, b int) int
- func MustJSONMarshal(obj interface{}) []byte
- func Object2Map(obj interface{}) (map[string]interface{}, error)
- func Object2RawExtension(obj interface{}) *runtime.RawExtension
- func Object2Unstructured(obj interface{}) (*unstructured.Unstructured, error)
- func PassLabel(parentObj, childObj labelAnnotationObject)
- func PassLabelAndAnnotation(parentObj, childObj labelAnnotationObject)
- func PatchCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, ...) error
- func RawExtension2AppConfig(raw runtime.RawExtension) (*v1alpha2.ApplicationConfiguration, error)
- func RawExtension2Application(raw runtime.RawExtension) (*v1beta1.Application, error)
- func RawExtension2Component(raw runtime.RawExtension) (*v1alpha2.Component, error)
- func RawExtension2Map(raw *runtime.RawExtension) (map[string]interface{}, error)
- func RawExtension2Unstructured(raw *runtime.RawExtension) (*unstructured.Unstructured, error)
- func RemoveAnnotations(o labelAnnotationObject, removeKeys []string)
- func RemoveLabels(o labelAnnotationObject, removeKeys []string)
- func SetNamespaceInCtx(ctx context.Context, namespace string) context.Context
- func UnMarshalStringToComponentDefinition(s string) (*v1beta1.ComponentDefinition, error)
- func UnMarshalStringToTraitDefinition(s string) (*v1beta1.TraitDefinition, error)
- func UnMarshalStringToWorkloadDefinition(s string) (*v1alpha2.WorkloadDefinition, error)
- func UnpackRevisionData(rev *appsv1.ControllerRevision) (*v1alpha2.Component, error)
- type AlreadyExistMatcher
- type ConditionedObject
- type ErrorMatcher
- type NotFoundMatcher
- type WorkloadType
Constants ¶
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 TraitDefinition found, all framework capabilities will work as default" // DefinitionNamespaceEnv is env key for specifying a namespace to fetch definition DefinitionNamespaceEnv = "DEFINITION_NAMESPACE" )
const ( // ErrReconcileErrInCondition indicates one or more error occurs and are recorded in status conditions ErrReconcileErrInCondition = "object level reconcile error, type: %q, msg: %q" // 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" // ErrStoreCapabilityInConfigMap is the error while storing capability in ConfigMap ErrStoreCapabilityInConfigMap = "cannot store capability %s in ConfigMap: %v" // ErrGenerateOpenAPIV2JSONSchemaForCapability is the error while generating OpenAPI v3 schema ErrGenerateOpenAPIV2JSONSchemaForCapability = "cannot generate OpenAPI v3 JSON schema for capability %s: %v" // ErrUpdateCapabilityInConfigMap is the error while creating or updating a capability ErrUpdateCapabilityInConfigMap = "cannot create or update capability %s in ConfigMap: %v" // ErrUpdateComponentDefinition is the error while update ComponentDefinition ErrUpdateComponentDefinition = "cannot update ComponentDefinition %s: %v" // ErrUpdateTraitDefinition is the error while update TraitDefinition ErrUpdateTraitDefinition = "cannot update TraitDefinition %s: %v" // ErrUpdateStepDefinition is the error while update WorkflowStepDefinition ErrUpdateStepDefinition = "cannot update WorkflowStepDefinition %s: %v" // ErrUpdatePolicyDefinition is the error while update PolicyDefinition ErrUpdatePolicyDefinition = "cannot update PolicyDefinition %s: %v" // ErrUpdateWorkflowStepDefinition is the error while update WorkflowStepDefinition ErrUpdateWorkflowStepDefinition = "cannot update WorkflowStepDefinition %s: %v" // ErrCreateConvertedWorklaodDefinition is the error while apply a WorkloadDefinition ErrCreateConvertedWorklaodDefinition = "cannot create converted WorkloadDefinition %s: %v" // ErrRefreshPackageDiscover is the error while refresh PackageDiscover ErrRefreshPackageDiscover = "cannot discover the open api of the CRD : %v" // ErrGenerateDefinitionRevision is the error while generate DefinitionRevision ErrGenerateDefinitionRevision = "cannot generate DefinitionRevision of %s: %v" // ErrCreateDefinitionRevision is the error while create or update DefinitionRevision ErrCreateDefinitionRevision = "cannot create DefinitionRevision %s: %v" )
const ( // AppDefinitionNamespace is context key to define app namespace AppDefinitionNamespace namespaceContextKey = iota )
const ErrBadRevision = "bad revision name"
ErrBadRevision represents an error when the revision name is not standardized
Variables ¶
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() )
Functions ¶
func AddAnnotations ¶
AddAnnotations will merge annotations with existing ones. If any conflict keys, use new value to override existing value.
func AddLabels ¶
AddLabels will merge labels with existing labels. If any conflict keys, use new value to override existing value.
func AsController ¶
func AsController(r *corev1.ObjectReference) metav1.OwnerReference
AsController converts the supplied object reference to a controller reference. You may also consider using metav1.NewControllerRef.
func AsOwner ¶
func AsOwner(r *corev1.ObjectReference) metav1.OwnerReference
AsOwner converts the supplied object reference to an owner reference.
func BeEquivalentToError ¶
func BeEquivalentToError(expected error) types.GomegaMatcher
BeEquivalentToError matches the error to take care of nil.
func CheckAppRevision ¶
func CheckAppRevision(revs []v1beta1.ApplicationRevision, collection []int) (bool, error)
CheckAppRevision check if appRevision list is right
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 ConvertComponentDef2WorkloadDef ¶
func ConvertComponentDef2WorkloadDef(dm discoverymapper.DiscoveryMapper, componentDef *v1beta1.ComponentDefinition, workloadDef *v1beta1.WorkloadDefinition) error
ConvertComponentDef2WorkloadDef help convert a ComponentDefinition to WorkloadDefinition
func ConvertDefinitionRevName ¶
ConvertDefinitionRevName can help convert definition type defined in Application to DefinitionRevision Name e.g., worker@v1.3.1 will be convert to worker-v1.3.1
func ConvertWorkloadGVK2Definition ¶
func ConvertWorkloadGVK2Definition(dm discoverymapper.DiscoveryMapper, def common.WorkloadGVK) (common.DefinitionReference, error)
ConvertWorkloadGVK2Definition help convert a GVK to DefinitionReference
func DeepHashObject ¶
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 EndReconcileWithNegativeCondition ¶
func EndReconcileWithNegativeCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, condition ...condition.Condition) error
EndReconcileWithNegativeCondition is used to handle reconcile failure for a conditioned resource. It will make ctrl-mgr to requeue the resource through patching changed conditions or returning an error. It should not handle reconcile success with positive conditions, otherwise it will trigger infinite requeue.
func EndReconcileWithPositiveCondition ¶
func EndReconcileWithPositiveCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, condition ...condition.Condition) error
EndReconcileWithPositiveCondition is used to handle reconcile success for a conditioned resource. It should only accept positive condition which means no need to requeue the resource.
func ExtractComponentName ¶
ExtractComponentName will extract the componentName from a revisionName
func ExtractRevisionNum ¶
ExtractRevisionNum extract revision number
func FetchScopeDefinition ¶
func FetchScopeDefinition(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, scope *unstructured.Unstructured) (*v1alpha2.ScopeDefinition, error)
FetchScopeDefinition fetch corresponding scopeDefinition given a scope
func FetchTraitDefinition ¶
func FetchTraitDefinition(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, trait *unstructured.Unstructured) (*v1alpha2.TraitDefinition, error)
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 ¶
func FetchWorkloadDefinition(ctx context.Context, r client.Reader, dm discoverymapper.DiscoveryMapper, workload *unstructured.Unstructured) (*v1alpha2.WorkloadDefinition, error)
FetchWorkloadDefinition fetch corresponding workloadDefinition given a workload
func GenTraitName ¶
func GenTraitName(componentName string, ct *v1alpha2.ComponentTrait, traitType string) string
GenTraitName generate trait name
func GenTraitNameCompatible ¶
func GenTraitNameCompatible(componentName string, trait *unstructured.Unstructured, traitType string) string
GenTraitNameCompatible generate trait name based on unstructured trait and re-use legacy GenTraitName for backward compatibility
func GetCapabilityDefinition ¶
func GetCapabilityDefinition(ctx context.Context, cli client.Reader, definition client.Object, definitionName string) error
GetCapabilityDefinition can get different versions of ComponentDefinition/TraitDefinition
func GetComponent ¶
func GetComponent(ctx context.Context, client client.Reader, acc v1alpha2.ApplicationConfigurationComponent, namespace string) (*v1alpha2.Component, string, error)
GetComponent will get Component and RevisionName by AppConfigComponent
func GetDefinition ¶
func GetDefinition(ctx context.Context, cli client.Reader, definition client.Object, definitionName string) error
GetDefinition get definition from two level namespace
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 GetDefinitionNamespaceWithCtx ¶
GetDefinitionNamespaceWithCtx will get namespace from context, it will try get `AppDefinitionNamespace` key, if not found, will use default system level namespace defined in `systemvar.SystemDefinitonNamespace`
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 common.DefinitionReference) (metav1.GroupVersionKind, error)
GetGVKFromDefinition help get Group Version Kind from DefinitionReference
func GetObjectGivenGVKAndName ¶
func GetObjectGivenGVKAndName(ctx context.Context, client client.Reader, gvk schema.GroupVersionKind, namespace, name string) (*unstructured.Unstructured, error)
GetObjectGivenGVKAndName fetches the kubernetes object given its gvk and name
func GetObjectsGivenGVKAndLabels ¶
func GetObjectsGivenGVKAndLabels(ctx context.Context, cli client.Reader, gvk schema.GroupVersionKind, namespace string, labels map[string]string) (*unstructured.UnstructuredList, error)
GetObjectsGivenGVKAndLabels fetches the kubernetes object given its gvk and labels by list API
func IsConditionChanged ¶
func IsConditionChanged(newCondition []condition.Condition, workload ConditionedObject) bool
IsConditionChanged will check if conditions in workload is changed compare to newCondition
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 ¶
MergeMapOverrideWithDst merges two could be nil maps. Keep the dst for any conflicts,
func MustJSONMarshal ¶
func MustJSONMarshal(obj interface{}) []byte
MustJSONMarshal json-marshals an object into bytes. It panics on err.
func Object2Map ¶
Object2Map turn the Object to a map
func Object2RawExtension ¶
func Object2RawExtension(obj interface{}) *runtime.RawExtension
Object2RawExtension converts an object to a rawExtension
func Object2Unstructured ¶
func Object2Unstructured(obj interface{}) (*unstructured.Unstructured, error)
Object2Unstructured converts an object to an unstructured struct
func PassLabel ¶
func PassLabel(parentObj, childObj labelAnnotationObject)
PassLabel passes through labels from the parent to the child object
func PassLabelAndAnnotation ¶
func PassLabelAndAnnotation(parentObj, childObj labelAnnotationObject)
PassLabelAndAnnotation passes through labels and annotation objectMeta from the parent to the child object when annotation or labels has conflicts, the parentObj will override the childObj.
func PatchCondition ¶
func PatchCondition(ctx context.Context, r client.StatusClient, workload ConditionedObject, condition ...condition.Condition) error
PatchCondition will patch status with condition and return, it generally used by cases which don't want reconcile after patch
func RawExtension2AppConfig ¶
func RawExtension2AppConfig(raw runtime.RawExtension) (*v1alpha2.ApplicationConfiguration, error)
RawExtension2AppConfig converts runtime.RawExtention to ApplicationConfiguration
func RawExtension2Application ¶
func RawExtension2Application(raw runtime.RawExtension) (*v1beta1.Application, error)
RawExtension2Application converts runtime.RawExtension to Application
func RawExtension2Component ¶
func RawExtension2Component(raw runtime.RawExtension) (*v1alpha2.Component, error)
RawExtension2Component converts runtime.RawExtention to Component
func RawExtension2Map ¶
func RawExtension2Map(raw *runtime.RawExtension) (map[string]interface{}, error)
RawExtension2Map will convert rawExtension to map
func RawExtension2Unstructured ¶
func RawExtension2Unstructured(raw *runtime.RawExtension) (*unstructured.Unstructured, error)
RawExtension2Unstructured converts a rawExtension to an unstructured struct
func RemoveAnnotations ¶
func RemoveAnnotations(o labelAnnotationObject, removeKeys []string)
RemoveAnnotations removes keys that contains in the removekeys slice from the annotation
func RemoveLabels ¶
func RemoveLabels(o labelAnnotationObject, removeKeys []string)
RemoveLabels removes keys that contains in the removekeys slice from the label
func SetNamespaceInCtx ¶
SetNamespaceInCtx set app namespace in context, Sometimes webhook handler may receive request that appNs is empty string, and will cause error when search definition So if namespace is empty, it will use `default` namespace by default.
func UnMarshalStringToComponentDefinition ¶
func UnMarshalStringToComponentDefinition(s string) (*v1beta1.ComponentDefinition, error)
UnMarshalStringToComponentDefinition parse a string to a componentDefinition object
func UnMarshalStringToTraitDefinition ¶
func UnMarshalStringToTraitDefinition(s string) (*v1beta1.TraitDefinition, error)
UnMarshalStringToTraitDefinition parse a string to a traitDefinition object
func UnMarshalStringToWorkloadDefinition ¶
func UnMarshalStringToWorkloadDefinition(s string) (*v1alpha2.WorkloadDefinition, error)
UnMarshalStringToWorkloadDefinition parse a string to a workloadDefinition 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 { client.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.
type WorkloadType ¶
type WorkloadType string
WorkloadType describe the workload type of ComponentDefinition
const ( // ComponentDef describe a workload of Defined by ComponentDefinition ComponentDef WorkloadType = "ComponentDef" // KubeDef describe a workload refer to raw K8s resource KubeDef WorkloadType = "KubeDef" // HELMDef describe a workload refer to HELM HELMDef WorkloadType = "HelmDef" // TerraformDef describes a workload refer to Terraform TerraformDef WorkloadType = "TerraformDef" // ReferWorkload describe an existing workload ReferWorkload WorkloadType = "ReferWorkload" )