register.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package v1
  14. import (
  15. "k8s.io/apimachinery/pkg/runtime"
  16. "k8s.io/apimachinery/pkg/runtime/schema"
  17. utilruntime "k8s.io/apimachinery/pkg/util/runtime"
  18. )
  19. // GroupName is the group name for this API.
  20. const GroupName = "meta.k8s.io"
  21. var (
  22. // localSchemeBuilder is used to make compiler happy for autogenerated
  23. // conversions. However, it's not used.
  24. schemeBuilder runtime.SchemeBuilder
  25. localSchemeBuilder = &schemeBuilder
  26. )
  27. // SchemeGroupVersion is group version used to register these objects
  28. var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
  29. // Unversioned is group version for unversioned API objects
  30. // TODO: this should be v1 probably
  31. var Unversioned = schema.GroupVersion{Group: "", Version: "v1"}
  32. // WatchEventKind is name reserved for serializing watch events.
  33. const WatchEventKind = "WatchEvent"
  34. // Kind takes an unqualified kind and returns a Group qualified GroupKind
  35. func Kind(kind string) schema.GroupKind {
  36. return SchemeGroupVersion.WithKind(kind).GroupKind()
  37. }
  38. // scheme is the registry for the common types that adhere to the meta v1 API spec.
  39. var scheme = runtime.NewScheme()
  40. // ParameterCodec knows about query parameters used with the meta v1 API spec.
  41. var ParameterCodec = runtime.NewParameterCodec(scheme)
  42. var optionsTypes = []runtime.Object{
  43. &ListOptions{},
  44. &GetOptions{},
  45. &DeleteOptions{},
  46. &CreateOptions{},
  47. &UpdateOptions{},
  48. &PatchOptions{},
  49. }
  50. // AddToGroupVersion registers common meta types into schemas.
  51. func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion) {
  52. scheme.AddKnownTypeWithName(groupVersion.WithKind(WatchEventKind), &WatchEvent{})
  53. scheme.AddKnownTypeWithName(
  54. schema.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}.WithKind(WatchEventKind),
  55. &InternalEvent{},
  56. )
  57. // Supports legacy code paths, most callers should use metav1.ParameterCodec for now
  58. scheme.AddKnownTypes(groupVersion, optionsTypes...)
  59. // Register Unversioned types under their own special group
  60. scheme.AddUnversionedTypes(Unversioned,
  61. &Status{},
  62. &APIVersions{},
  63. &APIGroupList{},
  64. &APIGroup{},
  65. &APIResourceList{},
  66. )
  67. // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
  68. utilruntime.Must(RegisterConversions(scheme))
  69. utilruntime.Must(RegisterDefaults(scheme))
  70. }
  71. // AddMetaToScheme registers base meta types into schemas.
  72. func AddMetaToScheme(scheme *runtime.Scheme) error {
  73. scheme.AddKnownTypes(SchemeGroupVersion,
  74. &Table{},
  75. &TableOptions{},
  76. &PartialObjectMetadata{},
  77. &PartialObjectMetadataList{},
  78. )
  79. return nil
  80. }
  81. func init() {
  82. scheme.AddUnversionedTypes(SchemeGroupVersion, optionsTypes...)
  83. utilruntime.Must(AddMetaToScheme(scheme))
  84. // register manually. This usually goes through the SchemeBuilder, which we cannot use here.
  85. utilruntime.Must(RegisterDefaults(scheme))
  86. }