Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions pkg/apis/autoscaling/v1alpha1/pa_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var podCondSet = apis.NewLivingConditionSet(
PodAutoscalerConditionActive,
PodAutoscalerConditionBootstrap,
)

func (pa *PodAutoscaler) GetGroupVersionKind() schema.GroupVersionKind {
Expand Down Expand Up @@ -138,6 +138,12 @@ func (pas *PodAutoscalerStatus) IsReady() bool {
return podCondSet.Manage(pas.duck()).IsHappy()
}

// HasFailed returns true if the Ready condition is false.
func (pas *PodAutoscalerStatus) HasFailed() bool {
cond := pas.GetCondition(PodAutoscalerConditionReady)
return cond != nil && cond.Status == corev1.ConditionFalse
}

// IsActivating returns true if the pod autoscaler is Activating if it is neither
// Active nor Inactive
func (pas *PodAutoscalerStatus) IsActivating() bool {
Expand All @@ -151,6 +157,12 @@ func (pas *PodAutoscalerStatus) IsInactive() bool {
return cond != nil && cond.Status == corev1.ConditionFalse
}

// IsActive returns true if the pod autoscaler is Active.
func (pas *PodAutoscalerStatus) IsActive() bool {
Comment thread
hohaichi marked this conversation as resolved.
cond := pas.GetCondition(PodAutoscalerConditionActive)
return cond != nil && cond.Status == corev1.ConditionTrue
}

// GetCondition gets the condition `t`.
func (pas *PodAutoscalerStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return podCondSet.Manage(pas.duck()).GetCondition(t)
Expand Down Expand Up @@ -179,17 +191,39 @@ func (pas *PodAutoscalerStatus) MarkInactive(reason, message string) {
// MarkResourceNotOwned changes the "Active" condition to false to reflect that the
// resource of the given kind and name has already been created, and we do not own it.
func (pas *PodAutoscalerStatus) MarkResourceNotOwned(kind, name string) {
pas.MarkInactive("NotOwned",
podCondSet.Manage(pas).MarkFalse(PodAutoscalerConditionBootstrap, "NotOwned",
fmt.Sprintf("There is an existing %s %q that we do not own.", kind, name))
}

// MarkResourceFailedCreation changes the "Active" condition to false to reflect that a
// critical resource of the given kind and name was unable to be created.
func (pas *PodAutoscalerStatus) MarkResourceFailedCreation(kind, name string) {
pas.MarkInactive("FailedCreate",
podCondSet.Manage(pas).MarkFalse(PodAutoscalerConditionBootstrap, "FailedCreate",
fmt.Sprintf("Failed to create %s %q.", kind, name))
}

// MarkContainerExiting changes the "Bootstrap" condition to false and records the exit code.
func (pas *PodAutoscalerStatus) MarkContainerExiting(exitCode int32, message string) {
exitCodeString := fmt.Sprintf("ExitCode%d", exitCode)
message = fmt.Sprintf("Container failed with: %s", message)
Comment thread
hohaichi marked this conversation as resolved.
podCondSet.Manage(pas).MarkFalse(PodAutoscalerConditionBootstrap, exitCodeString, message)
}

// MarkImagePullError changes the "Bootstrap" condition to false.
func (pas *PodAutoscalerStatus) MarkImagePullError(reason, message string) {
podCondSet.Manage(pas).MarkFalse(PodAutoscalerConditionBootstrap, reason, message)
}

// MarkPodUnscheduled changes the "Bootstrap" condition to false and records reason and message.
func (pas *PodAutoscalerStatus) MarkPodUnscheduled(reason, message string) {
podCondSet.Manage(pas).MarkFalse(PodAutoscalerConditionBootstrap, reason, message)
}

// MarkBootstrapSuccessful changes the "Bootstrap" condition to true.
func (pas *PodAutoscalerStatus) MarkBootstrapSuccessful() {
podCondSet.Manage(pas).MarkTrue(PodAutoscalerConditionBootstrap)
}

// CanScaleToZero checks whether the pod autoscaler has been in an inactive state
// for at least the specified grace period.
func (pas *PodAutoscalerStatus) CanScaleToZero(gracePeriod time.Duration) bool {
Expand Down
Loading