Conditions/operator config#1011
Conversation
|
Thanks for your PR,
To skip the vendors CIs, Maintainers can use one of:
|
Summary of ChangesHello @SchSeba, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the user experience and automation capabilities of the SR-IOV Network Operator by adopting standard Kubernetes conditions for its Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant improvement by adding standard Kubernetes conditions to the SriovOperatorConfig CRD, which greatly enhances observability. The addition of a dedicated pkg/status for handling status updates with retries and event emission is a solid architectural choice. The new tests for conditions are comprehensive. However, I've identified a few issues: a potential regression due to the removal of policy sorting logic, a minor bug in how object generation is used for conditions, and a design flaw in the new status patcher that could lead to incorrect event generation under race conditions. Please see my detailed comments for suggestions on how to address these points.
I am having trouble creating individual review comments. Click here to see my feedback.
controllers/sriovoperatorconfig_controller.go (118-129)
The logic for fetching and sorting SriovNetworkNodePolicyList has been removed. The comment on this code indicates that sorting is crucial to ensure a stable node affinity for the sriov-device-plugin and to prevent unnecessary pod recreations. Removing this logic without a replacement could introduce the instability that it was designed to prevent. Was this logic moved elsewhere, or is it no longer needed? If it's still required, it should be restored or its new location clarified.
controllers/sriovoperatorconfig_controller.go (608-621)
The ObservedGeneration for the conditions is being set using config.GetGeneration(). However, config is the object fetched at the beginning of the Reconcile loop. To avoid race conditions and ensure the generation matches the object version being updated, you should use the generation from updatedObj, which is fetched right before the conditions are updated.
// Operator components are having issues
r.StatusPatcher.SetCondition(&newConditions, sriovnetworkv1.ConditionReady, metav1.ConditionFalse,
sriovnetworkv1.ReasonOperatorComponentsNotHealthy, fmt.Sprintf("Operator reconciliation failed: %v", reconcileErr),
updatedObj.GetGeneration())
r.StatusPatcher.SetCondition(&newConditions, sriovnetworkv1.ConditionDegraded, metav1.ConditionTrue,
sriovnetworkv1.ReasonOperatorComponentsNotHealthy, fmt.Sprintf("Operator components failed to reconcile: %v", reconcileErr),
updatedObj.GetGeneration())
} else {
// Operator is ready and healthy
r.StatusPatcher.SetCondition(&newConditions, sriovnetworkv1.ConditionReady, metav1.ConditionTrue,
sriovnetworkv1.ReasonOperatorReady, "Operator components are running and healthy",
updatedObj.GetGeneration())
r.StatusPatcher.SetCondition(&newConditions, sriovnetworkv1.ConditionDegraded, metav1.ConditionFalse,
sriovnetworkv1.ReasonNotDegraded, "Operator is functioning correctly",
updatedObj.GetGeneration())pkg/status/patcher.go (146)
The UpdateStatusWithEvents function's design has a flaw regarding event generation during retries. The oldConditions parameter is captured before the retry loop. If a conflict occurs and the object is refreshed, oldConditions becomes stale. When DetectTransitions is called after a successful patch on a retry, it compares the stale oldConditions with newConditions, which can lead to incorrect or missed events.
To fix this, the oldConditions should be determined within the retry loop from the object just before it's modified. I suggest changing the signature of UpdateStatusWithEvents to have the updateFunc return the old conditions.
For example, you could change the signature to:
UpdateStatusWithEvents(ctx context.Context, obj client.Object, newConditions []metav1.Condition, updateFunc func() (oldConditions []metav1.Condition, err error)) error
And then inside the function:
// ... in for loop
oldConditions, err := updateFunc()
if err != nil {
return fmt.Errorf("failed to apply status update: %w", err)
}
// ... after successful patch
transitions := DetectTransitions(oldConditions, newConditions)
// ...The call site in sriovoperatorconfig_controller.go would then be adjusted to:
err := r.StatusPatcher.UpdateStatusWithEvents(ctx, updatedObj, newConditions, func() ([]metav1.Condition, error) {
old := updatedObj.Status.Conditions
updatedObj.Status.Conditions = newConditions
return old, nil
})This ensures that for each patch attempt, you are comparing against the correct "old" state for event generation.
Signed-off-by: Sebastian Sch <sebassch@gmail.com>
Add foundational condition support for SR-IOV Network Operator CRDs: - Define standard condition types (Ready, Progressing, Degraded) - Define drain-specific condition types (DrainProgressing, DrainDegraded, DrainComplete) - Add DrainState enum for tracking drain operation states - Add common condition reasons for various states - Add NetworkStatus type with Conditions field for network CRDs - Add ConditionsEqual helper for comparing conditions ignoring LastTransitionTime - Add SetConfigurationConditions and SetDrainConditions methods - Add comprehensive unit tests for condition handling This follows the Kubernetes API conventions for status conditions and provides the foundation for observability improvements across all SR-IOV CRDs. Signed-off-by: Sebastian Sch <sebassch@gmail.com>
6b1a6da to
69affb1
Compare
Pull Request Test Coverage Report for Build 22136514631Details
💛 - Coveralls |
Add a new status package with utilities for managing CRD status updates: Patcher (patcher.go): - Provides retry logic for status updates with conflict handling - Supports both Update and Patch operations - Includes UpdateStatusWithEvents for automatic event emission - Embeds condition management methods for convenience - Uses interface for easy mocking in tests Transitions (transitions.go): - DetectTransitions compares old and new conditions - Returns structured Transition objects for each change - EventType() method returns appropriate event type (Normal/Warning) - EventReason() generates suitable event reason strings - Supports Added, Changed, Removed, and Unchanged transitions Tests: - Comprehensive unit tests for patcher operations - Tests for transition detection logic - Tests for event type and reason generation This package provides a reusable foundation for consistent status handling across all controllers in the operator. Signed-off-by: Sebastian Sch <sebassch@gmail.com>
Update SriovOperatorConfig status type to include Kubernetes conditions: - Add Conditions field to SriovOperatorConfigStatus - Add kubebuilder printcolumns for Ready, Progressing, Degraded status Conditions follow Kubernetes conventions with patchMergeKey and listType annotations for proper strategic merge patch support. Signed-off-by: Sebastian Sch <sebassch@gmail.com>
Integrate condition management into SriovOperatorConfig controller: Controller Changes: - Add StatusPatcher dependency for condition management - Add updateConditions method to set Ready/Degraded conditions - Set Ready=True, Degraded=False on successful reconciliation - Set Ready=False, Degraded=True on reconciliation errors - Update conditions on webhook sync failures - Update conditions on config daemon sync failures - Update conditions on plugin daemon sync failures - Include error details in condition messages Tests: - Add test for Ready=True when operator reconciles successfully - Add test for Ready=False, Degraded=True on errors - Add test for observedGeneration consistency - Add test for condition presence validation - Add test for error message inclusion in conditions - Add dedicated test suite for degraded conditions Signed-off-by: Sebastian Sch <sebassch@gmail.com>
Update the kubernetes-conditions-integration.md design document to reflect the actual implementation details: - Add SriovNetworkNodePolicy as a supported CRD - Add drain-specific conditions (DrainProgressing, DrainDegraded, DrainComplete) - Document all condition reasons with actual constant names - Add NetworkStatus shared type used by network CRDs - Document pkg/status package with Patcher interface and transition detection - Add ConditionsEqual helper function documentation - Update API extension examples with actual struct definitions - Add matchedNodeCount/readyNodeCount to Policy and PoolConfig status - Add kubectl output examples showing new columns - Update implementation commits list - Mark document status as 'implemented' Signed-off-by: Sebastian Sch <sebassch@gmail.com>
- Remove SriovNetworkNodeState tests from conditions_test.go - Add findCondition helper to suite_test.go - Regenerate CRDs and deepcopy for SriovOperatorConfig type Signed-off-by: Sebastian Sch <sebassch@gmail.com>
Add cleanup logic to remove any existing SriovOperatorConfig before creating a new one in the SriovNetworkNodePolicy controller tests. This fixes a flaky test failure where the SriovOperatorConfig controller tests may leave a 'default' config behind that conflicts with the SriovNetworkNodePolicy tests when they run with different random seeds. The cleanup logic mirrors what's already in sriovoperatorconfig_controller_test.go: - Remove finalizers if present - Delete the object if not already deleted - Wait for the object to be fully gone before creating a new one Signed-off-by: Sebastian Sch <sebassch@gmail.com>
69affb1 to
3bf3c02
Compare
No description provided.