Skip to content

Commit

Permalink
Merge pull request crossplane#1921 from hasheddan/unknown-health
Browse files Browse the repository at this point in the history
Add Unknown health condition for package revisions
  • Loading branch information
hasheddan authored Nov 3, 2020
2 parents 393b6fe + d00d843 commit a66ef3f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
21 changes: 16 additions & 5 deletions apis/pkg/v1alpha1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const (

// Reasons a package is or is not installed.
const (
ReasonUnpacking runtimev1alpha1.ConditionReason = "UnpackingPackage"
ReasonInactive runtimev1alpha1.ConditionReason = "InactivePackageRevision"
ReasonActive runtimev1alpha1.ConditionReason = "ActivePackageRevision"
ReasonUnhealthy runtimev1alpha1.ConditionReason = "UnhealthyPackageRevision"
ReasonHealthy runtimev1alpha1.ConditionReason = "HealthyPackageRevision"
ReasonUnpacking runtimev1alpha1.ConditionReason = "UnpackingPackage"
ReasonInactive runtimev1alpha1.ConditionReason = "InactivePackageRevision"
ReasonActive runtimev1alpha1.ConditionReason = "ActivePackageRevision"
ReasonUnhealthy runtimev1alpha1.ConditionReason = "UnhealthyPackageRevision"
ReasonHealthy runtimev1alpha1.ConditionReason = "HealthyPackageRevision"
ReasonUnknownHealth runtimev1alpha1.ConditionReason = "UnknownPackageRevisionHealth"
)

// Unpacking indicates that the package manager is waiting for a package
Expand Down Expand Up @@ -93,3 +94,13 @@ func Healthy() runtimev1alpha1.Condition {
Reason: ReasonHealthy,
}
}

// UnknownHealth indicates that the health of the current revision is unknown.
func UnknownHealth() runtimev1alpha1.Condition {
return runtimev1alpha1.Condition{
Type: TypeHealthy,
Status: corev1.ConditionUnknown,
LastTransitionTime: metav1.Now(),
Reason: ReasonUnknownHealth,
}
}
7 changes: 6 additions & 1 deletion pkg/controller/pkg/manager/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const (
errUpdateStatus = "cannot update package status"
errUpdateInactivePackageRevision = "cannot update inactive package revision"

errUnhealthyPackageRevision = "current package revision is unhealthy"
errUnhealthyPackageRevision = "current package revision is unhealthy"
errUnknownPackageRevisionHealth = "current package revision health is unknown"
)

// Event reasons.
Expand Down Expand Up @@ -325,6 +326,10 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
p.SetConditions(v1alpha1.Unhealthy())
r.record.Event(p, event.Warning(reasonInstall, errors.New(errUnhealthyPackageRevision)))
}
if pr.GetCondition(v1alpha1.TypeHealthy).Status == corev1.ConditionUnknown {
p.SetConditions(v1alpha1.UnknownHealth())
r.record.Event(p, event.Warning(reasonInstall, errors.New(errUnknownPackageRevisionHealth)))
}

// Create the non-existent package revision.
pr.SetName(revisionName)
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/pkg/manager/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestReconcile(t *testing.T) {
want.SetGroupVersionKind(v1alpha1.ConfigurationGroupVersionKind)
want.SetCurrentRevision("test-1234567")
want.SetActivationPolicy(&v1alpha1.AutomaticActivation)
want.SetConditions(v1alpha1.UnknownHealth())
want.SetConditions(v1alpha1.Active())
if diff := cmp.Diff(want, o); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
Expand Down Expand Up @@ -198,6 +199,7 @@ func TestReconcile(t *testing.T) {
want.SetCurrentRevision("test-1234567")
want.SetActivationPolicy(&v1alpha1.AutomaticActivation)
want.SetPackagePullPolicy(&pullAlways)
want.SetConditions(v1alpha1.UnknownHealth())
want.SetConditions(v1alpha1.Active())
if diff := cmp.Diff(want, o); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
Expand Down Expand Up @@ -244,6 +246,7 @@ func TestReconcile(t *testing.T) {
want.SetGroupVersionKind(v1alpha1.ConfigurationGroupVersionKind)
want.SetActivationPolicy(&v1alpha1.ManualActivation)
want.SetCurrentRevision("test-1234567")
want.SetConditions(v1alpha1.UnknownHealth())
want.SetConditions(v1alpha1.Inactive())
if diff := cmp.Diff(want, o); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
Expand Down

0 comments on commit a66ef3f

Please sign in to comment.