-
Notifications
You must be signed in to change notification settings - Fork 38.6k
/
conversion.go
119 lines (103 loc) · 5 KB
/
conversion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"fmt"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kube-scheduler/config/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
)
// Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration converts to the internal.
func Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error {
if err := autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil {
return err
}
if in.HardPodAffinitySymmetricWeight != nil {
args := interpodaffinity.Args{HardPodAffinityWeight: in.HardPodAffinitySymmetricWeight}
plCfg := plugins.NewPluginConfig(interpodaffinity.Name, args)
out.PluginConfig = append(out.PluginConfig, plCfg)
}
return nil
}
// Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration handles deprecated parameters for leader election.
func Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in *v1alpha1.KubeSchedulerLeaderElectionConfiguration, out *config.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error {
if err := autoConvert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil {
return err
}
if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) == 0 {
out.ResourceNamespace = in.ResourceNamespace
} else if len(in.ResourceNamespace) == 0 && len(in.LockObjectNamespace) > 0 {
out.ResourceNamespace = in.LockObjectNamespace
} else if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) > 0 {
if in.ResourceNamespace == in.LockObjectNamespace {
out.ResourceNamespace = in.ResourceNamespace
} else {
return fmt.Errorf("ResourceNamespace and LockObjectNamespace are both set and do not match, ResourceNamespace: %s, LockObjectNamespace: %s", in.ResourceNamespace, in.LockObjectNamespace)
}
}
if len(in.ResourceName) > 0 && len(in.LockObjectName) == 0 {
out.ResourceName = in.ResourceName
} else if len(in.ResourceName) == 0 && len(in.LockObjectName) > 0 {
out.ResourceName = in.LockObjectName
} else if len(in.ResourceName) > 0 && len(in.LockObjectName) > 0 {
if in.ResourceName == in.LockObjectName {
out.ResourceName = in.ResourceName
} else {
return fmt.Errorf("ResourceName and LockObjectName are both set and do not match, ResourceName: %s, LockObjectName: %s", in.ResourceName, in.LockObjectName)
}
}
return nil
}
// Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration handles deprecated parameters for leader election.
func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha1.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error {
if err := autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil {
return err
}
out.ResourceNamespace = in.ResourceNamespace
out.LockObjectNamespace = in.ResourceNamespace
out.ResourceName = in.ResourceName
out.LockObjectName = in.ResourceName
return nil
}
func Convert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error {
if err := autoConvert_v1alpha1_Plugins_To_config_Plugins(in, out, s); err != nil {
return err
}
if in.PostFilter != nil {
postFilter, preScore := &in.PostFilter, &out.PreScore
*preScore = new(config.PluginSet)
if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*postFilter, *preScore, s); err != nil {
return err
}
} else {
out.PreScore = nil
}
return nil
}
func Convert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error {
if err := autoConvert_config_Plugins_To_v1alpha1_Plugins(in, out, s); err != nil {
return err
}
if in.PreScore != nil {
preScore, postFilter := &in.PreScore, &out.PostFilter
*postFilter = new(v1alpha1.PluginSet)
if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*preScore, *postFilter, s); err != nil {
return err
}
} else {
out.PostFilter = nil
}
return nil
}