utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 26 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 (
	ResourceLabelName = "name"
)
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.(*dplv1.Deployable)
		olddpl := e.ObjectOld.(*dplv1.Deployable)

		if len(newdpl.GetFinalizers()) > 0 {
			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

View Source
var SubscriptionPredicateFunc = predicate.Funcs{
	UpdateFunc: func(e event.UpdateEvent) bool {
		subOld := e.ObjectOld.(*subv1.Subscription)
		subNew := e.ObjectNew.(*subv1.Subscription)

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

		if !reflect.DeepEqual(subOld.GetLabels(), subNew.GetLabels()) {
			return true
		}

		if !reflect.DeepEqual(subOld.GetAnnotations(), subNew.GetAnnotations()) {
			return true
		}

		if !reflect.DeepEqual(subOld.Spec, subNew.Spec) {
			return true
		}

		if subNew.Status.Phase == "" || subNew.Status.Phase != subOld.Status.Phase {
			klog.V(5).Info("We care phase..", subNew.Status.Phase, " vs ", subOld.Status.Phase)
			return true
		}

		klog.V(1).Info("Something we don't care changed")
		return false
	},
}

SubscriptionPredicateFunc filters status update

Functions

func AppendClusterDplMap

func AppendClusterDplMap(statusdpl dplv1alpha1.Deployable, dpl dplv1alpha1.Deployable, allClusterDplMap map[string]*DplMap)

AppendClusterDplMap append dpl and its deployed cluster to allClusterDplMap

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 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 GetFnName

func GetFnName() string

GetFnName - get name of function

func GetUniqueDeployables

func GetUniqueDeployables(allDpls []*dplv1alpha1.Deployable) []*dplv1alpha1.Deployable

GetUniqueDeployables get unique deployable array

func GetUniqueSubscriptions

func GetUniqueSubscriptions(allSubs []*subv1alpha1.Subscription) []*subv1alpha1.Subscription

GetUniqueSubscriptions get unique subscription array

func PrintAllClusterDplMap

func PrintAllClusterDplMap(allClusterDplMap map[string]*DplMap)

PrintAllClusterDplMap print all cluster deployable map

func UpdateAppInstance

func UpdateAppInstance(oldApp, newApp *appv1beta1.Application) bool

Types

type DplMap

type DplMap struct {
	DplResourceMap map[string]*dplv1alpha1.Deployable
}

DplMap store all dpl names for a cluster [dplName]

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