func TestConvertToUlimits(t *testing.T) {
	softLimit := int64(1024)
	hardLimit := int64(2048)
	typeName := "nofile"
	basicType := yaml.NewUlimit(typeName, softLimit, softLimit)         // "nofile=1024"
	typeWithHardLimit := yaml.NewUlimit(typeName, softLimit, hardLimit) // "nofile=1024:2048"

	ulimitsIn := yaml.Ulimits{
		Elements: []yaml.Ulimit{basicType, typeWithHardLimit},
	}
	ulimitsOut, err := convertToULimits(ulimitsIn)
	if err != nil {
		t.Errorf("Expected to convert [%v] ulimits without errors. But got [%v]", ulimitsIn, err)
	}
	if len(ulimitsIn.Elements) != len(ulimitsOut) {
		t.Errorf("Incorrect conversion. Input [%v] Output [%v]", ulimitsIn, ulimitsOut)
	}
	verifyUlimit(t, ulimitsOut[0], typeName, softLimit, softLimit)
	verifyUlimit(t, ulimitsOut[1], typeName, softLimit, hardLimit)
}
func TestConvertToTaskDefinitionWithUlimits(t *testing.T) {
	softLimit := int64(1024)
	typeName := "nofile"
	basicType := yaml.NewUlimit(typeName, softLimit, softLimit) // "nofile=1024"
	serviceConfig := &config.ServiceConfig{
		Ulimits: yaml.Ulimits{Elements: []yaml.Ulimit{basicType}},
	}

	taskDefinition := convertToTaskDefinitionInTest(t, "name", serviceConfig)
	containerDef := *taskDefinition.ContainerDefinitions[0]
	verifyUlimit(t, containerDef.Ulimits[0], typeName, softLimit, softLimit)
}
Пример #3
0
func newTestConfig() TestConfig {
	return TestConfig{
		SystemContainers: map[string]*ServiceConfig{
			"udev": {
				Image:       "udev",
				Restart:     "always",
				NetworkMode: "host",
				Privileged:  true,
				DNS:         []string{"8.8.8.8", "8.8.4.4"},
				Environment: yamlTypes.MaporEqualSlice([]string{
					"DAEMON=true",
				}),
				Labels: yamlTypes.SliceorMap{
					"io.rancher.os.detach": "true",
					"io.rancher.os.scope":  "system",
				},
				VolumesFrom: []string{
					"system-volumes",
				},
				Ulimits: yamlTypes.Ulimits{
					Elements: []yamlTypes.Ulimit{
						yamlTypes.NewUlimit("nproc", 65557, 65557),
					},
				},
			},
			"system-volumes": {
				Image:       "state",
				NetworkMode: "none",
				ReadOnly:    true,
				Privileged:  true,
				Labels: yamlTypes.SliceorMap{
					"io.rancher.os.createonly": "true",
					"io.rancher.os.scope":      "system",
				},
				Volumes: []string{
					"/dev:/host/dev",
					"/var/lib/rancher/conf:/var/lib/rancher/conf",
					"/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt.rancher",
					"/lib/modules:/lib/modules",
					"/lib/firmware:/lib/firmware",
					"/var/run:/var/run",
					"/var/log:/var/log",
				},
				Logging: Log{
					Driver: "json-file",
				},
			},
		},
	}
}