Skip to content

Commit e0716b5

Browse files
committed
Revert "Add memory swap to swarm"
This reverts commit 71828f2. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent ee244f2 commit e0716b5

File tree

13 files changed

+11
-98
lines changed

13 files changed

+11
-98
lines changed

cli/command/service/opts.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,15 @@ type resourceOptions struct {
235235
resCPU opts.NanoCPUs
236236
resMemBytes opts.MemBytes
237237
resGenericResources []string
238-
swapBytes opts.MemBytes
239-
memSwappiness int64
240238
}
241239

242-
func (r *resourceOptions) ToResourceRequirements(flags *pflag.FlagSet) (*swarm.ResourceRequirements, error) {
240+
func (r *resourceOptions) ToResourceRequirements() (*swarm.ResourceRequirements, error) {
243241
generic, err := ParseGenericResources(r.resGenericResources)
244242
if err != nil {
245243
return nil, err
246244
}
247245

248-
resreq := &swarm.ResourceRequirements{
246+
return &swarm.ResourceRequirements{
249247
Limits: &swarm.Limit{
250248
NanoCPUs: r.limitCPU.Value(),
251249
MemoryBytes: r.limitMemBytes.Value(),
@@ -256,20 +254,7 @@ func (r *resourceOptions) ToResourceRequirements(flags *pflag.FlagSet) (*swarm.R
256254
MemoryBytes: r.resMemBytes.Value(),
257255
GenericResources: generic,
258256
},
259-
}
260-
261-
// SwapBytes and MemorySwappiness are *int64 (pointers), so we need to have
262-
// a variable we can take a pointer to. Additionally, we need to ensure
263-
// that these values are only set if they are set as options.
264-
if flags.Changed(flagSwapBytes) {
265-
swapBytes := r.swapBytes.Value()
266-
resreq.SwapBytes = &swapBytes
267-
}
268-
if flags.Changed(flagMemSwappiness) {
269-
resreq.MemorySwappiness = &r.memSwappiness
270-
}
271-
272-
return resreq, nil
257+
}, nil
273258
}
274259

275260
type restartPolicyOptions struct {
@@ -749,7 +734,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
749734
return networks[i].Target < networks[j].Target
750735
})
751736

752-
resources, err := options.resources.ToResourceRequirements(flags)
737+
resources, err := options.resources.ToResourceRequirements()
753738
if err != nil {
754739
return service, err
755740
}
@@ -904,10 +889,6 @@ func addServiceFlags(flags *pflag.FlagSet, options *serviceOptions, defaultFlagV
904889
flags.Var(&options.resources.resMemBytes, flagReserveMemory, "Reserve Memory")
905890
flags.Int64Var(&options.resources.limitPids, flagLimitPids, 0, "Limit maximum number of processes (default 0 = unlimited)")
906891
flags.SetAnnotation(flagLimitPids, "version", []string{"1.41"})
907-
flags.Var(&options.resources.swapBytes, flagSwapBytes, "Swap Bytes (-1 for unlimited)")
908-
flags.SetAnnotation(flagLimitPids, "version", []string{"1.52"})
909-
flags.Int64Var(&options.resources.memSwappiness, flagMemSwappiness, -1, "Tune memory swappiness (0-100), -1 to reset to default")
910-
flags.SetAnnotation(flagLimitPids, "version", []string{"1.52"})
911892

912893
flags.Var(&options.stopGrace, flagStopGracePeriod, flagDesc(flagStopGracePeriod, "Time to wait before force killing a container (ns|us|ms|s|m|h)"))
913894
flags.Var(&options.replicas, flagReplicas, "Number of tasks")
@@ -1092,8 +1073,6 @@ const (
10921073
flagUlimitAdd = "ulimit-add"
10931074
flagUlimitRemove = "ulimit-rm"
10941075
flagOomScoreAdj = "oom-score-adj"
1095-
flagSwapBytes = "memory-swap"
1096-
flagMemSwappiness = "memory-swappiness"
10971076
)
10981077

10991078
func toNetipAddrSlice(ips []string) []netip.Addr {

cli/command/service/opts_test.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
163163
},
164164
}
165165

166-
flags := newCreateCommand(nil).Flags()
167-
168166
for _, opt := range incorrectOptions {
169-
_, err := opt.ToResourceRequirements(flags)
167+
_, err := opt.ToResourceRequirements()
170168
assert.Check(t, is.ErrorContains(err, ""))
171169
}
172170

@@ -180,41 +178,12 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
180178
}
181179

182180
for _, opt := range correctOptions {
183-
r, err := opt.ToResourceRequirements(flags)
181+
r, err := opt.ToResourceRequirements()
184182
assert.NilError(t, err)
185183
assert.Check(t, is.Len(r.Reservations.GenericResources, len(opt.resGenericResources)))
186184
}
187185
}
188186

189-
func TestResourceOptionsToResourceRequirementsSwap(t *testing.T) {
190-
// first, check that no flag set means no field set in the return
191-
flags := newCreateCommand(nil).Flags()
192-
193-
// These should be the default values of the field.
194-
swapOptions := resourceOptions{
195-
swapBytes: 0,
196-
memSwappiness: -1,
197-
}
198-
199-
r, err := swapOptions.ToResourceRequirements(flags)
200-
assert.NilError(t, err)
201-
assert.Check(t, is.Nil(r.SwapBytes))
202-
assert.Check(t, is.Nil(r.MemorySwappiness))
203-
204-
// now set the flags and some values
205-
flags.Set(flagSwapBytes, "86000")
206-
flags.Set(flagMemSwappiness, "23")
207-
swapOptions.swapBytes = 86000
208-
swapOptions.memSwappiness = 23
209-
210-
r, err = swapOptions.ToResourceRequirements(flags)
211-
assert.NilError(t, err)
212-
assert.Check(t, r.SwapBytes != nil)
213-
assert.Check(t, is.Equal(*(r.SwapBytes), int64(86000)))
214-
assert.Check(t, r.MemorySwappiness != nil)
215-
assert.Check(t, is.Equal(*(r.MemorySwappiness), int64(23)))
216-
}
217-
218187
func TestToServiceNetwork(t *testing.T) {
219188
nws := []network.Inspect{
220189
{

cli/compose/convert/service.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,6 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement
560560
GenericResources: generic,
561561
}
562562
}
563-
// These fields are themselves pointers -- we can simply assign, no need to
564-
// nil-check them. Nil is nil.
565-
resources.SwapBytes = source.MemswapLimit
566-
resources.MemorySwappiness = source.MemSwappiness
567563
return resources, nil
568564
}
569565

cli/compose/convert/service_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ func TestConvertExtraHosts(t *testing.T) {
8181
}
8282

8383
func TestConvertResourcesFull(t *testing.T) {
84-
// create some variables so we can get pointers
85-
memswap := int64(72090)
86-
swappiness := int64(27)
8784
source := composetypes.Resources{
8885
Limits: &composetypes.ResourceLimit{
8986
NanoCPUs: "0.003",
@@ -93,8 +90,6 @@ func TestConvertResourcesFull(t *testing.T) {
9390
NanoCPUs: "0.002",
9491
MemoryBytes: composetypes.UnitBytes(200000000),
9592
},
96-
MemswapLimit: &memswap,
97-
MemSwappiness: &swappiness,
9893
}
9994
resources, err := convertResources(source)
10095
assert.NilError(t, err)
@@ -108,8 +103,6 @@ func TestConvertResourcesFull(t *testing.T) {
108103
NanoCPUs: 2000000,
109104
MemoryBytes: 200000000,
110105
},
111-
SwapBytes: &memswap,
112-
MemorySwappiness: &swappiness,
113106
}
114107
assert.Check(t, is.DeepEqual(expected, resources))
115108
}

cli/compose/loader/full-example.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ services:
7979
- discrete_resource_spec:
8080
kind: 'ssd'
8181
value: 1
82-
memswap_limit: 86000
83-
mem_swappiness: 27
8482
restart_policy:
8583
condition: on-failure
8684
delay: 5s

cli/compose/loader/full-struct_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
108108
},
109109
},
110110
},
111-
MemswapLimit: int64Ptr(86000),
112-
MemSwappiness: int64Ptr(27),
113111
},
114112
RestartPolicy: &types.RestartPolicy{
115113
Condition: "on-failure",

cli/compose/loader/loader_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,6 @@ func uint32Ptr(value uint32) *uint32 {
970970
return &value
971971
}
972972

973-
func int64Ptr(value int64) *int64 {
974-
return &value
975-
}
976-
977973
func TestFullExample(t *testing.T) {
978974
skip.If(t, runtime.GOOS == "windows", "FIXME: substitutes platform-specific HOME-dirs and requires platform-specific golden files; see https://github.com/docker/cli/pull/4610")
979975

cli/compose/loader/testdata/full-example.json.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@
181181
}
182182
}
183183
]
184-
},
185-
"memswap_limit": 86000,
186-
"mem_swappiness": 27
184+
}
187185
},
188186
"restart_policy": {
189187
"condition": "on-failure",

cli/compose/loader/testdata/full-example.yaml.golden

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ services:
7373
- discrete_resource_spec:
7474
kind: ssd
7575
value: 1
76-
memswap_limit: 86000
77-
mem_swappiness: 27
7876
restart_policy:
7977
condition: on-failure
8078
delay: 5s

cli/compose/schema/data/config_schema_v3.14.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"$schema": "http://json-schema.org/draft-04/schema#",
3-
"id": "config_schema_v3.14.json",
3+
"id": "config_schema_v3.13.json",
44
"type": "object",
55

66
"properties": {
77
"version": {
88
"type": "string",
9-
"default": "3.14"
9+
"default": "3.13"
1010
},
1111

1212
"services": {
@@ -413,12 +413,6 @@
413413
"generic_resources": {"$ref": "#/definitions/generic_resources"}
414414
},
415415
"additionalProperties": false
416-
},
417-
"memswap_limit": {
418-
"type": "integer"
419-
},
420-
"mem_swappiness": {
421-
"type": "integer"
422416
}
423417
},
424418
"additionalProperties": false

0 commit comments

Comments
 (0)