fix panic on --label-add
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 85bc3194aa
)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
84eae5d69f
commit
07735b4f0c
3 changed files with 43 additions and 3 deletions
|
@ -250,7 +250,7 @@ func updatePlacement(flags *pflag.FlagSet, placement *swarm.Placement) {
|
|||
|
||||
func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
|
||||
if flags.Changed(flagLabelAdd) {
|
||||
if field == nil {
|
||||
if *field == nil {
|
||||
*field = map[string]string{}
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
|
|||
}
|
||||
}
|
||||
|
||||
if field != nil && flags.Changed(flagLabelRemove) {
|
||||
if *field != nil && flags.Changed(flagLabelRemove) {
|
||||
toRemove := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetAll()
|
||||
for _, label := range toRemove {
|
||||
delete(*field, label)
|
||||
|
|
|
@ -120,7 +120,6 @@ func (d *SwarmDaemon) getService(c *check.C, id string) *swarm.Service {
|
|||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(json.Unmarshal(out, &service), checker.IsNil)
|
||||
c.Assert(service.ID, checker.Equals, id)
|
||||
return &service
|
||||
}
|
||||
|
||||
|
|
|
@ -43,3 +43,44 @@ func (s *DockerSwarmSuite) TestServiceUpdatePort(c *check.C) {
|
|||
}
|
||||
c.Assert(portConfig, checker.DeepEquals, expected)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestServiceUpdateLabel(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
out, err := d.Cmd("service", "create", "--name=test", "busybox", "top")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
service := d.getService(c, "test")
|
||||
c.Assert(service.Spec.Labels, checker.HasLen, 0)
|
||||
|
||||
// add label to empty set
|
||||
out, err = d.Cmd("service", "update", "test", "--label-add", "foo=bar")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
service = d.getService(c, "test")
|
||||
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
||||
c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar")
|
||||
|
||||
// add label to non-empty set
|
||||
out, err = d.Cmd("service", "update", "test", "--label-add", "foo2=bar")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
service = d.getService(c, "test")
|
||||
c.Assert(service.Spec.Labels, checker.HasLen, 2)
|
||||
c.Assert(service.Spec.Labels["foo2"], checker.Equals, "bar")
|
||||
|
||||
out, err = d.Cmd("service", "update", "test", "--label-rm", "foo2")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
service = d.getService(c, "test")
|
||||
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
||||
c.Assert(service.Spec.Labels["foo2"], checker.Equals, "")
|
||||
|
||||
out, err = d.Cmd("service", "update", "test", "--label-rm", "foo")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
service = d.getService(c, "test")
|
||||
c.Assert(service.Spec.Labels, checker.HasLen, 0)
|
||||
c.Assert(service.Spec.Labels["foo"], checker.Equals, "")
|
||||
|
||||
// now make sure we can add again
|
||||
out, err = d.Cmd("service", "update", "test", "--label-add", "foo=bar")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
service = d.getService(c, "test")
|
||||
c.Assert(service.Spec.Labels, checker.HasLen, 1)
|
||||
c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue