Skip to content

Commit 1c52460

Browse files
Merge pull request kubernetes#2097 from markturansky/v1beta3_podrefactor
Refactor internal API for Pods to match v1beta3
2 parents 218c5fb + 8af4ccb commit 1c52460

36 files changed

+569
-573
lines changed

cmd/e2e/e2e.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func waitForPodRunning(c *client.Client, id string) {
4646
glog.Warningf("Get pod failed: %v", err)
4747
continue
4848
}
49-
if pod.CurrentState.Status == api.PodRunning {
49+
if pod.Status.Condition == api.PodRunning {
5050
break
5151
}
52-
glog.Infof("Waiting for pod status to be running (%s)", pod.CurrentState.Status)
52+
glog.Infof("Waiting for pod status to be running (%s)", pod.Status.Condition)
5353
}
5454
}
5555

@@ -153,7 +153,7 @@ func TestPodUpdate(c *client.Client) bool {
153153
value = "time" + value
154154
pod.Labels["time"] = value
155155
pod.ResourceVersion = podOut.ResourceVersion
156-
pod.DesiredState.Manifest.UUID = podOut.DesiredState.Manifest.UUID
156+
pod.UID = podOut.UID
157157
pod, err = podClient.Update(pod)
158158
if err != nil {
159159
glog.Errorf("Failed to update pod: %v", err)

cmd/integration/integration.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func podsOnMinions(c *client.Client, pods api.PodList) wait.ConditionFunc {
216216
podInfo := fakeKubeletClient{}
217217
return func() (bool, error) {
218218
for i := range pods.Items {
219-
host, id, namespace := pods.Items[i].CurrentState.Host, pods.Items[i].Name, pods.Items[i].Namespace
219+
host, id, namespace := pods.Items[i].Status.Host, pods.Items[i].Name, pods.Items[i].Namespace
220220
if len(host) == 0 {
221221
return false, nil
222222
}
@@ -499,21 +499,18 @@ func runServiceTest(client *client.Client) {
499499
"name": "thisisalonglabel",
500500
},
501501
},
502-
DesiredState: api.PodState{
503-
Manifest: api.ContainerManifest{
504-
Version: "v1beta1",
505-
Containers: []api.Container{
506-
{
507-
Name: "c1",
508-
Image: "foo",
509-
Ports: []api.Port{
510-
{ContainerPort: 1234},
511-
},
502+
Spec: api.PodSpec{
503+
Containers: []api.Container{
504+
{
505+
Name: "c1",
506+
Image: "foo",
507+
Ports: []api.Port{
508+
{ContainerPort: 1234},
512509
},
513510
},
514511
},
515512
},
516-
CurrentState: api.PodState{
513+
Status: api.PodStatus{
517514
PodIP: "1.2.3.4",
518515
},
519516
}

pkg/api/conversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func init() {
8181

8282
// Convert Pod to BoundPod
8383
func(in *Pod, out *BoundPod, s conversion.Scope) error {
84-
if err := s.Convert(&in.DesiredState.Manifest, out, 0); err != nil {
84+
if err := s.Convert(&in.Spec, &out.Spec, 0); err != nil {
8585
return err
8686
}
8787
// Only copy a subset of fields, and override manifest attributes with the pod

pkg/api/testapi/testapi.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ func Codec() runtime.Codec {
4545
return interfaces.Codec
4646
}
4747

48+
// Converter returns the api.Scheme for the API version to test against, as set by the
49+
// KUBE_API_VERSION env var.
50+
func Converter() runtime.ObjectConvertor {
51+
interfaces, err := latest.InterfacesFor(Version())
52+
if err != nil {
53+
panic(err)
54+
}
55+
return interfaces.ObjectConvertor
56+
}
57+
4858
// MetadataAccessor returns the MetadataAccessor for the API version to test against,
4959
// as set by the KUBE_API_VERSION env var.
5060
func MetadataAccessor() meta.MetadataAccessor {

pkg/api/types.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,37 @@ type PodSpec struct {
455455
NodeSelector map[string]string `json:"nodeSelector,omitempty" yaml:"nodeSelector,omitempty"`
456456
}
457457

458+
// PodStatus represents information about the status of a pod. Status may trail the actual
459+
// state of a system.
460+
type PodStatus struct {
461+
Condition PodCondition `json:"condition,omitempty" yaml:"condition,omitempty"`
462+
463+
// Host is the name of the node that this Pod is currently bound to, or empty if no
464+
// assignment has been done.
465+
Host string `json:"host,omitempty" yaml:"host,omitempty"`
466+
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
467+
PodIP string `json:"podIP,omitempty" yaml:"podIP,omitempty"`
468+
469+
// The key of this map is the *name* of the container within the manifest; it has one
470+
// entry per container in the manifest. The value of this map is currently the output
471+
// of `docker inspect`. This output format is *not* final and should not be relied
472+
// upon.
473+
// TODO: Make real decisions about what our info should look like. Re-enable fuzz test
474+
// when we have done this.
475+
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
476+
}
477+
458478
// Pod is a collection of containers, used as either input (create, update) or as output (list, get).
459479
type Pod struct {
460480
TypeMeta `json:",inline" yaml:",inline"`
461481
ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
462482

463-
DesiredState PodState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
464-
CurrentState PodState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
465-
// NodeSelector is a selector which must be true for the pod to fit on a node
466-
NodeSelector map[string]string `json:"nodeSelector,omitempty" yaml:"nodeSelector,omitempty"`
483+
// Spec defines the behavior of a pod.
484+
Spec PodSpec `json:"spec,omitempty" yaml:"spec,omitempty"`
485+
486+
// Status represents the current information about a pod. This data may not be up
487+
// to date.
488+
Status PodStatus `json:"status,omitempty" yaml:"status,omitempty"`
467489
}
468490

469491
// PodTemplateSpec describes the data a pod should have when created from a template

pkg/api/v1beta1/conversion.go

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,32 @@ func init() {
160160
return nil
161161
},
162162

163+
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error {
164+
if err := s.Convert(&in.Condition, &out.Status, 0); err != nil {
165+
return err
166+
}
167+
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
168+
return err
169+
}
170+
out.Host = in.Host
171+
out.HostIP = in.HostIP
172+
out.PodIP = in.PodIP
173+
return nil
174+
},
175+
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error {
176+
if err := s.Convert(&in.Status, &out.Condition, 0); err != nil {
177+
return err
178+
}
179+
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
180+
return err
181+
}
182+
183+
out.Host = in.Host
184+
out.HostIP = in.HostIP
185+
out.PodIP = in.PodIP
186+
return nil
187+
},
188+
163189
// Convert all to the new PodCondition constants
164190
func(in *newer.PodCondition, out *PodStatus, s conversion.Scope) error {
165191
switch *in {
@@ -189,7 +215,7 @@ func init() {
189215
case PodRunning:
190216
*out = newer.PodRunning
191217
case PodTerminated:
192-
// Older API versions did not contain enough info to map to PodFailed
218+
// Older API versions did not contain enough info to map to PodSucceeded
193219
*out = newer.PodFailed
194220
default:
195221
return errors.New("The string provided is not a valid PodCondition constant value")
@@ -208,15 +234,13 @@ func init() {
208234
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
209235
return err
210236
}
211-
212-
if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
237+
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
213238
return err
214239
}
215-
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
240+
if err := s.Convert(&in.Status, &out.CurrentState, 0); err != nil {
216241
return err
217242
}
218-
219-
if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
243+
if err := s.Convert(&in.Spec.NodeSelector, &out.NodeSelector, 0); err != nil {
220244
return err
221245
}
222246
return nil
@@ -231,15 +255,13 @@ func init() {
231255
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
232256
return err
233257
}
234-
235-
if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
258+
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
236259
return err
237260
}
238-
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
261+
if err := s.Convert(&in.CurrentState, &out.Status, 0); err != nil {
239262
return err
240263
}
241-
242-
if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
264+
if err := s.Convert(&in.NodeSelector, &out.Spec.NodeSelector, 0); err != nil {
243265
return err
244266
}
245267
return nil
@@ -326,6 +348,19 @@ func init() {
326348
return nil
327349
},
328350

351+
func(in *newer.PodSpec, out *BoundPod, s conversion.Scope) error {
352+
if err := s.Convert(&in, &out.Spec, 0); err != nil {
353+
return err
354+
}
355+
return nil
356+
},
357+
func(in *BoundPod, out *newer.PodSpec, s conversion.Scope) error {
358+
if err := s.Convert(&in.Spec, &out, 0); err != nil {
359+
return err
360+
}
361+
return nil
362+
},
363+
329364
func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error {
330365
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
331366
return err

pkg/api/v1beta2/conversion.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func init() {
119119
case PodRunning:
120120
*out = newer.PodRunning
121121
case PodTerminated:
122-
// Older API versions did not contain enough info to map to PodFailed
122+
// Older API versions did not contain enough info to map to PodSucceeded
123123
*out = newer.PodFailed
124124
default:
125125
return errors.New("The string provided is not a valid PodCondition constant value")
@@ -138,15 +138,13 @@ func init() {
138138
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
139139
return err
140140
}
141-
142-
if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
141+
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
143142
return err
144143
}
145-
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
144+
if err := s.Convert(&in.Status, &out.CurrentState, 0); err != nil {
146145
return err
147146
}
148-
149-
if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
147+
if err := s.Convert(&in.Spec.NodeSelector, &out.NodeSelector, 0); err != nil {
150148
return err
151149
}
152150
return nil
@@ -161,15 +159,13 @@ func init() {
161159
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
162160
return err
163161
}
164-
165-
if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
162+
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
166163
return err
167164
}
168-
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
165+
if err := s.Convert(&in.CurrentState, &out.Status, 0); err != nil {
169166
return err
170167
}
171-
172-
if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
168+
if err := s.Convert(&in.NodeSelector, &out.Spec.NodeSelector, 0); err != nil {
173169
return err
174170
}
175171
return nil
@@ -282,6 +278,43 @@ func init() {
282278
return nil
283279
},
284280

281+
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error {
282+
if err := s.Convert(&in.Condition, &out.Status, 0); err != nil {
283+
return err
284+
}
285+
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
286+
return err
287+
}
288+
out.Host = in.Host
289+
out.HostIP = in.HostIP
290+
out.PodIP = in.PodIP
291+
return nil
292+
},
293+
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error {
294+
if err := s.Convert(&in.Status, &out.Condition, 0); err != nil {
295+
return err
296+
}
297+
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
298+
return err
299+
}
300+
out.Host = in.Host
301+
out.HostIP = in.HostIP
302+
out.PodIP = in.PodIP
303+
return nil
304+
},
305+
306+
func(in *newer.PodSpec, out *PodState, s conversion.Scope) error {
307+
if err := s.Convert(&in, &out.Manifest, 0); err != nil {
308+
return err
309+
}
310+
return nil
311+
},
312+
func(in *PodState, out *newer.PodSpec, s conversion.Scope) error {
313+
if err := s.Convert(&in.Manifest, &out, 0); err != nil {
314+
return err
315+
}
316+
return nil
317+
},
285318
func(in *newer.Service, out *Service, s conversion.Scope) error {
286319
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
287320
return err

pkg/api/validation/validation.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
345345
if !util.IsDNSSubdomain(pod.Namespace) {
346346
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace))
347347
}
348-
allErrs = append(allErrs, ValidatePodState(&pod.DesiredState).Prefix("desiredState")...)
348+
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
349349
allErrs = append(allErrs, validateLabels(pod.Labels)...)
350350
return allErrs
351351
}
@@ -383,22 +383,22 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList {
383383
allErrs = append(allErrs, errs.NewFieldInvalid("name", newPod.Name))
384384
}
385385

386-
if len(newPod.DesiredState.Manifest.Containers) != len(oldPod.DesiredState.Manifest.Containers) {
387-
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
386+
if len(newPod.Spec.Containers) != len(oldPod.Spec.Containers) {
387+
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers))
388388
return allErrs
389389
}
390390
pod := *newPod
391391
pod.Labels = oldPod.Labels
392392
pod.ResourceVersion = oldPod.ResourceVersion
393393
// Tricky, we need to copy the container list so that we don't overwrite the update
394394
var newContainers []api.Container
395-
for ix, container := range pod.DesiredState.Manifest.Containers {
396-
container.Image = oldPod.DesiredState.Manifest.Containers[ix].Image
395+
for ix, container := range pod.Spec.Containers {
396+
container.Image = oldPod.Spec.Containers[ix].Image
397397
newContainers = append(newContainers, container)
398398
}
399-
pod.DesiredState.Manifest.Containers = newContainers
400-
if !reflect.DeepEqual(pod.DesiredState.Manifest, oldPod.DesiredState.Manifest) {
401-
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
399+
pod.Spec.Containers = newContainers
400+
if !reflect.DeepEqual(pod.Spec, oldPod.Spec) {
401+
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers))
402402
}
403403
return allErrs
404404
}

0 commit comments

Comments
 (0)