utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExpectationsTimeout defines the length of time that a dormant
	// controller will wait for an expectation to be satisfied. It is
	// specifically targeted at the case where some problem prevents an update
	// of expectations, without it the controller could stay asleep forever. This should
	// be set based on the expected latency of watch events.
	ExpectationsTimeout = 5 * time.Minute
)
View Source
const (
	// ServiceAccountName will be a service account that can run the installer and then
	// upload artifacts to the cluster's namespace.
	ServiceAccountName = "cluster-installer"
)

Variables

View Source
var ExpKeyFunc = func(obj interface{}) (string, error) {
	if e, ok := obj.(*ControlleeExpectations); ok {
		return e.key, nil
	}
	return "", fmt.Errorf("Could not find key for obj %#v", obj)
}

ExpKeyFunc to parse out the key from a ControlleeExpectation

Functions

func AddAdditionalKubeconfigCAs

func AddAdditionalKubeconfigCAs(data []byte) ([]byte, error)

AddAdditionalKubeconfigCAs adds additional certificate authorities to a given kubeconfig

func AddControllerMetricsTransportWrapper

func AddControllerMetricsTransportWrapper(cfg *rest.Config, controllerName string, remote bool)

AddControllerMetricsTransportWrapper adds a transport wrapper to the given rest config which exposes metrics based on the requests being made.

func AddFinalizer

func AddFinalizer(object metav1.Object, finalizer string)

AddFinalizer adds a finalizer to the given object

func AddTypeMeta

func AddTypeMeta(objects []runtime.RawExtension, scheme *runtime.Scheme) ([]runtime.RawExtension, error)

AddTypeMeta adds type metadata to objects in a list of RawExtension TypeMeta is needed for proper serialization/deserialization

func CalculateJobSpecHash

func CalculateJobSpecHash(job *batchv1.Job) (string, error)

CalculateJobSpecHash returns a hash of the job.Spec.

func DNSZoneName

func DNSZoneName(cdName string) string

DNSZoneName returns the predictable name for a DNSZone for the given ClusterDeployment.

func DeleteFinalizer

func DeleteFinalizer(object metav1.Object, finalizer string)

DeleteFinalizer removes a finalizer from the given object

func Dotted

func Dotted(domain string) string

Dotted adds a trailing dot to a domain if it doesn't exist.

func FindClusterDeploymentCondition

func FindClusterDeploymentCondition(conditions []hivev1.ClusterDeploymentCondition, conditionType hivev1.ClusterDeploymentConditionType) *hivev1.ClusterDeploymentCondition

FindClusterDeploymentCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil.

func FindClusterProvisionCondition

func FindClusterProvisionCondition(conditions []hivev1.ClusterProvisionCondition, conditionType hivev1.ClusterProvisionConditionType) *hivev1.ClusterProvisionCondition

FindClusterProvisionCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil.

func FindDNSZoneCondition

func FindDNSZoneCondition(conditions []hivev1.DNSZoneCondition, conditionType hivev1.DNSZoneConditionType) *hivev1.DNSZoneCondition

FindDNSZoneCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil.

func FindMachinePoolCondition

func FindMachinePoolCondition(conditions []hivev1.MachinePoolCondition, conditionType hivev1.MachinePoolConditionType) *hivev1.MachinePoolCondition

FindMachinePoolCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil.

func FindSyncCondition

func FindSyncCondition(conditions []hivev1.SyncCondition, conditionType hivev1.SyncConditionType) *hivev1.SyncCondition

FindSyncCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil.

func GetChecksumOfObject

func GetChecksumOfObject(object interface{}) (string, error)

GetChecksumOfObject returns the md5sum hash of the object passed in.

func GetChecksumOfObjects

func GetChecksumOfObjects(objects ...interface{}) (string, error)

GetChecksumOfObjects returns the md5sum hash of the objects passed in.

func GetConcurrentReconciles

func GetConcurrentReconciles() int

GetConcurrentReconciles returns the number of goroutines each controller should use for parallel processing of their queue. For now this is a static value of 5. In future this may be read from an env var set by the operator, and driven by HiveConfig.

func GetRuntimeObjects

func GetRuntimeObjects(c client.Client, typesToList []runtime.Object, namespace string) ([]runtime.Object, error)

GetRuntimeObjects returns a slice of runtime objects returned from the kubernetes client based on the passed in list of types to return.

func HasFinalizer

func HasFinalizer(object metav1.Object, finalizer string) bool

HasFinalizer returns true if the given object has the given finalizer

func IsFailed

func IsFailed(job *batchv1.Job) bool

IsFailed returns true if the job failed

func IsFinished

func IsFinished(job *batchv1.Job) bool

IsFinished returns true if the job completed (succeeded or failed)

func IsSuccessful

func IsSuccessful(job *batchv1.Job) bool

IsSuccessful returns true if the job was successful

func LoadSecretData

func LoadSecretData(c client.Client, secretName, namespace, dataKey string) (string, error)

LoadSecretData loads a given secret key and returns it's data as a string.

func LogLevel

func LogLevel(err error) log.Level

LogLevel returns the log level to use to log the specified error.

func MergeJsons

func MergeJsons(globalPullSecret string, localPullSecret string, cdLog log.FieldLogger) (string, error)

MergeJsons will merge the global and local pull secret and return it

func NewClientWithMetricsOrDie

func NewClientWithMetricsOrDie(mgr manager.Manager, ctrlrName string) client.Client

NewClientWithMetricsOrDie creates a new controller-runtime client with a wrapper which increments metrics for requests by controller name, HTTP method, URL path, and whether or not the request was to a remote cluster.. The client will re-use the managers cache. This should be used in all Hive controllers.

func SetClusterDeploymentCondition

func SetClusterDeploymentCondition(
	conditions []hivev1.ClusterDeploymentCondition,
	conditionType hivev1.ClusterDeploymentConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []hivev1.ClusterDeploymentCondition

SetClusterDeploymentCondition sets a condition on a ClusterDeployment resource's status

func SetClusterDeploymentConditionWithChangeCheck

func SetClusterDeploymentConditionWithChangeCheck(
	conditions []hivev1.ClusterDeploymentCondition,
	conditionType hivev1.ClusterDeploymentConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) ([]hivev1.ClusterDeploymentCondition, bool)

SetClusterDeploymentConditionWithChangeCheck sets a condition on a ClusterDeployment resource's status. It returns the conditions as well a boolean indicating whether there was a change made to the conditions.

func SetClusterProvisionCondition

func SetClusterProvisionCondition(
	conditions []hivev1.ClusterProvisionCondition,
	conditionType hivev1.ClusterProvisionConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []hivev1.ClusterProvisionCondition

SetClusterProvisionCondition sets a condition on a ClusterProvision resource's status

func SetDNSZoneCondition

func SetDNSZoneCondition(
	conditions []hivev1.DNSZoneCondition,
	conditionType hivev1.DNSZoneConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []hivev1.DNSZoneCondition

SetDNSZoneCondition sets a condition on a DNSZone resource's status

func SetDNSZoneConditionWithChangeCheck

func SetDNSZoneConditionWithChangeCheck(
	conditions []hivev1.DNSZoneCondition,
	conditionType hivev1.DNSZoneConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) ([]hivev1.DNSZoneCondition, bool)

SetDNSZoneConditionWithChangeCheck sets a condition on a DNSZone resource's status It returns the conditions as well a boolean indicating whether there was a change made to the conditions.

func SetMachinePoolCondition

func SetMachinePoolCondition(
	conditions []hivev1.MachinePoolCondition,
	conditionType hivev1.MachinePoolConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []hivev1.MachinePoolCondition

SetMachinePoolCondition sets a condition on a MachinePool resource's status

func SetMachinePoolConditionWithChangeCheck

func SetMachinePoolConditionWithChangeCheck(
	conditions []hivev1.MachinePoolCondition,
	conditionType hivev1.MachinePoolConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) ([]hivev1.MachinePoolCondition, bool)

SetMachinePoolConditionWithChangeCheck sets a condition on a MachinePool resource's status. It returns the conditions as well a boolean indicating whether there was a change made to the conditions.

func SetSyncCondition

func SetSyncCondition(
	conditions []hivev1.SyncCondition,
	conditionType hivev1.SyncConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []hivev1.SyncCondition

SetSyncCondition sets a condition on a SyncSet or resource's status

func SetupAdditionalCA

func SetupAdditionalCA() error

SetupAdditionalCA reads a file referenced by the ADDITIONAL_CA environment variable that contains an additional CA. This should only be called once on initialization

func SetupClusterInstallServiceAccount

func SetupClusterInstallServiceAccount(c client.Client, namespace string, logger log.FieldLogger) error

SetupClusterInstallServiceAccount ensures a service account exists which can upload the required artifacts after running the installer in a pod. (metadata, admin kubeconfig)

func Undotted

func Undotted(domain string) string

Undotted removes the trailing dot from a domain if it exists.

func UpdateConditionAlways

func UpdateConditionAlways(_, _, _, _ string) bool

UpdateConditionAlways returns true. The condition will always be updated.

func UpdateConditionIfReasonOrMessageChange

func UpdateConditionIfReasonOrMessageChange(oldReason, oldMessage, newReason, newMessage string) bool

UpdateConditionIfReasonOrMessageChange returns true if there is a change in the reason or the message of the condition.

func UpdateConditionNever

func UpdateConditionNever(_, _, _, _ string) bool

UpdateConditionNever return false. The condition will never be updated, unless there is a change in the status of the condition.

func WrapEventHandlerWithLogging

func WrapEventHandlerWithLogging(eventHandler handler.EventHandler, logger log.FieldLogger) handler.EventHandler

WrapEventHandlerWithLogging wraps the specified event handler inside a new event handler that will log when events are handled and items are added to the queue.

Types

type ControlleeExpectations

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

ControlleeExpectations track controllee creates/deletes.

func (*ControlleeExpectations) Add

func (e *ControlleeExpectations) Add(add, del int64)

Add increments the add and del counters.

func (*ControlleeExpectations) Fulfilled

func (e *ControlleeExpectations) Fulfilled() bool

Fulfilled returns true if this expectation has been fulfilled.

func (*ControlleeExpectations) GetExpectations

func (e *ControlleeExpectations) GetExpectations() (int64, int64)

GetExpectations returns the add and del expectations of the controllee.

type ControllerMetricsTripper

type ControllerMetricsTripper struct {
	http.RoundTripper
	Controller string
	Remote     bool
}

ControllerMetricsTripper is a RoundTripper implementation which tracks our metrics for client requests.

func (*ControllerMetricsTripper) RoundTrip

func (cmt *ControllerMetricsTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http RoundTripper interface.

type Expectations

type Expectations struct {
	cache.Store
	// contains filtered or unexported fields
}

Expectations is a cache mapping controllers to what they expect to see before being woken up for a sync.

func NewExpectations

func NewExpectations(logger log.FieldLogger) *Expectations

NewExpectations returns a store for Expectations.

func (*Expectations) CreationObserved

func (r *Expectations) CreationObserved(controllerKey string)

CreationObserved atomically decrements the `add` expectation count of the given controller.

func (*Expectations) DeleteExpectations

func (r *Expectations) DeleteExpectations(controllerKey string)

DeleteExpectations deletes the expectations of the given controller from the TTLStore.

func (*Expectations) DeletionObserved

func (r *Expectations) DeletionObserved(controllerKey string)

DeletionObserved atomically decrements the `del` expectation count of the given controller.

func (*Expectations) ExpectCreations

func (r *Expectations) ExpectCreations(controllerKey string, adds int) error

ExpectCreations sets the expectations to expect the specified number of additions for the controller with the specified key.

func (*Expectations) ExpectDeletions

func (r *Expectations) ExpectDeletions(controllerKey string, dels int) error

ExpectDeletions sets the expectations to expect the specified number of deletions for the controller with the specified key.

func (*Expectations) GetExpectations

func (r *Expectations) GetExpectations(controllerKey string) (*ControlleeExpectations, bool, error)

GetExpectations returns the ControlleeExpectations of the given controller.

func (*Expectations) LowerExpectations

func (r *Expectations) LowerExpectations(controllerKey string, add, del int)

LowerExpectations decrements the expectation counts of the given controller.

func (*Expectations) RaiseExpectations

func (r *Expectations) RaiseExpectations(controllerKey string, add, del int)

RaiseExpectations increments the expectation counts of the given controller.

func (*Expectations) SatisfiedExpectations

func (r *Expectations) SatisfiedExpectations(controllerKey string) bool

SatisfiedExpectations returns true if the required adds/dels for the given controller have been observed. Add/del counts are established by the controller at sync time, and updated as controllees are observed by the controller manager.

func (*Expectations) SetExpectations

func (r *Expectations) SetExpectations(controllerKey string, add, del int) error

SetExpectations registers new expectations for the given controller. Forgets existing expectations.

type ExpectationsInterface

type ExpectationsInterface interface {
	GetExpectations(controllerKey string) (*ControlleeExpectations, bool, error)
	SatisfiedExpectations(controllerKey string) bool
	DeleteExpectations(controllerKey string)
	SetExpectations(controllerKey string, add, del int) error
	ExpectCreations(controllerKey string, adds int) error
	ExpectDeletions(controllerKey string, dels int) error
	CreationObserved(controllerKey string)
	DeletionObserved(controllerKey string)
	RaiseExpectations(controllerKey string, add, del int)
	LowerExpectations(controllerKey string, add, del int)
}

ExpectationsInterface is an interface that allows users to set and wait on expectations. Only abstracted out for testing. Warning: if using KeyFunc it is not safe to use a single ExpectationsInterface with different types of controllers, because the keys might conflict across types.

type UpdateConditionCheck

type UpdateConditionCheck func(oldReason, oldMessage, newReason, newMessage string) bool

UpdateConditionCheck tests whether a condition should be updated from the old condition to the new condition. Returns true if the condition should be updated.

Jump to

Keyboard shortcuts

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