scheme.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. Copyright 2017 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 scheme
  14. import (
  15. "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
  16. "k8s.io/apimachinery/pkg/runtime"
  17. "k8s.io/apimachinery/pkg/runtime/serializer"
  18. )
  19. // All kubectl code should eventually switch to use this Registry and Scheme instead of the global ones.
  20. // Scheme is the default instance of runtime.Scheme to which types in the Kubernetes API are already registered.
  21. var Scheme = runtime.NewScheme()
  22. // Codecs provides access to encoding and decoding for the scheme
  23. var Codecs = serializer.NewCodecFactory(Scheme)
  24. // ParameterCodec handles versioning of objects that are converted to query parameters.
  25. var ParameterCodec = runtime.NewParameterCodec(Scheme)
  26. // DefaultJSONEncoder returns a default encoder for our scheme
  27. func DefaultJSONEncoder() runtime.Encoder {
  28. return unstructured.JSONFallbackEncoder{Encoder: Codecs.LegacyCodec(Scheme.PrioritizedVersionsAllGroups()...)}
  29. }