@@ -34,7 +34,7 @@ import (
3434// ObjectTreeOptions defines the options for an ObjectTree.
3535type ObjectTreeOptions struct {
3636 // ShowOtherConditions is a list of comma separated kind or kind/name for which we should add the ShowObjectConditionsAnnotation
37- // to signal to the presentation layer to show all the conditions for the objects.
37+ // to signal to the presentation layer to show the conditions for the objects and also which filter to apply .
3838 ShowOtherConditions string
3939
4040 // ShowMachineSets instructs the discovery process to include machine sets in the ObjectTree.
@@ -74,11 +74,9 @@ type ObjectTree struct {
7474
7575// NewObjectTree creates a new object tree with the given root and options.
7676func NewObjectTree (root client.Object , options ObjectTreeOptions ) * ObjectTree {
77- // If it is requested to show all the conditions for the root, add
77+ // If it is requested to show conditions for the root, add
7878 // the ShowObjectConditionsAnnotation to signal this to the presentation layer.
79- if isObjDebug (root , options .ShowOtherConditions ) {
80- addAnnotation (root , ShowObjectConditionsAnnotation , "True" )
81- }
79+ addAnnotation (root , ShowObjectConditionsAnnotation , string (showConditions (root , options .ShowOtherConditions )))
8280
8381 return & ObjectTree {
8482 root : root ,
@@ -116,11 +114,9 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
116114 parentReady = GetReadyCondition (parent )
117115 }
118116
119- // If it is requested to show all the conditions for the object, add
117+ // If it is requested to show conditions for the object, add
120118 // the ShowObjectConditionsAnnotation to signal this to the presentation layer.
121- if isObjDebug (obj , od .options .ShowOtherConditions ) {
122- addAnnotation (obj , ShowObjectConditionsAnnotation , "True" )
123- }
119+ addAnnotation (obj , ShowObjectConditionsAnnotation , string (showConditions (obj , od .options .ShowOtherConditions )))
124120
125121 // If echo should be dropped from the ObjectTree, return if the object's ready condition is true, and it is the same it has of parent's object ready condition (it is an echo).
126122 // Note: the Echo option applies only for infrastructure machine or bootstrap config objects, and for those objects only Ready condition makes sense.
@@ -497,28 +493,36 @@ func updateV1Beta1GroupNode(groupObj client.Object, groupReady *clusterv1.Condit
497493 }
498494}
499495
500- func isObjDebug (obj client.Object , debugFilter string ) bool {
501- if debugFilter == "" {
502- return false
496+ func showConditions (obj client.Object , showOtherConditions string ) ConditionFilterType {
497+ if showOtherConditions == "" {
498+ return ShownNoConditions
503499 }
504- for _ , filter := range strings .Split (strings .ToLower (debugFilter ), "," ) {
505- filter = strings .TrimSpace (filter )
500+ for _ , filter := range strings .Split (showOtherConditions , "," ) {
506501 if filter == "" {
507502 continue
508503 }
509- if strings .EqualFold (filter , "all" ) {
510- return true
504+ if strings .EqualFold ("all" , strings .TrimSuffix (filter , ShowNonZeroConditionsSuffix )) {
505+ if strings .HasSuffix (filter , ShowNonZeroConditionsSuffix ) {
506+ return ShowNonZeroConditions
507+ }
508+ return ShowAllConditions
511509 }
512510 kn := strings .Split (filter , "/" )
513511 if len (kn ) == 2 {
514- if strings .ToLower (obj .GetObjectKind ().GroupVersionKind ().Kind ) == kn [0 ] && obj .GetName () == kn [1 ] {
515- return true
512+ if strings .EqualFold (obj .GetObjectKind ().GroupVersionKind ().Kind , kn [0 ]) && strings .EqualFold (obj .GetName (), strings .TrimSuffix (kn [1 ], ShowNonZeroConditionsSuffix )) {
513+ if strings .HasSuffix (kn [1 ], ShowNonZeroConditionsSuffix ) {
514+ return ShowNonZeroConditions
515+ }
516+ return ShowAllConditions
516517 }
517518 continue
518519 }
519- if strings .ToLower (obj .GetObjectKind ().GroupVersionKind ().Kind ) == kn [0 ] {
520- return true
520+ if strings .EqualFold (obj .GetObjectKind ().GroupVersionKind ().Kind , strings .TrimSuffix (kn [0 ], ShowNonZeroConditionsSuffix )) {
521+ if strings .HasSuffix (kn [0 ], ShowNonZeroConditionsSuffix ) {
522+ return ShowNonZeroConditions
523+ }
524+ return ShowAllConditions
521525 }
522526 }
523- return false
527+ return ShownNoConditions
524528}
0 commit comments