Skip to content

Commit

Permalink
Merge pull request #132 from Peefy/chore-disable-dup-res-check
Browse files Browse the repository at this point in the history
chore: disable resource check and enable it after fixing the KCL issues
  • Loading branch information
Peefy authored Aug 12, 2024
2 parents 8f5ba17 + c955895 commit 2ef08e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ env:
XPKG: xpkg.upbound.io/${{ github.repository}}

# The package version to push. The default is 0.0.0-gitsha.
XPKG_VERSION: v0.9.3
XPKG_VERSION: v0.9.4

jobs:
lint:
Expand Down
67 changes: 34 additions & 33 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,39 +192,40 @@ func TestRunFunctionSimple(t *testing.T) {
},
},
},
"MultipleResourceError": {
reason: "The Function should return a fatal result if input resources have duplicate names",
args: args{
req: &fnv1beta1.RunFunctionRequest{
Meta: &fnv1beta1.RequestMeta{Tag: "multiple-resource-error"},
Input: resource.MustStructJSON(`{
"apiVersion": "krm.kcl.dev/v1alpha1",
"kind": "KCLInput",
"metadata": {
"name": "basic"
},
"spec": {
"source": "items = [\n{\n apiVersion: \"example.org/v1\"\n kind: \"Generated\"\n metadata.annotations = {\"krm.kcl.dev/composition-resource-name\": \"custom-composition-resource-name\"}\n}\n{\n apiVersion: \"example.org/v1\"\n kind: \"Generated\"\n metadata.annotations = {\"krm.kcl.dev/composition-resource-name\": \"custom-composition-resource-name\"}\n}\n]\n"
}
}`),
Observed: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR"}`),
},
},
},
},
want: want{
rsp: &fnv1beta1.RunFunctionResponse{
Meta: &fnv1beta1.ResponseMeta{Tag: "multiple-resource-error", Ttl: durationpb.New(response.DefaultTTL)},
Results: []*fnv1beta1.Result{
{
Severity: fnv1beta1.Severity_SEVERITY_FATAL,
Message: "cannot process xr and state with the pipeline output in *v1beta1.RunFunctionResponse: duplicate resource names custom-composition-resource-name found, when returning multiple resources, you need to set different metadata.name or metadata.annotations.\"krm.kcl.dev/composition-resource-name\" to distinguish between different resources in the composition functions.",
},
}},
},
},
// TODO: disable the resource check, and fix the kcl dup resource evaluation issues.
// "MultipleResourceError": {
// reason: "The Function should return a fatal result if input resources have duplicate names",
// args: args{
// req: &fnv1beta1.RunFunctionRequest{
// Meta: &fnv1beta1.RequestMeta{Tag: "multiple-resource-error"},
// Input: resource.MustStructJSON(`{
// "apiVersion": "krm.kcl.dev/v1alpha1",
// "kind": "KCLInput",
// "metadata": {
// "name": "basic"
// },
// "spec": {
// "source": "items = [\n{\n apiVersion: \"example.org/v1\"\n kind: \"Generated\"\n metadata.annotations = {\"krm.kcl.dev/composition-resource-name\": \"custom-composition-resource-name\"}\n}\n{\n apiVersion: \"example.org/v1\"\n kind: \"Generated\"\n metadata.annotations = {\"krm.kcl.dev/composition-resource-name\": \"custom-composition-resource-name\"}\n}\n]\n"
// }
// }`),
// Observed: &fnv1beta1.State{
// Composite: &fnv1beta1.Resource{
// Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR"}`),
// },
// },
// },
// },
// want: want{
// rsp: &fnv1beta1.RunFunctionResponse{
// Meta: &fnv1beta1.ResponseMeta{Tag: "multiple-resource-error", Ttl: durationpb.New(response.DefaultTTL)},
// Results: []*fnv1beta1.Result{
// {
// Severity: fnv1beta1.Severity_SEVERITY_FATAL,
// Message: "cannot process xr and state with the pipeline output in *v1beta1.RunFunctionResponse: duplicate resource names custom-composition-resource-name found, when returning multiple resources, you need to set different metadata.name or metadata.annotations.\"krm.kcl.dev/composition-resource-name\" to distinguish between different resources in the composition functions.",
// },
// }},
// },
// },
}

for name, tc := range cases {
Expand Down
3 changes: 2 additions & 1 deletion pkg/resource/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ func CheckAndSetDesired(desired map[resource.Name]*resource.DesiredComposed, che
if _, existed := checked[name]; existed {
return errors.Errorf("duplicate resource names %s found, when returning multiple resources, you need to set different metadata.name or metadata.annotations.\"krm.kcl.dev/composition-resource-name\" to distinguish between different resources in the composition functions.", name)
}
checked[name] = struct{}{}
// TODO: disable the resource check, and fix the kcl dup resource evaluation issues.
// checked[name] = struct{}{}
desired[resource.Name(name)] = cd
return nil
}
Expand Down

0 comments on commit 2ef08e1

Please sign in to comment.