utils

package
v0.0.0-...-a429faa Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const NoiseLogLel = 5

NoiseLogLel - information inside "important functions"

View Source
const QuiteLogLel = 4

QuiteLogLel - "important" information

View Source
const VeryNoisy = 10

VeryNoisy = show call stack, routine and everything

Variables

View Source
var DeployablePredicateFunc = predicate.Funcs{
	UpdateFunc: func(e event.UpdateEvent) bool {
		newdpl := e.ObjectNew.(*appv1alpha1.Deployable)
		olddpl := e.ObjectOld.(*appv1alpha1.Deployable)

		if len(newdpl.GetFinalizers()) > 0 {
			return true
		}

		hosting := GetHostDeployableFromObject(newdpl)
		if hosting != nil {

			return true
		}

		if !reflect.DeepEqual(newdpl.GetAnnotations(), olddpl.GetAnnotations()) {
			return true
		}

		if !reflect.DeepEqual(newdpl.GetLabels(), olddpl.GetLabels()) {
			return true
		}

		oldtmpl := &unstructured.Unstructured{}
		newtmpl := &unstructured.Unstructured{}

		if olddpl.Spec.Template == nil || olddpl.Spec.Template.Raw == nil {
			return true
		}
		err := json.Unmarshal(olddpl.Spec.Template.Raw, oldtmpl)
		if err != nil {
			return true
		}
		if newdpl.Spec.Template.Raw == nil {
			return true
		}
		err = json.Unmarshal(newdpl.Spec.Template.Raw, newtmpl)
		if err != nil {
			return true
		}

		if !reflect.DeepEqual(newtmpl, oldtmpl) {
			return true
		}

		olddpl.Spec.Template = newdpl.Spec.Template.DeepCopy()
		return !reflect.DeepEqual(olddpl.Spec, newdpl.Spec)
	},
}

DeployablePredicateFunc defines predicate function for deployable watch in deployable controller

Functions

func CheckAndInstallCRD

func CheckAndInstallCRD(crdconfig *rest.Config, pathname string) error

CheckAndInstallCRD checks if deployable belongs to this cluster managed cluster annotation matches or no managed cluster annotation (local)

func CompareDeployable

func CompareDeployable(olddpl *appv1alpha1.Deployable, newdpl *appv1alpha1.Deployable) bool

CompareDeployable compare two deployables and return true if they are equal.

func ContainsName

func ContainsName(a []types.NamespacedName, x string) bool

ContainsName check whether the namespacedName array a contains string x

func ConvertLabels

func ConvertLabels(labelSelector *metav1.LabelSelector) (labels.Selector, error)

ConvertLabels coverts label selector to lables.Selector

func EnterFnString

func EnterFnString() string

EnterFnString - called when enter a function

func ExitFuString

func ExitFuString(s string)

ExitFuString - called when exiting a function

func GenerateOverrides

func GenerateOverrides(src, dst *appv1alpha1.Deployable) (covs []appv1alpha1.ClusterOverride)

GenerateOverrides compare 2 deployable and generate array for overrides

func GetClusterFromResourceObject

func GetClusterFromResourceObject(obj metav1.Object) *types.NamespacedName

GetClusterFromResourceObject return nil if no host is found

func GetFnName

func GetFnName() string

GetFnName - get name of function

func GetHostDeployableFromObject

func GetHostDeployableFromObject(obj metav1.Object) *types.NamespacedName

GetHostDeployableFromObject return nil if no host is found

func GetUnstructuredTemplateFromDeployable

func GetUnstructuredTemplateFromDeployable(instance *appv1alpha1.Deployable) (*unstructured.Unstructured, error)

GetUnstructuredTemplateFromDeployable return error if needed

func IsDependencyDeployable

func IsDependencyDeployable(instance *appv1alpha1.Deployable) bool

IsDependencyDeployable return true the deploable is dependent depolyable

func OverrideTemplate

func OverrideTemplate(template *unstructured.Unstructured, overrides []appv1alpha1.ClusterOverride) (*unstructured.Unstructured, error)

OverrideTemplate alter the given template with overrides

func PrepareInstance

func PrepareInstance(instance *appv1alpha1.Deployable) bool

PrepareInstance prepares the deployable instane for later actions

func PrepareOverrides

func PrepareOverrides(cluster types.NamespacedName, instance *appv1alpha1.Deployable) ([]appv1alpha1.ClusterOverride, error)

PrepareOverrides returns the overridemap for given deployable instance

func PrintPropagatedStatus

func PrintPropagatedStatus(r map[string]*appv1alpha1.ResourceUnitStatus, msg string)

PrintPropagatedStatus output Propagated Status for each cluster

func UpdateDeployableStatus

func UpdateDeployableStatus(statusClient client.Client, templateerr error, tplunit metav1.Object, status interface{}) error

UpdateDeployableStatus based on error message, and propagate resource status - nil: success - others: failed, with error message in reason

Types

type EventRecorder

type EventRecorder struct {
	record.EventRecorder
}

EventRecorder - record kubernetes event

func NewEventRecorder

func NewEventRecorder(cfg *rest.Config, scheme *apiruntime.Scheme) (*EventRecorder, error)

NewEventRecorder - create new event recorder from rect config

func (*EventRecorder) RecordEvent

func (rec *EventRecorder) RecordEvent(obj apiruntime.Object, reason, msg string, err error)

RecordEvent - record kuberentes event

Jump to

Keyboard shortcuts

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