mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Remaining refactor for PodTemplateSpec and fixing test cases
This commit is contained in:
parent
72bf12c86d
commit
94c873e7a4
@ -237,24 +237,24 @@ func runReplicationControllerTest(c *client.Client) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Unexpected error: %#v", err)
|
glog.Fatalf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
var controllerRequest api.ReplicationController
|
var controller api.ReplicationController
|
||||||
if err := json.Unmarshal(data, &controllerRequest); err != nil {
|
if err := json.Unmarshal(data, &controller); err != nil {
|
||||||
glog.Fatalf("Unexpected error: %#v", err)
|
glog.Fatalf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("Creating replication controllers")
|
glog.Infof("Creating replication controllers")
|
||||||
if _, err := c.ReplicationControllers(api.NamespaceDefault).Create(&controllerRequest); err != nil {
|
if _, err := c.ReplicationControllers(api.NamespaceDefault).Create(&controller); err != nil {
|
||||||
glog.Fatalf("Unexpected error: %#v", err)
|
glog.Fatalf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
glog.Infof("Done creating replication controllers")
|
glog.Infof("Done creating replication controllers")
|
||||||
|
|
||||||
// Give the controllers some time to actually create the pods
|
// Give the controllers some time to actually create the pods
|
||||||
if err := wait.Poll(time.Second, time.Second*30, c.ControllerHasDesiredReplicas(controllerRequest)); err != nil {
|
if err := wait.Poll(time.Second, time.Second*30, c.ControllerHasDesiredReplicas(controller)); err != nil {
|
||||||
glog.Fatalf("FAILED: pods never created %v", err)
|
glog.Fatalf("FAILED: pods never created %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for minions to indicate they have info about the desired pods
|
// wait for minions to indicate they have info about the desired pods
|
||||||
pods, err := c.Pods(api.NamespaceDefault).List(labels.Set(controllerRequest.DesiredState.ReplicaSelector).AsSelector())
|
pods, err := c.Pods(api.NamespaceDefault).List(labels.Set(controller.Spec.Selector).AsSelector())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("FAILED: unable to get pods to list: %v", err)
|
glog.Fatalf("FAILED: unable to get pods to list: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,18 @@ func validateObject(obj runtime.Object) (errors []error) {
|
|||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
switch t := obj.(type) {
|
switch t := obj.(type) {
|
||||||
case *api.ReplicationController:
|
case *api.ReplicationController:
|
||||||
errors = validation.ValidateManifest(&t.DesiredState.PodTemplate.DesiredState.Manifest)
|
if t.Namespace == "" {
|
||||||
|
t.Namespace = api.NamespaceDefault
|
||||||
|
}
|
||||||
|
errors = validation.ValidateReplicationController(t)
|
||||||
case *api.ReplicationControllerList:
|
case *api.ReplicationControllerList:
|
||||||
for i := range t.Items {
|
for i := range t.Items {
|
||||||
errors = append(errors, validateObject(&t.Items[i])...)
|
errors = append(errors, validateObject(&t.Items[i])...)
|
||||||
}
|
}
|
||||||
case *api.Service:
|
case *api.Service:
|
||||||
|
if t.Namespace == "" {
|
||||||
|
t.Namespace = api.NamespaceDefault
|
||||||
|
}
|
||||||
api.ValidNamespace(ctx, &t.ObjectMeta)
|
api.ValidNamespace(ctx, &t.ObjectMeta)
|
||||||
errors = validation.ValidateService(t, registrytest.NewServiceRegistry(), api.NewDefaultContext())
|
errors = validation.ValidateService(t, registrytest.NewServiceRegistry(), api.NewDefaultContext())
|
||||||
case *api.ServiceList:
|
case *api.ServiceList:
|
||||||
@ -49,8 +55,11 @@ func validateObject(obj runtime.Object) (errors []error) {
|
|||||||
errors = append(errors, validateObject(&t.Items[i])...)
|
errors = append(errors, validateObject(&t.Items[i])...)
|
||||||
}
|
}
|
||||||
case *api.Pod:
|
case *api.Pod:
|
||||||
|
if t.Namespace == "" {
|
||||||
|
t.Namespace = api.NamespaceDefault
|
||||||
|
}
|
||||||
api.ValidNamespace(ctx, &t.ObjectMeta)
|
api.ValidNamespace(ctx, &t.ObjectMeta)
|
||||||
errors = validation.ValidateManifest(&t.DesiredState.Manifest)
|
errors = validation.ValidatePod(t)
|
||||||
case *api.PodList:
|
case *api.PodList:
|
||||||
for i := range t.Items {
|
for i := range t.Items {
|
||||||
errors = append(errors, validateObject(&t.Items[i])...)
|
errors = append(errors, validateObject(&t.Items[i])...)
|
||||||
|
@ -75,6 +75,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
statuses := []internal.PodCondition{internal.PodPending, internal.PodRunning, internal.PodFailed}
|
statuses := []internal.PodCondition{internal.PodPending, internal.PodRunning, internal.PodFailed}
|
||||||
*j = statuses[c.Rand.Intn(len(statuses))]
|
*j = statuses[c.Rand.Intn(len(statuses))]
|
||||||
},
|
},
|
||||||
|
func(j *internal.ReplicationControllerSpec, c fuzz.Continue) {
|
||||||
|
// TemplateRef must be nil for round trip
|
||||||
|
c.Fuzz(&j.Template)
|
||||||
|
if j.Template == nil {
|
||||||
|
// TODO: v1beta1/2 can't round trip a nil template correctly, fix by having v1beta1/2
|
||||||
|
// conversion compare converted object to nil via DeepEqual
|
||||||
|
j.Template = &internal.PodTemplateSpec{}
|
||||||
|
}
|
||||||
|
j.Template.ObjectMeta = internal.ObjectMeta{Labels: j.Template.ObjectMeta.Labels}
|
||||||
|
j.Template.Spec.NodeSelector = nil
|
||||||
|
c.Fuzz(&j.Selector)
|
||||||
|
j.Replicas = int(c.RandUint64())
|
||||||
|
},
|
||||||
|
func(j *internal.ReplicationControllerStatus, c fuzz.Continue) {
|
||||||
|
// only replicas round trips
|
||||||
|
j.Replicas = int(c.RandUint64())
|
||||||
|
},
|
||||||
func(intstr *util.IntOrString, c fuzz.Continue) {
|
func(intstr *util.IntOrString, c fuzz.Continue) {
|
||||||
// util.IntOrString will panic if its kind is set wrong.
|
// util.IntOrString will panic if its kind is set wrong.
|
||||||
if c.RandBool() {
|
if c.RandBool() {
|
||||||
@ -127,6 +144,7 @@ func TestInternalRoundTrip(t *testing.T) {
|
|||||||
|
|
||||||
if err := internal.Scheme.Convert(obj, newer); err != nil {
|
if err := internal.Scheme.Convert(obj, newer); err != nil {
|
||||||
t.Errorf("unable to convert %#v to %#v: %v", obj, newer, err)
|
t.Errorf("unable to convert %#v to %#v: %v", obj, newer, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, err := internal.Scheme.New("", k)
|
actual, err := internal.Scheme.New("", k)
|
||||||
@ -137,6 +155,7 @@ func TestInternalRoundTrip(t *testing.T) {
|
|||||||
|
|
||||||
if err := internal.Scheme.Convert(newer, actual); err != nil {
|
if err := internal.Scheme.Convert(newer, actual); err != nil {
|
||||||
t.Errorf("unable to convert %#v to %#v: %v", newer, actual, err)
|
t.Errorf("unable to convert %#v to %#v: %v", newer, actual, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(obj, actual) {
|
if !reflect.DeepEqual(obj, actual) {
|
||||||
|
@ -90,6 +90,23 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed}
|
statuses := []api.PodCondition{api.PodPending, api.PodRunning, api.PodFailed}
|
||||||
*j = statuses[c.Rand.Intn(len(statuses))]
|
*j = statuses[c.Rand.Intn(len(statuses))]
|
||||||
},
|
},
|
||||||
|
func(j *api.ReplicationControllerSpec, c fuzz.Continue) {
|
||||||
|
// TemplateRef must be nil for round trip
|
||||||
|
c.Fuzz(&j.Template)
|
||||||
|
if j.Template == nil {
|
||||||
|
// TODO: v1beta1/2 can't round trip a nil template correctly, fix by having v1beta1/2
|
||||||
|
// conversion compare converted object to nil via DeepEqual
|
||||||
|
j.Template = &api.PodTemplateSpec{}
|
||||||
|
}
|
||||||
|
j.Template.ObjectMeta = api.ObjectMeta{Labels: j.Template.ObjectMeta.Labels}
|
||||||
|
j.Template.Spec.NodeSelector = nil
|
||||||
|
c.Fuzz(&j.Selector)
|
||||||
|
j.Replicas = int(c.RandUint64())
|
||||||
|
},
|
||||||
|
func(j *api.ReplicationControllerStatus, c fuzz.Continue) {
|
||||||
|
// only replicas round trips
|
||||||
|
j.Replicas = int(c.RandUint64())
|
||||||
|
},
|
||||||
func(intstr *util.IntOrString, c fuzz.Continue) {
|
func(intstr *util.IntOrString, c fuzz.Continue) {
|
||||||
// util.IntOrString will panic if its kind is set wrong.
|
// util.IntOrString will panic if its kind is set wrong.
|
||||||
if c.RandBool() {
|
if c.RandBool() {
|
||||||
@ -176,18 +193,21 @@ func TestSpecificKind(t *testing.T) {
|
|||||||
api.Scheme.Log(nil)
|
api.Scheme.Log(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTypes(t *testing.T) {
|
var nonRoundTrippableTypes = util.NewStringSet("ContainerManifest")
|
||||||
|
|
||||||
|
func TestRoundTripTypes(t *testing.T) {
|
||||||
for kind := range api.Scheme.KnownTypes("") {
|
for kind := range api.Scheme.KnownTypes("") {
|
||||||
|
if nonRoundTrippableTypes.Has(kind) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Try a few times, since runTest uses random values.
|
// Try a few times, since runTest uses random values.
|
||||||
for i := 0; i < *fuzzIters; i++ {
|
for i := 0; i < *fuzzIters; i++ {
|
||||||
item, err := api.Scheme.New("", kind)
|
item, err := api.Scheme.New("", kind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Couldn't make a %v? %v", kind, err)
|
t.Fatalf("Couldn't make a %v? %v", kind, err)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if _, err := meta.Accessor(item); err != nil {
|
if _, err := meta.Accessor(item); err != nil {
|
||||||
t.Logf("%s is not a TypeMeta and cannot be round tripped: %v", kind, err)
|
t.Fatalf("%q is not a TypeMeta and cannot be tested - add it to nonRoundTrippableTypes: %v", kind, err)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
runTest(t, v1beta1.Codec, item)
|
runTest(t, v1beta1.Codec, item)
|
||||||
runTest(t, v1beta2.Codec, item)
|
runTest(t, v1beta2.Codec, item)
|
||||||
|
@ -309,8 +309,9 @@ func TestListControllers(t *testing.T) {
|
|||||||
"name": "baz",
|
"name": "baz",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
|
Template: &api.PodTemplateSpec{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -335,8 +336,9 @@ func TestGetController(t *testing.T) {
|
|||||||
"name": "baz",
|
"name": "baz",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
|
Template: &api.PodTemplateSpec{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -361,8 +363,9 @@ func TestUpdateController(t *testing.T) {
|
|||||||
"name": "baz",
|
"name": "baz",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
|
Template: &api.PodTemplateSpec{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -396,8 +399,9 @@ func TestCreateController(t *testing.T) {
|
|||||||
"name": "baz",
|
"name": "baz",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
|
Template: &api.PodTemplateSpec{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -26,10 +26,10 @@ import (
|
|||||||
// for a controller's ReplicaSelector equals the Replicas count.
|
// for a controller's ReplicaSelector equals the Replicas count.
|
||||||
func (c *Client) ControllerHasDesiredReplicas(controller api.ReplicationController) wait.ConditionFunc {
|
func (c *Client) ControllerHasDesiredReplicas(controller api.ReplicationController) wait.ConditionFunc {
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
pods, err := c.Pods(controller.Namespace).List(labels.Set(controller.DesiredState.ReplicaSelector).AsSelector())
|
pods, err := c.Pods(controller.Namespace).List(labels.Set(controller.Spec.Selector).AsSelector())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return len(pods.Items) == controller.DesiredState.Replicas, nil
|
return len(pods.Items) == controller.Spec.Replicas, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,14 @@ type ReplicationManager struct {
|
|||||||
syncTime <-chan time.Time
|
syncTime <-chan time.Time
|
||||||
|
|
||||||
// To allow injection of syncReplicationController for testing.
|
// To allow injection of syncReplicationController for testing.
|
||||||
syncHandler func(controllerSpec api.ReplicationController) error
|
syncHandler func(controller api.ReplicationController) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodControlInterface is an interface that knows how to add or delete pods
|
// PodControlInterface is an interface that knows how to add or delete pods
|
||||||
// created as an interface to allow testing.
|
// created as an interface to allow testing.
|
||||||
type PodControlInterface interface {
|
type PodControlInterface interface {
|
||||||
// createReplica creates new replicated pods according to the spec.
|
// createReplica creates new replicated pods according to the spec.
|
||||||
createReplica(namespace string, controllerSpec api.ReplicationController)
|
createReplica(namespace string, controller api.ReplicationController)
|
||||||
// deletePod deletes the pod identified by podID.
|
// deletePod deletes the pod identified by podID.
|
||||||
deletePod(namespace string, podID string) error
|
deletePod(namespace string, podID string) error
|
||||||
}
|
}
|
||||||
@ -52,16 +52,19 @@ type RealPodControl struct {
|
|||||||
kubeClient client.Interface
|
kubeClient client.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r RealPodControl) createReplica(namespace string, controllerSpec api.ReplicationController) {
|
func (r RealPodControl) createReplica(namespace string, controller api.ReplicationController) {
|
||||||
desiredLabels := make(labels.Set)
|
desiredLabels := make(labels.Set)
|
||||||
for k, v := range controllerSpec.DesiredState.PodTemplate.Labels {
|
for k, v := range controller.Spec.Template.Labels {
|
||||||
desiredLabels[k] = v
|
desiredLabels[k] = v
|
||||||
}
|
}
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Labels: desiredLabels,
|
Labels: desiredLabels,
|
||||||
},
|
},
|
||||||
DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
|
}
|
||||||
|
if err := api.Scheme.Convert(&controller.Spec.Template.Spec, &pod.DesiredState.Manifest); err != nil {
|
||||||
|
glog.Errorf("Unable to convert pod template: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if _, err := r.kubeClient.Pods(namespace).Create(pod); err != nil {
|
if _, err := r.kubeClient.Pods(namespace).Create(pod); err != nil {
|
||||||
glog.Errorf("Unable to create pod replica: %v", err)
|
glog.Errorf("Unable to create pod replica: %v", err)
|
||||||
@ -142,14 +145,14 @@ func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rm *ReplicationManager) syncReplicationController(controllerSpec api.ReplicationController) error {
|
func (rm *ReplicationManager) syncReplicationController(controller api.ReplicationController) error {
|
||||||
s := labels.Set(controllerSpec.DesiredState.ReplicaSelector).AsSelector()
|
s := labels.Set(controller.Spec.Selector).AsSelector()
|
||||||
podList, err := rm.kubeClient.Pods(controllerSpec.Namespace).List(s)
|
podList, err := rm.kubeClient.Pods(controller.Namespace).List(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
filteredList := rm.filterActivePods(podList.Items)
|
filteredList := rm.filterActivePods(podList.Items)
|
||||||
diff := len(filteredList) - controllerSpec.DesiredState.Replicas
|
diff := len(filteredList) - controller.Spec.Replicas
|
||||||
if diff < 0 {
|
if diff < 0 {
|
||||||
diff *= -1
|
diff *= -1
|
||||||
wait := sync.WaitGroup{}
|
wait := sync.WaitGroup{}
|
||||||
@ -158,7 +161,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
|
|||||||
for i := 0; i < diff; i++ {
|
for i := 0; i < diff; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
defer wait.Done()
|
defer wait.Done()
|
||||||
rm.podControl.createReplica(controllerSpec.Namespace, controllerSpec)
|
rm.podControl.createReplica(controller.Namespace, controller)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wait.Wait()
|
wait.Wait()
|
||||||
@ -169,7 +172,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
|
|||||||
for i := 0; i < diff; i++ {
|
for i := 0; i < diff; i++ {
|
||||||
go func(ix int) {
|
go func(ix int) {
|
||||||
defer wait.Done()
|
defer wait.Done()
|
||||||
rm.podControl.deletePod(controllerSpec.Namespace, filteredList[ix].Name)
|
rm.podControl.deletePod(controller.Namespace, filteredList[ix].Name)
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wait.Wait()
|
wait.Wait()
|
||||||
@ -180,20 +183,20 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
|
|||||||
func (rm *ReplicationManager) synchronize() {
|
func (rm *ReplicationManager) synchronize() {
|
||||||
// TODO: remove this method completely and rely on the watch.
|
// TODO: remove this method completely and rely on the watch.
|
||||||
// Add resource version tracking to watch to make this work.
|
// Add resource version tracking to watch to make this work.
|
||||||
var controllerSpecs []api.ReplicationController
|
var controllers []api.ReplicationController
|
||||||
list, err := rm.kubeClient.ReplicationControllers(api.NamespaceAll).List(labels.Everything())
|
list, err := rm.kubeClient.ReplicationControllers(api.NamespaceAll).List(labels.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Synchronization error: %v (%#v)", err, err)
|
glog.Errorf("Synchronization error: %v (%#v)", err, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
controllerSpecs = list.Items
|
controllers = list.Items
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(len(controllerSpecs))
|
wg.Add(len(controllers))
|
||||||
for ix := range controllerSpecs {
|
for ix := range controllers {
|
||||||
go func(ix int) {
|
go func(ix int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
glog.V(4).Infof("periodic sync of %v", controllerSpecs[ix].Name)
|
glog.V(4).Infof("periodic sync of %v", controllers[ix].Name)
|
||||||
err := rm.syncHandler(controllerSpecs[ix])
|
err := rm.syncHandler(controllers[ix])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error synchronizing: %#v", err)
|
glog.Errorf("Error synchronizing: %#v", err)
|
||||||
}
|
}
|
||||||
|
@ -62,21 +62,21 @@ func (f *FakePodControl) deletePod(namespace string, podName string) error {
|
|||||||
|
|
||||||
func newReplicationController(replicas int) api.ReplicationController {
|
func newReplicationController(replicas int) api.ReplicationController {
|
||||||
return api.ReplicationController{
|
return api.ReplicationController{
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: replicas,
|
Replicas: replicas,
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Manifest: api.ContainerManifest{
|
Labels: map[string]string{
|
||||||
Containers: []api.Container{
|
"name": "foo",
|
||||||
{
|
"type": "production",
|
||||||
Image: "foo/bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Spec: api.PodSpec{
|
||||||
"name": "foo",
|
Containers: []api.Container{
|
||||||
"type": "production",
|
{
|
||||||
|
Image: "foo/bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -188,21 +188,21 @@ func TestCreateReplica(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Manifest: api.ContainerManifest{
|
Labels: map[string]string{
|
||||||
Containers: []api.Container{
|
"name": "foo",
|
||||||
{
|
"type": "production",
|
||||||
Image: "foo/bar",
|
"replicationController": "test",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Spec: api.PodSpec{
|
||||||
"name": "foo",
|
Containers: []api.Container{
|
||||||
"type": "production",
|
{
|
||||||
"replicationController": "test",
|
Image: "foo/bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -210,11 +210,18 @@ func TestCreateReplica(t *testing.T) {
|
|||||||
|
|
||||||
podControl.createReplica(ns, controllerSpec)
|
podControl.createReplica(ns, controllerSpec)
|
||||||
|
|
||||||
|
manifest := api.ContainerManifest{}
|
||||||
|
if err := api.Scheme.Convert(&controllerSpec.Spec.Template.Spec, &manifest); err != nil {
|
||||||
|
t.Fatalf("unexpected error", err)
|
||||||
|
}
|
||||||
|
|
||||||
expectedPod := api.Pod{
|
expectedPod := api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Labels: controllerSpec.DesiredState.PodTemplate.Labels,
|
Labels: controllerSpec.Spec.Template.Labels,
|
||||||
|
},
|
||||||
|
DesiredState: api.PodState{
|
||||||
|
Manifest: manifest,
|
||||||
},
|
},
|
||||||
DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
|
|
||||||
}
|
}
|
||||||
fakeHandler.ValidateRequest(t, makeURL("/pods?namespace=default"), "POST", nil)
|
fakeHandler.ValidateRequest(t, makeURL("/pods?namespace=default"), "POST", nil)
|
||||||
actualPod, err := client.Codec.Decode([]byte(fakeHandler.RequestBody))
|
actualPod, err := client.Codec.Decode([]byte(fakeHandler.RequestBody))
|
||||||
@ -230,42 +237,42 @@ func TestCreateReplica(t *testing.T) {
|
|||||||
func TestSynchonize(t *testing.T) {
|
func TestSynchonize(t *testing.T) {
|
||||||
controllerSpec1 := api.ReplicationController{
|
controllerSpec1 := api.ReplicationController{
|
||||||
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
|
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 4,
|
Replicas: 4,
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Manifest: api.ContainerManifest{
|
Labels: map[string]string{
|
||||||
Containers: []api.Container{
|
"name": "foo",
|
||||||
{
|
"type": "production",
|
||||||
Image: "foo/bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Spec: api.PodSpec{
|
||||||
"name": "foo",
|
Containers: []api.Container{
|
||||||
"type": "production",
|
{
|
||||||
|
Image: "foo/bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
controllerSpec2 := api.ReplicationController{
|
controllerSpec2 := api.ReplicationController{
|
||||||
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
|
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 3,
|
Replicas: 3,
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Manifest: api.ContainerManifest{
|
Labels: map[string]string{
|
||||||
Containers: []api.Container{
|
"name": "bar",
|
||||||
{
|
"type": "production",
|
||||||
Image: "bar/baz",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Spec: api.PodSpec{
|
||||||
"name": "bar",
|
Containers: []api.Container{
|
||||||
"type": "production",
|
{
|
||||||
|
Image: "bar/baz",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -134,14 +134,14 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(imageName) != 0 {
|
if len(imageName) != 0 {
|
||||||
controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image = imageName
|
controller.Spec.Template.Spec.Containers[0].Image = imageName
|
||||||
controller, err = client.ReplicationControllers(controller.Namespace).Update(controller)
|
controller, err = client.ReplicationControllers(controller.Namespace).Update(controller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s := labels.Set(controller.DesiredState.ReplicaSelector).AsSelector()
|
s := labels.Set(controller.Spec.Selector).AsSelector()
|
||||||
|
|
||||||
podList, err := client.Pods(api.Namespace(ctx)).List(s)
|
podList, err := client.Pods(api.Namespace(ctx)).List(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,7 +181,7 @@ func ResizeController(ctx api.Context, name string, replicas int, client client.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
controller.DesiredState.Replicas = replicas
|
controller.Spec.Replicas = replicas
|
||||||
controllerOut, err := client.ReplicationControllers(api.Namespace(ctx)).Update(controller)
|
controllerOut, err := client.ReplicationControllers(api.Namespace(ctx)).Update(controller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -251,26 +251,25 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: replicas,
|
Replicas: replicas,
|
||||||
ReplicaSelector: map[string]string{
|
Selector: map[string]string{
|
||||||
"name": name,
|
"name": name,
|
||||||
},
|
},
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Manifest: api.ContainerManifest{
|
Labels: map[string]string{
|
||||||
Version: "v1beta2",
|
"name": name,
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Name: strings.ToLower(name),
|
|
||||||
Image: image,
|
|
||||||
Ports: ports,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Spec: api.PodSpec{
|
||||||
"name": name,
|
Containers: []api.Container{
|
||||||
|
{
|
||||||
|
Name: strings.ToLower(name),
|
||||||
|
Image: image,
|
||||||
|
Ports: ports,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -328,8 +327,8 @@ func DeleteController(ctx api.Context, name string, client client.Interface) err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if controller.DesiredState.Replicas != 0 {
|
if controller.Spec.Replicas != 0 {
|
||||||
return fmt.Errorf("controller has non-zero replicas (%d), please stop it first", controller.DesiredState.Replicas)
|
return fmt.Errorf("controller has non-zero replicas (%d), please stop it first", controller.Spec.Replicas)
|
||||||
}
|
}
|
||||||
return client.ReplicationControllers(api.Namespace(ctx)).Delete(name)
|
return client.ReplicationControllers(api.Namespace(ctx)).Delete(name)
|
||||||
}
|
}
|
||||||
|
@ -74,13 +74,11 @@ func TestUpdateWithNewImage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Ctrl: api.ReplicationController{
|
Ctrl: api.ReplicationController{
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
Spec: api.PodSpec{
|
||||||
Manifest: api.ContainerManifest{
|
Containers: []api.Container{
|
||||||
Containers: []api.Container{
|
{Image: "fooImage:1"},
|
||||||
{Image: "fooImage:1"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -94,7 +92,7 @@ func TestUpdateWithNewImage(t *testing.T) {
|
|||||||
validateAction(client.FakeAction{Action: "get-controller", Value: "foo"}, fakeClient.Actions[0], t)
|
validateAction(client.FakeAction{Action: "get-controller", Value: "foo"}, fakeClient.Actions[0], t)
|
||||||
|
|
||||||
newCtrl := api.Scheme.CopyOrDie(&fakeClient.Ctrl).(*api.ReplicationController)
|
newCtrl := api.Scheme.CopyOrDie(&fakeClient.Ctrl).(*api.ReplicationController)
|
||||||
newCtrl.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image = "fooImage:2"
|
newCtrl.Spec.Template.Spec.Containers[0].Image = "fooImage:2"
|
||||||
validateAction(client.FakeAction{Action: "update-controller", Value: newCtrl}, fakeClient.Actions[1], t)
|
validateAction(client.FakeAction{Action: "update-controller", Value: newCtrl}, fakeClient.Actions[1], t)
|
||||||
|
|
||||||
validateAction(client.FakeAction{Action: "list-pods"}, fakeClient.Actions[2], t)
|
validateAction(client.FakeAction{Action: "list-pods"}, fakeClient.Actions[2], t)
|
||||||
@ -115,8 +113,8 @@ func TestRunController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller := fakeClient.Actions[0].Value.(*api.ReplicationController)
|
controller := fakeClient.Actions[0].Value.(*api.ReplicationController)
|
||||||
if controller.Name != name ||
|
if controller.Name != name ||
|
||||||
controller.DesiredState.Replicas != replicas ||
|
controller.Spec.Replicas != replicas ||
|
||||||
controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image != image {
|
controller.Spec.Template.Spec.Containers[0].Image != image {
|
||||||
t.Errorf("Unexpected controller: %#v", controller)
|
t.Errorf("Unexpected controller: %#v", controller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,8 +134,8 @@ func TestRunControllerWithWrongArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller := fakeClient.Actions[0].Value.(*api.ReplicationController)
|
controller := fakeClient.Actions[0].Value.(*api.ReplicationController)
|
||||||
if controller.Name != name ||
|
if controller.Name != name ||
|
||||||
controller.DesiredState.Replicas != replicas ||
|
controller.Spec.Replicas != replicas ||
|
||||||
controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image != image {
|
controller.Spec.Template.Spec.Containers[0].Image != image {
|
||||||
t.Errorf("Unexpected controller: %#v", controller)
|
t.Errorf("Unexpected controller: %#v", controller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,8 +153,8 @@ func TestRunControllerWithService(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller := fakeClient.Actions[0].Value.(*api.ReplicationController)
|
controller := fakeClient.Actions[0].Value.(*api.ReplicationController)
|
||||||
if controller.Name != name ||
|
if controller.Name != name ||
|
||||||
controller.DesiredState.Replicas != replicas ||
|
controller.Spec.Replicas != replicas ||
|
||||||
controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image != image {
|
controller.Spec.Template.Spec.Containers[0].Image != image {
|
||||||
t.Errorf("Unexpected controller: %#v", controller)
|
t.Errorf("Unexpected controller: %#v", controller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +172,7 @@ func TestStopController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller := fakeClient.Actions[1].Value.(*api.ReplicationController)
|
controller := fakeClient.Actions[1].Value.(*api.ReplicationController)
|
||||||
if fakeClient.Actions[1].Action != "update-controller" ||
|
if fakeClient.Actions[1].Action != "update-controller" ||
|
||||||
controller.DesiredState.Replicas != 0 {
|
controller.Spec.Replicas != 0 {
|
||||||
t.Errorf("Unexpected Action: %#v", fakeClient.Actions[1])
|
t.Errorf("Unexpected Action: %#v", fakeClient.Actions[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +191,7 @@ func TestResizeController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller := fakeClient.Actions[1].Value.(*api.ReplicationController)
|
controller := fakeClient.Actions[1].Value.(*api.ReplicationController)
|
||||||
if fakeClient.Actions[1].Action != "update-controller" ||
|
if fakeClient.Actions[1].Action != "update-controller" ||
|
||||||
controller.DesiredState.Replicas != 17 {
|
controller.Spec.Replicas != 17 {
|
||||||
t.Errorf("Unexpected Action: %#v", fakeClient.Actions[1])
|
t.Errorf("Unexpected Action: %#v", fakeClient.Actions[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +219,7 @@ func TestCloudCfgDeleteController(t *testing.T) {
|
|||||||
func TestCloudCfgDeleteControllerWithReplicas(t *testing.T) {
|
func TestCloudCfgDeleteControllerWithReplicas(t *testing.T) {
|
||||||
fakeClient := client.Fake{
|
fakeClient := client.Fake{
|
||||||
Ctrl: api.ReplicationController{
|
Ctrl: api.ReplicationController{
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -107,18 +107,15 @@ func TestParseController(t *testing.T) {
|
|||||||
DoParseTest(t, "replicationControllers", &api.ReplicationController{
|
DoParseTest(t, "replicationControllers", &api.ReplicationController{
|
||||||
TypeMeta: api.TypeMeta{APIVersion: "v1beta1", Kind: "ReplicationController"},
|
TypeMeta: api.TypeMeta{APIVersion: "v1beta1", Kind: "ReplicationController"},
|
||||||
ObjectMeta: api.ObjectMeta{Name: "my controller"},
|
ObjectMeta: api.ObjectMeta{Name: "my controller"},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 9001,
|
Replicas: 9001,
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
Spec: api.PodSpec{
|
||||||
Manifest: api.ContainerManifest{
|
Containers: []api.Container{
|
||||||
ID: "My manifest",
|
{Name: "my container"},
|
||||||
Containers: []api.Container{
|
},
|
||||||
{Name: "my container"},
|
Volumes: []api.Volume{
|
||||||
},
|
{Name: "volume"},
|
||||||
Volumes: []api.Volume{
|
|
||||||
{Name: "volume"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -185,6 +185,14 @@ func makeImageList(manifest api.ContainerManifest) string {
|
|||||||
return strings.Join(images, ",")
|
return strings.Join(images, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeImageListPodSpec(spec api.PodSpec) string {
|
||||||
|
var images []string
|
||||||
|
for _, container := range spec.Containers {
|
||||||
|
images = append(images, container.Image)
|
||||||
|
}
|
||||||
|
return strings.Join(images, ",")
|
||||||
|
}
|
||||||
|
|
||||||
func podHostString(host, ip string) string {
|
func podHostString(host, ip string) string {
|
||||||
if host == "" && ip == "" {
|
if host == "" && ip == "" {
|
||||||
return "<unassigned>"
|
return "<unassigned>"
|
||||||
@ -211,8 +219,8 @@ func printPodList(podList *api.PodList, w io.Writer) error {
|
|||||||
|
|
||||||
func printReplicationController(controller *api.ReplicationController, w io.Writer) error {
|
func printReplicationController(controller *api.ReplicationController, w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n",
|
||||||
controller.Name, makeImageList(controller.DesiredState.PodTemplate.DesiredState.Manifest),
|
controller.Name, makeImageListPodSpec(controller.Spec.Template.Spec),
|
||||||
labels.Set(controller.DesiredState.ReplicaSelector), controller.DesiredState.Replicas)
|
labels.Set(controller.Spec.Selector), controller.Spec.Replicas)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,9 +87,15 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove me when pods are converted
|
||||||
|
spec := &api.PodSpec{}
|
||||||
|
if err := api.Scheme.Convert(&pod.DesiredState.Manifest, spec); err != nil {
|
||||||
|
glog.Errorf("Unable to convert pod manifest: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return tabbedString(func(out *tabwriter.Writer) error {
|
return tabbedString(func(out *tabwriter.Writer) error {
|
||||||
fmt.Fprintf(out, "Name:\t%s\n", pod.Name)
|
fmt.Fprintf(out, "Name:\t%s\n", pod.Name)
|
||||||
fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(pod.DesiredState.Manifest))
|
fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(spec))
|
||||||
fmt.Fprintf(out, "Host:\t%s\n", pod.CurrentState.Host+"/"+pod.CurrentState.HostIP)
|
fmt.Fprintf(out, "Host:\t%s\n", pod.CurrentState.Host+"/"+pod.CurrentState.HostIP)
|
||||||
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(pod.Labels))
|
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(pod.Labels))
|
||||||
fmt.Fprintf(out, "Status:\t%s\n", string(pod.CurrentState.Status))
|
fmt.Fprintf(out, "Status:\t%s\n", string(pod.CurrentState.Status))
|
||||||
@ -127,10 +133,10 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string) (strin
|
|||||||
|
|
||||||
return tabbedString(func(out *tabwriter.Writer) error {
|
return tabbedString(func(out *tabwriter.Writer) error {
|
||||||
fmt.Fprintf(out, "Name:\t%s\n", controller.Name)
|
fmt.Fprintf(out, "Name:\t%s\n", controller.Name)
|
||||||
fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(controller.DesiredState.PodTemplate.DesiredState.Manifest))
|
fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(&controller.Spec.Template.Spec))
|
||||||
fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(controller.DesiredState.ReplicaSelector))
|
fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(controller.Spec.Selector))
|
||||||
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(controller.Labels))
|
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(controller.Labels))
|
||||||
fmt.Fprintf(out, "Replicas:\t%d current / %d desired\n", controller.CurrentState.Replicas, controller.DesiredState.Replicas)
|
fmt.Fprintf(out, "Replicas:\t%d current / %d desired\n", controller.Status.Replicas, controller.Spec.Replicas)
|
||||||
fmt.Fprintf(out, "Pods Status:\t%d Running / %d Waiting / %d Succeeded / %d Failed\n", running, waiting, succeeded, failed)
|
fmt.Fprintf(out, "Pods Status:\t%d Running / %d Waiting / %d Succeeded / %d Failed\n", running, waiting, succeeded, failed)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -197,7 +203,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
|
|||||||
// Find the ones that match labelsToMatch.
|
// Find the ones that match labelsToMatch.
|
||||||
var matchingRCs []api.ReplicationController
|
var matchingRCs []api.ReplicationController
|
||||||
for _, controller := range rcs.Items {
|
for _, controller := range rcs.Items {
|
||||||
selector := labels.SelectorFromSet(controller.DesiredState.ReplicaSelector)
|
selector := labels.SelectorFromSet(controller.Spec.Selector)
|
||||||
if selector.Matches(labelsToMatch) {
|
if selector.Matches(labelsToMatch) {
|
||||||
matchingRCs = append(matchingRCs, controller)
|
matchingRCs = append(matchingRCs, controller)
|
||||||
}
|
}
|
||||||
@ -206,7 +212,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
|
|||||||
// Format the matching RC's into strings.
|
// Format the matching RC's into strings.
|
||||||
var rcStrings []string
|
var rcStrings []string
|
||||||
for _, controller := range matchingRCs {
|
for _, controller := range matchingRCs {
|
||||||
rcStrings = append(rcStrings, fmt.Sprintf("%s (%d/%d replicas created)", controller.Name, controller.CurrentState.Replicas, controller.DesiredState.Replicas))
|
rcStrings = append(rcStrings, fmt.Sprintf("%s (%d/%d replicas created)", controller.Name, controller.Status.Replicas, controller.Spec.Replicas))
|
||||||
}
|
}
|
||||||
|
|
||||||
list := strings.Join(rcStrings, ", ")
|
list := strings.Join(rcStrings, ", ")
|
||||||
@ -217,7 +223,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getPodStatusForReplicationController(c client.PodInterface, controller *api.ReplicationController) (running, waiting, succeeded, failed int, err error) {
|
func getPodStatusForReplicationController(c client.PodInterface, controller *api.ReplicationController) (running, waiting, succeeded, failed int, err error) {
|
||||||
rcPods, err := c.List(labels.SelectorFromSet(controller.DesiredState.ReplicaSelector))
|
rcPods, err := c.List(labels.SelectorFromSet(controller.Spec.Selector))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -139,9 +139,9 @@ func formatLabels(labelMap map[string]string) string {
|
|||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeImageList(manifest api.ContainerManifest) string {
|
func makeImageList(spec *api.PodSpec) string {
|
||||||
var images []string
|
var images []string
|
||||||
for _, container := range manifest.Containers {
|
for _, container := range spec.Containers {
|
||||||
images = append(images, container.Image)
|
images = append(images, container.Image)
|
||||||
}
|
}
|
||||||
return strings.Join(images, ",")
|
return strings.Join(images, ",")
|
||||||
|
@ -206,8 +206,14 @@ func podHostString(host, ip string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printPod(pod *api.Pod, w io.Writer) error {
|
func printPod(pod *api.Pod, w io.Writer) error {
|
||||||
|
// TODO: remove me when pods are converted
|
||||||
|
spec := &api.PodSpec{}
|
||||||
|
if err := api.Scheme.Convert(&pod.DesiredState.Manifest, spec); err != nil {
|
||||||
|
glog.Errorf("Unable to convert pod manifest: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
|
||||||
pod.Name, makeImageList(pod.DesiredState.Manifest),
|
pod.Name, makeImageList(spec),
|
||||||
podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP),
|
podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP),
|
||||||
labels.Set(pod.Labels), pod.CurrentState.Status)
|
labels.Set(pod.Labels), pod.CurrentState.Status)
|
||||||
return err
|
return err
|
||||||
@ -224,8 +230,8 @@ func printPodList(podList *api.PodList, w io.Writer) error {
|
|||||||
|
|
||||||
func printReplicationController(controller *api.ReplicationController, w io.Writer) error {
|
func printReplicationController(controller *api.ReplicationController, w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n",
|
||||||
controller.Name, makeImageList(controller.DesiredState.PodTemplate.DesiredState.Manifest),
|
controller.Name, makeImageList(&controller.Spec.Template.Spec),
|
||||||
labels.Set(controller.DesiredState.ReplicaSelector), controller.DesiredState.Replicas)
|
labels.Set(controller.Spec.Selector), controller.Spec.Replicas)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +64,6 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
|
|||||||
if len(controller.Name) == 0 {
|
if len(controller.Name) == 0 {
|
||||||
controller.Name = util.NewUUID().String()
|
controller.Name = util.NewUUID().String()
|
||||||
}
|
}
|
||||||
// Pod Manifest ID should be assigned by the pod API
|
|
||||||
controller.DesiredState.PodTemplate.DesiredState.Manifest.ID = ""
|
|
||||||
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
||||||
return nil, errors.NewInvalid("replicationController", controller.Name, errs)
|
return nil, errors.NewInvalid("replicationController", controller.Name, errs)
|
||||||
}
|
}
|
||||||
@ -158,41 +156,41 @@ func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVer
|
|||||||
// TODO(lavalamp): remove watch.Filter, which is broken. Implement consistent way of filtering.
|
// TODO(lavalamp): remove watch.Filter, which is broken. Implement consistent way of filtering.
|
||||||
// TODO(lavalamp): this watch method needs a test.
|
// TODO(lavalamp): this watch method needs a test.
|
||||||
return watch.Filter(incoming, func(e watch.Event) (watch.Event, bool) {
|
return watch.Filter(incoming, func(e watch.Event) (watch.Event, bool) {
|
||||||
repController, ok := e.Object.(*api.ReplicationController)
|
controller, ok := e.Object.(*api.ReplicationController)
|
||||||
if !ok {
|
if !ok {
|
||||||
// must be an error event-- pass it on
|
// must be an error event-- pass it on
|
||||||
return e, true
|
return e, true
|
||||||
}
|
}
|
||||||
match := label.Matches(labels.Set(repController.Labels))
|
match := label.Matches(labels.Set(controller.Labels))
|
||||||
if match {
|
if match {
|
||||||
rs.fillCurrentState(ctx, repController)
|
rs.fillCurrentState(ctx, controller)
|
||||||
}
|
}
|
||||||
return e, match
|
return e, match
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *REST) waitForController(ctx api.Context, ctrl *api.ReplicationController) (runtime.Object, error) {
|
func (rs *REST) waitForController(ctx api.Context, controller *api.ReplicationController) (runtime.Object, error) {
|
||||||
for {
|
for {
|
||||||
pods, err := rs.podLister.ListPods(ctx, labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
|
pods, err := rs.podLister.ListPods(ctx, labels.Set(controller.Spec.Selector).AsSelector())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctrl, err
|
return controller, err
|
||||||
}
|
}
|
||||||
if len(pods.Items) == ctrl.DesiredState.Replicas {
|
if len(pods.Items) == controller.Spec.Replicas {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(rs.pollPeriod)
|
time.Sleep(rs.pollPeriod)
|
||||||
}
|
}
|
||||||
return ctrl, nil
|
return controller, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *REST) fillCurrentState(ctx api.Context, ctrl *api.ReplicationController) error {
|
func (rs *REST) fillCurrentState(ctx api.Context, controller *api.ReplicationController) error {
|
||||||
if rs.podLister == nil {
|
if rs.podLister == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
list, err := rs.podLister.ListPods(ctx, labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
|
list, err := rs.podLister.ListPods(ctx, labels.Set(controller.Spec.Selector).AsSelector())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctrl.CurrentState.Replicas = len(list.Items)
|
controller.Status.Replicas = len(list.Items)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,15 @@ func TestControllerDecode(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
|
Spec: api.ReplicationControllerSpec{
|
||||||
|
Template: &api.PodTemplateSpec{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"name": "nginx",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
body, err := latest.Codec.Encode(controller)
|
body, err := latest.Codec.Encode(controller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -140,30 +149,30 @@ func TestControllerParsing(t *testing.T) {
|
|||||||
"name": "nginx",
|
"name": "nginx",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
ReplicaSelector: map[string]string{
|
Selector: map[string]string{
|
||||||
"name": "nginx",
|
"name": "nginx",
|
||||||
},
|
},
|
||||||
PodTemplate: api.PodTemplate{
|
Template: &api.PodTemplateSpec{
|
||||||
DesiredState: api.PodState{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Manifest: api.ContainerManifest{
|
Labels: map[string]string{
|
||||||
Containers: []api.Container{
|
"name": "nginx",
|
||||||
{
|
},
|
||||||
Image: "dockerfile/nginx",
|
},
|
||||||
Ports: []api.Port{
|
Spec: api.PodSpec{
|
||||||
{
|
Containers: []api.Container{
|
||||||
ContainerPort: 80,
|
{
|
||||||
HostPort: 8080,
|
Image: "dockerfile/nginx",
|
||||||
},
|
Ports: []api.Port{
|
||||||
|
{
|
||||||
|
ContainerPort: 80,
|
||||||
|
HostPort: 8080,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
|
||||||
"name": "nginx",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -205,9 +214,11 @@ func TestControllerParsing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var validPodTemplate = api.PodTemplate{
|
var validPodTemplate = api.PodTemplate{
|
||||||
DesiredState: api.PodState{
|
Spec: api.PodTemplateSpec{
|
||||||
Manifest: api.ContainerManifest{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Version: "v1beta1",
|
Labels: map[string]string{"a": "b"},
|
||||||
|
},
|
||||||
|
Spec: api.PodSpec{
|
||||||
Containers: []api.Container{
|
Containers: []api.Container{
|
||||||
{
|
{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -216,7 +227,6 @@ var validPodTemplate = api.PodTemplate{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Labels: map[string]string{"a": "b"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateController(t *testing.T) {
|
func TestCreateController(t *testing.T) {
|
||||||
@ -240,10 +250,10 @@ func TestCreateController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
controller := &api.ReplicationController{
|
controller := &api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test"},
|
ObjectMeta: api.ObjectMeta{Name: "test"},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
ReplicaSelector: map[string]string{"a": "b"},
|
Selector: map[string]string{"a": "b"},
|
||||||
PodTemplate: validPodTemplate,
|
Template: &validPodTemplate.Spec,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
@ -273,13 +283,13 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
|
|||||||
failureCases := map[string]api.ReplicationController{
|
failureCases := map[string]api.ReplicationController{
|
||||||
"empty ID": {
|
"empty ID": {
|
||||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
ReplicaSelector: map[string]string{"bar": "baz"},
|
Selector: map[string]string{"bar": "baz"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"empty selector": {
|
"empty selector": {
|
||||||
ObjectMeta: api.ObjectMeta{Name: "abc"},
|
ObjectMeta: api.ObjectMeta{Name: "abc"},
|
||||||
DesiredState: api.ReplicationControllerState{},
|
Spec: api.ReplicationControllerSpec{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
@ -304,13 +314,13 @@ func TestControllerStorageValidatesUpdate(t *testing.T) {
|
|||||||
failureCases := map[string]api.ReplicationController{
|
failureCases := map[string]api.ReplicationController{
|
||||||
"empty ID": {
|
"empty ID": {
|
||||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
ReplicaSelector: map[string]string{"bar": "baz"},
|
Selector: map[string]string{"bar": "baz"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"empty selector": {
|
"empty selector": {
|
||||||
ObjectMeta: api.ObjectMeta{Name: "abc"},
|
ObjectMeta: api.ObjectMeta{Name: "abc"},
|
||||||
DesiredState: api.ReplicationControllerState{},
|
Spec: api.ReplicationControllerSpec{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
@ -351,19 +361,19 @@ func TestFillCurrentState(t *testing.T) {
|
|||||||
podLister: &fakeLister,
|
podLister: &fakeLister,
|
||||||
}
|
}
|
||||||
controller := api.ReplicationController{
|
controller := api.ReplicationController{
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
ReplicaSelector: map[string]string{
|
Selector: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
storage.fillCurrentState(ctx, &controller)
|
storage.fillCurrentState(ctx, &controller)
|
||||||
if controller.CurrentState.Replicas != 2 {
|
if controller.Status.Replicas != 2 {
|
||||||
t.Errorf("expected 2, got: %d", controller.CurrentState.Replicas)
|
t.Errorf("expected 2, got: %d", controller.Status.Replicas)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(fakeLister.s, labels.Set(controller.DesiredState.ReplicaSelector).AsSelector()) {
|
if !reflect.DeepEqual(fakeLister.s, labels.Set(controller.Spec.Selector).AsSelector()) {
|
||||||
t.Errorf("unexpected output: %#v %#v", labels.Set(controller.DesiredState.ReplicaSelector).AsSelector(), fakeLister.s)
|
t.Errorf("unexpected output: %#v %#v", labels.Set(controller.Spec.Selector).AsSelector(), fakeLister.s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -960,7 +960,7 @@ func TestEtcdUpdateController(t *testing.T) {
|
|||||||
registry := NewTestEtcdRegistry(fakeClient)
|
registry := NewTestEtcdRegistry(fakeClient)
|
||||||
err := registry.UpdateController(ctx, &api.ReplicationController{
|
err := registry.UpdateController(ctx, &api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)},
|
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)},
|
||||||
DesiredState: api.ReplicationControllerState{
|
Spec: api.ReplicationControllerSpec{
|
||||||
Replicas: 2,
|
Replicas: 2,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -969,7 +969,7 @@ func TestEtcdUpdateController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctrl, err := registry.GetController(ctx, "foo")
|
ctrl, err := registry.GetController(ctx, "foo")
|
||||||
if ctrl.DesiredState.Replicas != 2 {
|
if ctrl.Spec.Replicas != 2 {
|
||||||
t.Errorf("Unexpected controller: %#v", ctrl)
|
t.Errorf("Unexpected controller: %#v", ctrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user