MCPcopy Index your code
hub / github.com/docker/cli / runServiceScale

Function runServiceScale

cli/command/service/scale.go:95–119  ·  view source on GitHub ↗
(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64)

Source from the content-addressed store, hash-verified

93}
94
95func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64) (warnings []string, _ error) {
96 res, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{})
97 if err != nil {
98 return nil, err
99 }
100
101 serviceMode := &res.Service.Spec.Mode
102 switch {
103 case serviceMode.Replicated != nil:
104 serviceMode.Replicated.Replicas = &scale
105 case serviceMode.ReplicatedJob != nil:
106 serviceMode.ReplicatedJob.TotalCompletions = &scale
107 default:
108 return nil, errors.New("scale can only be used with replicated or replicated-job mode")
109 }
110
111 response, err := apiClient.ServiceUpdate(ctx, res.Service.ID, client.ServiceUpdateOptions{
112 Version: res.Service.Version,
113 Spec: res.Service.Spec,
114 })
115 if err != nil {
116 return nil, err
117 }
118 return response.Warnings, nil
119}
120
121// completeScaleArgs returns a completion function for the args of the scale command.
122// It completes service names followed by "=", suppressing the trailing space.

Callers 1

runScaleFunction · 0.85

Calls 2

ServiceInspectMethod · 0.45
ServiceUpdateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…