Remove or relocate deprecated status conditions

The references resolved condition was marked deprecated in v0.8 and has no known
callers. The secret resolution success condition is only used by the target
controller.

Signed-off-by: Nic Cope <negz@rk0n.org>
This commit is contained in:
Nic Cope 2020-09-09 15:11:45 -07:00
parent 5b15db1f2a
commit 1121c851c5
3 changed files with 34 additions and 94 deletions

View File

@ -34,13 +34,6 @@ const (
// TypeSynced resources are believed to be in sync with the
// Kubernetes resources that manage their lifecycle.
TypeSynced ConditionType = "Synced"
// TypeReferencesResolved resources' references are resolved
TypeReferencesResolved ConditionType = "ReferencesResolved"
// TypeSecretPropagated resources have had connection information
// propagated to their secret reference.
TypeSecretPropagated ConditionType = "ConnectionSecretPropagated"
)
// A ConditionReason represents the reason a resource is in a condition.
@ -60,18 +53,6 @@ const (
ReasonReconcileError ConditionReason = "ReconcileError"
)
// Reason references for a resource are or are not resolved.
const (
ReasonReferenceResolveSuccess ConditionReason = "ResolutionSuccess"
ReasonResolveReferencesBlocked ConditionReason = "ResolutionBlocked"
)
// Reason a referenced secret has or has not been propagated to.
const (
ReasonSecretPropagationSuccess ConditionReason = "PropagationSuccess"
ReasonSecretPropagationError ConditionReason = "PropagationError"
)
// A Condition that may apply to a resource.
type Condition struct {
// Type of this condition. At most one of each condition type may apply to
@ -269,57 +250,3 @@ func ReconcileError(err error) Condition {
Message: err.Error(),
}
}
// ReferenceResolutionSuccess returns a condition indicating that Crossplane
// successfully resolved the references used in the resource.
//
// Deprecated: Use ReconcileSuccess.
func ReferenceResolutionSuccess() Condition {
return Condition{
Type: TypeReferencesResolved,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: ReasonReferenceResolveSuccess,
}
}
// ReferenceResolutionBlocked returns a condition indicating that Crossplane is
// unable to resolve the references used in the resource. This could
// mean that one or more of referred resources do not yet exist, or are not yet
// Ready.
//
// Deprecated: Use ReconcileError.
func ReferenceResolutionBlocked(err error) Condition {
return Condition{
Type: TypeReferencesResolved,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: ReasonResolveReferencesBlocked,
Message: err.Error(),
}
}
// SecretPropagationSuccess returns a condition indicating that Crossplane
// successfully propagated connection data to the referenced secret.
func SecretPropagationSuccess() Condition {
return Condition{
Type: TypeSecretPropagated,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: ReasonSecretPropagationSuccess,
}
}
// SecretPropagationError returns a condition indicating that Crossplane was
// unable to propagate connection data to the referenced secret. This could be
// because it was unable to find the managed resource that owns the secret to be
// propagated.
func SecretPropagationError(err error) Condition {
return Condition{
Type: TypeSecretPropagated,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: ReasonSecretPropagationError,
Message: err.Error(),
}
}

View File

@ -22,6 +22,8 @@ import (
"time"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
@ -55,6 +57,18 @@ const (
reasonPropagatedSecret event.Reason = "PropagatedSecret"
)
// TypeSecretPropagated resources have had connection information
// propagated to their secret reference.
const TypeSecretPropagated v1alpha1.ConditionType = "ConnectionSecretPropagated"
// NOTE(negz): This reconciler exists to service KubernetesApplications, which
// are deprecated per https://github.com/crossplane/crossplane/issues/1595. It
// had a PropagationSuccess condition but did not use it. I elected not to fix
// this due to its impending removal.
// ReasonSecretPropagationError indicates that secret propagation failed.
const ReasonSecretPropagationError v1alpha1.ConditionReason = "PropagationError"
// ControllerName returns the recommended name for controllers that use this
// package to reconcile a particular kind of target.
func ControllerName(kind string) string {
@ -183,7 +197,7 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
if err := r.client.Get(ctx, meta.NamespacedNameOf(target.GetResourceReference()), managed); err != nil {
log.Debug("Cannot get referenced managed resource", "error", err, "requeue-after", time.Now().Add(aShortWait))
record.Event(target, event.Warning(reasonCannotGetManaged, err))
target.SetConditions(v1alpha1.SecretPropagationError(err))
target.SetConditions(SecretPropagationError(err))
return reconcile.Result{RequeueAfter: aShortWait}, errors.Wrap(r.client.Status().Update(ctx, target), errUpdateTarget)
}
@ -191,7 +205,7 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
// TODO(negz): Should we really consider this an error?
log.Debug("Managed resource is not yet bound to a resource claim", "requeue-after", time.Now().Add(aShortWait))
record.Event(target, event.Normal(reasonWaitingUntilBound, "Managed resource is not yet bound to a resource claim"))
target.SetConditions(v1alpha1.SecretPropagationError(errors.New(errManagedResourceIsNotBound)))
target.SetConditions(SecretPropagationError(errors.New(errManagedResourceIsNotBound)))
return reconcile.Result{RequeueAfter: aShortWait}, errors.Wrap(r.client.Status().Update(ctx, target), errUpdateTarget)
}
@ -200,7 +214,7 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
// resource, we try again after a short wait.
log.Debug("Cannot propagate connection secret", "error", err, "requeue-after", time.Now().Add(aShortWait))
record.Event(target, event.Warning(reasonCannotPropagateSecret, err))
target.SetConditions(v1alpha1.SecretPropagationError(err))
target.SetConditions(SecretPropagationError(err))
return reconcile.Result{RequeueAfter: aShortWait}, errors.Wrap(r.client.Status().Update(ctx, target), errUpdateTarget)
}
@ -209,3 +223,17 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
record.Event(target, event.Normal(reasonPropagatedSecret, "Successfully propagated connection secret"))
return reconcile.Result{Requeue: false}, nil
}
// SecretPropagationError returns a condition indicating that Crossplane was
// unable to propagate connection data to the referenced secret. This could be
// because it was unable to find the managed resource that owns the secret to be
// propagated.
func SecretPropagationError(err error) v1alpha1.Condition {
return v1alpha1.Condition{
Type: TypeSecretPropagated,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: ReasonSecretPropagationError,
Message: err.Error(),
}
}

View File

@ -232,7 +232,7 @@ func TestReconciler(t *testing.T) {
Name: mgname,
})
want.SetWriteConnectionSecretToReference(&v1alpha1.LocalSecretReference{Name: tgcsname})
want.SetConditions(v1alpha1.SecretPropagationError(errBoom))
want.SetConditions(SecretPropagationError(errBoom))
if diff := cmp.Diff(want, got, test.EquateConditions()); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
}
@ -293,7 +293,7 @@ func TestReconciler(t *testing.T) {
Name: mgname,
})
want.SetWriteConnectionSecretToReference(&v1alpha1.LocalSecretReference{Name: tgcsname})
want.SetConditions(v1alpha1.SecretPropagationError(errors.New(errManagedResourceIsNotBound)))
want.SetConditions(SecretPropagationError(errors.New(errManagedResourceIsNotBound)))
if diff := cmp.Diff(want, got, test.EquateConditions()); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
}
@ -354,7 +354,7 @@ func TestReconciler(t *testing.T) {
Name: mgname,
})
want.SetWriteConnectionSecretToReference(&v1alpha1.LocalSecretReference{Name: tgcsname})
want.SetConditions(v1alpha1.SecretPropagationError(errBoom))
want.SetConditions(SecretPropagationError(errBoom))
if diff := cmp.Diff(want, got, test.EquateConditions()); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
}
@ -413,21 +413,6 @@ func TestReconciler(t *testing.T) {
return errUnexpected
}
},
MockStatusUpdate: test.NewMockStatusUpdateFn(nil, func(got runtime.Object) error {
want := &fake.Target{}
want.SetName(tgname)
want.SetNamespace(ns)
want.SetUID(tguid)
want.SetResourceReference(&corev1.ObjectReference{
Name: mgname,
})
want.SetWriteConnectionSecretToReference(&v1alpha1.LocalSecretReference{Name: tgcsname})
want.SetConditions(v1alpha1.SecretPropagationSuccess())
if diff := cmp.Diff(want, got, test.EquateConditions()); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
}
return nil
}),
},
Scheme: fake.SchemeWith(&fake.Target{}, &fake.Managed{}),
},