kcl-lang / modules

KCL Community Modules. View on Artifact Hub: https://artifacthub.io/packages/search?org=kcl&sort=relevance&page=1
https://kcl-lang.io
Apache License 2.0
18 stars 22 forks source link

Parts of the k8s module doesn't compile #159

Closed Petrosz007 closed 4 months ago

Petrosz007 commented 4 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

kcl mod init
kcl mod add k8s

In the main.k:

import k8s.api.apps.v1.stateful_set

statefulSet = stateful_set.StatefulSet {}

Run kcl run main.k

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

The code compiles

3. What did you see instead (Required)

failed to compile the kcl package

error[E2L23]: CompileError
  --> /Users/pandi/.kcl/kpm/k8s_1.30/api/apps/v1/stateful_set.k:36:12
   |
36 |     spec?: StatefulSetSpec
   |            ^ name 'StatefulSetSpec' is not defined, did you mean '["StatefulSet"]'?
   |

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

$ kcl version
0.9.0-rc.1-darwin-arm64

kcl.mod.lock:

[dependencies]
  [dependencies.k8s]
    name = "k8s"
    full_name = "k8s_1.30"
    version = "1.30"
    reg = "ghcr.io"
    repo = "kcl-lang/k8s"
    oci_tag = "1.30"
Peefy commented 4 months ago

Hello @Petrosz007 For this error, you need to import the entire k8s.api.apps.v1 package. For example

import k8s.api.apps.v1 as appsv1
import k8s.api.core.v1 as corev1
import k8s.apimachinery.pkg.apis.meta.v1 as metav1

statefulSet = appsv1.StatefulSet {
    spec: appsv1.StatefulSetSpec{
        serviceName: "foo"
        template: corev1.PodTemplateSpec{}
        selector: metav1.LabelSelector{}
    }
}
Petrosz007 commented 4 months ago

Oh cool, thank you so much! I'm new to KCL and I didn't know that the import system should be used this way 😄