kubewarden / policy-sdk-go

Kubewarden Policy SDK for the Go programming language
https://kubewarden.io
Apache License 2.0
8 stars 7 forks source link

Add more Go types #26

Closed flavio closed 2 years ago

flavio commented 2 years ago

Provide Go types describing:

Some of the objects would need to rely on interface{} (see for example the KubernetesAdmissionRequest.Object). However this is not doable with TinyGo, because it would cause a runtime error when trying to unmarshal the object.

Because of that, some attributes are defined as easyjson.RawMessage. This is a type that acts as a kind of []byte. This makes possible to unmarshal the contents of the variable using a proper Go type that implements the easyjson interfaces.

For example, assuming the policy is interested in Ingress-releated events. The ingress object can be loaded in this way:

ingress := networkingv1.Ingress{}
err := easyjson.Unmarshal(kubernetesAdmissionRequest.Object, &ingress)

This commit makes possible to write policies that are NOT using gjson