-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: only list container stats which are created by cri
Signed-off-by: YaoZengzeng <[email protected]>
- Loading branch information
1 parent
7addef1
commit d1262fc
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package utils | ||
|
||
// Move the public utility methods which are used by both v1alpha1 | ||
// and v1alpha2 here to reduce the code duplication. | ||
|
||
// matchLabelSelector returns true if labels cover selector. | ||
func matchLabelSelector(selector, labels map[string]string) bool { | ||
for k, v := range selector { | ||
if val, ok := labels[k]; ok { | ||
if v != val { | ||
return false | ||
} | ||
} else { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_matchLabelSelector(t *testing.T) { | ||
type args struct { | ||
selector map[string]string | ||
labels map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "Normal Test", | ||
args: args{ | ||
selector: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
labels: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Uncovered Test", | ||
args: args{ | ||
selector: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
labels: map[string]string{ | ||
"a2": "b2", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Unmatched Test", | ||
args: args{ | ||
selector: map[string]string{ | ||
"a1": "b0", | ||
"a2": "b2", | ||
}, | ||
labels: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := matchLabelSelector(tt.args.selector, tt.args.labels); got != tt.want { | ||
t.Errorf("matchLabelSelector() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters