@@ -672,19 +672,17 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
672672 let jsondata = quote ! {
673673 #schemagen
674674
675- let jsondata = #serde_json:: json!( {
675+ let mut jsondata = #serde_json:: json!( {
676676 "metadata" : {
677677 #crd_meta
678678 } ,
679679 "spec" : {
680680 "group" : #group,
681681 "scope" : #scope,
682682 "names" : {
683- "categories" : categories,
684683 "plural" : #plural,
685684 "singular" : #name,
686685 "kind" : #kind,
687- "shortNames" : shorts
688686 } ,
689687 "versions" : [ {
690688 "name" : #version,
@@ -694,7 +692,6 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
694692 "schema" : {
695693 "openAPIV3Schema" : schema,
696694 } ,
697- "additionalPrinterColumns" : columns,
698695 #selectable
699696 "subresources" : subres,
700697 } ] ,
@@ -707,13 +704,10 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
707704 impl #extver:: CustomResourceExt for #rootident {
708705
709706 fn crd( ) -> #apiext:: CustomResourceDefinition {
710- let columns : Vec <#apiext:: CustomResourceColumnDefinition > = #serde_json:: from_str( #printers) . expect( "valid printer column json" ) ;
711707 #k8s_openapi:: k8s_if_ge_1_30! {
712708 let fields : Vec <#apiext:: SelectableField > = #serde_json:: from_str( #fields) . expect( "valid selectableField column json" ) ;
713709 }
714710 let scale: Option <#apiext:: CustomResourceSubresourceScale > = #scale;
715- let categories: Vec <String > = #serde_json:: from_str( #categories_json) . expect( "valid categories" ) ;
716- let shorts : Vec <String > = #serde_json:: from_str( #short_json) . expect( "valid shortnames" ) ;
717711 let subres = if #has_status {
718712 if let Some ( s) = & scale {
719713 #serde_json:: json!( {
@@ -728,6 +722,24 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
728722 } ;
729723
730724 #jsondata
725+
726+ // These fields should only be set if they are non-empty to avoid reconciliation issues
727+ // with systems
728+ let columns: Vec <#apiext:: CustomResourceColumnDefinition > = #serde_json:: from_str( #printers) . expect( "valid printer column json" ) ;
729+ if !columns. is_empty( ) {
730+ jsondata[ "spec" ] [ "versions" ] [ 0 ] [ "additionalPrinterColumns" ] = #serde_json:: json!( columns) ;
731+ }
732+
733+ let categories: Vec <String > = #serde_json:: from_str( #categories_json) . expect( "valid categories" ) ;
734+ if !categories. is_empty( ) {
735+ jsondata[ "spec" ] [ "names" ] [ "categories" ] = #serde_json:: json!( categories) ;
736+ }
737+
738+ let shorts: Vec <String > = #serde_json:: from_str( #short_json) . expect( "valid shortnames" ) ;
739+ if !shorts. is_empty( ) {
740+ jsondata[ "spec" ] [ "names" ] [ "shortNames" ] = #serde_json:: json!( shorts) ;
741+ }
742+
731743 #serde_json:: from_value( jsondata)
732744 . expect( "valid custom resource from #[kube(attrs..)]" )
733745 }
0 commit comments