Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPSTREAM: <carry>: apiextensions-apiserver allow for disabling generation repair #132

Open
wants to merge 1 commit into
base: kcp-feature-logical-clusters-1.24-v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ type ExtraConfig struct {
// used with the embedded cache server in kcp
DisableServerSideApply bool

// DisableGenerationRepair allows for disabling setting a generation during an object decoding (for objects that haven't had it)
// this field is meant to be set by the cache server so that built-in (assuming all CRs must have it) source objects
// don't differ from the replicated ones.
DisableGenerationRepair bool

// ConversionFactory is used to provider converters for CRs.
ConversionFactory conversion.Factory
}
Expand Down Expand Up @@ -242,6 +247,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
apiGroupInfo.StaticOpenAPISpec,
c.GenericConfig.MaxRequestBodyBytes,
c.ExtraConfig.DisableServerSideApply,
c.ExtraConfig.DisableGenerationRepair,
)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ type crdHandler struct {
// disableServerSideApply allows to deactivate Server Side Apply for a specific API server instead of globally through the feature gate
// used for embedded cache server with kcp
disableServerSideApply bool

// disableGenerationRepair allows for disabling setting a generation during an object decoding (for objects that haven't had it)
// this field is meant to be set by the cache server so that built-in (assuming all CRs must have it) source objects
// don't differ from the replicated ones.
disableGenerationRepair bool
}

// crdInfo stores enough information to serve the storage for the custom resource
Expand Down Expand Up @@ -210,6 +215,7 @@ func NewCustomResourceDefinitionHandler(
staticOpenAPISpec *spec.Swagger,
maxRequestBodyBytes int64,
disableServerSideApply bool,
disableGenerationRepair bool,
) (*crdHandler, error) {
if converterFactory == nil {
return nil, fmt.Errorf("converterFactory is required")
Expand All @@ -233,6 +239,7 @@ func NewCustomResourceDefinitionHandler(
staticOpenAPISpec: staticOpenAPISpec,
maxRequestBodyBytes: maxRequestBodyBytes,
disableServerSideApply: disableServerSideApply,
disableGenerationRepair: disableGenerationRepair,
}
crdInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: ret.createCustomResourceDefinition,
Expand Down Expand Up @@ -1030,6 +1037,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(crd *apiextensionsv1.CustomResour
structuralSchemas: structuralSchemas,
structuralSchemaGK: kind.GroupKind(),
preserveUnknownFields: crd.Spec.PreserveUnknownFields,
repairGeneration: !r.disableGenerationRepair,
},
crd: crd,
},
Expand Down Expand Up @@ -1400,6 +1408,7 @@ type crdConversionRESTOptionsGetter struct {
structuralSchemas map[string]*structuralschema.Structural // by version
structuralSchemaGK schema.GroupKind
preserveUnknownFields bool
repairGeneration bool
}

func (t crdConversionRESTOptionsGetter) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) {
Expand All @@ -1408,7 +1417,7 @@ func (t crdConversionRESTOptionsGetter) GetRESTOptions(resource schema.GroupReso
d := schemaCoercingDecoder{delegate: ret.StorageConfig.Codec, validator: unstructuredSchemaCoercer{
// drop invalid fields while decoding old CRs (before we haven't had any ObjectMeta validation)
dropInvalidMetadata: true,
repairGeneration: true,
repairGeneration: t.repairGeneration,
structuralSchemas: t.structuralSchemas,
structuralSchemaGK: t.structuralSchemaGK,
preserveUnknownFields: t.preserveUnknownFields,
Expand Down