util

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultMachineDeploymentUniqueLabelKey = "machine-template-hash"

	// RevisionAnnotation is the revision annotation of a machine deployment's machine sets which records its rollout sequence.
	RevisionAnnotation = "machinedeployment.clusters.k8s.io/revision"
	// RevisionHistoryAnnotation maintains the history of all old revisions that a machine set has served for a machine deployment.
	RevisionHistoryAnnotation = "machinedeployment.clusters.k8s.io/revision-history"
	// DesiredReplicasAnnotation is the desired replicas for a machine deployment recorded as an annotation
	// in its machine sets. Helps in separating scaling events from the rollout process and for
	// determining if the new machine set for a deployment is really saturated.
	DesiredReplicasAnnotation = "machinedeployment.clusters.k8s.io/desired-replicas"
	// MaxReplicasAnnotation is the maximum replicas a deployment can have at a given point, which
	// is machinedeployment.spec.replicas + maxSurge. Used by the underlying machine sets to estimate their
	// proportions in case the deployment has surge replicas.
	MaxReplicasAnnotation = "machinedeployment.clusters.k8s.io/max-replicas"

	// FailedMSCreateReason is added in a machine deployment when it cannot create a new machine set.
	FailedMSCreateReason = "MachineSetCreateError"
	// FoundNewMSReason is added in a machine deployment when it adopts an existing machine set.
	FoundNewMSReason = "FoundNewMachineSet"
	// PausedDeployReason is added in a deployment when it is paused. Lack of progress shouldn't be
	// estimated once a deployment is paused.
	PausedDeployReason = "DeploymentPaused"

	// MinimumReplicasAvailable is added in a deployment when it has its minimum replicas required available.
	MinimumReplicasAvailable = "MinimumReplicasAvailable"
	// MinimumReplicasUnavailable is added in a deployment when it doesn't have the minimum required replicas
	// available.
	MinimumReplicasUnavailable = "MinimumReplicasUnavailable"
)

Variables

This section is empty.

Functions

func CloneAndAddLabel

func CloneAndAddLabel(labels map[string]string, labelKey, labelValue string) map[string]string

Clones the given map and returns a new map with the given key and value added. Returns the given map, if labelKey is empty.

func CloneSelectorAndAddLabel

func CloneSelectorAndAddLabel(selector *metav1.LabelSelector, labelKey, labelValue string) *metav1.LabelSelector

Clones the given selector and returns a new selector with the given key and value added. Returns the given selector, if labelKey is empty.

func ComputeHash

func ComputeHash(template *v1alpha1.MachineTemplateSpec) uint32

func DeepHashObject

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

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 DeploymentComplete

func DeploymentComplete(deployment *v1alpha1.MachineDeployment, newStatus *v1alpha1.MachineDeploymentStatus) bool

DeploymentComplete considers a deployment to be complete once all of its desired replicas are updated and available, and no old machines are running.

func EqualIgnoreHash

func EqualIgnoreHash(template1, template2 *v1alpha1.MachineTemplateSpec) bool

EqualIgnoreHash returns true if two given machineTemplateSpec are equal, ignoring the diff in value of Labels[machine-template-hash] We ignore machine-template-hash because:

  1. The hash result would be different upon machineTemplateSpec API changes (e.g. the addition of a new field will cause the hash code to change)
  2. The deployment template won't have hash labels.

func FilterActiveMachineSets

func FilterActiveMachineSets(machineSets []*v1alpha1.MachineSet) []*v1alpha1.MachineSet

FilterActiveMachineSets returns machine sets that have (or at least ought to have) machines.

func FilterMachineSets

func FilterMachineSets(MSes []*v1alpha1.MachineSet, filterFn filterMS) []*v1alpha1.MachineSet

FilterMachineSets returns machine sets that are filtered by filterFn (all returned ones should match filterFn).

func FindNewMachineSet

func FindNewMachineSet(deployment *v1alpha1.MachineDeployment, msList []*v1alpha1.MachineSet) *v1alpha1.MachineSet

FindNewMachineSet returns the new MS this given deployment targets (the one with the same machine template).

func FindOldMachineSets

func FindOldMachineSets(deployment *v1alpha1.MachineDeployment, msList []*v1alpha1.MachineSet) ([]*v1alpha1.MachineSet, []*v1alpha1.MachineSet)

FindOldMachineSets returns the old machine sets targeted by the given Deployment, with the given slice of MSes. Returns two list of machine sets

  • the first contains all old machine sets with all non-zero replicas
  • the second contains all old machine sets

func FindOneActiveOrLatest

func FindOneActiveOrLatest(newMS *v1alpha1.MachineSet, oldMSs []*v1alpha1.MachineSet) *v1alpha1.MachineSet

FindOneActiveOrLatest returns the only active or the latest machine set in case there is at most one active machine set. If there are more than one active machine sets, return nil so machine sets can be scaled down to the point where there is only one active machine set.

func GetActualReplicaCountForMachineSets

func GetActualReplicaCountForMachineSets(machineSets []*v1alpha1.MachineSet) int32

GetActualReplicaCountForMachineSets returns the sum of actual replicas of the given machine sets.

func GetAvailableReplicaCountForMachineSets

func GetAvailableReplicaCountForMachineSets(machineSets []*v1alpha1.MachineSet) int32

GetAvailableReplicaCountForMachineSets returns the number of available machines corresponding to the given machine sets.

func GetDesiredReplicasAnnotation

func GetDesiredReplicasAnnotation(log *zap.SugaredLogger, ms *v1alpha1.MachineSet) (int32, bool)

GetDesiredReplicasAnnotation returns the number of desired replicas.

func GetMachineDeploymentNameAndRevisionForMachine

func GetMachineDeploymentNameAndRevisionForMachine(ctx context.Context, machine *clusterv1alpha1.Machine, c client.Client) (string, string, error)

func GetProportion

func GetProportion(log *zap.SugaredLogger, ms *v1alpha1.MachineSet, d v1alpha1.MachineDeployment, deploymentReplicasToAdd, deploymentReplicasAdded int32) int32

GetProportion will estimate the proportion for the provided machine set using 1. the current size of the parent deployment, 2. the replica count that needs be added on the machine sets of the deployment, and 3. the total replicas added in the machine sets of the deployment so far.

func GetReadyReplicaCountForMachineSets

func GetReadyReplicaCountForMachineSets(machineSets []*v1alpha1.MachineSet) int32

GetReadyReplicaCountForMachineSets returns the number of ready machines corresponding to the given machine sets.

func GetReplicaCountForMachineSets

func GetReplicaCountForMachineSets(machineSets []*v1alpha1.MachineSet) int32

GetReplicaCountForMachineSets returns the sum of Replicas of the given machine sets.

func IsRollingUpdate

func IsRollingUpdate(deployment *v1alpha1.MachineDeployment) bool

IsRollingUpdate returns true if the strategy type is a rolling update.

func IsSaturated

func IsSaturated(deployment *v1alpha1.MachineDeployment, ms *v1alpha1.MachineSet) bool

IsSaturated checks if the new machine set is saturated by comparing its size with its deployment size. Both the deployment and the machine set have to believe this machine set can own all of the desired replicas in the deployment and the annotation helps in achieving that. All machines of the MachineSet need to be available.

func MaxRevision

func MaxRevision(log *zap.SugaredLogger, allMSs []*v1alpha1.MachineSet) int64

MaxRevision finds the highest revision in the machine sets.

func MaxSurge

func MaxSurge(deployment v1alpha1.MachineDeployment) int32

MaxSurge returns the maximum surge machines a rolling deployment can take.

func MaxUnavailable

func MaxUnavailable(deployment v1alpha1.MachineDeployment) int32

MaxUnavailable returns the maximum unavailable machines a rolling deployment can take.

func NewMSNewReplicas

func NewMSNewReplicas(deployment *v1alpha1.MachineDeployment, allMSs []*v1alpha1.MachineSet, newMS *v1alpha1.MachineSet) (int32, error)

NewMSNewReplicas calculates the number of replicas a deployment's new MS should have. When one of the following is true, we're rolling out the deployment; otherwise, we're scaling it. 1) The new MS is saturated: newMS's replicas == deployment's replicas 2) Max number of machines allowed is reached: deployment's replicas + maxSurge == all MSs' replicas.

func ReplicasAnnotationsNeedUpdate

func ReplicasAnnotationsNeedUpdate(ms *v1alpha1.MachineSet, desiredReplicas, maxReplicas int32) bool

AnnotationsNeedUpdate return true if ReplicasAnnotations need to be updated.

func ResolveFenceposts

func ResolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired int32) (int32, int32, error)

ResolveFenceposts resolves both maxSurge and maxUnavailable. This needs to happen in one step. For example:

2 desired, max unavailable 1%, surge 0% - should scale old(-1), then new(+1), then old(-1), then new(+1) 1 desired, max unavailable 1%, surge 0% - should scale old(-1), then new(+1) 2 desired, max unavailable 25%, surge 1% - should scale new(+1), then old(-1), then new(+1), then old(-1) 1 desired, max unavailable 25%, surge 1% - should scale new(+1), then old(-1) 2 desired, max unavailable 0%, surge 1% - should scale new(+1), then old(-1), then new(+1), then old(-1) 1 desired, max unavailable 0%, surge 1% - should scale new(+1), then old(-1).

func Revision

func Revision(obj runtime.Object) (int64, error)

Revision returns the revision number of the input object.

func SetDeploymentRevision

func SetDeploymentRevision(deployment *v1alpha1.MachineDeployment, revision string) bool

SetDeploymentRevision updates the revision for a deployment.

func SetNewMachineSetAnnotations

func SetNewMachineSetAnnotations(mdLog *zap.SugaredLogger, deployment *v1alpha1.MachineDeployment, newMS *v1alpha1.MachineSet, newRevision string, exists bool) bool

SetNewMachineSetAnnotations sets new machine set's annotations appropriately by updating its revision and copying required deployment annotations to it; it returns true if machine set's annotation is changed.

func SetReplicasAnnotations

func SetReplicasAnnotations(ms *v1alpha1.MachineSet, desiredReplicas, maxReplicas int32) bool

SetReplicasAnnotations sets the desiredReplicas and maxReplicas into the annotations.

Types

type MachineSetsByCreationTimestamp

type MachineSetsByCreationTimestamp []*v1alpha1.MachineSet

MachineSetsByCreationTimestamp sorts a list of MachineSet by creation timestamp, using their names as a tie breaker.

func (MachineSetsByCreationTimestamp) Len

func (MachineSetsByCreationTimestamp) Less

func (MachineSetsByCreationTimestamp) Swap

func (o MachineSetsByCreationTimestamp) Swap(i, j int)

type MachineSetsBySizeNewer

type MachineSetsBySizeNewer []*v1alpha1.MachineSet

MachineSetsBySizeNewer sorts a list of MachineSet by size in descending order, using their creation timestamp or name as a tie breaker. By using the creation timestamp, this sorts from new to old machine sets.

func (MachineSetsBySizeNewer) Len

func (o MachineSetsBySizeNewer) Len() int

func (MachineSetsBySizeNewer) Less

func (o MachineSetsBySizeNewer) Less(i, j int) bool

func (MachineSetsBySizeNewer) Swap

func (o MachineSetsBySizeNewer) Swap(i, j int)

type MachineSetsBySizeOlder

type MachineSetsBySizeOlder []*v1alpha1.MachineSet

MachineSetsBySizeOlder sorts a list of MachineSet by size in descending order, using their creation timestamp or name as a tie breaker. By using the creation timestamp, this sorts from old to new machine sets.

func (MachineSetsBySizeOlder) Len

func (o MachineSetsBySizeOlder) Len() int

func (MachineSetsBySizeOlder) Less

func (o MachineSetsBySizeOlder) Less(i, j int) bool

func (MachineSetsBySizeOlder) Swap

func (o MachineSetsBySizeOlder) Swap(i, j int)

Jump to

Keyboard shortcuts

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