Skip to content

Commit 00e3442

Browse files
committed
Merge pull request kubernetes#13002 from nikhiljindal/registerDeployment
Register deployment API Object
2 parents 655645e + c664b5b commit 00e3442

File tree

8 files changed

+3248
-74
lines changed

8 files changed

+3248
-74
lines changed

pkg/expapi/deep_copy_generated.go

Lines changed: 728 additions & 0 deletions
Large diffs are not rendered by default.

pkg/expapi/register.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func init() {
2828
// Adds the list of known types to api.Scheme.
2929
func addKnownTypes() {
3030
api.Scheme.AddKnownTypes("",
31+
&Deployment{},
32+
&DeploymentList{},
3133
&HorizontalPodAutoscaler{},
3234
&HorizontalPodAutoscalerList{},
3335
&ReplicationControllerDummy{},
@@ -37,6 +39,8 @@ func addKnownTypes() {
3739
)
3840
}
3941

42+
func (*Deployment) IsAnAPIObject() {}
43+
func (*DeploymentList) IsAnAPIObject() {}
4044
func (*HorizontalPodAutoscaler) IsAnAPIObject() {}
4145
func (*HorizontalPodAutoscalerList) IsAnAPIObject() {}
4246
func (*ReplicationControllerDummy) IsAnAPIObject() {}

pkg/expapi/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,10 @@ type DeploymentStatus struct {
264264
// Total number of new ready pods with the desired template spec.
265265
UpdatedReplicas int `json:"updatedReplicas,omitempty"`
266266
}
267+
268+
type DeploymentList struct {
269+
api.TypeMeta `json:",inline"`
270+
api.ListMeta `json:"metadata,omitempty"`
271+
272+
Items []Deployment `json:"items"`
273+
}

pkg/expapi/v1/conversion.go

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,156 @@ limitations under the License.
1616

1717
package v1
1818

19-
func addConversionFuncs() {}
19+
import (
20+
"reflect"
21+
22+
"k8s.io/kubernetes/pkg/api"
23+
v1 "k8s.io/kubernetes/pkg/api/v1"
24+
"k8s.io/kubernetes/pkg/conversion"
25+
)
26+
27+
func addConversionFuncs() {
28+
// Add non-generated conversion functions
29+
err := api.Scheme.AddConversionFuncs(
30+
convert_api_PodSpec_To_v1_PodSpec,
31+
convert_v1_PodSpec_To_api_PodSpec,
32+
)
33+
if err != nil {
34+
// If one of the conversion functions is malformed, detect it immediately.
35+
panic(err)
36+
}
37+
}
38+
39+
// The following two PodSpec conversions functions where copied from pkg/api/conversion.go
40+
// for the generated functions to work properly.
41+
// This should be fixed: https://github.com/kubernetes/kubernetes/issues/12977
42+
func convert_api_PodSpec_To_v1_PodSpec(in *api.PodSpec, out *v1.PodSpec, s conversion.Scope) error {
43+
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
44+
defaulting.(func(*api.PodSpec))(in)
45+
}
46+
if in.Volumes != nil {
47+
out.Volumes = make([]v1.Volume, len(in.Volumes))
48+
for i := range in.Volumes {
49+
if err := convert_api_Volume_To_v1_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
50+
return err
51+
}
52+
}
53+
} else {
54+
out.Volumes = nil
55+
}
56+
if in.Containers != nil {
57+
out.Containers = make([]v1.Container, len(in.Containers))
58+
for i := range in.Containers {
59+
if err := convert_api_Container_To_v1_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
60+
return err
61+
}
62+
}
63+
} else {
64+
out.Containers = nil
65+
}
66+
out.RestartPolicy = v1.RestartPolicy(in.RestartPolicy)
67+
if in.TerminationGracePeriodSeconds != nil {
68+
out.TerminationGracePeriodSeconds = new(int64)
69+
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
70+
} else {
71+
out.TerminationGracePeriodSeconds = nil
72+
}
73+
if in.ActiveDeadlineSeconds != nil {
74+
out.ActiveDeadlineSeconds = new(int64)
75+
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
76+
} else {
77+
out.ActiveDeadlineSeconds = nil
78+
}
79+
out.DNSPolicy = v1.DNSPolicy(in.DNSPolicy)
80+
if in.NodeSelector != nil {
81+
out.NodeSelector = make(map[string]string)
82+
for key, val := range in.NodeSelector {
83+
out.NodeSelector[key] = val
84+
}
85+
} else {
86+
out.NodeSelector = nil
87+
}
88+
out.ServiceAccountName = in.ServiceAccountName
89+
// DeprecatedServiceAccount is an alias for ServiceAccountName.
90+
out.DeprecatedServiceAccount = in.ServiceAccountName
91+
out.NodeName = in.NodeName
92+
out.HostNetwork = in.HostNetwork
93+
if in.ImagePullSecrets != nil {
94+
out.ImagePullSecrets = make([]v1.LocalObjectReference, len(in.ImagePullSecrets))
95+
for i := range in.ImagePullSecrets {
96+
if err := convert_api_LocalObjectReference_To_v1_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
97+
return err
98+
}
99+
}
100+
} else {
101+
out.ImagePullSecrets = nil
102+
}
103+
return nil
104+
}
105+
106+
func convert_v1_PodSpec_To_api_PodSpec(in *v1.PodSpec, out *api.PodSpec, s conversion.Scope) error {
107+
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
108+
defaulting.(func(*v1.PodSpec))(in)
109+
}
110+
if in.Volumes != nil {
111+
out.Volumes = make([]api.Volume, len(in.Volumes))
112+
for i := range in.Volumes {
113+
if err := convert_v1_Volume_To_api_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
114+
return err
115+
}
116+
}
117+
} else {
118+
out.Volumes = nil
119+
}
120+
if in.Containers != nil {
121+
out.Containers = make([]api.Container, len(in.Containers))
122+
for i := range in.Containers {
123+
if err := convert_v1_Container_To_api_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
124+
return err
125+
}
126+
}
127+
} else {
128+
out.Containers = nil
129+
}
130+
out.RestartPolicy = api.RestartPolicy(in.RestartPolicy)
131+
if in.TerminationGracePeriodSeconds != nil {
132+
out.TerminationGracePeriodSeconds = new(int64)
133+
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
134+
} else {
135+
out.TerminationGracePeriodSeconds = nil
136+
}
137+
if in.ActiveDeadlineSeconds != nil {
138+
out.ActiveDeadlineSeconds = new(int64)
139+
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
140+
} else {
141+
out.ActiveDeadlineSeconds = nil
142+
}
143+
out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
144+
if in.NodeSelector != nil {
145+
out.NodeSelector = make(map[string]string)
146+
for key, val := range in.NodeSelector {
147+
out.NodeSelector[key] = val
148+
}
149+
} else {
150+
out.NodeSelector = nil
151+
}
152+
// We support DeprecatedServiceAccount as an alias for ServiceAccountName.
153+
// If both are specified, ServiceAccountName (the new field) wins.
154+
out.ServiceAccountName = in.ServiceAccountName
155+
if in.ServiceAccountName == "" {
156+
out.ServiceAccountName = in.DeprecatedServiceAccount
157+
}
158+
out.NodeName = in.NodeName
159+
out.HostNetwork = in.HostNetwork
160+
if in.ImagePullSecrets != nil {
161+
out.ImagePullSecrets = make([]api.LocalObjectReference, len(in.ImagePullSecrets))
162+
for i := range in.ImagePullSecrets {
163+
if err := convert_v1_LocalObjectReference_To_api_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
164+
return err
165+
}
166+
}
167+
} else {
168+
out.ImagePullSecrets = nil
169+
}
170+
return nil
171+
}

0 commit comments

Comments
 (0)