Skip to content

Commit

Permalink
refact: add operation field to log
Browse files Browse the repository at this point in the history
Signed-off-by: kaku <[email protected]>
  • Loading branch information
likakuli committed May 7, 2022
1 parent 53b0be3 commit f53ba7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions util/overridemanager/overridemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (o *overrideManagerImpl) ApplyOverridePolicies(rawObj *unstructured.Unstruc
func (o *overrideManagerImpl) applyClusterOverridePolicies(rawObj *unstructured.Unstructured, operation admissionv1.Operation) (*AppliedOverrides, error) {
cops, err := o.copLister.List(labels.Everything())
if err != nil {
klog.ErrorS(err, "Failed to list cluster override policies.")
klog.ErrorS(err, "Failed to list cluster override policies.", "resource", klog.KObj(rawObj), "operation", operation)
return nil, err
}

Expand All @@ -107,17 +107,17 @@ func (o *overrideManagerImpl) applyClusterOverridePolicies(rawObj *unstructured.

matchingPolicyOverriders := o.getOverridersFromOverridePolicies(items, rawObj, operation)
if len(matchingPolicyOverriders) == 0 {
klog.V(2).InfoS("No cluster override policy.", "resource", klog.KObj(rawObj))
klog.V(2).InfoS("No cluster override policy.", "resource", klog.KObj(rawObj), "operation", operation)
return nil, nil
}

appliedOverrides := &AppliedOverrides{}
for _, p := range matchingPolicyOverriders {
if err := applyPolicyOverriders(rawObj, p.overriders); err != nil {
klog.ErrorS(err, "Failed to apply cluster overriders.", "clusteroverridepolicy", p.name, "resource", klog.KObj(rawObj))
klog.ErrorS(err, "Failed to apply cluster overriders.", "clusteroverridepolicy", p.name, "resource", klog.KObj(rawObj), "operation", operation)
return nil, err
}
klog.V(2).InfoS("Applied cluster overriders.", "clusteroverridepolicy", p.name, "resource", klog.KObj(rawObj))
klog.V(2).InfoS("Applied cluster overriders.", "clusteroverridepolicy", p.name, "resource", klog.KObj(rawObj), "operation", operation)
appliedOverrides.Add(p.name, p.overriders)
}

Expand All @@ -127,7 +127,7 @@ func (o *overrideManagerImpl) applyClusterOverridePolicies(rawObj *unstructured.
func (o *overrideManagerImpl) applyOverridePolicies(rawObj *unstructured.Unstructured, operation admissionv1.Operation) (*AppliedOverrides, error) {
ops, err := o.opLister.List(labels.Everything())
if err != nil {
klog.ErrorS(err, "Failed to list override policies.", "namespace", rawObj.GetNamespace())
klog.ErrorS(err, "Failed to list override policies.", "namespace", rawObj.GetNamespace(), "resource", klog.KObj(rawObj), "operation", operation)
return nil, err
}

Expand All @@ -142,17 +142,17 @@ func (o *overrideManagerImpl) applyOverridePolicies(rawObj *unstructured.Unstruc

matchingPolicyOverriders := o.getOverridersFromOverridePolicies(items, rawObj, operation)
if len(matchingPolicyOverriders) == 0 {
klog.V(2).InfoS("No override policy.", "resource", klog.KObj(rawObj))
klog.V(2).InfoS("No override policy.", "resource", klog.KObj(rawObj), "operation", operation)
return nil, nil
}

appliedOverriders := &AppliedOverrides{}
for _, p := range matchingPolicyOverriders {
if err := applyPolicyOverriders(rawObj, p.overriders); err != nil {
klog.ErrorS(err, "Failed to apply overriders.", "overridepolicy", fmt.Sprintf("%s/%s", p.namespace, p.name), "resource", klog.KObj(rawObj))
klog.ErrorS(err, "Failed to apply overriders.", "overridepolicy", fmt.Sprintf("%s/%s", p.namespace, p.name), "resource", klog.KObj(rawObj), "operation", operation)
return nil, err
}
klog.V(2).InfoS("Applied overriders", "overridepolicy", fmt.Sprintf("%s/%s", p.namespace, p.name), "resource", klog.KObj(rawObj))
klog.V(2).InfoS("Applied overriders", "overridepolicy", fmt.Sprintf("%s/%s", p.namespace, p.name), "resource", klog.KObj(rawObj), "operation", operation)
appliedOverriders.Add(p.name, p.overriders)
}

Expand Down
8 changes: 4 additions & 4 deletions util/validatemanager/validatemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func NewValidateManager(cvpLister v1alpha1.ClusterValidatePolicyLister) Validate
func (m *validateManagerImpl) ApplyValidatePolicies(rawObj *unstructured.Unstructured, oldObj *unstructured.Unstructured, operation admissionv1.Operation) (*ValidateResult, error) {
cvps, err := m.cvpLister.List(labels.Everything())
if err != nil {
klog.ErrorS(err, "Failed to list validate policies.")
klog.ErrorS(err, "Failed to list validate policies.", "resource", klog.KObj(rawObj), "operation", operation)
return nil, err
}

if len(cvps) == 0 {
klog.V(2).InfoS("No validate policy.", "resource", klog.KObj(rawObj))
klog.V(2).InfoS("No validate policy.", "resource", klog.KObj(rawObj), "operation", operation)
return &ValidateResult{
Valid: true,
}, nil
Expand All @@ -56,10 +56,10 @@ func (m *validateManagerImpl) ApplyValidatePolicies(rawObj *unstructured.Unstruc
}
result, err := executeCue(rawObj, oldObj, rule.Cue)
if err != nil {
klog.ErrorS(err, "Failed to apply validate policy.", "validatepolicy", cvp.Name, "resource", klog.KObj(rawObj))
klog.ErrorS(err, "Failed to apply validate policy.", "validatepolicy", cvp.Name, "resource", klog.KObj(rawObj), "operation", operation)
return nil, err
}
klog.V(2).InfoS("Applied validate policy.", "validatepolicy", cvp.Name, "resource", klog.KObj(rawObj))
klog.V(2).InfoS("Applied validate policy.", "validatepolicy", cvp.Name, "resource", klog.KObj(rawObj), "operation", operation)
if !result.Valid {
return result, nil
}
Expand Down

0 comments on commit f53ba7c

Please sign in to comment.