GoogleCloudPlatform / flink-on-k8s-operator

[DEPRECATED] Kubernetes operator for managing the lifecycle of Apache Flink and Beam applications.
Apache License 2.0
657 stars 265 forks source link

Reject unknown fields in the CR #85

Open functicons opened 4 years ago

functicons commented 4 years ago

Currently, the operator doesn't reject unknown fields in the CR which makes it error-prone. We need to validate this.

functicons commented 4 years ago

This doesn't seem to be supported by Kubebuilder https://github.com/kubernetes-sigs/kubebuilder/issues/1174. Still not aware of how to solve it.

elanv commented 4 years ago

Do you mean pruning function? If so, since version 1.15 it seems to be supported by k8s apiserver.

note: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#pruning-versus-preserving-unknown-fields

I tested this feature in 1.15, but there were another problem. controller-tools included in kubebuilder is not able to create a "structural schema" intact. To use the pruning feature, the openapi validation schema must be defined as "structural schema". There are two issues with structural schema that are problematic.

https://github.com/kubernetes-sigs/controller-tools/issues/304 (resolved recently) https://github.com/kubernetes-sigs/controller-tools/issues/279

elanv commented 4 years ago

controller-tools 0.2.4 included in kubebuilder v2.2.0 supports the generation of CRD V1 and structural schema, which allows you to use preserveUnknownFields. If you are using k8s 1.15 this issue seems to be resolved.

I have tested generating CRD with controller-tools 0.2.4, deploying CRD to k8s 1.15 cluster and deploying CR with unknown field, and api-server-validation works well.

functicons commented 4 years ago

Thanks, will check!