Skip to content

Commit 4c8a0f2

Browse files
committed
UPSTREAM: <carry>: apiextensions-apiserver allow for disabling generation repair
Exposes DisableGenerationRepair option that 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 source objects don't differ from the replicated ones.
1 parent 6ebb9f0 commit 4c8a0f2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/apiserver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ type ExtraConfig struct {
9494
// used with the embedded cache server in kcp
9595
DisableServerSideApply bool
9696

97+
// DisableGenerationRepair allows for disabling setting a generation during an object decoding (for objects that haven't had it)
98+
// this field is meant to be set by the cache server so that built-in (assuming all CRs must have it) source objects
99+
// don't differ from the replicated ones.
100+
DisableGenerationRepair bool
101+
97102
// ConversionFactory is used to provider converters for CRs.
98103
ConversionFactory conversion.Factory
99104
}
@@ -242,6 +247,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
242247
apiGroupInfo.StaticOpenAPISpec,
243248
c.GenericConfig.MaxRequestBodyBytes,
244249
c.ExtraConfig.DisableServerSideApply,
250+
c.ExtraConfig.DisableGenerationRepair,
245251
)
246252
if err != nil {
247253
return nil, err

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ type crdHandler struct {
156156
// disableServerSideApply allows to deactivate Server Side Apply for a specific API server instead of globally through the feature gate
157157
// used for embedded cache server with kcp
158158
disableServerSideApply bool
159+
160+
// disableGenerationRepair allows for disabling setting a generation during an object decoding (for objects that haven't had it)
161+
// this field is meant to be set by the cache server so that built-in (assuming all CRs must have it) source objects
162+
// don't differ from the replicated ones.
163+
disableGenerationRepair bool
159164
}
160165

161166
// crdInfo stores enough information to serve the storage for the custom resource
@@ -210,6 +215,7 @@ func NewCustomResourceDefinitionHandler(
210215
staticOpenAPISpec *spec.Swagger,
211216
maxRequestBodyBytes int64,
212217
disableServerSideApply bool,
218+
disableGenerationRepair bool,
213219
) (*crdHandler, error) {
214220
if converterFactory == nil {
215221
return nil, fmt.Errorf("converterFactory is required")
@@ -233,6 +239,7 @@ func NewCustomResourceDefinitionHandler(
233239
staticOpenAPISpec: staticOpenAPISpec,
234240
maxRequestBodyBytes: maxRequestBodyBytes,
235241
disableServerSideApply: disableServerSideApply,
242+
disableGenerationRepair: disableGenerationRepair,
236243
}
237244
crdInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
238245
AddFunc: ret.createCustomResourceDefinition,
@@ -1030,6 +1037,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(crd *apiextensionsv1.CustomResour
10301037
structuralSchemas: structuralSchemas,
10311038
structuralSchemaGK: kind.GroupKind(),
10321039
preserveUnknownFields: crd.Spec.PreserveUnknownFields,
1040+
repairGeneration: !r.disableGenerationRepair,
10331041
},
10341042
crd: crd,
10351043
},
@@ -1400,6 +1408,7 @@ type crdConversionRESTOptionsGetter struct {
14001408
structuralSchemas map[string]*structuralschema.Structural // by version
14011409
structuralSchemaGK schema.GroupKind
14021410
preserveUnknownFields bool
1411+
repairGeneration bool
14031412
}
14041413

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

0 commit comments

Comments
 (0)