From 30ba67aee013b62128e5281dff03c7bc97168626 Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Wed, 28 Jun 2017 15:02:54 -0700 Subject: [PATCH] Do not add duplicate platform information to service spec Signed-off-by: Nishant Totla Upstream-commit: da85b62001ec390bdc30b321c4a5cd23c17eeb81 Component: engine --- components/engine/client/service_create.go | 12 +++++++----- components/engine/client/service_update.go | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/engine/client/service_create.go b/components/engine/client/service_create.go index 71a7583e86..c2fc2776a8 100644 --- a/components/engine/client/service_create.go +++ b/components/engine/client/service_create.go @@ -39,7 +39,7 @@ func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, service.TaskTemplate.ContainerSpec.Image = img } // add platforms that are compatible with the service - service.TaskTemplate.Placement = updateServicePlatforms(service.TaskTemplate.Placement, distributionInspect) + service.TaskTemplate.Placement = setServicePlatforms(service.TaskTemplate.Placement, distributionInspect) } } var response types.ServiceCreateResponse @@ -86,13 +86,15 @@ func imageWithTagString(image string) string { return "" } -// updateServicePlatforms updates the Platforms in swarm.Placement to list -// all compatible platforms for the service, as found in distributionInspect -// and returns a pointer to the new or updated swarm.Placement struct -func updateServicePlatforms(placement *swarm.Placement, distributionInspect registrytypes.DistributionInspect) *swarm.Placement { +// setServicePlatforms sets Platforms in swarm.Placement to list all +// compatible platforms for the service, as found in distributionInspect +// and returns a pointer to the new or updated swarm.Placement struct. +func setServicePlatforms(placement *swarm.Placement, distributionInspect registrytypes.DistributionInspect) *swarm.Placement { if placement == nil { placement = &swarm.Placement{} } + // reset any existing listed platforms + placement.Platforms = []swarm.Platform{} for _, p := range distributionInspect.Platforms { placement.Platforms = append(placement.Platforms, swarm.Platform{ Architecture: p.Architecture, diff --git a/components/engine/client/service_update.go b/components/engine/client/service_update.go index 412790b5dd..a72adc997c 100644 --- a/components/engine/client/service_update.go +++ b/components/engine/client/service_update.go @@ -51,7 +51,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version service.TaskTemplate.ContainerSpec.Image = img } // add platforms that are compatible with the service - service.TaskTemplate.Placement = updateServicePlatforms(service.TaskTemplate.Placement, distributionInspect) + service.TaskTemplate.Placement = setServicePlatforms(service.TaskTemplate.Placement, distributionInspect) } }