X Tutup
Skip to content

Commit da85b62

Browse files
committed
Do not add duplicate platform information to service spec
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
1 parent 8b29ba5 commit da85b62

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

client/service_create.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec,
3939
service.TaskTemplate.ContainerSpec.Image = img
4040
}
4141
// add platforms that are compatible with the service
42-
service.TaskTemplate.Placement = updateServicePlatforms(service.TaskTemplate.Placement, distributionInspect)
42+
service.TaskTemplate.Placement = setServicePlatforms(service.TaskTemplate.Placement, distributionInspect)
4343
}
4444
}
4545
var response types.ServiceCreateResponse
@@ -86,13 +86,15 @@ func imageWithTagString(image string) string {
8686
return ""
8787
}
8888

89-
// updateServicePlatforms updates the Platforms in swarm.Placement to list
90-
// all compatible platforms for the service, as found in distributionInspect
91-
// and returns a pointer to the new or updated swarm.Placement struct
92-
func updateServicePlatforms(placement *swarm.Placement, distributionInspect registrytypes.DistributionInspect) *swarm.Placement {
89+
// setServicePlatforms sets Platforms in swarm.Placement to list all
90+
// compatible platforms for the service, as found in distributionInspect
91+
// and returns a pointer to the new or updated swarm.Placement struct.
92+
func setServicePlatforms(placement *swarm.Placement, distributionInspect registrytypes.DistributionInspect) *swarm.Placement {
9393
if placement == nil {
9494
placement = &swarm.Placement{}
9595
}
96+
// reset any existing listed platforms
97+
placement.Platforms = []swarm.Platform{}
9698
for _, p := range distributionInspect.Platforms {
9799
placement.Platforms = append(placement.Platforms, swarm.Platform{
98100
Architecture: p.Architecture,

client/service_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version
5151
service.TaskTemplate.ContainerSpec.Image = img
5252
}
5353
// add platforms that are compatible with the service
54-
service.TaskTemplate.Placement = updateServicePlatforms(service.TaskTemplate.Placement, distributionInspect)
54+
service.TaskTemplate.Placement = setServicePlatforms(service.TaskTemplate.Placement, distributionInspect)
5555
}
5656
}
5757

0 commit comments

Comments
 (0)
X Tutup