1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

policy support added

This commit is contained in:
NoSkillGirl 2020-11-01 23:18:58 +05:30
parent 1ccde5412e
commit 94babfe4bd
2 changed files with 26 additions and 16 deletions

View file

@ -103,7 +103,14 @@ func getPolicyFromCluster(policyName string, cluster bool, dClient *client.Clien
policy, err := dClient.GetResource("", kind, namespace, policyName, "")
fmt.Println("------------policy : ", policy)
if err != nil {
return &v1.ClusterPolicy{}, err
fmt.Println("could not find clusterpolicy ... checking policy")
// try getting policy
kind := "Policy"
policy, err = dClient.GetResource("", kind, namespace, policyName, "")
if err != nil {
fmt.Println("error occurred while fetching policy", err)
return &v1.ClusterPolicy{}, err
}
}
policyBytes, err := json.Marshal(policy.Object)
@ -127,25 +134,28 @@ func getPoliciesFromCluster(cluster bool, dClient *client.Client, namespace stri
return res, nil
}
policyList, err := dClient.ListResource("", "ClusterPolicy", namespace, nil)
if err != nil {
return res, err
}
for _, policy := range policyList.Items {
policyBytes, err := json.Marshal(policy.Object)
policyTypes := []string{"ClusterPolicy", "Policy"}
for _, policy := range policyTypes {
policyList, err := dClient.ListResource("", policy, namespace, nil)
if err != nil {
return res, err
}
var p v1.ClusterPolicy
err = json.Unmarshal(policyBytes, &p)
for _, policy := range policyList.Items {
policyBytes, err := json.Marshal(policy.Object)
if err != nil {
return res, err
}
if err != nil {
return res, err
var p v1.ClusterPolicy
err = json.Unmarshal(policyBytes, &p)
if err != nil {
return res, err
}
res = append(res, &p)
}
res = append(res, &p)
}
return res, nil

View file

@ -32,8 +32,8 @@ func GetPolicy(file []byte) (clusterPolicies []*v1.ClusterPolicy, errors []error
continue
}
if policy.TypeMeta.Kind != "ClusterPolicy" {
errors = append(errors, fmt.Errorf(fmt.Sprintf("resource %v is not a cluster policy", policy.Name)))
if !(policy.TypeMeta.Kind == "ClusterPolicy" || policy.TypeMeta.Kind == "Policy") {
errors = append(errors, fmt.Errorf(fmt.Sprintf("resource %v is not a policy/cluster policy", policy.Name)))
continue
}
clusterPolicies = append(clusterPolicies, policy)