mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
make taint.ToString() consistent with the reverse parsing logic
This commit is contained in:
parent
e12f96adc6
commit
23b7ae6041
@ -27,8 +27,14 @@ func (t *Taint) MatchTaint(taintToMatch Taint) bool {
|
|||||||
return t.Key == taintToMatch.Key && t.Effect == taintToMatch.Effect
|
return t.Key == taintToMatch.Key && t.Effect == taintToMatch.Effect
|
||||||
}
|
}
|
||||||
|
|
||||||
// taint.ToString() converts taint struct to string in format key=value:effect or key:effect.
|
// taint.ToString() converts taint struct to string in format '<key>=<value>:<effect>', '<key>=<value>:', '<key>:<effect>', or '<key>'.
|
||||||
func (t *Taint) ToString() string {
|
func (t *Taint) ToString() string {
|
||||||
|
if len(t.Effect) == 0 {
|
||||||
|
if len(t.Value) == 0 {
|
||||||
|
return fmt.Sprintf("%v", t.Key)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%v=%v:", t.Key, t.Value)
|
||||||
|
}
|
||||||
if len(t.Value) == 0 {
|
if len(t.Value) == 0 {
|
||||||
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
|
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,19 @@ func TestTaintToString(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedString: "foo:NoSchedule",
|
expectedString: "foo:NoSchedule",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
taint: &Taint{
|
||||||
|
Key: "foo",
|
||||||
|
},
|
||||||
|
expectedString: "foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
taint: &Taint{
|
||||||
|
Key: "foo",
|
||||||
|
Value: "bar",
|
||||||
|
},
|
||||||
|
expectedString: "foo=bar:",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
|
@ -24,8 +24,14 @@ func (t *Taint) MatchTaint(taintToMatch *Taint) bool {
|
|||||||
return t.Key == taintToMatch.Key && t.Effect == taintToMatch.Effect
|
return t.Key == taintToMatch.Key && t.Effect == taintToMatch.Effect
|
||||||
}
|
}
|
||||||
|
|
||||||
// taint.ToString() converts taint struct to string in format key=value:effect or key:effect.
|
// taint.ToString() converts taint struct to string in format '<key>=<value>:<effect>', '<key>=<value>:', '<key>:<effect>', or '<key>'.
|
||||||
func (t *Taint) ToString() string {
|
func (t *Taint) ToString() string {
|
||||||
|
if len(t.Effect) == 0 {
|
||||||
|
if len(t.Value) == 0 {
|
||||||
|
return fmt.Sprintf("%v", t.Key)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%v=%v:", t.Key, t.Value)
|
||||||
|
}
|
||||||
if len(t.Value) == 0 {
|
if len(t.Value) == 0 {
|
||||||
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
|
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,19 @@ func TestTaintToString(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedString: "foo:NoSchedule",
|
expectedString: "foo:NoSchedule",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
taint: &Taint{
|
||||||
|
Key: "foo",
|
||||||
|
},
|
||||||
|
expectedString: "foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
taint: &Taint{
|
||||||
|
Key: "foo",
|
||||||
|
Value: "bar",
|
||||||
|
},
|
||||||
|
expectedString: "foo=bar:",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user