conversion.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 internalversion
  14. import (
  15. "fmt"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. "k8s.io/apimachinery/pkg/conversion"
  18. "k8s.io/apimachinery/pkg/util/validation/field"
  19. )
  20. func Convert_internalversion_ListOptions_To_v1_ListOptions(in *ListOptions, out *metav1.ListOptions, s conversion.Scope) error {
  21. if err := metav1.Convert_fields_Selector_To_string(&in.FieldSelector, &out.FieldSelector, s); err != nil {
  22. return err
  23. }
  24. if err := metav1.Convert_labels_Selector_To_string(&in.LabelSelector, &out.LabelSelector, s); err != nil {
  25. return err
  26. }
  27. out.IncludeUninitialized = in.IncludeUninitialized
  28. out.ResourceVersion = in.ResourceVersion
  29. out.TimeoutSeconds = in.TimeoutSeconds
  30. out.Watch = in.Watch
  31. out.Limit = in.Limit
  32. out.Continue = in.Continue
  33. return nil
  34. }
  35. func Convert_v1_ListOptions_To_internalversion_ListOptions(in *metav1.ListOptions, out *ListOptions, s conversion.Scope) error {
  36. if err := metav1.Convert_string_To_fields_Selector(&in.FieldSelector, &out.FieldSelector, s); err != nil {
  37. return err
  38. }
  39. if err := metav1.Convert_string_To_labels_Selector(&in.LabelSelector, &out.LabelSelector, s); err != nil {
  40. return err
  41. }
  42. out.IncludeUninitialized = in.IncludeUninitialized
  43. out.ResourceVersion = in.ResourceVersion
  44. out.TimeoutSeconds = in.TimeoutSeconds
  45. out.Watch = in.Watch
  46. out.Limit = in.Limit
  47. out.Continue = in.Continue
  48. return nil
  49. }
  50. func Convert_map_to_v1_LabelSelector(in *map[string]string, out *metav1.LabelSelector, s conversion.Scope) error {
  51. if in == nil {
  52. return nil
  53. }
  54. out = new(metav1.LabelSelector)
  55. for labelKey, labelValue := range *in {
  56. metav1.AddLabelToSelector(out, labelKey, labelValue)
  57. }
  58. return nil
  59. }
  60. func Convert_v1_LabelSelector_to_map(in *metav1.LabelSelector, out *map[string]string, s conversion.Scope) error {
  61. var err error
  62. *out, err = metav1.LabelSelectorAsMap(in)
  63. if err != nil {
  64. err = field.Invalid(field.NewPath("labelSelector"), *in, fmt.Sprintf("cannot convert to old selector: %v", err))
  65. }
  66. return err
  67. }