utils

package
v1.8.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 45 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TerraformVariableString string = "string"
	TerraformVariableNumber string = "number"
	TerraformVariableBool   string = "bool"
	TerraformVariableList   string = "list"
	TerraformVariableTuple  string = "tuple"
	TerraformVariableMap    string = "map"
	TerraformVariableObject string = "object"
	TerraformVariableNull   string = ""
	TerraformVariableAny    string = "any"

	TerraformListTypePrefix   string = "list("
	TerraformTupleTypePrefix  string = "tuple("
	TerraformMapTypePrefix    string = "map("
	TerraformObjectTypePrefix string = "object("
	TerraformSetTypePrefix    string = "set("
)

data types of parameter value

View Source
const (
	// GitCredsKnownHosts is a key in git credentials secret
	GitCredsKnownHosts string = "known_hosts"
)
View Source
const LabelPodSpecable = "workload.oam.dev/podspecable"

LabelPodSpecable defines whether a workload has podSpec or not.

Variables

View Source
var DefaultBackoff = wait.Backoff{
	Duration: 1 * time.Second,
	Factor:   2,
	Steps:    5,
	Jitter:   0.1,
}

DefaultBackoff is the backoff we use in controller

View Source
var ExtractComponentName = util.ExtractComponentName

ExtractComponentName will extract the componentName from a revisionName

Functions

func CheckDisabledCapabilities added in v0.2.0

func CheckDisabledCapabilities(disableCaps string) error

CheckDisabledCapabilities checks whether the disabled capability controllers are valid

func CompareWithRevision added in v1.0.0

func CompareWithRevision(ctx context.Context, c client.Client, componentName, nameSpace,
	latestRevision string, curCompSpec *v1alpha2.ComponentSpec) (bool, error)

CompareWithRevision compares a component's spec with the component's latest revision content

func ComputeSpecHash added in v1.0.0

func ComputeSpecHash(spec interface{}) (string, error)

ComputeSpecHash computes the hash value of a k8s resource spec

func ConstructRevisionName added in v1.0.0

func ConstructRevisionName(componentName string, revision int64) string

ConstructRevisionName will generate a revisionName given the componentName and revision will be <componentName>-v<RevisionNumber>, for example: comp-v1

func DiscoveryFromPodSpec

func DiscoveryFromPodSpec(w *unstructured.Unstructured, fieldPath string) ([]intstr.IntOrString, error)

DiscoveryFromPodSpec will discover pods from podSpec

func DiscoveryFromPodTemplate

func DiscoveryFromPodTemplate(w *unstructured.Unstructured, fields ...string) ([]intstr.IntOrString, map[string]string, error)

DiscoveryFromPodTemplate not only discovery port, will also use labels in podTemplate

func ExtractRevision added in v1.0.0

func ExtractRevision(revisionName string) (int, error)

ExtractRevision will extract the revision from a revisionName

func FreezeApplication added in v1.3.1

func FreezeApplication(ctx context.Context, cli client.Client, app *v1beta1.Application, mutate func()) (string, error)

FreezeApplication freeze application to disable the reconciling process for it

func GetAppNextRevision added in v1.0.0

func GetAppNextRevision(app *v1beta1.Application) (string, int64)

GetAppNextRevision will generate the next revision name and revision number for application

func GetGitSSHPublicKey added in v1.7.0

func GetGitSSHPublicKey(ctx context.Context, k8sClient client.Client, gitCredentialsSecretReference *v1.SecretReference) (*gitssh.PublicKeys, error)

GetGitSSHPublicKey gets a kubernetes secret containing the SSH private key based on gitCredentialsSecretReference parameters for component and trait definition

func GetKubeSchematicOpenAPISchema added in v1.1.0

func GetKubeSchematicOpenAPISchema(params []commontypes.KubeParameter) ([]byte, error)

GetKubeSchematicOpenAPISchema gets OpenAPI v3 schema based on kube schematic parameters for component and trait definition

func GetOpenAPISchemaFromTerraformComponentDefinition added in v1.0.6

func GetOpenAPISchemaFromTerraformComponentDefinition(configuration string) ([]byte, error)

GetOpenAPISchemaFromTerraformComponentDefinition gets OpenAPI v3 schema by WorkloadDefinition name

func GetPodSpecPath

func GetPodSpecPath(workloadDef *v1alpha2.WorkloadDefinition) (string, bool)

GetPodSpecPath get podSpec field and label

func GetTerraformConfigurationFromRemote added in v1.2.0

func GetTerraformConfigurationFromRemote(name, remoteURL, remotePath string, sshPublicKey *gitssh.PublicKeys) (string, error)

GetTerraformConfigurationFromRemote gets Terraform Configuration(HCL)

func GetUnstructuredObjectStatusCondition added in v1.1.0

func GetUnstructuredObjectStatusCondition(obj *unstructured.Unstructured, condType string) (*condition.Condition, bool, error)

GetUnstructuredObjectStatusCondition returns the status.condition with matching condType from an unstructured object.

func RefreshPackageDiscover added in v1.0.2

func RefreshPackageDiscover(ctx context.Context, k8sClient client.Client, dm discoverymapper.DiscoveryMapper,
	pd *packages.PackageDiscover, definition runtime.Object) error

RefreshPackageDiscover help refresh package discover Deprecated: The function RefreshKubePackagesFromCluster affects performance and the code has been commented a long time.

func SelectOAMAppLabelsWithoutRevision

func SelectOAMAppLabelsWithoutRevision(labels map[string]string) map[string]string

SelectOAMAppLabelsWithoutRevision will filter and return OAM app labels only, if no labels, return the original one.

func StoreInSet added in v0.2.0

func StoreInSet(disableCaps string) mapset.Set

StoreInSet stores items in Set

func UnfreezeApplication added in v1.3.1

func UnfreezeApplication(ctx context.Context, cli client.Client, app *v1beta1.Application, mutate func(), originalControllerRequirement string) error

UnfreezeApplication unfreeze application to enable the reconciling process for it

Types

type CapabilityBaseDefinition added in v1.0.0

type CapabilityBaseDefinition struct {
}

CapabilityBaseDefinition is the base struct for CapabilityWorkloadDefinition and CapabilityTraitDefinition

func (*CapabilityBaseDefinition) CreateOrUpdateConfigMap added in v1.0.0

func (def *CapabilityBaseDefinition) CreateOrUpdateConfigMap(ctx context.Context, k8sClient client.Client, namespace,
	definitionName, definitionType string, labels map[string]string, appliedWorkloads []string, jsonSchema []byte, ownerReferences []metav1.OwnerReference) (string, error)

CreateOrUpdateConfigMap creates ConfigMap to store OpenAPI v3 schema or or updates data in ConfigMap

type CapabilityComponentDefinition added in v1.0.0

type CapabilityComponentDefinition struct {
	Name                string                      `json:"name"`
	ComponentDefinition v1beta1.ComponentDefinition `json:"componentDefinition"`

	WorkloadType    util.WorkloadType `json:"workloadType"`
	WorkloadDefName string            `json:"workloadDefName"`

	Helm      *commontypes.Helm      `json:"helm"`
	Kube      *commontypes.Kube      `json:"kube"`
	Terraform *commontypes.Terraform `json:"terraform"`
	CapabilityBaseDefinition
}

CapabilityComponentDefinition is the struct for ComponentDefinition

func NewCapabilityComponentDef added in v1.1.0

func NewCapabilityComponentDef(componentDefinition *v1beta1.ComponentDefinition) CapabilityComponentDefinition

NewCapabilityComponentDef will create a CapabilityComponentDefinition

func (*CapabilityComponentDefinition) GetOpenAPISchema added in v1.0.0

func (def *CapabilityComponentDefinition) GetOpenAPISchema(name string) ([]byte, error)

GetOpenAPISchema gets OpenAPI v3 schema by WorkloadDefinition name

func (*CapabilityComponentDefinition) StoreOpenAPISchema added in v1.0.0

func (def *CapabilityComponentDefinition) StoreOpenAPISchema(ctx context.Context, k8sClient client.Client, namespace, name, revName string) (string, error)

StoreOpenAPISchema stores OpenAPI v3 schema in ConfigMap from WorkloadDefinition

type CapabilityDefinitionInterface added in v1.0.0

type CapabilityDefinitionInterface interface {
	GetCapabilityObject(ctx context.Context, k8sClient client.Client, namespace, name string) (*types.Capability, error)
	GetOpenAPISchema(ctx context.Context, k8sClient client.Client, namespace, name string) ([]byte, error)
}

CapabilityDefinitionInterface is the interface for Capability (WorkloadDefinition and TraitDefinition)

type CapabilityPolicyDefinition added in v1.4.0

type CapabilityPolicyDefinition struct {
	Name             string                   `json:"name"`
	PolicyDefinition v1beta1.PolicyDefinition `json:"policyDefinition"`

	CapabilityBaseDefinition
}

CapabilityPolicyDefinition is the Capability struct for PolicyDefinition

func NewCapabilityPolicyDef added in v1.4.0

func NewCapabilityPolicyDef(policydefinition *v1beta1.PolicyDefinition) CapabilityPolicyDefinition

NewCapabilityPolicyDef will create a CapabilityPolicyDefinition

func (*CapabilityPolicyDefinition) GetOpenAPISchema added in v1.4.0

func (def *CapabilityPolicyDefinition) GetOpenAPISchema(name string) ([]byte, error)

GetOpenAPISchema gets OpenAPI v3 schema by StepDefinition name

func (*CapabilityPolicyDefinition) StoreOpenAPISchema added in v1.4.0

func (def *CapabilityPolicyDefinition) StoreOpenAPISchema(ctx context.Context, k8sClient client.Client, namespace, name, revName string) (string, error)

StoreOpenAPISchema stores OpenAPI v3 schema from StepDefinition in ConfigMap

type CapabilityStepDefinition added in v1.1.8

type CapabilityStepDefinition struct {
	Name           string                         `json:"name"`
	StepDefinition v1beta1.WorkflowStepDefinition `json:"stepDefinition"`

	CapabilityBaseDefinition
}

CapabilityStepDefinition is the Capability struct for WorkflowStepDefinition

func NewCapabilityStepDef added in v1.1.8

func NewCapabilityStepDef(stepdefinition *v1beta1.WorkflowStepDefinition) CapabilityStepDefinition

NewCapabilityStepDef will create a CapabilityStepDefinition

func (*CapabilityStepDefinition) GetOpenAPISchema added in v1.1.8

func (def *CapabilityStepDefinition) GetOpenAPISchema(name string) ([]byte, error)

GetOpenAPISchema gets OpenAPI v3 schema by StepDefinition name

func (*CapabilityStepDefinition) StoreOpenAPISchema added in v1.1.8

func (def *CapabilityStepDefinition) StoreOpenAPISchema(ctx context.Context, k8sClient client.Client, namespace, name string, revName string) (string, error)

StoreOpenAPISchema stores OpenAPI v3 schema from StepDefinition in ConfigMap

type CapabilityTraitDefinition added in v1.0.0

type CapabilityTraitDefinition struct {
	Name            string                  `json:"name"`
	TraitDefinition v1beta1.TraitDefinition `json:"traitDefinition"`

	DefCategoryType util.WorkloadType `json:"defCategoryType"`

	Kube *commontypes.Kube `json:"kube"`

	CapabilityBaseDefinition
}

CapabilityTraitDefinition is the Capability struct for TraitDefinition

func NewCapabilityTraitDef added in v1.1.0

func NewCapabilityTraitDef(traitdefinition *v1beta1.TraitDefinition) CapabilityTraitDefinition

NewCapabilityTraitDef will create a CapabilityTraitDefinition

func (*CapabilityTraitDefinition) GetOpenAPISchema added in v1.0.0

func (def *CapabilityTraitDefinition) GetOpenAPISchema(name string) ([]byte, error)

GetOpenAPISchema gets OpenAPI v3 schema by TraitDefinition name

func (*CapabilityTraitDefinition) StoreOpenAPISchema added in v1.0.0

func (def *CapabilityTraitDefinition) StoreOpenAPISchema(ctx context.Context, k8sClient client.Client, namespace, name string, revName string) (string, error)

StoreOpenAPISchema stores OpenAPI v3 schema from TraitDefinition in ConfigMap

type ErrNoSectionParameterInCue added in v1.0.0

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

ErrNoSectionParameterInCue means there is not parameter section in Cue template of a workload

func (ErrNoSectionParameterInCue) Error added in v1.1.0

Jump to

Keyboard shortcuts

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