crossplane-contrib / function-environment-configs

A function building the environment from EnvironmentConfigs
Apache License 2.0
15 stars 4 forks source link

function crashes when environmentconfig reference is not found #26

Closed dprts closed 7 months ago

dprts commented 7 months ago

What happened?

Function crashes when referencing to non-existing environment config.

How can we reproduce it?

Test environment config:

apiVersion: apiextensions.crossplane.io/v1alpha1
metadata:
  name: environment
data:
  branch: feature/dev
  environment: dev
kind: EnvironmentConfig

Setup step in composition that reads something similar to:

  - step: environment-configs
    functionRef:
      name: function-environment-configs
    input:
      apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
      kind: Input
      spec:
        environmentConfigs:
          - type: Reference
            ref:
              name: does_not_exist

Submit and you'll get:

2024-03-28T22:35:58.242Z        INFO    fn/fn.go:40     Running function        {"tag": ""}
2024-03-28T22:35:58.242Z        DEBUG   fn/fn.go:72     No extra resources specified, exiting   {"requirements": "extra_resources:{key:\"environment-config-0\" value:{api_version:\"apiextensions.crossplane.io/v1alpha1\" kind:\"EnvironmentConfig\" match_name:\"does_not_exist\"}}"}
2024-03-28T22:35:58.246Z        INFO    fn/fn.go:40     Running function        {"tag": ""}
2024-03-28T22:35:58.246Z        DEBUG   fn/fn.go:83     Loaded Composition environment from Function context    {"context-key": "apiextensions.crossplane.io/environment"}
panic: runtime error: index out of range [0] with length 0

goroutine 5363 [running]:
main.getSelectedEnvConfigs(0xc0004c2500, 0x175a8a3?)
        /fn/fn.go:150 +0x7ab
main.(*Function).RunFunction(0xc00041e840, {0xc0002a0660?, 0x499ae6?}, 0xc0002a0660)
        /fn/fn.go:92 +0x328
github.com/crossplane/function-sdk-go/proto/v1beta1._FunctionRunnerService_RunFunction_Handler({0x1558b20?, 0xc00041e840}, {0x196f8c0, 0xc00052c0c0}, 0xc0001e4c00, 0x0)
        /go/pkg/mod/github.com/crossplane/function-sdk-go@v0.2.0/proto/v1beta1/run_function_grpc.pb.go:104 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000fa000, {0x196f8c0, 0xc00052c030}, {0x1975140, 0xc0005029c0}, 0xc000417b00, 0xc00058a630, 0x248b7d0, 0x0)
        /go/pkg/mod/google.golang.org/grpc@v1.61.0/server.go:1385 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc0000fa000, {0x1975140, 0xc0005029c0}, 0xc000417b00)
        /go/pkg/mod/google.golang.org/grpc@v1.61.0/server.go:1796 +0xfec
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        /go/pkg/mod/google.golang.org/grpc@v1.61.0/server.go:1029 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 8
        /go/pkg/mod/google.golang.org/grpc@v1.61.0/server.go:1040 +0x135

What environment did it happen in?

Function version: 0.0.4 - 0.0.6 Crossplane: 1.15.0 (testing locally via crank/crossplane validation and in k8s cluster)

phisco commented 7 months ago

yep, totally right, on it 😅

phisco commented 7 months ago

fix is available in v0.0.7, thanks for reaching out 🙏