Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have Repeat run the if conditional . #1410

Closed
liangyuanpeng opened this issue Jun 13, 2024 · 2 comments
Closed

Have Repeat run the if conditional . #1410

liangyuanpeng opened this issue Jun 13, 2024 · 2 comments
Assignees

Comments

@liangyuanpeng
Copy link
Contributor

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

_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

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.

$ 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

4. What is your KCL components version? (Required)

$ kcl version
0.9.0-beta.1-linux-amd64
@liangyuanpeng liangyuanpeng changed the title Repeat run if Have Repeat run the if conditional . Jun 13, 2024
@He1pa
Copy link
Contributor

He1pa commented Jun 17, 2024

Minimal reproduce step

_a = 1
if True:
    _a += 1
elif False:
    _a += 1
a=_a

@Peefy
Copy link
Contributor

Peefy commented Jun 20, 2024

Closed by #1416, #1418 and #1423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants