mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: namespace label matching for Namespace (#7837)
* Feat: namespaceLabel matching for ns Signed-off-by: ShutingZhao <shuting@nirmata.com> * Fix: update kuttl tests Signed-off-by: ShutingZhao <shuting@nirmata.com> --------- Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
5a8caaf4fe
commit
537612b609
7 changed files with 40 additions and 9 deletions
|
@ -115,8 +115,10 @@ func doesResourceMatchConditionBlock(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if conditionBlock.NamespaceSelector != nil && resource.GetKind() != "Namespace" &&
|
if conditionBlock.NamespaceSelector != nil {
|
||||||
(resource.GetKind() != "" || slices.Contains(conditionBlock.Kinds, "*") && wildcard.Match("*", resource.GetKind())) {
|
if resource.GetKind() == "Namespace" {
|
||||||
|
errs = append(errs, fmt.Errorf("namespace selector is not applicable for namespace resource"))
|
||||||
|
} else if resource.GetKind() != "" || slices.Contains(conditionBlock.Kinds, "*") && wildcard.Match("*", resource.GetKind()) {
|
||||||
hasPassed, err := matchutils.CheckSelector(conditionBlock.NamespaceSelector, namespaceLabels)
|
hasPassed, err := matchutils.CheckSelector(conditionBlock.NamespaceSelector, namespaceLabels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to parse namespace selector: %v", err))
|
errs = append(errs, fmt.Errorf("failed to parse namespace selector: %v", err))
|
||||||
|
@ -126,6 +128,7 @@ func doesResourceMatchConditionBlock(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(conditionBlock.Operations) > 0 {
|
if len(conditionBlock.Operations) > 0 {
|
||||||
if !slices.Contains(conditionBlock.Operations, operation) {
|
if !slices.Contains(conditionBlock.Operations, operation) {
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: pod-reader-fake
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- pods
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- list
|
||||||
|
- watch
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Specifying the kind as `TestStep` performs certain behaviors like this delete operation.
|
||||||
|
apiVersion: kuttl.dev/v1beta1
|
||||||
|
kind: TestStep
|
||||||
|
delete:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
name: test-wildcard
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Specifying the kind as `TestStep` performs certain behaviors like this delete operation.
|
||||||
|
apiVersion: kuttl.dev/v1beta1
|
||||||
|
kind: TestStep
|
||||||
|
delete:
|
||||||
|
- apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
name: pod-reader-fake
|
|
@ -10,3 +10,4 @@ The pod `test-validate/nginx-block` is blocked, and the pod `default/nginx-pass`
|
||||||
## Reference Issue(s)
|
## Reference Issue(s)
|
||||||
|
|
||||||
https://github.com/kyverno/kyverno/issues/6015
|
https://github.com/kyverno/kyverno/issues/6015
|
||||||
|
https://github.com/kyverno/kyverno/issues/7771
|
Loading…
Add table
Reference in a new issue