kcl-lang / konfig

KCL Kubernetes Config Abstraction & Composition Module
https://kcl-lang.io
Apache License 2.0
8 stars 7 forks source link

kcl run k8s manifest fail #22

Closed riven-blade closed 2 months ago

riven-blade commented 2 months ago

General Question

dev % kcl run main.k error[E2L23]: CompileError --> /Users/doudou/.kcl/kpm/k8s_1.28/api/apps/v1/deployment.k:26:12 | 26 | spec?: DeploymentSpec | ^ name 'DeploymentSpec' is not defined, did you mean '["Deployment"]'?

import k8s.api.apps.v1.deployment

app: deployment.Deployment {
    apiVersion = "apps/v1"
    kind = "Deployment"
    metadata = {
.....

    spec = {
        progressDeadlineSeconds = 600
        replicas = 2
        revisionHistoryLimit = 10
        selector = {
riven-blade commented 2 months ago

General Question

dev % kcl run main.k error[E2L23]: CompileError --> /Users/doudou/.kcl/kpm/k8s_1.28/api/apps/v1/deployment.k:26:12 | 26 | spec?: DeploymentSpec | ^ name 'DeploymentSpec' is not defined, did you mean '["Deployment"]'?

import k8s.api.apps.v1.deployment

app: deployment.Deployment {
    apiVersion = "apps/v1"
    kind = "Deployment"
    metadata = {
.....

    spec = {
        progressDeadlineSeconds = 600
        replicas = 2
        revisionHistoryLimit = 10
        selector = {
Peefy commented 2 months ago

You can write the following code

import k8s.api.apps.v1 # Import the full package instead of the single deployment.k

app: v1.Deployment {
    apiVersion = "apps/v1"
    kind = "Deployment"
    metadata = {
.....

    spec = {
        progressDeadlineSeconds = 600
        replicas = 2
        revisionHistoryLimit = 10
        selector = {

This is because KCL supports importing a single file, and the single file only contains the definition of Deployment but not the definition of Deployment Spec

riven-blade commented 2 months ago

Yes, you are right. Thank you