Insert the current state of a replica controller.

This commit is contained in:
Brendan Burns 2014-09-09 15:23:34 -07:00
parent 1fd12778eb
commit 4ba4762827
3 changed files with 13 additions and 1 deletions

View File

@ -324,6 +324,7 @@ func (*ReplicationControllerList) IsAnAPIObject() {}
type ReplicationController struct {
JSONBase `json:",inline" yaml:",inline"`
DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState ReplicationControllerState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

View File

@ -17,10 +17,10 @@ limitations under the License.
package v1beta1
import (
"github.com/fsouza/go-dockerclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/fsouza/go-dockerclient"
)
// Common string formats
@ -337,6 +337,7 @@ func (*ReplicationControllerList) IsAnAPIObject() {}
type ReplicationController struct {
JSONBase `json:",inline" yaml:",inline"`
DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
CurrentState ReplicationControllerState `json:"currentState,omitempty" yaml:"currentState,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

View File

@ -92,6 +92,7 @@ func (rs *REST) Get(id string) (runtime.Object, error) {
if err != nil {
return nil, err
}
rs.fillCurrentState(&controller)
return controller, err
}
@ -104,6 +105,7 @@ func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
filtered := []api.ReplicationController{}
for _, controller := range controllers.Items {
if selector.Matches(labels.Set(controller.Labels)) {
rs.fillCurrentState(&controller)
filtered = append(filtered, controller)
}
}
@ -164,3 +166,11 @@ func (rs *REST) waitForController(ctrl *api.ReplicationController) (runtime.Obje
}
return ctrl, nil
}
func (rs *REST) fillCurrentState(ctrl *api.ReplicationController) error {
list, err := rs.podLister.ListPods(ctrl.DesiredState.ReplicaSelector)
if err != nil {
return err
}
ctrl.CurrentState.Replicas = len(list.Items)
}