Documentation
¶
Index ¶
- func DeploymentReplicas(owner Owner, existing *appsv1.Deployment) *int32
- func DesiredDeploymentReplicas(ctx context.Context, cl client.Reader, owner Owner, key client.ObjectKey) (*int32, error)
- func Ensure(ctx context.Context, cl client.Client, logger logr.Logger, owner Owner, ...) (op.Result, error)
- type Owner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeploymentReplicas ¶
func DeploymentReplicas(owner Owner, existing *appsv1.Deployment) *int32
DeploymentReplicas returns the spec.replicas to apply to a Deployment owned by owner. It can be used to determine initial replica count for the Deployment, when existing is nil.
func DesiredDeploymentReplicas ¶
func DesiredDeploymentReplicas( ctx context.Context, cl client.Reader, owner Owner, key client.ObjectKey, ) (*int32, error)
DesiredDeploymentReplicas returns the spec.replicas to apply to the Deployment owned by owner and identified by key. When owner is horizontally scaled, the Deployment is fetched from cluster and actual value is used. Once spec.replicas has been set through the scale subresource (i.e. by the HPA), nil is returned: spec.replicas must then be left out of the applied configuration, so that the HPA scale is never reverted. The scale took ownership of the field away from other field managers, so leaving it out does not remove it. The exception is a Deployment scaled to 0 (e.g. with kubectl scale): the HPA does not scale a target at 0 replicas, so it is scaled back up, see DeploymentReplicas.
func Ensure ¶
func Ensure( ctx context.Context, cl client.Client, logger logr.Logger, owner Owner, deploymentName string, ) (op.Result, error)
Ensure reconciles the HorizontalPodAutoscaler owned by owner that targets the Deployment named deploymentName. If owner has no horizontal scaling configured, any existing HPAs owned by owner are deleted.
Types ¶
type Owner ¶
type Owner interface {
client.Object
// GetReplicas returns the static replica count, or nil when it is not set.
// It is ignored when horizontal scaling is configured.
GetReplicas() *int32
// GetHorizontalScaling returns the horizontal scaling options, or nil when
// horizontal scaling is not configured.
GetHorizontalScaling() *commonv1alpha1.HorizontalScaling
}
Owner is an object that owns a Deployment which can be horizontally scaled by a HorizontalPodAutoscaler.