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

Name conflict for resources of Different Kinds #241

Open
patryk-przekwas-airspace-intelligence opened this issue Feb 11, 2025 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@patryk-przekwas-airspace-intelligence
Copy link

What happened?

While generating resources with KCL, I encountered an issue where creating resources with the same name (but of different types) resulted in the removal of duplicated names from the output. There were no errors during the process, making debugging quite difficult. I expected the function to return a complete list of resources, as the resource types were different despite having the same name.

I found an issue that describes pretty much the same problem. It was closed, but it seems the problem still persists: #91

How can we reproduce it?

Go to https://github.com/crossplane-contrib/function-kcl/tree/main/examples/resources/network and modify composition.yaml to duplicate name:

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: xlabels.fn-demo.crossplane.io
  labels:
    provider: aws
spec:
  writeConnectionSecretsToNamespace: crossplane-system
  compositeTypeRef:
    apiVersion: fn-demo.crossplane.io/v1alpha1
    kind: XNetwork
  mode: Pipeline
  pipeline:
  - step: normal
    functionRef:
      name: kcl-function
    input:
      apiVersion: krm.kcl.dev/v1alpha1
      kind: KCLInput
      metadata:
        name: basic
      spec:
        target: Resources
        source: |
          # Get the XR spec fields
          id = option("params")?.oxr?.spec.id or ""
          # Render XR to crossplane managed resources
          network_id_labels = {"networks.meta.fn.crossplane.io/network-id" = id} if id else {}
          vpc = {
              apiVersion = "ec2.aws.upbound.io/v1beta1"
              kind = "VPC"
              metadata.name = "vpc"
              metadata.labels: network_id_labels
              spec.forProvider = {
                  region = "eu-west-1"
                  cidrBlock = "192.168.0.0/16"
                  enableDnsSupport = True
                  enableDnsHostnames = True
              }
          }
          gateway = {
              apiVersion = "ec2.aws.upbound.io/v1beta1"
              kind = "InternetGateway"
              metadata.name = "vpc"                                            # <--- modified here
              metadata.labels: network_id_labels
              spec.forProvider = {
                  region = "eu-west-1"
                  vpcIdSelector.matchControllerRef = True
              }
          }
          items = [vpc, gateway]

Output of crossplane render xr.yaml composition.yaml functions.yaml -r looks as follows:

---
apiVersion: fn-demo.crossplane.io/v1alpha1
kind: Network
metadata:
  name: network-test-functions
status:
  conditions:
  - lastTransitionTime: "2024-01-01T00:00:00Z"
    message: 'Unready resources: vpc'
    reason: Creating
    status: "False"
    type: Ready
---
apiVersion: ec2.aws.upbound.io/v1beta1
kind: InternetGateway
metadata:
  annotations:
    crossplane.io/composition-resource-name: vpc
  generateName: network-test-functions-
  labels:
    crossplane.io/composite: network-test-functions
    networks.meta.fn.crossplane.io/network-id: network-test-functions
  name: vpc
  ownerReferences:
  - apiVersion: fn-demo.crossplane.io/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: Network
    name: network-test-functions
    uid: ""
spec:
  forProvider:
    region: eu-west-1
    vpcIdSelector:
      matchControllerRef: true

As you can see the VPC resource is missing.

What environment did it happen in?

Function version: main

  • Running function-kcl locally on my M1 mac
  • Kernel Darwin ASI-J4WN77WP43 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 arm64
@patryk-przekwas-airspace-intelligence patryk-przekwas-airspace-intelligence added the bug Something isn't working label Feb 11, 2025
@Peefy
Copy link
Collaborator

Peefy commented Feb 11, 2025

Note here.

Image

Image

@patryk-przekwas-airspace-intelligence

Thanks for the quick response! I wish an error was returned when multiple resources had the same name.

@johngmyers
Copy link

johngmyers commented Feb 12, 2025

I was bitten by this as well. It took quite a long time to diagnose.

function-kcl should return a clear error when this happens. It should not silently discard some of the resources or render what is left. "ON ERROR RESUME NEXT" is a terrible strategy.

@Peefy Peefy added the enhancement New feature or request label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants