scheme.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/runtime"
  16. "k8s.io/apimachinery/pkg/runtime/serializer"
  17. kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
  18. kubeletconfigv1beta1 "k8s.io/kubernetes/pkg/kubelet/apis/config/v1beta1"
  19. )
  20. // Utility functions for the Kubelet's kubeletconfig API group
  21. // NewSchemeAndCodecs is a utility function that returns a Scheme and CodecFactory
  22. // that understand the types in the kubeletconfig API group. Passing mutators allows
  23. // for adjusting the behavior of the CodecFactory, for example enable strict decoding.
  24. func NewSchemeAndCodecs(mutators ...serializer.CodecFactoryOptionsMutator) (*runtime.Scheme, *serializer.CodecFactory, error) {
  25. scheme := runtime.NewScheme()
  26. if err := kubeletconfig.AddToScheme(scheme); err != nil {
  27. return nil, nil, err
  28. }
  29. if err := kubeletconfigv1beta1.AddToScheme(scheme); err != nil {
  30. return nil, nil, err
  31. }
  32. codecs := serializer.NewCodecFactory(scheme, mutators...)
  33. return scheme, &codecs, nil
  34. }