Allow specifying the hub group-version for a handler
Kubernetes-commit: 0e9b06df0f21b421ff69fd455d4542883d61e8c3
This commit is contained in:
parent
b758170bd7
commit
dba666528b
|
@ -77,7 +77,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, admit admission.Inte
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
decoder := scope.Serializer.DecoderToVersion(s.Serializer, schema.GroupVersion{Group: gv.Group, Version: runtime.APIVersionInternal})
|
decoder := scope.Serializer.DecoderToVersion(s.Serializer, scope.HubGroupVersion)
|
||||||
|
|
||||||
body, err := readBody(req)
|
body, err := readBody(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -118,9 +118,10 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gv := scope.Kind.GroupVersion()
|
gv := scope.Kind.GroupVersion()
|
||||||
|
|
||||||
codec := runtime.NewCodec(
|
codec := runtime.NewCodec(
|
||||||
scope.Serializer.EncoderForVersion(s.Serializer, gv),
|
scope.Serializer.EncoderForVersion(s.Serializer, gv),
|
||||||
scope.Serializer.DecoderToVersion(s.Serializer, schema.GroupVersion{Group: gv.Group, Version: runtime.APIVersionInternal}),
|
scope.Serializer.DecoderToVersion(s.Serializer, scope.HubGroupVersion),
|
||||||
)
|
)
|
||||||
|
|
||||||
userInfo, _ := request.UserFrom(ctx)
|
userInfo, _ := request.UserFrom(ctx)
|
||||||
|
@ -163,6 +164,8 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
|
||||||
kind: scope.Kind,
|
kind: scope.Kind,
|
||||||
resource: scope.Resource,
|
resource: scope.Resource,
|
||||||
|
|
||||||
|
hubGroupVersion: scope.HubGroupVersion,
|
||||||
|
|
||||||
createValidation: rest.AdmissionToValidateObjectFunc(admit, staticAdmissionAttributes),
|
createValidation: rest.AdmissionToValidateObjectFunc(admit, staticAdmissionAttributes),
|
||||||
updateValidation: rest.AdmissionToValidateObjectUpdateFunc(admit, staticAdmissionAttributes),
|
updateValidation: rest.AdmissionToValidateObjectUpdateFunc(admit, staticAdmissionAttributes),
|
||||||
admissionCheck: admissionCheck,
|
admissionCheck: admissionCheck,
|
||||||
|
@ -218,6 +221,8 @@ type patcher struct {
|
||||||
resource schema.GroupVersionResource
|
resource schema.GroupVersionResource
|
||||||
kind schema.GroupVersionKind
|
kind schema.GroupVersionKind
|
||||||
|
|
||||||
|
hubGroupVersion schema.GroupVersion
|
||||||
|
|
||||||
// Validation functions
|
// Validation functions
|
||||||
createValidation rest.ValidateObjectFunc
|
createValidation rest.ValidateObjectFunc
|
||||||
updateValidation rest.ValidateObjectUpdateFunc
|
updateValidation rest.ValidateObjectUpdateFunc
|
||||||
|
@ -315,9 +320,8 @@ func (p *smpPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (ru
|
||||||
if err := strategicPatchObject(p.defaulter, currentVersionedObject, p.patchJS, versionedObjToUpdate, p.schemaReferenceObj); err != nil {
|
if err := strategicPatchObject(p.defaulter, currentVersionedObject, p.patchJS, versionedObjToUpdate, p.schemaReferenceObj); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Convert the object back to unversioned (aka internal version).
|
// Convert the object back to the hub version
|
||||||
gvk := p.kind.GroupKind().WithVersion(runtime.APIVersionInternal)
|
return p.unsafeConvertor.ConvertToVersion(versionedObjToUpdate, p.hubGroupVersion)
|
||||||
return p.unsafeConvertor.ConvertToVersion(versionedObjToUpdate, gvk.GroupVersion())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// strategicPatchObject applies a strategic merge patch of <patchJS> to
|
// strategicPatchObject applies a strategic merge patch of <patchJS> to
|
||||||
|
|
|
@ -65,6 +65,9 @@ type RequestScope struct {
|
||||||
Subresource string
|
Subresource string
|
||||||
|
|
||||||
MetaGroupVersion schema.GroupVersion
|
MetaGroupVersion schema.GroupVersion
|
||||||
|
|
||||||
|
// HubGroupVersion indicates what version objects read from etcd or incoming requests should be converted to for in-memory handling.
|
||||||
|
HubGroupVersion schema.GroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scope *RequestScope) err(err error, w http.ResponseWriter, req *http.Request) {
|
func (scope *RequestScope) err(err error, w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
|
@ -367,6 +367,7 @@ func (tc *patchTestCase) Run(t *testing.T) {
|
||||||
kind := examplev1.SchemeGroupVersion.WithKind("Pod")
|
kind := examplev1.SchemeGroupVersion.WithKind("Pod")
|
||||||
resource := examplev1.SchemeGroupVersion.WithResource("pods")
|
resource := examplev1.SchemeGroupVersion.WithResource("pods")
|
||||||
schemaReferenceObj := &examplev1.Pod{}
|
schemaReferenceObj := &examplev1.Pod{}
|
||||||
|
hubVersion := example.SchemeGroupVersion
|
||||||
|
|
||||||
for _, patchType := range []types.PatchType{types.JSONPatchType, types.MergePatchType, types.StrategicMergePatchType} {
|
for _, patchType := range []types.PatchType{types.JSONPatchType, types.MergePatchType, types.StrategicMergePatchType} {
|
||||||
// This needs to be reset on each iteration.
|
// This needs to be reset on each iteration.
|
||||||
|
@ -439,6 +440,8 @@ func (tc *patchTestCase) Run(t *testing.T) {
|
||||||
kind: kind,
|
kind: kind,
|
||||||
resource: resource,
|
resource: resource,
|
||||||
|
|
||||||
|
hubGroupVersion: hubVersion,
|
||||||
|
|
||||||
createValidation: rest.ValidateAllObjectFunc,
|
createValidation: rest.ValidateAllObjectFunc,
|
||||||
updateValidation: admissionValidation,
|
updateValidation: admissionValidation,
|
||||||
admissionCheck: admissionMutation,
|
admissionCheck: admissionMutation,
|
||||||
|
|
|
@ -89,8 +89,9 @@ func UpdateResource(r rest.Updater, scope RequestScope, admit admission.Interfac
|
||||||
}
|
}
|
||||||
defaultGVK := scope.Kind
|
defaultGVK := scope.Kind
|
||||||
original := r.New()
|
original := r.New()
|
||||||
|
|
||||||
trace.Step("About to convert to expected version")
|
trace.Step("About to convert to expected version")
|
||||||
decoder := scope.Serializer.DecoderToVersion(s.Serializer, schema.GroupVersion{Group: defaultGVK.Group, Version: runtime.APIVersionInternal})
|
decoder := scope.Serializer.DecoderToVersion(s.Serializer, scope.HubGroupVersion)
|
||||||
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
obj, gvk, err := decoder.Decode(body, &defaultGVK, original)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = transformDecodeError(scope.Typer, err, original, gvk, body)
|
err = transformDecodeError(scope.Typer, err, original, gvk, body)
|
||||||
|
|
|
@ -506,6 +506,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
||||||
Subresource: subresource,
|
Subresource: subresource,
|
||||||
Kind: fqKindToRegister,
|
Kind: fqKindToRegister,
|
||||||
|
|
||||||
|
HubGroupVersion: schema.GroupVersion{Group: fqKindToRegister.Group, Version: runtime.APIVersionInternal},
|
||||||
|
|
||||||
MetaGroupVersion: metav1.SchemeGroupVersion,
|
MetaGroupVersion: metav1.SchemeGroupVersion,
|
||||||
}
|
}
|
||||||
if a.group.MetaGroupVersion != nil {
|
if a.group.MetaGroupVersion != nil {
|
||||||
|
|
Loading…
Reference in New Issue