11package validator
22
33import (
4- "fmt"
54 "log"
65 "regexp"
76 "strconv"
@@ -11,7 +10,6 @@ import (
1110
1211func evaluateRule (expression types.MatchExpression , nodeLabels map [string ]string ) bool {
1312 // Get the value of the label from the node
14- fmt .Printf ("Checking expression %s against node labels %s" , expression , nodeLabels )
1513 nodeVal , ok := nodeLabels [expression .Key ]
1614
1715 switch expression .Op {
@@ -66,7 +64,7 @@ func evaluateRule(expression types.MatchExpression, nodeLabels map[string]string
6664 if err != nil {
6765 // A malformed regex in the spec is a spec error, not a node error.
6866 // Log it and treat it as a non-match for this pattern.
69- log .Printf ("WARN: Invalid regexp in compatibility spec: '%s'. Error: %v" , pattern , err )
67+ log .Printf ("WARN: Invalid regexp in compatibility spec: '%s'. Error: %v\n " , pattern , err )
7068 continue
7169 }
7270 // Found a regex match.
@@ -77,7 +75,7 @@ func evaluateRule(expression types.MatchExpression, nodeLabels map[string]string
7775 // No patterns matched.
7876 return false
7977
80- case types .MatchOpGt , types .MatchOpLt :
78+ case types .MatchOpGt , types .MatchOpLt , types . MatchOpGte , types . MatchOpLte :
8179 // Rule matches if the key exists AND its integer value is > or < the spec's value.
8280 if ! ok {
8381
@@ -93,22 +91,28 @@ func evaluateRule(expression types.MatchExpression, nodeLabels map[string]string
9391 // Convert node value to an integer.
9492 nodeInt , err := strconv .Atoi (nodeVal )
9593 if err != nil {
96- log .Printf ("WARN: Could not convert node label value '%s' to int for Gt/Lt comparison. Key: %s" , nodeVal , expression .Key )
94+ log .Printf ("WARN: Could not convert node label value '%s' to int for Gt/Lt/Gte/Lte comparison. Key: %s" , nodeVal , expression .Key )
9795 return false
9896 }
9997
10098 // Convert spec value to an integer.
10199 specInt , err := strconv .Atoi (specValStr )
102100 if err != nil {
103- log .Printf ("WARN: Could not convert spec value '%s' to int for Gt/Lt comparison. Key: %s" , specValStr , expression .Key )
101+ log .Printf ("WARN: Could not convert spec value '%s' to int for Gt/Lt/Gte/Lte comparison. Key: %s" , specValStr , expression .Key )
104102 return false
105103 }
106104
107105 // Perform the correct comparison.
106+ if expression .Op == types .MatchOpGte {
107+ return nodeInt >= specInt
108+ }
108109 if expression .Op == types .MatchOpGt {
109110 return nodeInt > specInt
110111 }
111- // If not Gt, it must be Lt.
112+ if expression .Op == types .MatchOpLte {
113+ return nodeInt <= specInt
114+ }
115+ // Last comparison, Lte
112116 return nodeInt < specInt
113117
114118 default :
0 commit comments