mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
let dynamic client handle non-registered ListOptions;
register ListOptions for apis/policy
This commit is contained in:
parent
554b7010fa
commit
d9f07925be
@ -174,6 +174,20 @@ var nonRoundTrippableTypes = sets.NewString(
|
|||||||
"WatchEvent",
|
"WatchEvent",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var commonKinds = []string{"ListOptions", "DeleteOptions"}
|
||||||
|
|
||||||
|
// verify all external group/versions have the common kinds like the ListOptions, DeleteOptions are registered.
|
||||||
|
func TestCommonKindsRegistered(t *testing.T) {
|
||||||
|
for _, kind := range commonKinds {
|
||||||
|
for _, group := range testapi.Groups {
|
||||||
|
gv := group.GroupVersion()
|
||||||
|
if _, err := api.Scheme.New(gv.WithKind(kind)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var nonInternalRoundTrippableTypes = sets.NewString("List", "ListOptions", "ExportOptions")
|
var nonInternalRoundTrippableTypes = sets.NewString("List", "ListOptions", "ExportOptions")
|
||||||
var nonRoundTrippableTypesByVersion = map[string][]string{}
|
var nonRoundTrippableTypesByVersion = map[string][]string{}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ func addKnownTypes(scheme *runtime.Scheme) {
|
|||||||
&PetSet{},
|
&PetSet{},
|
||||||
&PetSetList{},
|
&PetSetList{},
|
||||||
&v1.ListOptions{},
|
&v1.ListOptions{},
|
||||||
|
&v1.DeleteOptions{},
|
||||||
)
|
)
|
||||||
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ func addKnownTypes(scheme *runtime.Scheme) {
|
|||||||
&HorizontalPodAutoscalerList{},
|
&HorizontalPodAutoscalerList{},
|
||||||
&Scale{},
|
&Scale{},
|
||||||
&v1.ListOptions{},
|
&v1.ListOptions{},
|
||||||
|
&v1.DeleteOptions{},
|
||||||
)
|
)
|
||||||
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ func addKnownTypes(scheme *runtime.Scheme) {
|
|||||||
&Job{},
|
&Job{},
|
||||||
&JobList{},
|
&JobList{},
|
||||||
&v1.ListOptions{},
|
&v1.ListOptions{},
|
||||||
|
&v1.DeleteOptions{},
|
||||||
)
|
)
|
||||||
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ func addKnownTypes(scheme *runtime.Scheme) {
|
|||||||
&ScheduledJob{},
|
&ScheduledJob{},
|
||||||
&ScheduledJobList{},
|
&ScheduledJobList{},
|
||||||
&v1.ListOptions{},
|
&v1.ListOptions{},
|
||||||
|
&v1.DeleteOptions{},
|
||||||
)
|
)
|
||||||
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package v1alpha1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
versionedwatch "k8s.io/kubernetes/pkg/watch/versioned"
|
versionedwatch "k8s.io/kubernetes/pkg/watch/versioned"
|
||||||
)
|
)
|
||||||
@ -41,6 +42,8 @@ func addKnownTypes(scheme *runtime.Scheme) {
|
|||||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||||
&PodDisruptionBudget{},
|
&PodDisruptionBudget{},
|
||||||
&PodDisruptionBudgetList{},
|
&PodDisruptionBudgetList{},
|
||||||
|
&v1.ListOptions{},
|
||||||
|
&v1.DeleteOptions{},
|
||||||
)
|
)
|
||||||
// Add the watch version that applies
|
// Add the watch version that applies
|
||||||
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||||
|
@ -270,3 +270,26 @@ func (parameterCodec) DecodeParameters(parameters url.Values, from unversioned.G
|
|||||||
}
|
}
|
||||||
|
|
||||||
var defaultParameterEncoder runtime.ParameterCodec = parameterCodec{}
|
var defaultParameterEncoder runtime.ParameterCodec = parameterCodec{}
|
||||||
|
|
||||||
|
type versionedParameterEncoderWithV1Fallback struct{}
|
||||||
|
|
||||||
|
func (versionedParameterEncoderWithV1Fallback) EncodeParameters(obj runtime.Object, to unversioned.GroupVersion) (url.Values, error) {
|
||||||
|
ret, err := api.ParameterCodec.EncodeParameters(obj, to)
|
||||||
|
if err != nil && runtime.IsNotRegisteredError(err) {
|
||||||
|
// fallback to v1
|
||||||
|
return api.ParameterCodec.EncodeParameters(obj, v1.SchemeGroupVersion)
|
||||||
|
}
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (versionedParameterEncoderWithV1Fallback) DecodeParameters(parameters url.Values, from unversioned.GroupVersion, into runtime.Object) error {
|
||||||
|
return errors.New("DecodeParameters not implemented on versionedParameterEncoderWithV1Fallback")
|
||||||
|
}
|
||||||
|
|
||||||
|
// VersionedParameterEncoderWithV1Fallback is useful for encoding query
|
||||||
|
// parameters for thirdparty resources. It tries to convert object to the
|
||||||
|
// specified version before converting it to query parameters, and falls back to
|
||||||
|
// converting to v1 if the object is not registered in the specified version.
|
||||||
|
// For the record, currently API server always treats query parameters sent to a
|
||||||
|
// thirdparty resource endpoint as v1.
|
||||||
|
var VersionedParameterEncoderWithV1Fallback runtime.ParameterCodec = versionedParameterEncoderWithV1Fallback{}
|
||||||
|
@ -443,11 +443,9 @@ func gcListWatcher(client *dynamic.Client, resource unversioned.GroupVersionReso
|
|||||||
// namespaces if it's namespace scoped, so leave
|
// namespaces if it's namespace scoped, so leave
|
||||||
// APIResource.Namespaced as false is all right.
|
// APIResource.Namespaced as false is all right.
|
||||||
apiResource := unversioned.APIResource{Name: resource.Resource}
|
apiResource := unversioned.APIResource{Name: resource.Resource}
|
||||||
// The default parameter codec used by the dynamic client cannot
|
return client.ParameterCodec(dynamic.VersionedParameterEncoderWithV1Fallback).
|
||||||
// encode api.ListOptions.
|
Resource(&apiResource, api.NamespaceAll).
|
||||||
// TODO: api.ParameterCodec doesn't support thirdparty objects.
|
List(&options)
|
||||||
// We need a generic parameter codec.
|
|
||||||
return client.ParameterCodec(api.ParameterCodec).Resource(&apiResource, api.NamespaceAll).List(&options)
|
|
||||||
},
|
},
|
||||||
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
|
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
|
||||||
// APIResource.Kind is not used by the dynamic client, so
|
// APIResource.Kind is not used by the dynamic client, so
|
||||||
@ -455,9 +453,9 @@ func gcListWatcher(client *dynamic.Client, resource unversioned.GroupVersionReso
|
|||||||
// namespaces if it's namespace scoped, so leave
|
// namespaces if it's namespace scoped, so leave
|
||||||
// APIResource.Namespaced as false is all right.
|
// APIResource.Namespaced as false is all right.
|
||||||
apiResource := unversioned.APIResource{Name: resource.Resource}
|
apiResource := unversioned.APIResource{Name: resource.Resource}
|
||||||
// The default parameter codec used by the dynamic client cannot
|
return client.ParameterCodec(dynamic.VersionedParameterEncoderWithV1Fallback).
|
||||||
// encode api.ListOptions.
|
Resource(&apiResource, api.NamespaceAll).
|
||||||
return client.ParameterCodec(api.ParameterCodec).Resource(&apiResource, api.NamespaceAll).Watch(&options)
|
Watch(&options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user