Skip to content

Commit

Permalink
fix: default value for skipBackgroundRequests
Browse files Browse the repository at this point in the history
Signed-off-by: ShutingZhao <[email protected]>
  • Loading branch information
realshuting committed Jun 28, 2024
1 parent 52ec560 commit 18114c4
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
9 changes: 8 additions & 1 deletion api/kyverno/v1/rule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type Rule struct {
// generate and mutateExisting rules to those requests.
// +kubebuilder:default=true
// +kubebuilder:validation:Optional
SkipBackgroundRequests bool `json:"skipBackgroundRequests,omitempty" yaml:"skipBackgroundRequests,omitempty"`
SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty" yaml:"skipBackgroundRequests,omitempty"`
}

// HasMutate checks for mutate rule
Expand Down Expand Up @@ -174,6 +174,13 @@ func (r *Rule) IsPodSecurity() bool {
return r.Validation.PodSecurity != nil
}

func (r *Rule) SkipBackgroundRequestsEnabled() bool {
if r.SkipBackgroundRequests == nil {
return true
}
return *r.SkipBackgroundRequests
}

func (r *Rule) GetTypeAndSyncAndOrphanDownstream() (_ GenerateType, sync bool, orphanDownstream bool) {
if !r.HasGenerate() {
return
Expand Down
9 changes: 8 additions & 1 deletion api/kyverno/v2beta1/rule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Rule struct {
// generate and mutateExisting rules to those requests.
// +kubebuilder:default=true
// +kubebuilder:validation:Optional
SkipBackgroundRequests bool `json:"skipBackgroundRequests,omitempty" yaml:"skipBackgroundRequests,omitempty"`
SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty" yaml:"skipBackgroundRequests,omitempty"`
}

// HasMutate checks for mutate rule
Expand Down Expand Up @@ -137,6 +137,13 @@ func (r *Rule) HasGenerate() bool {
return !datautils.DeepEqual(r.Generation, kyvernov1.Generation{})
}

func (r *Rule) SkipBackgroundRequestsEnabled() bool {
if r.SkipBackgroundRequests == nil {
return true
}
return *r.SkipBackgroundRequests
}

func (r *Rule) GetGenerateTypeAndSync() (_ kyvernov1.GenerateType, sync bool, orphanDownstream bool) {
if !r.HasGenerate() {
return
Expand Down
1 change: 1 addition & 0 deletions pkg/policy/policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func (pc *policyController) handleUpdateRequest(ur *kyvernov2.UpdateRequest, tri
return true, nil
}

fmt.Println("=====> engineResponse.PolicyResponse.Rules: ", len(engineResponse.PolicyResponse.Rules))
for _, ruleResponse := range engineResponse.PolicyResponse.Rules {
if ruleResponse.Status() != engineapi.RuleStatusPass {
pc.log.V(4).Info("skip creating URs on policy update", "policy", policy.GetName(), "rule", ruleName, "rule.Status", ruleResponse.Status())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
- default
- kube-public
- kyverno
- local-path-storage
generate:
apiVersion: v1
data:
Expand All @@ -33,3 +34,119 @@ spec:
kinds:
- Namespace
name: k-kafka-address
- exclude:
any:
- resources:
namespaces:
- kube-system
- default
- kube-public
- kyverno
- local-path-storage
generate:
apiVersion: v1
data:
data:
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181
kind: ConfigMap
metadata:
labels:
somekey: somevalue
kind: ConfigMap
name: zk-kafka-address-2
namespace: '{{request.object.metadata.name}}'
synchronize: true
match:
any:
- resources:
kinds:
- Namespace
name: k-kafka-address-2
- exclude:
any:
- resources:
namespaces:
- kube-system
- default
- kube-public
- kyverno
- local-path-storage
generate:
apiVersion: v1
data:
data:
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181
kind: ConfigMap
metadata:
labels:
somekey: somevalue
kind: ConfigMap
name: zk-kafka-address-3
namespace: '{{request.object.metadata.name}}'
synchronize: true
match:
any:
- resources:
kinds:
- Namespace
name: k-kafka-address-3
# - exclude:
# any:
# - resources:
# namespaces:
# - kube-system
# - default
# - kube-public
# - kyverno
# - local-path-storage
# generate:
# apiVersion: v1
# data:
# data:
# KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
# ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181
# kind: ConfigMap
# metadata:
# labels:
# somekey: somevalue
# kind: ConfigMap
# name: zk-kafka-address-4
# namespace: '{{request.object.metadata.name}}'
# synchronize: true
# match:
# any:
# - resources:
# kinds:
# - Namespace
# name: k-kafka-address-4
# - exclude:
# any:
# - resources:
# namespaces:
# - kube-system
# - default
# - kube-public
# - kyverno
# - local-path-storage
# generate:
# apiVersion: v1
# data:
# data:
# KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
# ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181
# kind: ConfigMap
# metadata:
# labels:
# somekey: somevalue
# kind: ConfigMap
# name: zk-kafka-address-5
# namespace: '{{request.object.metadata.name}}'
# synchronize: true
# match:
# any:
# - resources:
# kinds:
# - Namespace
# name: k-kafka-address-5

0 comments on commit 18114c4

Please sign in to comment.