Skip to content

Don't support running multiple KCLRun simultaneously #9

Open
@jianzs

Description

@jianzs

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

I've written two KCLRun objects in a single YAML file. When I run kubectl kcl run, I encounter an error.

$ kubectl kcl run -f ./bug.yml 
panic: runtime error: index out of range [2] with length 1

goroutine 1 [running]:
kcl-lang.io/krm-kcl/pkg/kio.Filter.Filter({0x140008e3880}, {0x14000121d70, 0x3, 0x3})
        kcl-lang.io/krm-kcl@v0.4.2-0.20231011034337-d2338c4e1083/pkg/kio/filter.go:31 +0x180
sigs.k8s.io/kustomize/kyaml/kio.Pipeline.ExecuteWithCallback({{0x14000b9fc58, 0x1, 0x1}, {0x14000b9fc48, 0x1, 0x1}, {0x14000b9fc38, 0x1, 0x1}, 0x0}, ...)
        sigs.k8s.io/kustomize/kyaml@v0.14.3/kio/kio.go:137 +0x24c
sigs.k8s.io/kustomize/kyaml/kio.Pipeline.Execute({{0x1400093fc58, 0x1, 0x1}, {0x1400093fc48, 0x1, 0x1}, {0x1400093fc38, 0x1, 0x1}, 0x0})
        sigs.k8s.io/kustomize/kyaml@v0.14.3/kio/kio.go:104 +0x6c
kcl-lang.io/kubectl-kcl/pkg/options.(*RunOptions).Run(0x0?)
        kcl-lang.io/kubectl-kcl/pkg/options/run.go:35 +0x184
kcl-lang.io/kubectl-kcl/cmd.NewRunCmd.func1(0x14000abc600, {0x1017aacc5, 0x2, 0x2})
        kcl-lang.io/kubectl-kcl/cmd/run.go:19 +0x20
github.com/spf13/cobra.(*Command).execute(0x14000abc600, {0x14000ab9160, 0x2, 0x2})
        github.com/spf13/cobra@v1.7.0/command.go:940 +0x5c8
github.com/spf13/cobra.(*Command).ExecuteC(0x14000abc000)
        github.com/spf13/cobra@v1.7.0/command.go:1068 +0x35c
github.com/spf13/cobra.(*Command).Execute(0x101d5f520?)
        github.com/spf13/cobra@v1.7.0/command.go:992 +0x1c
main.main()
        kcl-lang.io/kubectl-kcl/main.go:10 +0x20

However, if I run each object separately, it works fine. But the result includes two annotations for each object that KCL added itself:

annotations:
    config.kubernetes.io/index: '0'
    internal.config.kubernetes.io/index: '0'

This is the yaml including two KCLRun object.

apiVersion: v1
kind: Service
metadata:
  name: default-domain-service
  namespace: knative-serving
spec:
  clusterIP: None
  selector:
    app: default-domain
  ports:
    - name: http
      port: 80
      targetPort: 8080
  type: ClusterIP
---
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLRun
metadata:
  name: change-service-type
spec:
  params:
    annotations:
      managed-by: kubectl-kcl
  source: |
    [item | {
      if item.kind == "Service":
          spec.type = "LoadBalance"
    } for item in option("items")]
---
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLRun
metadata:
  name: add-labels
spec:
  params:
    annotations:
      managed-by: kubectl-kcl
  source: |
    [item | {
      if item.kind == "Service":
          metadata.labels = {
              app = item.metadata.name
          }
    } for item in option("items")]
---

2. What did you expect to see? (Required)

Get the correct result.

3. What did you see instead (Required)

Encountered an error.

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

  • kubectl-kcl 0.4.0
  • kcl 0.5.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions