github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0036.yml (about) 1 doc_meta: | 2 folder: template 3 title: builtin funcs 4 head: | 5 Demo dvars merge in local scope in execution time 6 7 sections: 8 - title: flag verbose level 9 content: | 10 if you put a flag like vvv together with dvar definition, you will see the evaluated result will be printed in that verbose level for you to debug or trace problem 11 12 - title: Demo 13 log: yes 14 15 related: 16 refs: 17 - title: default golang template reference 18 link: https://golang.org/pkg/text/template/ 19 20 notes: 21 goal: 22 - test usage of buitin golang template funcs 23 - slice is not working as expected yet 24 - add auto logging flag vvvv to display value of dvar value 25 26 27 vars: 28 ns: prod 29 pod_name: web_app 30 ha: true 31 age: 34 32 old: 54 33 admins: [tom, jason, alice] 34 managers: 35 - tom 36 - jason 37 - alice 38 fieldnames: 39 name-with-dash: | 40 this_is_a_field_with_dash: you will have to use index func to access the field 41 note: direct access this field will trigger template rendering error 42 43 #we intend to access the dynamic value of the pod_name, which has got value of web_app 44 #this is an example of indirect access of varname 45 where_is_my_deploy: pod_name 46 47 dvars: 48 - name: instance_full_name 49 value: "{{.ns}}-{{.pod_name}}" 50 51 - name: var_space_not_trimmed 52 value: "{{.ns}} - {{.pod_name}}" 53 54 - name: var_space_trimmed 55 value: "{{.ns -}} - {{- .pod_name}}" 56 57 - name: var_commented 58 value: "{{/*this is funny*/}} {{.ns}}-{{.pod_name}}" 59 60 - name: var_commented_trimmed 61 value: "{{- /*this is funny*/ -}}{{.ns}}-{{.pod_name}}" 62 63 - name: var_with_if 64 value: "{{if .ha }}{{.ns}}-{{.pod_name}}-HA{{end}}" 65 66 #extra: {{if pipeline}} T1 {{else if pipeline}} T0 {{end}} 67 - name: var_with_range 68 value: "{{range .managers}} x {{end}}" 69 flags: [vvvv,] 70 71 - name: var_with_range_item 72 value: "{{range $x:=.managers}} {{$x}} {{end}}" 73 flags: [vvvv,] 74 75 - name: var_with_range_item_simpler 76 value: "{{range .managers}} {{.}} {{end}}" 77 flags: [vvvv,] 78 79 - name: var_with_ifelse 80 value: "{{if .ha }}{{.ns}}-{{.pod_name}}-HA{{else}}{{.ns}}-{{.pod_name}}{{end}}" 81 82 - name: var_with_ifelse_multilines 83 value: " 84 {{if .ha }} 85 {{.ns}}-{{.pod_name}}-HA 86 {{else}} 87 {{.ns}}-{{.pod_name}} 88 {{end}}" 89 90 - name: var_with_not 91 value: "{{if not .ha }}{{.ns}}-{{.pod_name}}{{else}}{{.ns}}-{{.pod_name}}{{end}}" 92 flags: [toObj,] 93 94 - name: var_length 95 value: "{{len .var_with_not}}" 96 97 - name: var_with_or 98 desc: return the first non-empty argument or the last argument 99 value: "{{or .ns .pod_name}}" 100 101 - name: var_with_print 102 value: "{{print .ns .pod_name}}" 103 104 - name: var_test_log_auto_print 105 value: "{{print .ns .pod_name}}" 106 flags: [vvvv,toObj] 107 108 - name: var_with_and 109 desc: and x y behaves as if x then y else x 110 value: "{{and .ns .pod_name}}" 111 flags: [vvvv,] 112 113 114 - name: var_slice_index 115 value: "{{ index .admins 1 }}" 116 flags: [vvvv,] 117 118 - name: out_of_normal_field_name 119 value: '{{ index .fieldnames "name-with-dash" }}' 120 flags: [vvvv,] 121 122 - name: indirect_var_reference 123 value: '{{ index . ".where_is_my_deploy" }}' 124 flags: [vvvv,] 125 126 - name: var_slice 127 value: "{{ slice .managers 1 2}}" 128 flags: [vvvv,] 129 130 - name: var_equal 131 value: "{{ eq .ns .pod_name }}" 132 flags: [vvvv,] 133 134 - name: var_not_equal 135 value: "{{ ne .ns .pod_name }}" 136 flags: [vvvv,] 137 138 - name: var_not_equal_another_way 139 value: "{{ not (eq .ns .pod_name) }}" 140 flags: [vvvv,] 141 142 - name: var_greater 143 value: "{{ gt .ns .pod_name }}" 144 flags: [vvvv,] 145 146 - name: var_greater_and_equal 147 value: "{{ ge .old .age }}" 148 flags: [vvvv,] 149 150 - name: var_greater_and_equal 151 value: "{{ if ge .old .age }}hello{{end}}" 152 flags: [vvvv,] 153 154 - name: var_use_and_operator 155 value: '{{ and (eq .ns "prod") (ne .age 35)}}' 156 flags: [v,] 157 158 - name: var_use_or_operator 159 value: '{{ or (eq .ns "prod") (ne .age 35)}}' 160 flags: [v ,] 161 162 - name: var_concat_values 163 value: '{{ printf "%s: %d years old" .pod_name .age}}' 164 flags: [v ,] 165 166 #extra: lt, le 167 - name: template_def 168 value: | 169 {{define "T1"}}ONE{{end}} 170 {{define "T2"}}TWO{{end}} 171 {{define "T3"}}{{template "T1"}} {{template "T2"}}{{end}} 172 {{template "T3"}}" 173 flags: [vvvv,] 174 175 176 tasks: 177 - 178 name: task 179 task: 180 181 - 182 func: shell 183 do: 184 - echo "{{.instance_full_name}}" 185 - echo "{{.var_space_not_trimmed}}" 186 - echo "{{.var_space_trimmed}}" 187 - echo "{{.var_commented}}" 188 - echo "{{.var_commented_trimmed}}" 189 - echo "{{.var_with_if}}" 190 - echo "{{.var_with_ifelse}}" 191 - echo "{{.var_with_ifelse_multilines}}" 192 - echo "{{.var_with_not}}" 193 - echo "{{.var_with_not_object}}" 194 - echo "{{.var_length}}" 195 - echo "{{.var_with_or}}" 196 - echo "{{.var_with_print}}" 197 - echo "check the value of other dvar using vvvv flag print out"