how to reuse k8s validation in my own CRD controller how to reuse k8s validation in my own CRD controller kubernetes kubernetes

how to reuse k8s validation in my own CRD controller


You can reuse the upstream ValidatePodSpec directly.

You would need to import a couple packages first:

import (    "k8s.io/kubernetes/pkg/apis/core/validation"    "k8s.io/apimachinery/pkg/util/validation/field")

Then make use of ValidatePodSpec in your controller method:

errs := validation.ValidatePodSpec(instance.podSpec, field.NewPath("podSpec"))


Also desire such a functionality to be provided as a library. There is a comment about using go get for k8s.io/kubernetes upstream.https://github.com/kubernetes/kubernetes/issues/80316#issuecomment-512991205And the issue that is caused by using wrong configuration for PodTemplateSpec could be found here https://github.com/googleforgames/agones/issues/1298Namely: we create a CRD successfully, however it become unhealthy later because pod could not be created.