register.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. )
  18. // SchemeGroupVersion is group version used to register these objects
  19. // TODO this should be in the "kubeconfig" group
  20. var SchemeGroupVersion = schema.GroupVersion{Group: "", Version: "v1"}
  21. var (
  22. // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
  23. // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
  24. SchemeBuilder runtime.SchemeBuilder
  25. localSchemeBuilder = &SchemeBuilder
  26. AddToScheme = localSchemeBuilder.AddToScheme
  27. )
  28. func init() {
  29. // We only register manually written functions here. The registration of the
  30. // generated functions takes place in the generated files. The separation
  31. // makes the code compile even when the generated files are missing.
  32. localSchemeBuilder.Register(addKnownTypes, addDefaultingFuncs)
  33. }
  34. func addKnownTypes(scheme *runtime.Scheme) error {
  35. scheme.AddKnownTypes(SchemeGroupVersion,
  36. &Config{},
  37. )
  38. return nil
  39. }
  40. func (obj *Config) GetObjectKind() schema.ObjectKind { return obj }
  41. func (obj *Config) SetGroupVersionKind(gvk schema.GroupVersionKind) {
  42. obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
  43. }
  44. func (obj *Config) GroupVersionKind() schema.GroupVersionKind {
  45. return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
  46. }