Change:
Most of the FooApplyConfiguration constructors pre-fill the Kind and APIVersion fields to make using them smooth. But () is missing this, making patterns like this fail: Currently this code fails with (server-side) error . The constructor should set the minimum required fields for the resulting object to be usable with calls, similar to how e.g. the `D Create a deployment (however) Create a clientset, and get the Deployments client from it Try to call deployments.ApplyScale using a ScaleApplyConfiguration created by the Scale() constructor I can see that the presence or absence of these metadata fields is driven by some code generation, but I wasn't able to follow through to what configures that code generation. I assume it's something in the schemas somewhere, but that wasn't clear to me. <details</details<detailsminikube v1.25.1 </detailsN/A N/A N/A N/A
/sig api-machinery
/assign /triage accepted
/assign

Discussion:
// ScaleApplyConfiguration constructs an declarative configuration of the Scale type for use with // apply. func Scale() *ScaleApplyConfiguration { <del> return &ScaleApplyConfiguration{} </del> <ins> b := &ScaleApplyConfiguration{} b.WithKind("Scale") b.WithAPIVersion("apps/v1beta2") return b </ins> } // WithKind sets the Kind field in the declarative configuration to the given value

// ScaleApplyConfiguration constructs an declarative configuration of the Scale type for use with // apply. func Scale() *ScaleApplyConfiguration { <del> return &ScaleApplyConfiguration{} </del> <ins> b := &ScaleApplyConfiguration{} b.WithKind("Scale") b.WithAPIVersion("autoscaling/v1") return b </ins> } // WithKind sets the Kind field in the declarative configuration to the given value

// ScaleApplyConfiguration constructs an declarative configuration of the Scale type for use with // apply. func Scale() *ScaleApplyConfiguration { <del> return &ScaleApplyConfiguration{} </del> <ins> b := &ScaleApplyConfiguration{} b.WithKind("Scale") b.WithAPIVersion("extensions/v1beta1") return b </ins> } // WithKind sets the Kind field in the declarative configuration to the given value

// DeleteOptionsApplyConfiguration constructs an declarative configuration of the DeleteOptions type for use with // apply. func DeleteOptions() *DeleteOptionsApplyConfiguration { <del> return &DeleteOptionsApplyConfiguration{} </del> <ins> b := &DeleteOptionsApplyConfiguration{} b.WithKind("DeleteOptions") b.WithAPIVersion("meta.k8s.io/v1") return b </ins> } // WithKind sets the Kind field in the declarative configuration to the given value

g.generateClientgenExtract(sw, typeParams, !typeParams.Tags.NoStatus) } } else { <del> sw.Do(constructor, typeParams) </del> <ins> if hasTypeMetaField(t) { sw.Do(constructorWithTypeMeta, typeParams) } else { sw.Do(constructor, typeParams) } </ins> } g.generateWithFuncs(t, typeParams, sw, nil) return sw.Error() } <ins> func hasTypeMetaField(t *types.Type) bool { for _, member := range t.Members { if typeMeta.Name == member.Type.Name { return true } } return false } </ins> func blocklisted(t *types.Type, member types.Member) bool { if objectMeta.Name == t.Name && member.Name == "ManagedFields" { return true

} ` <ins> var constructorWithTypeMeta = ` // $.ApplyConfig.ApplyConfiguration|public$ constructs an declarative configuration of the $.ApplyConfig.Type|public$ type for use with // apply. func $.ApplyConfig.Type|public$() *$.ApplyConfig.ApplyConfiguration|public$ { b := &$.ApplyConfig.ApplyConfiguration|public${} b.WithKind("$.ApplyConfig.Type|singularKind$") b.WithAPIVersion("$.APIVersion$") return b } ` </ins> var constructor = ` // $.ApplyConfig.ApplyConfiguration|public$ constructs an declarative configuration of the $.ApplyConfig.Type|public$ type for use with // apply.

var ( applyConfiguration = types.Ref("k8s.io/apimachinery/pkg/runtime", "ApplyConfiguration") groupVersionKind   = types.Ref("k8s.io/apimachinery/pkg/runtime/schema", "GroupVersionKind") <ins> typeMeta           = types.Ref("k8s.io/apimachinery/pkg/apis/meta/v1", "TypeMeta") </ins> objectMeta         = types.Ref("k8s.io/apimachinery/pkg/apis/meta/v1", "ObjectMeta") rawExtension       = types.Ref("k8s.io/apimachinery/pkg/runtime", "RawExtension") unknown            = types.Ref("k8s.io/apimachinery/pkg/runtime", "Unknown")