conversion.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. Copyright 2019 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 v1alpha1
  14. import (
  15. "fmt"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. "k8s.io/apimachinery/pkg/conversion"
  18. "k8s.io/kube-scheduler/config/v1alpha1"
  19. "k8s.io/kubernetes/pkg/scheduler/apis/config"
  20. "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
  21. "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
  22. )
  23. // Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration converts to the internal.
  24. func Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error {
  25. if err := autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil {
  26. return err
  27. }
  28. var profile config.KubeSchedulerProfile
  29. if err := metav1.Convert_Pointer_string_To_string(&in.SchedulerName, &profile.SchedulerName, s); err != nil {
  30. return err
  31. }
  32. if in.Plugins != nil {
  33. profile.Plugins = &config.Plugins{}
  34. if err := Convert_v1alpha1_Plugins_To_config_Plugins(in.Plugins, profile.Plugins, s); err != nil {
  35. return err
  36. }
  37. } else {
  38. profile.Plugins = nil
  39. }
  40. if in.PluginConfig != nil {
  41. profile.PluginConfig = make([]config.PluginConfig, len(in.PluginConfig))
  42. for i := range in.PluginConfig {
  43. if err := Convert_v1alpha1_PluginConfig_To_config_PluginConfig(&in.PluginConfig[i], &profile.PluginConfig[i], s); err != nil {
  44. return err
  45. }
  46. }
  47. }
  48. if in.HardPodAffinitySymmetricWeight != nil {
  49. args := interpodaffinity.Args{HardPodAffinityWeight: in.HardPodAffinitySymmetricWeight}
  50. plCfg := plugins.NewPluginConfig(interpodaffinity.Name, args)
  51. profile.PluginConfig = append(profile.PluginConfig, plCfg)
  52. }
  53. out.Profiles = []config.KubeSchedulerProfile{profile}
  54. return nil
  55. }
  56. func Convert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(in *config.KubeSchedulerConfiguration, out *v1alpha1.KubeSchedulerConfiguration, s conversion.Scope) error {
  57. // Conversion from internal to v1alpha1 is not relevant for kube-scheduler.
  58. return autoConvert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(in, out, s)
  59. }
  60. // Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration handles deprecated parameters for leader election.
  61. func Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in *v1alpha1.KubeSchedulerLeaderElectionConfiguration, out *config.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error {
  62. if err := autoConvert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil {
  63. return err
  64. }
  65. if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) == 0 {
  66. out.ResourceNamespace = in.ResourceNamespace
  67. } else if len(in.ResourceNamespace) == 0 && len(in.LockObjectNamespace) > 0 {
  68. out.ResourceNamespace = in.LockObjectNamespace
  69. } else if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) > 0 {
  70. if in.ResourceNamespace == in.LockObjectNamespace {
  71. out.ResourceNamespace = in.ResourceNamespace
  72. } else {
  73. return fmt.Errorf("ResourceNamespace and LockObjectNamespace are both set and do not match, ResourceNamespace: %s, LockObjectNamespace: %s", in.ResourceNamespace, in.LockObjectNamespace)
  74. }
  75. }
  76. if len(in.ResourceName) > 0 && len(in.LockObjectName) == 0 {
  77. out.ResourceName = in.ResourceName
  78. } else if len(in.ResourceName) == 0 && len(in.LockObjectName) > 0 {
  79. out.ResourceName = in.LockObjectName
  80. } else if len(in.ResourceName) > 0 && len(in.LockObjectName) > 0 {
  81. if in.ResourceName == in.LockObjectName {
  82. out.ResourceName = in.ResourceName
  83. } else {
  84. return fmt.Errorf("ResourceName and LockObjectName are both set and do not match, ResourceName: %s, LockObjectName: %s", in.ResourceName, in.LockObjectName)
  85. }
  86. }
  87. return nil
  88. }
  89. // Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration handles deprecated parameters for leader election.
  90. func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha1.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error {
  91. if err := autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil {
  92. return err
  93. }
  94. out.ResourceNamespace = in.ResourceNamespace
  95. out.LockObjectNamespace = in.ResourceNamespace
  96. out.ResourceName = in.ResourceName
  97. out.LockObjectName = in.ResourceName
  98. return nil
  99. }
  100. func Convert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error {
  101. if err := autoConvert_v1alpha1_Plugins_To_config_Plugins(in, out, s); err != nil {
  102. return err
  103. }
  104. if in.PostFilter != nil {
  105. postFilter, preScore := &in.PostFilter, &out.PreScore
  106. *preScore = new(config.PluginSet)
  107. if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*postFilter, *preScore, s); err != nil {
  108. return err
  109. }
  110. } else {
  111. out.PreScore = nil
  112. }
  113. return nil
  114. }
  115. func Convert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error {
  116. if err := autoConvert_config_Plugins_To_v1alpha1_Plugins(in, out, s); err != nil {
  117. return err
  118. }
  119. if in.PreScore != nil {
  120. preScore, postFilter := &in.PreScore, &out.PostFilter
  121. *postFilter = new(v1alpha1.PluginSet)
  122. if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*preScore, *postFilter, s); err != nil {
  123. return err
  124. }
  125. } else {
  126. out.PostFilter = nil
  127. }
  128. return nil
  129. }