Skip to content

Conversation

@lmiccini
Copy link
Contributor

No description provided.

Function verifies:
- Ready condition is True
- observedGeneration matches generation
Comment on lines +174 to +179
// Check status.conditions for Ready condition
conditions, found, err := unstructured.NestedSlice(owner.Object, "status", "conditions")
if err != nil || !found {
h.GetLogger().Info("No conditions found in owner status, waiting", "kind", ownerRef.Kind, "name", ownerRef.Name)
return false, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it be easier at some point to marshal/unmarshal the unstructured conditions and use existing functionality from the conditions pkg to validate their status, something like the following, instead of manual parsing the unstructured data?

diff --git a/modules/common/object/metadata.go b/modules/common/object/metadata.go
index fd2fc81..ee93ec3 100644
--- a/modules/common/object/metadata.go
+++ b/modules/common/object/metadata.go
@@ -23,6 +23,7 @@ import (
        "fmt"
        "slices"
 
+       "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
        "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
        "k8s.io/apimachinery/pkg/runtime"
        "k8s.io/apimachinery/pkg/types"
@@ -178,24 +179,22 @@ func IsOwnerServiceReady(
                return false, nil
        }
 
-       // Look for Ready condition with status=True
-       isReady := false
-       for _, c := range conditions {
-               condition, ok := c.(map[string]any)
-               if !ok {
-                       continue
-               }
-
-               condType, _, _ := unstructured.NestedString(condition, "type")
-               status, _, _ := unstructured.NestedString(condition, "status")
+       // Marshal unstructured conditions to condition.Conditions to use existing helper functions
+       conditionsJSON, err := json.Marshal(conditions)
+       if err != nil {
+               h.GetLogger().Info("Failed to marshal owner conditions, waiting", "kind", ownerRef.Kind, "name", ownerRef.Name)
+               return false, nil
+       }
 
-               if condType == "Ready" && status == "True" {
-                       isReady = true
-                       break
-               }
+       var ownerConditions condition.Conditions
+       err = json.Unmarshal(conditionsJSON, &ownerConditions)
+       if err != nil {
+               h.GetLogger().Info("Failed to unmarshal owner conditions, waiting", "kind", ownerRef.Kind, "name", ownerRef.Name)
+               return false, nil
        }
 
-       if !isReady {
+       // Use existing helper function to check if Ready condition is True
+       if !ownerConditions.IsTrue(condition.ReadyCondition) {
                h.GetLogger().Info("Owner service not ready, waiting", "kind", ownerRef.Kind, "name", ownerRef.Name)
                return false, nil
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants