Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent behaviour across kyverno and kyverno json[Feature] #427

Open
1 task done
anushkamittal2001 opened this issue Jul 16, 2024 · 2 comments
Open
1 task done
Labels
enhancement New feature or request triage Default label assigned to all new issues indicating label curation is needed to fully organize.

Comments

@anushkamittal2001
Copy link
Contributor

Problem Statement

Today the responses of kyverno and kyverno json arent similar, they behave slightly differently. It makes sense that we have some basic consistent behaviour across the two with Kyverno Json as a child project.

Solution Description

we need some convergence of behaviors and at least common fields between our projects

Alternatives

No response

Additional Context

No response

Slack discussion

No response

Research

  • I have searched other issues in this repository and mine is not recorded.
@anushkamittal2001 anushkamittal2001 added enhancement New feature or request triage Default label assigned to all new issues indicating label curation is needed to fully organize. labels Jul 16, 2024
@anushkamittal2001
Copy link
Contributor Author

Today the Kyverno response looks like this:

type EngineResponse struct {
	// Resource is the original resource
	Resource unstructured.Unstructured
	// Policy is the original policy
	policy GenericPolicy
	// namespaceLabels given by policy context
	namespaceLabels map[string]string
	// PatchedResource is the resource patched with the engine action changes
	PatchedResource unstructured.Unstructured
	// PolicyResponse contains the engine policy response
	PolicyResponse PolicyResponse
	// stats contains engine statistics
	stats ExecutionStats
}
type PolicyResponse struct {
	// stats contains policy statistics
	stats PolicyStats
	// Rules contains policy rules responses
	Rules []RuleResponse
}
type RuleResponse struct {
	// name is the rule name specified in policy
	name string
	// ruleType is the rule type (Mutation,Generation,Validation) for Kyverno Policy
	ruleType RuleType
	// message is the message response from the rule application
	message string
	// status rule status
	status RuleStatus
	// stats contains rule statistics
	stats ExecutionStats
	// generatedResource is the generated by the generate rules of a policy
	generatedResource unstructured.Unstructured
	// patchedTarget is the patched resource for mutate.targets
	patchedTarget *unstructured.Unstructured
	// patchedTargetParentResourceGVR is the GVR of the parent resource of the PatchedTarget. This is only populated when PatchedTarget is a subresource.
	patchedTargetParentResourceGVR metav1.GroupVersionResource
	// patchedTargetSubresourceName is the name of the subresource which is patched, empty if the resource patched is not a subresource.
	patchedTargetSubresourceName string
	// podSecurityChecks contains pod security checks (only if this is a pod security rule)
	podSecurityChecks *PodSecurityChecks
	// exception is the exception applied (if any)
	exception *kyvernov2beta1.PolicyException
	// binding is the validatingadmissionpolicybinding (if any)
	binding *v1alpha1.ValidatingAdmissionPolicyBinding
	// emitWarning enable passing rule message as warning to api server warning header
	emitWarning bool
}

In kyverno json it looks like this:

type Response struct {
	Resource any
	Policies []PolicyResponse
}

type PolicyResponse struct {
	Policy *v1alpha1.ValidatingPolicy
	Rules  []RuleResponse
}

type RuleResponse struct {
	Rule       v1alpha1.ValidatingRule
	Timestamp  time.Time
	Identifier string
	Error      error
	Violations []matching.Result
}
type Result struct {
	field.ErrorList
	Message string
}

I think it makes sense to have some similarity in the two especially in the RuleResponse : rule status and message. New json engine struct could be something like this:

type Response struct {
	Resource any
	PolicyResponse []PolicyResponse
}

type PolicyResponse struct {
	Policy *v1alpha1.ValidatingPolicy
	Rules  []RuleResponse
}

type RuleResponse struct {
	Rule       v1alpha1.ValidatingRule
	Message    string
	Timestamp  time.Time
	Identifier string
	Status     RuleStatus
	Violations []matching.Result
}

@anushkamittal2001
Copy link
Contributor Author

We can discuss what changes we could make further here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage Default label assigned to all new issues indicating label curation is needed to fully organize.
Projects
None yet
Development

No branches or pull requests

1 participant