Closed liangyuanpeng closed 1 week ago
Please answer these questions before submitting your issue. Thanks!
when i generate yaml from kcl, it have repeat run the if conditional .
kind.k
_nodes=[{ role = "control-plane", image = option("kindimage",default="kindest/node:v1.30.0") extraMounts = [ { hostPath = "/home/runner/work/lanactions/lanactions/config/apiserver-audit-policy.yaml", containerPath = "/etc/kubernetes/audit-policy/apiserver-audit-policy.yaml" } ] kubeadmConfigPatches = [ """\ kind: ClusterConfiguration etcd: external: endpoints: [${ETCD_ENDPOINTS}] apiServer: extraArgs: runtime-config: api/all=true storage-media-type: ${REALLY_STORAGE_MEDIA_TYPE} audit-log-path: /var/log/audit/kube-apiserver-audit.log audit-policy-file: /etc/kubernetes/audit-policy/apiserver-audit-policy.yaml extraVolumes: - name: "audit-logs" hostPath: /var/log/audit mountPath: /var/log/audit - name: audit-policy hostPath: /etc/kubernetes/audit-policy mountPath: /etc/kubernetes/audit-policy """ ] } ] _count = option("count",default="default") if _count == 3: print("The value of a is", _count) _nodes+=[{ role = "worker" image = option("kindimage",default="kindest/node:v1.30.0") } ] elif _count == 5: _nodes+=[ { role = "worker" image = option("kindimage",default="kindest/node:v1.30.0") },{ role = "worker" image = option("kindimage",default="kindest/node:v1.30.0") },{ role = "worker" image = option("kindimage",default="kindest/node:v1.30.0") },{ role = "worker" image = option("kindimage",default="kindest/node:v1.30.0") },{ role = "worker" image = option("kindimage",default="kindest/node:v1.30.0") } ] #print("The value of a is", _count) #print(_count==3) #print(_count==5) kind = "Cluster" apiVersion = "kind.x-k8s.io/v1alpha4" networking = { #https://kcl-lang.io/docs/user_docs/support/faq-kcl#39-how-to-set-default-value-for-option-function-in-kcl apiServerAddress = option("apiaddress",default="0.0.0.0") ipFamily = option("ipFamily",default="ipv4") kubeProxyMode = option("kubeProxyMode",default="iptables") } nodes=_nodes
do not run repeat if condition.
You can see that print was executed repeatedly, and i just print once. Remind me if i missed something,Thanks.
$ kcl kind2.k -D count=3 The value of a is 3 The value of a is 3 The value of a is 3 The value of a is 3 kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 networking: apiServerAddress: '0.0.0.0' ipFamily: ipv4 kubeProxyMode: iptables nodes: - role: control-plane image: kindest/node:v1.30.0 extraMounts: - hostPath: /home/runner/work/lanactions/lanactions/config/apiserver-audit-policy.yaml containerPath: /etc/kubernetes/audit-policy/apiserver-audit-policy.yaml kubeadmConfigPatches: - | kind: ClusterConfiguration etcd: external: endpoints: [http://192.168.66.2:2379] apiServer: extraArgs: runtime-config: api/all=true storage-media-type: application/json audit-log-path: /var/log/audit/kube-apiserver-audit.log audit-policy-file: /etc/kubernetes/audit-policy/apiserver-audit-policy.yaml extraVolumes: - name: "audit-logs" hostPath: /var/log/audit mountPath: /var/log/audit - name: audit-policy hostPath: /etc/kubernetes/audit-policy mountPath: /etc/kubernetes/audit-policy - role: worker image: kindest/node:v1.30.0 - role: worker image: kindest/node:v1.30.0 - role: worker image: kindest/node:v1.30.0
$ kcl version 0.9.0-beta.1-linux-amd64
Minimal reproduce step
_a = 1 if True: _a += 1 elif False: _a += 1 a=_a
Closed by #1416, #1418 and #1423
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
when i generate yaml from kcl, it have repeat run the if conditional .
kind.k
2. What did you expect to see? (Required)
do not run repeat if condition.
3. What did you see instead (Required)
You can see that print was executed repeatedly, and i just print once. Remind me if i missed something,Thanks.
4. What is your KCL components version? (Required)