Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Condition Messages for Better Clarity and Debugging #416

Closed
wants to merge 1 commit into from
Closed
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
Enhance Condition Messages for Better Clarity and Debugging
sankett45 authored Mar 18, 2025
commit ad33a09149397bc2a164f6564f4e763093e5421b
37 changes: 15 additions & 22 deletions pkg/controller/resourcegraphdefinition/controller_status.go
Original file line number Diff line number Diff line change
@@ -40,46 +40,39 @@ func NewStatusProcessor() *StatusProcessor {
state: v1alpha1.ResourceGraphDefinitionStateActive,
}
}

// setDefaultConditions sets the default conditions for an active resource graph definition
func (sp *StatusProcessor) setDefaultConditions() {
sp.conditions = []v1alpha1.Condition{
newReconcilerReadyCondition(metav1.ConditionTrue, ""),
newGraphVerifiedCondition(metav1.ConditionTrue, ""),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionTrue, ""),
newReconcilerReadyCondition(metav1.ConditionTrue, "ReconcilerAvailable"),
newGraphVerifiedCondition(metav1.ConditionTrue, "GraphValidated"),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionTrue, "CRDSynced"),
Comment on lines +45 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to duplicated the same message in both message and reason

}
}

// processGraphError handles graph-related errors
func (sp *StatusProcessor) processGraphError(err error) {
sp.conditions = []v1alpha1.Condition{
newGraphVerifiedCondition(metav1.ConditionFalse, err.Error()),
newReconcilerReadyCondition(metav1.ConditionUnknown, "Faulty Graph"),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionUnknown, "Faulty Graph"),
newGraphVerifiedCondition(metav1.ConditionFalse, "GraphValidationFailed"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to surface graph building errors to the users

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need to let err.Error into the condition message?

newReconcilerReadyCondition(metav1.ConditionUnknown, "GraphIssue"),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionUnknown, "GraphIssue"),
}
sp.state = v1alpha1.ResourceGraphDefinitionStateInactive
}

// processCRDError handles CRD-related errors
func (sp *StatusProcessor) processCRDError(err error) {
sp.conditions = []v1alpha1.Condition{
newGraphVerifiedCondition(metav1.ConditionTrue, ""),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionFalse, err.Error()),
newReconcilerReadyCondition(metav1.ConditionUnknown, "CRD not-synced"),
newGraphVerifiedCondition(metav1.ConditionTrue, "GraphValidated"),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionFalse, "CRDNotSynced"),
newReconcilerReadyCondition(metav1.ConditionUnknown, "CRDNotReady"),
}
sp.state = v1alpha1.ResourceGraphDefinitionStateInactive
}

// processMicroControllerError handles microcontroller-related errors
func (sp *StatusProcessor) processMicroControllerError(err error) {
sp.conditions = []v1alpha1.Condition{
newGraphVerifiedCondition(metav1.ConditionTrue, ""),
newCustomResourceDefinitionSyncedCondition(metav1.ConditionTrue, ""),
newReconcilerReadyCondition(metav1.ConditionFalse, err.Error()),
newGraphVerifiedCondition(metav1.ConditionTrue, "GraphValidated"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am shocked setting reason to "" worked before, this violates the built in type validation of conditions if you use the upstream open api.

newCustomResourceDefinitionSyncedCondition(metav1.ConditionTrue, "CRDSynced"),
newReconcilerReadyCondition(metav1.ConditionFalse, "ReconcilerFailure"),
}
sp.state = v1alpha1.ResourceGraphDefinitionStateInactive
}

// setResourceGraphDefinitionStatus calculates the ResourceGraphDefinition status and updates it
// in the API server.
func (r *ResourceGraphDefinitionReconciler) setResourceGraphDefinitionStatus(
@@ -172,13 +165,13 @@ func (r *ResourceGraphDefinitionReconciler) setUnmanaged(ctx context.Context, rg
}

func newReconcilerReadyCondition(status metav1.ConditionStatus, reason string) v1alpha1.Condition {
return v1alpha1.NewCondition(v1alpha1.ResourceGraphDefinitionConditionTypeReconcilerReady, status, reason, "micro controller is ready")
return v1alpha1.NewCondition("ReconcilerReady", status, reason, "Reconciler is available and processing updates")
}

func newGraphVerifiedCondition(status metav1.ConditionStatus, reason string) v1alpha1.Condition {
return v1alpha1.NewCondition(v1alpha1.ResourceGraphDefinitionConditionTypeGraphVerified, status, reason, "Directed Acyclic Graph is synced")
return v1alpha1.NewCondition("GraphVerified", status, reason, "Graph validation is complete and no issues were found")
}

func newCustomResourceDefinitionSyncedCondition(status metav1.ConditionStatus, reason string) v1alpha1.Condition {
return v1alpha1.NewCondition(v1alpha1.ResourceGraphDefinitionConditionTypeCustomResourceDefinitionSynced, status, reason, "Custom Resource Definition is synced")
return v1alpha1.NewCondition("CustomResourceDefinitionSynced", status, reason, "Custom Resource Definitions have been successfully applied and reconciled")
Comment on lines +168 to +176
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we replacing constants usage with literal strings?

}