Skip to content

Commit

Permalink
v1beta3 Pod refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
markturansky committed Nov 18, 2014
1 parent df0981b commit 8af4ccb
Show file tree
Hide file tree
Showing 36 changed files with 569 additions and 573 deletions.
6 changes: 3 additions & 3 deletions cmd/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func waitForPodRunning(c *client.Client, id string) {
glog.Warningf("Get pod failed: %v", err)
continue
}
if pod.CurrentState.Status == api.PodRunning {
if pod.Status.Condition == api.PodRunning {
break
}
glog.Infof("Waiting for pod status to be running (%s)", pod.CurrentState.Status)
glog.Infof("Waiting for pod status to be running (%s)", pod.Status.Condition)
}
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func TestPodUpdate(c *client.Client) bool {
value = "time" + value
pod.Labels["time"] = value
pod.ResourceVersion = podOut.ResourceVersion
pod.DesiredState.Manifest.UUID = podOut.DesiredState.Manifest.UUID
pod.UID = podOut.UID
pod, err = podClient.Update(pod)
if err != nil {
glog.Errorf("Failed to update pod: %v", err)
Expand Down
21 changes: 9 additions & 12 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func podsOnMinions(c *client.Client, pods api.PodList) wait.ConditionFunc {
podInfo := fakeKubeletClient{}
return func() (bool, error) {
for i := range pods.Items {
host, id, namespace := pods.Items[i].CurrentState.Host, pods.Items[i].Name, pods.Items[i].Namespace
host, id, namespace := pods.Items[i].Status.Host, pods.Items[i].Name, pods.Items[i].Namespace
if len(host) == 0 {
return false, nil
}
Expand Down Expand Up @@ -499,21 +499,18 @@ func runServiceTest(client *client.Client) {
"name": "thisisalonglabel",
},
},
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Version: "v1beta1",
Containers: []api.Container{
{
Name: "c1",
Image: "foo",
Ports: []api.Port{
{ContainerPort: 1234},
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "c1",
Image: "foo",
Ports: []api.Port{
{ContainerPort: 1234},
},
},
},
},
CurrentState: api.PodState{
Status: api.PodStatus{
PodIP: "1.2.3.4",
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func init() {

// Convert Pod to BoundPod
func(in *Pod, out *BoundPod, s conversion.Scope) error {
if err := s.Convert(&in.DesiredState.Manifest, out, 0); err != nil {
if err := s.Convert(&in.Spec, &out.Spec, 0); err != nil {
return err
}
// Only copy a subset of fields, and override manifest attributes with the pod
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/testapi/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func Codec() runtime.Codec {
return interfaces.Codec
}

// Converter returns the api.Scheme for the API version to test against, as set by the
// KUBE_API_VERSION env var.
func Converter() runtime.ObjectConvertor {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
}
return interfaces.ObjectConvertor
}

// MetadataAccessor returns the MetadataAccessor for the API version to test against,
// as set by the KUBE_API_VERSION env var.
func MetadataAccessor() meta.MetadataAccessor {
Expand Down
30 changes: 26 additions & 4 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,37 @@ type PodSpec struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty" yaml:"nodeSelector,omitempty"`
}

// PodStatus represents information about the status of a pod. Status may trail the actual
// state of a system.
type PodStatus struct {
Condition PodCondition `json:"condition,omitempty" yaml:"condition,omitempty"`

// Host is the name of the node that this Pod is currently bound to, or empty if no
// assignment has been done.
Host string `json:"host,omitempty" yaml:"host,omitempty"`
HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
PodIP string `json:"podIP,omitempty" yaml:"podIP,omitempty"`

// The key of this map is the *name* of the container within the manifest; it has one
// entry per container in the manifest. The value of this map is currently the output
// of `docker inspect`. This output format is *not* final and should not be relied
// upon.
// TODO: Make real decisions about what our info should look like. Re-enable fuzz test
// when we have done this.
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
}

// Pod is a collection of containers, used as either input (create, update) or as output (list, get).
type Pod struct {
TypeMeta `json:",inline" yaml:",inline"`
ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

DesiredState PodState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState PodState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
// NodeSelector is a selector which must be true for the pod to fit on a node
NodeSelector map[string]string `json:"nodeSelector,omitempty" yaml:"nodeSelector,omitempty"`
// Spec defines the behavior of a pod.
Spec PodSpec `json:"spec,omitempty" yaml:"spec,omitempty"`

// Status represents the current information about a pod. This data may not be up
// to date.
Status PodStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// PodTemplateSpec describes the data a pod should have when created from a template
Expand Down
57 changes: 46 additions & 11 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,32 @@ func init() {
return nil
},

func(in *newer.PodStatus, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in.Condition, &out.Status, 0); err != nil {
return err
}
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
return err
}
out.Host = in.Host
out.HostIP = in.HostIP
out.PodIP = in.PodIP
return nil
},
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error {
if err := s.Convert(&in.Status, &out.Condition, 0); err != nil {
return err
}
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
return err
}

out.Host = in.Host
out.HostIP = in.HostIP
out.PodIP = in.PodIP
return nil
},

// Convert all to the new PodCondition constants
func(in *newer.PodCondition, out *PodStatus, s conversion.Scope) error {
switch *in {
Expand Down Expand Up @@ -189,7 +215,7 @@ func init() {
case PodRunning:
*out = newer.PodRunning
case PodTerminated:
// Older API versions did not contain enough info to map to PodFailed
// Older API versions did not contain enough info to map to PodSucceeded
*out = newer.PodFailed
default:
return errors.New("The string provided is not a valid PodCondition constant value")
Expand All @@ -208,15 +234,13 @@ func init() {
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
return err
}
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
if err := s.Convert(&in.Status, &out.CurrentState, 0); err != nil {
return err
}

if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
if err := s.Convert(&in.Spec.NodeSelector, &out.NodeSelector, 0); err != nil {
return err
}
return nil
Expand All @@ -231,15 +255,13 @@ func init() {
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
return err
}
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
if err := s.Convert(&in.CurrentState, &out.Status, 0); err != nil {
return err
}

if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
if err := s.Convert(&in.NodeSelector, &out.Spec.NodeSelector, 0); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -326,6 +348,19 @@ func init() {
return nil
},

func(in *newer.PodSpec, out *BoundPod, s conversion.Scope) error {
if err := s.Convert(&in, &out.Spec, 0); err != nil {
return err
}
return nil
},
func(in *BoundPod, out *newer.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Spec, &out, 0); err != nil {
return err
}
return nil
},

func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
Expand Down
55 changes: 44 additions & 11 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func init() {
case PodRunning:
*out = newer.PodRunning
case PodTerminated:
// Older API versions did not contain enough info to map to PodFailed
// Older API versions did not contain enough info to map to PodSucceeded
*out = newer.PodFailed
default:
return errors.New("The string provided is not a valid PodCondition constant value")
Expand All @@ -138,15 +138,13 @@ func init() {
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
if err := s.Convert(&in.Spec, &out.DesiredState.Manifest, 0); err != nil {
return err
}
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
if err := s.Convert(&in.Status, &out.CurrentState, 0); err != nil {
return err
}

if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
if err := s.Convert(&in.Spec.NodeSelector, &out.NodeSelector, 0); err != nil {
return err
}
return nil
Expand All @@ -161,15 +159,13 @@ func init() {
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

if err := s.Convert(&in.DesiredState, &out.DesiredState, 0); err != nil {
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
return err
}
if err := s.Convert(&in.CurrentState, &out.CurrentState, 0); err != nil {
if err := s.Convert(&in.CurrentState, &out.Status, 0); err != nil {
return err
}

if err := s.Convert(&in.NodeSelector, &out.NodeSelector, 0); err != nil {
if err := s.Convert(&in.NodeSelector, &out.Spec.NodeSelector, 0); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -282,6 +278,43 @@ func init() {
return nil
},

func(in *newer.PodStatus, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in.Condition, &out.Status, 0); err != nil {
return err
}
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
return err
}
out.Host = in.Host
out.HostIP = in.HostIP
out.PodIP = in.PodIP
return nil
},
func(in *PodState, out *newer.PodStatus, s conversion.Scope) error {
if err := s.Convert(&in.Status, &out.Condition, 0); err != nil {
return err
}
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
return err
}
out.Host = in.Host
out.HostIP = in.HostIP
out.PodIP = in.PodIP
return nil
},

func(in *newer.PodSpec, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in, &out.Manifest, 0); err != nil {
return err
}
return nil
},
func(in *PodState, out *newer.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Manifest, &out, 0); err != nil {
return err
}
return nil
},
func(in *newer.Service, out *Service, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
Expand Down
16 changes: 8 additions & 8 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
if !util.IsDNSSubdomain(pod.Namespace) {
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace))
}
allErrs = append(allErrs, ValidatePodState(&pod.DesiredState).Prefix("desiredState")...)
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
allErrs = append(allErrs, validateLabels(pod.Labels)...)
return allErrs
}
Expand Down Expand Up @@ -383,22 +383,22 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList {
allErrs = append(allErrs, errs.NewFieldInvalid("name", newPod.Name))
}

if len(newPod.DesiredState.Manifest.Containers) != len(oldPod.DesiredState.Manifest.Containers) {
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
if len(newPod.Spec.Containers) != len(oldPod.Spec.Containers) {
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers))
return allErrs
}
pod := *newPod
pod.Labels = oldPod.Labels
pod.ResourceVersion = oldPod.ResourceVersion
// Tricky, we need to copy the container list so that we don't overwrite the update
var newContainers []api.Container
for ix, container := range pod.DesiredState.Manifest.Containers {
container.Image = oldPod.DesiredState.Manifest.Containers[ix].Image
for ix, container := range pod.Spec.Containers {
container.Image = oldPod.Spec.Containers[ix].Image
newContainers = append(newContainers, container)
}
pod.DesiredState.Manifest.Containers = newContainers
if !reflect.DeepEqual(pod.DesiredState.Manifest, oldPod.DesiredState.Manifest) {
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
pod.Spec.Containers = newContainers
if !reflect.DeepEqual(pod.Spec, oldPod.Spec) {
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers))
}
return allErrs
}
Expand Down
Loading

0 comments on commit 8af4ccb

Please sign in to comment.