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

Unique Key Error for Crossplane Module #178

Closed karlderkaefer closed 3 months ago

karlderkaefer commented 3 months ago

Bug Report

Im trying to import the crossplane kcl module an create a CompositeResourceDefinition. The docs are not that extensive on the import topic, please correct me if the bug report is not valid

1. Minimal reproduce step (Required)

kcl version
# 0.9.2-darwin-arm64
kcl mod init
kcl mod add crossplane:1.15.2

the file main.k content:

import crossplane.v1 as crossplane

crossplane.CompositeResourceDefinition = {
}

the content of kcl.mod.lock

[dependencies]
  [dependencies.crossplane]
    name = "crossplane"
    full_name = "crossplane_1.15.2"
    version = "1.15.2"
    sum = "R7PZR/mIwiBP76BIsPDczo8bu7O/I/Mfbmu/FsCQY/k="
  [dependencies.k8s]
    name = "k8s"
    full_name = "k8s_1.28"
    version = "1.28"
    sum = "aTxPUVZyr9MdiB3YdiY/8pCh9sC55yURnZdGlJsKG6Q="
    reg = "ghcr.io"
    repo = "kcl-lang/k8s"
    oci_tag = "1.28"

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

Render a CompositionResourceDefinition

3. What did you see instead (Required)

then trying to render results in error message. This probably already happens during import

 kcl main.k
Error:
error[E2L28]: UniqueKeyError
 --> ~/.kcl/kpm/crossplane_1.15.2/v1/pkg_crossplane_io_v1_configuration.k:8:1
  |
8 | schema Configuration:
  | ^ unique key error name 'Configuration'
  |

error[E2L28]: UniqueKeyError
 --> ~/.kcl/kpm/crossplane_1.15.2/v1/pkg_crossplane_io_v1_provider.k:8:1
  |
8 | schema Provider:
  | ^ unique key error name 'Provider'
  |

error[E2G22]: TypeError
  --> ~/.kcl/kpm/crossplane_1.15.2/v1/meta_pkg_crossplane_io_v1_configuration.k:25:5
   |
25 |     apiVersion: "meta.pkg.crossplane.io/v1" = "meta.pkg.crossplane.io/v1"
   |     ^ expected str(pkg.crossplane.io/v1), got str(meta.pkg.crossplane.io/v1)
   |

error[E2G22]: TypeError
  --> ~/.kcl/kpm/crossplane_1.15.2/v1/meta_pkg_crossplane_io_v1_provider.k:25:5
   |
25 |     apiVersion: "meta.pkg.crossplane.io/v1" = "meta.pkg.crossplane.io/v1"
   |     ^ expected str(pkg.crossplane.io/v1), got str(meta.pkg.crossplane.io/v1)
   |

error[E2L28]: UniqueKeyError
 --> ~/.kcl/kpm/crossplane_1.15.2/v1/pkg_crossplane_io_v1_configuration.k:8:8
  |
8 | schema Configuration:
  |        ^ Unique key error name 'Configuration'
  |

 --> ~/.kcl/kpm/crossplane_1.15.2/v1/meta_pkg_crossplane_io_v1_configuration.k:8:8
  |
8 | schema Configuration:
  |        ^ The variable 'Configuration' is declared here
  |

error[E2L28]: UniqueKeyError
 --> ~/.kcl/kpm/crossplane_1.15.2/v1/pkg_crossplane_io_v1_provider.k:8:8
  |
8 | schema Provider:
  |        ^ Unique key error name 'Provider'
  |

 --> ~/.kcl/kpm/crossplane_1.15.2/v1/meta_pkg_crossplane_io_v1_provider.k:8:8
  |
8 | schema Provider:
  |        ^ The variable 'Provider' is declared here
  |

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

0.9.2

karlderkaefer commented 3 months ago

While reading through other github issue, I have found that I need to import specific kcl file. This version is working

import crossplane.v1.apiextensions_crossplane_io_v1_composite_resource_definition as xrd

xrd.CompositeResourceDefinition{
  metadata.name: "my-xrd"
}
Peefy commented 3 months ago

You can just use the following code.

import crossplane.v1

cc = v1.CompositeResourceDefinition{
  metadata.name: "my-xrd"
}
karlderkaefer commented 3 months ago

thank you, that was the fastest fix I have ever seen in a github repo under 8min 👍 . I can confirm it works now