replicaset

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 27 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// EphemeralMetadataAnnotation denotes pod metadata which is ephemerally injected to canary/stable pods
	EphemeralMetadataAnnotation = annotations.RolloutLabel + "/ephemeral-metadata"
)

Variables

This section is empty.

Functions

func AtDesiredReplicaCountsForCanary added in v0.2.0

func AtDesiredReplicaCountsForCanary(ro *v1alpha1.Rollout, newRS, stableRS *appsv1.ReplicaSet, olderRSs []*appsv1.ReplicaSet, weights *v1alpha1.TrafficWeights) bool

func BeforeStartingStep added in v0.7.0

func BeforeStartingStep(rollout *v1alpha1.Rollout) bool

BeforeStartingStep checks if canary rollout is at the starting step

func CalculateReplicaCountsForBasicCanary added in v1.1.0

func CalculateReplicaCountsForBasicCanary(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, stableRS *appsv1.ReplicaSet, oldRSs []*appsv1.ReplicaSet) (int32, int32)

CalculateReplicaCountsForBasicCanary calculates the number of replicas for the newRS and the stableRS when using the basic canary strategy. The function calculates the desired number of replicas for the new and stable RS using the following equations:

desired newRS Replica count = spec.Replica * (setweight / maxweight) desired stableRS Replica count = spec.Replica - newRS

The function for newRS finds the closest whole number of replicas based on the weight percentage and rounds up the desired replica count in case of a tie.

Then, the function finds the number of replicas it can scale up using the following equation:

scaleUpCount := (maxSurge + rollout.Spec.Replica) - sum of rollout's RSs spec.Replica

If the rollout has not reached its max number of replicas, it will scale up the RS whose desired replica count is greater than its current count to the desired number. The rollout will either scale the RS up as much as it can unless the rollout can reach the RS desired count. In order to give precedence to the stableRS, the function will scale up the stable RS to desired count before scaling up the new RS.

At this point, the function then finds the number of replicas it can scale down using the following equation:

scaleDownCount := count of all the available replicas - (spec.Replica - maxUnavailable)

If the rollout has not reached at the min available replicas count, it will scale down the RS whose desired replica count is less than its current count to the desired number. However before scaling any new or stable RS down, the function will scale down the replicas in the old RS list first. Afterwards if the rollout is not at the min available replica count, the function will check the newRS before the stableRS.

Examples: replicas 10 currentWeight 10 NewRS 0 stableRS 10 max unavailable 1, surge 1 - should return newRS 1 stableRS 9 replicas 10 currentWeight 30 NewRS 0 stableRS 10 max unavailable 0, surge 3 - should return newRS 3 stableRS 10 replicas 10 currentWeight 30 NewRS 0 stableRS 10 max unavailable 5, surge 0 - should return newRS 0 stableRS 7 replicas 10 currentWeight 5 NewRS 0 stableRS 10 max unavailable 1, surge 1 - should return newRS 1 stableRS 9 replicas 1 currentWeight 5 NewRS 0 stableRS 1 max unavailable 0, surge 1 - should return newRS 1 stableRS 1 replicas 1 currentWeight 95 NewRS 0 stableRS 1 max unavailable 0, surge 1 - should return newRS 1 stableRS 1 For more examples, check the CalculateReplicaCountsForBasicCanary test in canary/canary_test.go

func CalculateReplicaCountsForTrafficRoutedCanary added in v1.1.0

func CalculateReplicaCountsForTrafficRoutedCanary(rollout *v1alpha1.Rollout, weights *v1alpha1.TrafficWeights) (int32, int32)

CalculateReplicaCountsForTrafficRoutedCanary calculates the canary and stable replica counts when using canary with traffic routing. If current traffic weights are supplied, we factor the those weights into the and return the higher of current traffic scale vs. desired traffic scale If MinPodsPerReplicaSet is defined and the number of replicas in either RS is not 0, then return at least MinPodsPerReplicaSet

func CheckMinPodsPerReplicaSet added in v1.4.0

func CheckMinPodsPerReplicaSet(rollout *v1alpha1.Rollout, count int32) int32

CheckMinPodsPerReplicaSet ensures that if the desired number of pods in a stable or canary ReplicaSet is not zero, then it is at least MinPodsPerReplicaSet for High Availability. Only applicable if using TrafficRouting

func CheckPodSpecChange added in v0.2.0

func CheckPodSpecChange(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet) bool

checkPodSpecChange indicates if the rollout spec has changed indicating that the rollout needs to reset the currentStepIndex to zero. If there is no previous pod spec to compare to the function defaults to false

func CheckStableRSExists added in v0.2.0

func CheckStableRSExists(newRS, stableRS *appsv1.ReplicaSet) bool

CheckStableRSExists checks if the stableRS exists and is different than the newRS

func CreateInjectedAntiAffinityRule added in v0.8.0

func CreateInjectedAntiAffinityRule(rollout v1alpha1.Rollout) corev1.PodAffinityTerm

func FindActiveOrLatest

func FindActiveOrLatest(newRS *appsv1.ReplicaSet, oldRSs []*appsv1.ReplicaSet) *appsv1.ReplicaSet

FindActiveOrLatest returns the only active or the latest replica set in case there is at most one active replica set. If there are more active replica sets, then we should proportionally scale them.

func FindNewReplicaSet

func FindNewReplicaSet(rollout *v1alpha1.Rollout, rsList []*appsv1.ReplicaSet) *appsv1.ReplicaSet

FindNewReplicaSet returns the new RS this given rollout targets from the given list. Returns nil if the ReplicaSet does not exist in the list.

func FindOldReplicaSets

func FindOldReplicaSets(rollout *v1alpha1.Rollout, rsList []*appsv1.ReplicaSet, newRS *appsv1.ReplicaSet) []*appsv1.ReplicaSet

FindOldReplicaSets returns the old replica sets targeted by the given Rollout, with the given slice of RSes.

func GenerateReplicaSetAffinity added in v0.8.0

func GenerateReplicaSetAffinity(rollout v1alpha1.Rollout) *corev1.Affinity

func GetActualReplicaCountForReplicaSets

func GetActualReplicaCountForReplicaSets(replicaSets []*appsv1.ReplicaSet) int32

GetActualReplicaCountForReplicaSets returns the sum of actual replicas of the given replica sets.

func GetAvailableReplicaCountForReplicaSets

func GetAvailableReplicaCountForReplicaSets(replicaSets []*appsv1.ReplicaSet) int32

GetAvailableReplicaCountForReplicaSets returns the number of available pods corresponding to the given replica sets.

func GetCanaryReplicasOrWeight added in v0.10.0

func GetCanaryReplicasOrWeight(rollout *v1alpha1.Rollout) (*int32, int32)

GetCanaryReplicasOrWeight either returns a static set of replicas or a weight percentage

func GetCurrentCanaryStep added in v0.2.0

func GetCurrentCanaryStep(rollout *v1alpha1.Rollout) (*v1alpha1.CanaryStep, *int32)

GetCurrentCanaryStep returns the current canary step. If there are no steps or the rollout has already executed the last step, the func returns nil

func GetCurrentExperimentStep added in v0.6.0

func GetCurrentExperimentStep(r *v1alpha1.Rollout) *v1alpha1.RolloutExperimentStep

GetCurrentExperimentStep grabs the latest Experiment step

func GetCurrentSetWeight added in v0.2.0

func GetCurrentSetWeight(rollout *v1alpha1.Rollout) int32

GetCurrentSetWeight grabs the current setWeight used by the rollout by iterating backwards from the current step until it finds a setWeight step. The controller defaults to 100 if it iterates through all the steps with no setWeight or if there is no current step (i.e. the controller has already stepped through all the steps).

func GetOtherRSs added in v0.10.0

func GetOtherRSs(rollout *v1alpha1.Rollout, newRS, stableRS *appsv1.ReplicaSet, allRSs []*appsv1.ReplicaSet) []*appsv1.ReplicaSet

GetOtherRSs the function goes through a list of ReplicaSets and returns a list of RS that are not the new or stable RS

func GetPodTemplateHash added in v0.4.0

func GetPodTemplateHash(rs *appsv1.ReplicaSet) string

GetPodTemplateHash returns the rollouts-pod-template-hash value from a ReplicaSet's labels

func GetPodsOwnedByReplicaSet added in v0.10.0

func GetPodsOwnedByReplicaSet(ctx context.Context, client kubernetes.Interface, rs *appsv1.ReplicaSet) ([]*corev1.Pod, error)

GetPodsOwnedByReplicaSet returns a list of pods owned by the given replicaset

func GetReadyReplicaCountForReplicaSets

func GetReadyReplicaCountForReplicaSets(replicaSets []*appsv1.ReplicaSet) int32

GetReadyReplicaCountForReplicaSets returns the number of ready pods corresponding to the given replica sets.

func GetReplicaCountForReplicaSets

func GetReplicaCountForReplicaSets(replicaSets []*appsv1.ReplicaSet) int32

GetReplicaCountForReplicaSets returns the sum of Replicas of the given replica sets.

func GetReplicaSetByTemplateHash added in v0.3.1

func GetReplicaSetByTemplateHash(allRS []*appsv1.ReplicaSet, podTemplateHash string) (*appsv1.ReplicaSet, []*appsv1.ReplicaSet)

GetReplicaSetByTemplateHash find the replicaset that matches the podTemplateHash

func GetReplicaSetRevision added in v0.8.0

func GetReplicaSetRevision(ro *v1alpha1.Rollout, rs *appsv1.ReplicaSet) int

func GetReplicasForScaleDown added in v0.4.2

func GetReplicasForScaleDown(rs *appsv1.ReplicaSet, ignoreAvailability bool) int32

GetReplicasForScaleDown returns the total number of replicas to consider for scaling down the given ReplicaSet. ignoreAvailability indicates if we are allowed to ignore availability of pods during the calculation, in which case we return just the desired replicas. The purpose of ignoring availability is to handle the case when the ReplicaSet which we are considering for scaledown might be scaled up, but its pods may be unavailable (e.g. because of a CrashloopBackoff). In this case we need to return the spec.Replicas so that the controller will still consider scaling down this ReplicaSet. Without this, a rollout could become stuck not scaling down the stable, in order to make room for more canaries.

func GetRolloutAffinity added in v0.8.0

func GetRolloutAffinity(rollout v1alpha1.Rollout) *v1alpha1.AntiAffinity

func GetStableRS added in v0.2.0

func GetStableRS(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, rslist []*appsv1.ReplicaSet) *appsv1.ReplicaSet

GetStableRS finds the stable RS using the RS's RolloutUniqueLabelKey and the stored StableRS in the rollout status

func GetTimeRemainingBeforeScaleDownDeadline added in v1.1.0

func GetTimeRemainingBeforeScaleDownDeadline(rs *appsv1.ReplicaSet) (*time.Duration, error)

func HasInjectedAntiAffinityRule added in v0.8.0

func HasInjectedAntiAffinityRule(affinity *corev1.Affinity, rollout v1alpha1.Rollout) (int, *corev1.PodAffinityTerm)

func HasScaleDownDeadline added in v0.9.2

func HasScaleDownDeadline(rs *appsv1.ReplicaSet) bool

HasScaleDownDeadline returns whether or not the given ReplicaSet is annotated with a scale-down delay

func IfInjectedAntiAffinityRuleNeedsUpdate added in v0.8.0

func IfInjectedAntiAffinityRuleNeedsUpdate(affinity *corev1.Affinity, rollout v1alpha1.Rollout) bool

func IsActive added in v1.6.0

func IsActive(rs *appsv1.ReplicaSet) bool

IsActive returns if replica set is active (has, or at least ought to have pods).

func IsReplicaSetAvailable added in v1.2.0

func IsReplicaSetAvailable(rs *appsv1.ReplicaSet) bool

IsReplicaSetAvailable returns if a ReplicaSet is scaled up and its ready count is >= desired count

func IsReplicaSetPartiallyAvailable added in v1.3.2

func IsReplicaSetPartiallyAvailable(rs *appsv1.ReplicaSet) bool

IsReplicaSetPartiallyAvailable returns if a ReplicaSet is scaled up and has at least 1 pod available

func MaxRevision

func MaxRevision(allRSs []*appsv1.ReplicaSet) int64

MaxRevision finds the highest revision in the replica sets

func MaxSurge added in v0.2.0

func MaxSurge(rollout *v1alpha1.Rollout) int32

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

func MaxUnavailable added in v0.2.0

func MaxUnavailable(rollout *v1alpha1.Rollout) int32

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

func NeedsRestart added in v0.8.0

func NeedsRestart(rollout *v1alpha1.Rollout) bool

func NewRSNewReplicas

func NewRSNewReplicas(rollout *v1alpha1.Rollout, allRSs []*appsv1.ReplicaSet, newRS *appsv1.ReplicaSet, weights *v1alpha1.TrafficWeights) (int32, error)

NewRSNewReplicas calculates the number of replicas a Rollout's new RS should have. When one of the followings is true, we're rolling out the deployment; otherwise, we're scaling it. 1) The new RS is saturated: newRS's replicas == deployment's replicas 2) Max number of pods allowed is reached: deployment's replicas + maxSurge == all RSs' replicas

func ParseExistingPodMetadata added in v0.10.2

func ParseExistingPodMetadata(rs *appsv1.ReplicaSet) *v1alpha1.PodTemplateMetadata

ParseExistingPodMetadata returns the existing podMetadata which was injected to the ReplicaSet based on examination of rollout.argoproj.io/ephemeral-metadata annotation on the ReplicaSet. Returns nil if there was no metadata, or the metadata was not parseable.

func PodTemplateEqualIgnoreHash added in v0.4.0

func PodTemplateEqualIgnoreHash(live, desired *corev1.PodTemplateSpec) bool

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

  1. The hash result would be different upon podTemplateSpec 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

NOTE: This is a modified version of deploymentutil.EqualIgnoreHash, but modified to perform defaulting on the desired spec. This is so that defaulted fields by the replicaset controller factor into the comparison. The reason this is necessary, is because unlike the deployment controller, the rollout controller does not benefit/operate on a completely defaulted rollout object.

func PodTemplateOrStepsChanged added in v0.4.0

func PodTemplateOrStepsChanged(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet) bool

PodTemplateOrStepsChanged detects if there is a change in either the pod template, or canary steps

func ReadyForPause added in v0.3.1

func ReadyForPause(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, allRSs []*appsv1.ReplicaSet) bool

func RemoveInjectedAntiAffinityRule added in v0.8.0

func RemoveInjectedAntiAffinityRule(affinity *corev1.Affinity, rollout v1alpha1.Rollout) *corev1.Affinity

func ResetCurrentStepIndex added in v0.2.0

func ResetCurrentStepIndex(rollout *v1alpha1.Rollout) *int32

ResetCurrentStepIndex resets the index back to zero unless there are no steps

func Revision

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

Revision returns the revision number of the input object.

func SyncEphemeralPodMetadata added in v0.10.2

func SyncEphemeralPodMetadata(metadata *metav1.ObjectMeta, existingPodMetadata, desiredPodMetadata *v1alpha1.PodTemplateMetadata) (*metav1.ObjectMeta, bool)

SyncEphemeralPodMetadata will inject the desired pod metadata to the ObjectMeta as well as remove previously injected pod metadata which is no longer desired. This function is careful to only modify metadata that we injected previously, and not affect other metadata which might be controlled by other controllers (e.g. istio pod sidecar injector)

func SyncReplicaSetEphemeralPodMetadata added in v0.10.2

func SyncReplicaSetEphemeralPodMetadata(rs *appsv1.ReplicaSet, podMetadata *v1alpha1.PodTemplateMetadata) (*appsv1.ReplicaSet, bool)

SyncReplicaSetEphemeralPodMetadata injects the desired pod metadata to the ReplicaSet, and removes previously injected metadata (based on the rollout.argoproj.io/ephemeral-metadata annotation) if it is no longer desired. A podMetadata value of nil indicates all ephemeral metadata should be removed completely.

func UseSetCanaryScale added in v0.10.0

func UseSetCanaryScale(rollout *v1alpha1.Rollout) *v1alpha1.SetCanaryScale

UseSetCanaryScale will return a SetCanaryScale if specified and should be used, returns nil otherwise. TrafficRouting is required to be set for SetCanaryScale to be applicable. If MatchTrafficWeight is set after a previous SetCanaryScale step, it will likewise be ignored.

Types

type ReplicaSetsByRevisionNumber added in v0.5.0

type ReplicaSetsByRevisionNumber []*appsv1.ReplicaSet

ReplicaSetsByRevisionNumber sorts a list of ReplicaSet by revision timestamp, using their creation timestamp as a tie breaker.

func (ReplicaSetsByRevisionNumber) Len added in v0.5.0

func (ReplicaSetsByRevisionNumber) Less added in v0.5.0

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

func (ReplicaSetsByRevisionNumber) Swap added in v0.5.0

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

Jump to

Keyboard shortcuts

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