mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
5b8ab3842b
* initial commit * variable substitution * update tests * update test * refactor engine packages for validate & generate * update vendor * update toml * support variable substitution in overlay mutation * missing update * fix indentation in logs * store context values as single JSON document using merge patches. * remove duplicate functions * fix message string * Handle processing of policies in background (#569) * remove condition check while generating mutation patch as conditions are verified in the first iteration * initial commit * background policy validation * correct message * skip non-background policy process for add/update * fix order to correct policy registration * update comment Co-authored-by: shuting <shutting06@gmail.com> * refactor Co-authored-by: shuting <shutting06@gmail.com>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package policy
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/golang/glog"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
)
|
|
|
|
func buildPolicyLabel(policyName string) (labels.Selector, error) {
|
|
policyLabelmap := map[string]string{"policy": policyName}
|
|
//NOt using a field selector, as the match function will have to cast the runtime.object
|
|
// to get the field, while it can get labels directly, saves the cast effort
|
|
ls := &metav1.LabelSelector{}
|
|
if err := metav1.Convert_Map_string_To_string_To_v1_LabelSelector(&policyLabelmap, ls, nil); err != nil {
|
|
return nil, fmt.Errorf("failed to generate label sector of Policy name %s: %v", policyName, err)
|
|
}
|
|
policySelector, err := metav1.LabelSelectorAsSelector(ls)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Policy %s has invalid label selector: %v", policyName, err)
|
|
}
|
|
return policySelector, nil
|
|
}
|
|
|
|
func transformResource(resource unstructured.Unstructured) []byte {
|
|
data, err := resource.MarshalJSON()
|
|
if err != nil {
|
|
glog.Errorf("failed to marshall resource %v: %v", resource, err)
|
|
return nil
|
|
}
|
|
return data
|
|
}
|