Documentation
¶
Overview ¶
Package mdutil implements MachineDeployment utilities meant to be consumed internally by the controller.
Package mdutil implements MachineDeployment utilities.
Index ¶
- func CloneAndAddLabel(labels map[string]string, labelKey, labelValue string) map[string]string
- func CloneSelectorAndAddLabel(selector *metav1.LabelSelector, labelKey, labelValue string) *metav1.LabelSelector
- func ComputeRevisionAnnotations(ctx context.Context, newMS *clusterv1.MachineSet, ...) (map[string]string, string, error)
- func DeploymentComplete(deployment *clusterv1.MachineDeployment, ...) bool
- func FilterActiveMachineSets(machineSets []*clusterv1.MachineSet) []*clusterv1.MachineSet
- func FilterMachineSets(mSes []*clusterv1.MachineSet, filterFn filterMS) []*clusterv1.MachineSet
- func FindNewAndOldMachineSets(deployment *clusterv1.MachineDeployment, msList []*clusterv1.MachineSet, ...) (newMS *clusterv1.MachineSet, oldMSs []*clusterv1.MachineSet, ...)
- func FindOneActiveOrLatest(newMS *clusterv1.MachineSet, oldMSs []*clusterv1.MachineSet) *clusterv1.MachineSet
- func GetActualReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) *int32
- func GetAvailableReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) *int32
- func GetProportion(ms *clusterv1.MachineSet, md clusterv1.MachineDeployment, ...) int32
- func GetReadyReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) *int32
- func GetReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) int32
- func GetRevisionAnnotations(_ context.Context, oldMS *clusterv1.MachineSet) map[string]string
- func GetUptoDateReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) *int32
- func GetV1Beta1AvailableReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) int32
- func GetV1Beta1ReadyReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) int32
- func IsRollingUpdate(deployment *clusterv1.MachineDeployment) bool
- func IsSaturated(deployment *clusterv1.MachineDeployment, ms *clusterv1.MachineSet) bool
- func MachineSetAnnotationsFromMachineDeployment(_ context.Context, deployment *clusterv1.MachineDeployment) map[string]string
- func MachineTemplateDeepCopyRolloutFields(template *clusterv1.MachineTemplateSpec) *clusterv1.MachineTemplateSpec
- func MaxRevision(ctx context.Context, allMSs []*clusterv1.MachineSet) int64
- func MaxSurge(deployment clusterv1.MachineDeployment) int32
- func MaxUnavailable(deployment clusterv1.MachineDeployment) int32
- func NewMSNewReplicas(deployment *clusterv1.MachineDeployment, allMSs []*clusterv1.MachineSet, ...) (int32, error)
- func ResolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired int32) (int32, int32, error)
- func Revision(obj runtime.Object) (int64, error)
- func TotalMachineSetsReplicaSum(machineSets []*clusterv1.MachineSet) int32
- type MachineSetsByCreationTimestamp
- type MachineSetsByDecreasingReplicas
- type MachineSetsBySizeNewer
- type MachineSetsBySizeOlder
- type UpToDateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneAndAddLabel ¶
CloneAndAddLabel 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
CloneSelectorAndAddLabel 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 ComputeRevisionAnnotations ¶
func ComputeRevisionAnnotations(ctx context.Context, newMS *clusterv1.MachineSet, oldMSs []*clusterv1.MachineSet) (map[string]string, string, error)
ComputeRevisionAnnotations returns revision annotations to be set on a newMS.
func DeploymentComplete ¶
func DeploymentComplete(deployment *clusterv1.MachineDeployment, newStatus *clusterv1.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 FilterActiveMachineSets ¶
func FilterActiveMachineSets(machineSets []*clusterv1.MachineSet) []*clusterv1.MachineSet
FilterActiveMachineSets returns machine sets that have (or at least ought to have) machines.
func FilterMachineSets ¶
func FilterMachineSets(mSes []*clusterv1.MachineSet, filterFn filterMS) []*clusterv1.MachineSet
FilterMachineSets returns machine sets that are filtered by filterFn (all returned ones should match filterFn).
func FindNewAndOldMachineSets ¶
func FindNewAndOldMachineSets(deployment *clusterv1.MachineDeployment, msList []*clusterv1.MachineSet, reconciliationTime metav1.Time) (newMS *clusterv1.MachineSet, oldMSs []*clusterv1.MachineSet, upToDateResults map[string]UpToDateResult, createReason string)
FindNewAndOldMachineSets returns the newMS for a MachineDeployment (the one with the same machine template, ignoring in-place mutable fields) as well as return oldMSs. Note: If the reconciliation time is after the deployment's `rolloutAfter` time, a MS has to be newer than `rolloutAfter` to be considered as matching the deployment's intent. NOTE: If we find a matching MachineSet which only differs in in-place mutable fields we can use it to fulfill the intent of the MachineDeployment by just updating the MachineSet to propagate in-place mutable fields. Thus we don't have to create a new MachineSet and we can avoid an unnecessary rollout.
func FindOneActiveOrLatest ¶
func FindOneActiveOrLatest(newMS *clusterv1.MachineSet, oldMSs []*clusterv1.MachineSet) *clusterv1.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 []*clusterv1.MachineSet) *int32
GetActualReplicaCountForMachineSets returns the sum of actual replicas of the given machine sets.
func GetAvailableReplicaCountForMachineSets ¶
func GetAvailableReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) *int32
GetAvailableReplicaCountForMachineSets returns the number of available machines corresponding to the given machine sets. Note: When none of the ms.Status.V1Beta2.AvailableReplicas are set, the func returns nil.
func GetProportion ¶
func GetProportion(ms *clusterv1.MachineSet, md clusterv1.MachineDeployment, deploymentReplicasToAdd, deploymentReplicasAdded int32, logger logr.Logger) 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 []*clusterv1.MachineSet) *int32
GetReadyReplicaCountForMachineSets returns the number of ready machines corresponding to the given machine sets. Note: When none of the ms.Status.V1Beta2.ReadyReplicas are set, the func returns nil.
func GetReplicaCountForMachineSets ¶
func GetReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) int32
GetReplicaCountForMachineSets returns the sum of Replicas of the given machine sets.
func GetRevisionAnnotations ¶
GetRevisionAnnotations returns revision annotations to be preserved on oldMSs.
func GetUptoDateReplicaCountForMachineSets ¶ added in v1.11.0
func GetUptoDateReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) *int32
GetUptoDateReplicaCountForMachineSets returns the number of up to date machines corresponding to the given machine sets. Note: When none of the ms.Status.V1Beta2.UpToDateReplicas are set, the func returns nil.
func GetV1Beta1AvailableReplicaCountForMachineSets ¶ added in v1.11.0
func GetV1Beta1AvailableReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) int32
GetV1Beta1AvailableReplicaCountForMachineSets returns the number of available machines corresponding to the given machine sets.
func GetV1Beta1ReadyReplicaCountForMachineSets ¶ added in v1.11.0
func GetV1Beta1ReadyReplicaCountForMachineSets(machineSets []*clusterv1.MachineSet) int32
GetV1Beta1ReadyReplicaCountForMachineSets returns the number of ready machines corresponding to the given machine sets.
func IsRollingUpdate ¶
func IsRollingUpdate(deployment *clusterv1.MachineDeployment) bool
IsRollingUpdate returns true if the strategy type is a rolling update.
func IsSaturated ¶
func IsSaturated(deployment *clusterv1.MachineDeployment, ms *clusterv1.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 MachineSetAnnotationsFromMachineDeployment ¶
func MachineSetAnnotationsFromMachineDeployment(_ context.Context, deployment *clusterv1.MachineDeployment) map[string]string
MachineSetAnnotationsFromMachineDeployment return the annotations that should be set on all the MachineSets and that are derived from the controlling MachineDeployment.
func MachineTemplateDeepCopyRolloutFields ¶ added in v1.4.0
func MachineTemplateDeepCopyRolloutFields(template *clusterv1.MachineTemplateSpec) *clusterv1.MachineTemplateSpec
MachineTemplateDeepCopyRolloutFields copies a MachineTemplateSpec and sets all fields that should be propagated in-place to nil and drops version from external references.
func MaxRevision ¶
func MaxRevision(ctx context.Context, allMSs []*clusterv1.MachineSet) int64
MaxRevision finds the highest revision in the machine sets.
func MaxSurge ¶
func MaxSurge(deployment clusterv1.MachineDeployment) int32
MaxSurge returns the maximum surge machines a rolling deployment can take.
func MaxUnavailable ¶
func MaxUnavailable(deployment clusterv1.MachineDeployment) int32
MaxUnavailable returns the maximum unavailable machines a rolling deployment can take.
func NewMSNewReplicas ¶
func NewMSNewReplicas(deployment *clusterv1.MachineDeployment, allMSs []*clusterv1.MachineSet, newMSReplicas int32) (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) For RollingUpdateStrategy: Max number of machines allowed is reached: deployment's replicas + maxSurge == all MSs' replicas. 3) For OnDeleteStrategy: Max number of machines allowed is reached: deployment's replicas == all MSs' replicas.
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 TotalMachineSetsReplicaSum ¶
func TotalMachineSetsReplicaSum(machineSets []*clusterv1.MachineSet) int32
TotalMachineSetsReplicaSum returns sum of max(ms.Spec.Replicas, ms.Status.Replicas) across all the machine sets.
This is used to guarantee that the total number of machines will not exceed md.Spec.Replicas + maxSurge. Use max(spec.Replicas,status.Replicas) to cover the cases that: 1. Scale up, where spec.Replicas increased but no machine created yet, so spec.Replicas > status.Replicas 2. Scale down, where spec.Replicas decreased but machine not deleted yet, so spec.Replicas < status.Replicas.
Types ¶
type MachineSetsByCreationTimestamp ¶
type MachineSetsByCreationTimestamp []*clusterv1.MachineSet
MachineSetsByCreationTimestamp sorts a list of MachineSet by creation timestamp, using their names as a tie breaker.
func (MachineSetsByCreationTimestamp) Len ¶
func (o MachineSetsByCreationTimestamp) Len() int
func (MachineSetsByCreationTimestamp) Less ¶
func (o MachineSetsByCreationTimestamp) Less(i, j int) bool
func (MachineSetsByCreationTimestamp) Swap ¶
func (o MachineSetsByCreationTimestamp) Swap(i, j int)
type MachineSetsByDecreasingReplicas ¶ added in v1.4.0
type MachineSetsByDecreasingReplicas []*clusterv1.MachineSet
MachineSetsByDecreasingReplicas sorts the list of MachineSets in decreasing order of replicas, using creation time (ascending order) and name (alphabetical) as tie breakers.
func (MachineSetsByDecreasingReplicas) Len ¶ added in v1.4.0
func (o MachineSetsByDecreasingReplicas) Len() int
func (MachineSetsByDecreasingReplicas) Less ¶ added in v1.4.0
func (o MachineSetsByDecreasingReplicas) Less(i, j int) bool
func (MachineSetsByDecreasingReplicas) Swap ¶ added in v1.4.0
func (o MachineSetsByDecreasingReplicas) Swap(i, j int)
type MachineSetsBySizeNewer ¶
type MachineSetsBySizeNewer []*clusterv1.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 []*clusterv1.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)
type UpToDateResult ¶
type UpToDateResult struct {
LogMessages []string
ConditionMessages []string
EligibleForInPlaceUpdate bool
}
UpToDateResult is the result of calling the MachineTemplateUpToDate func for a MachineTemplateSpec.
func MachineTemplateUpToDate ¶ added in v1.9.0
func MachineTemplateUpToDate(current, desired *clusterv1.MachineTemplateSpec) (bool, UpToDateResult)
MachineTemplateUpToDate returns true if the current MachineTemplateSpec is up-to-date with a corresponding desired MachineTemplateSpec. Note: The comparison does not consider any in-place propagated fields, as well as the version from external references.