From ecbdafc214538aadc78ec8447f2fa12d0057492b Mon Sep 17 00:00:00 2001 From: Eirik A Date: Fri, 18 Oct 2024 11:50:24 +0100 Subject: [PATCH] Add a compile_error if setting selectable fields on K8s < 1.30 (#1612) Signed-off-by: clux --- kube-derive/src/custom_resource.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kube-derive/src/custom_resource.rs b/kube-derive/src/custom_resource.rs index cbc5684f3..c342d99b4 100644 --- a/kube-derive/src/custom_resource.rs +++ b/kube-derive/src/custom_resource.rs @@ -411,6 +411,17 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea quote! {} }; + // Known constraints that are hard to enforce elsewhere + let compile_constraints = if !selectable.is_empty() { + quote! { + #k8s_openapi::k8s_if_le_1_29! { + compile_error!("selectable fields require Kubernetes >= 1.30"); + } + } + } else { + quote! {} + }; + let jsondata = quote! { #schemagen @@ -493,6 +504,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea // Concat output quote! { + #compile_constraints #root_obj #impl_resource #impl_default