File tree Expand file tree Collapse file tree 6 files changed +57
-3
lines changed
Expand file tree Collapse file tree 6 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,11 @@ brew install kcl-lang/tap/kcl
1717
1818``` sh
1919# execute program and output yaml
20- kcl kcl/hello.k
21- kcl kcl/server-1.k
22- kcl kcl/server-2.k
20+ kcl kcl/examples/hello.k
21+ kcl kcl/examples/server-1.k
22+ kcl kcl/examples/server-2.k
23+
24+ # labs
25+ kcl kcl/lab-1/my_config.k kcl/lab-1/my_config_test.k
26+ kcl kcl/lab-1/my_config.k -D priority=2
2327```
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ # variables with underscore prefix are non-exported and mutable
2+ # i.e. it will not appear in the output YAML, and it can be assigned multiple times
3+ _priority = option("priority" )
4+ _cpu = 256
5+ _env = "dev"
6+
7+ if _priority == 1 :
8+ _cpu = 256
9+ elif _priority == 2 :
10+ _cpu = 512
11+ elif _priority == 3 :
12+ _cpu = 1024
13+ else :
14+ _cpu = 2048
15+
16+ _priorityCpuMap = {
17+ "1" = 256
18+ "2" = 512
19+ "3" = 1024
20+ }
21+
22+ _name = "nginx"
23+
24+ cpu = _cpu
25+ # using a dict to simplify logic and the default value is 2048
26+ cpuFromMap = _priorityCpuMap[str (_priority)] or 2048
27+ memory = _cpu * 2
28+
29+ _command = [_name] # a list
30+ _command = _command + ["-f" , "file" ] # Append items into command using + operator to contact two lists
31+ command = [c.lower() for c in _command] # Take each element in the list to lowercase
32+
33+ _labels = {
34+ run = "my-{}" .format(_name)
35+ if _env:
36+ env = _env # Append a dict key-value pair when the _env is not None/Undefined or empty using if expressions
37+ }
38+ labels = _labels # a dict
39+
40+ image = "{}:1.14.2" .format(_name) # string format
41+ service = "my-service"
Original file line number Diff line number Diff line change 1+ import my_config
2+
3+ # debugging
4+ print(my_config.labels)
5+
6+ # tests
7+ assert len(my_config.labels) > 0, "labels can't be empty"
8+ assert my_config.cpu > 256 , "cpu cannot be less than 256"
9+ # assert "foo" in labels, "foo label is a must"
You can’t perform that action at this time.
0 commit comments