diff --git a/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/components.go b/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/components.go index 7f423468f..05d613924 100644 --- a/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/components.go +++ b/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/components.go @@ -1,6 +1,8 @@ package comp import ( + "fmt" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/goutils/set" @@ -21,9 +23,13 @@ func ProcessComponents(ctx clictx.Context, ictx inputs.Context, repo ocm.Reposit for _, elem := range elems { if r, ok := elem.Spec().(*ResourceSpec); ok { + if len(r.References) > 0 && len(r.OldReferences) > 0 { + return fmt.Errorf("only field references or componentReferences (deprecated) is possible") + } list.Add(addhdlrs.ValidateElementSpecIdentities("resource", elem.Source().String(), sliceutils.Convert[addhdlrs.ElementSpec](r.Resources))) list.Add(addhdlrs.ValidateElementSpecIdentities("source", elem.Source().String(), sliceutils.Convert[addhdlrs.ElementSpec](r.Sources))) list.Add(addhdlrs.ValidateElementSpecIdentities("reference", elem.Source().String(), sliceutils.Convert[addhdlrs.ElementSpec](r.References))) + list.Add(addhdlrs.ValidateElementSpecIdentities("reference", elem.Source().String(), sliceutils.Convert[addhdlrs.ElementSpec](r.OldReferences))) } } if err := list.Result(); err != nil { diff --git a/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/elements.go b/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/elements.go index bd47976aa..c0634d863 100644 --- a/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/elements.go +++ b/cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/elements.go @@ -143,10 +143,18 @@ func (h *ResourceSpecHandler) Add(ctx clictx.Context, ictx inputs.Context, elem if err != nil { return err } + + if len(r.References) > 0 && len(r.OldReferences) > 0 { + return fmt.Errorf("only field references or componentReferences (deprecated) is possible") + } err = handle(ctx, ictx, elem.Source(), cv, r.References, h.refhandler) if err != nil { return err } + err = handle(ctx, ictx, elem.Source(), cv, r.OldReferences, h.refhandler) + if err != nil { + return err + } return comp.AddVersion(cv) } @@ -169,7 +177,10 @@ type ResourceSpec struct { // Sources defines sources that produced the component Sources []*srcs.ResourceSpec `json:"sources"` // References references component dependencies that can be resolved in the current context. - References []*refs.ResourceSpec `json:"componentReferences"` + References []*refs.ResourceSpec `json:"references"` + // OldReferences references component dependencies that can be resolved in the current context. + // Deprecated: use field References. + OldReferences []*refs.ResourceSpec `json:"componentReferences"` // Resources defines all resources that are created by the component and by a third party. Resources []*rscs.ResourceSpec `json:"resources"` } diff --git a/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go b/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go index 22435d1af..a225d098b 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/components/add/cmd_test.go @@ -16,7 +16,7 @@ import ( "ocm.software/ocm/api/ocm/extensions/accessmethods/ociartifact" resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes" "ocm.software/ocm/api/ocm/extensions/repositories/ctf" - ocmutils "ocm.software/ocm/api/ocm/ocmutils" + "ocm.software/ocm/api/ocm/ocmutils" "ocm.software/ocm/api/ocm/valuemergehandler/handlers/defaultmerge" "ocm.software/ocm/api/utils/accessio" "ocm.software/ocm/api/utils/accessobj" @@ -92,6 +92,12 @@ var _ = Describe("Test Environment", func() { CheckComponent(env, nil) }) + It("creates ctf and adds component (deprecated)", func() { + Expect(env.Execute("add", "c", "-fc", "--file", ARCH, "testdata/component-constructor-old.yaml")).To(Succeed()) + Expect(env.DirExists(ARCH)).To(BeTrue()) + CheckComponent(env, nil) + }) + It("creates ctf and adds components", func() { Expect(env.Execute("add", "c", "-fc", "--file", ARCH, "--version", "1.0.0", "testdata/component-constructor.yaml")).To(Succeed()) Expect(env.DirExists(ARCH)).To(BeTrue()) diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor-old.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor-old.yaml new file mode 100644 index 000000000..fe0909372 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor-old.yaml @@ -0,0 +1,34 @@ +name: ocm.software/demo/test +version: 1.0.0 +provider: + name: ocm.software + labels: + - name: city + value: Karlsruhe +labels: + - name: purpose + value: test + +resources: + - name: text + type: PlainText + labels: + - name: city + value: Karlsruhe + merge: + algorithm: default + config: + overwrite: inbound + input: + type: file + path: testdata + - name: data + type: PlainText + input: + type: binary + data: IXN0cmluZ2RhdGE= + +componentReferences: + - name: ref + version: v1 + componentName: github.com/mandelsoft/test2 diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor.yaml index fe0909372..5145f331e 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor.yaml +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-constructor.yaml @@ -28,7 +28,7 @@ resources: type: binary data: IXN0cmluZ2RhdGE= -componentReferences: +references: - name: ref version: v1 componentName: github.com/mandelsoft/test2 diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-ref.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-ref.yaml index e8bd8c4a6..c1969bf37 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-ref.yaml +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-ref.yaml @@ -28,7 +28,7 @@ resources: type: binary data: IXN0cmluZ2RhdGE= -componentReferences: +references: - name: ref version: v1 componentName: github.com/mandelsoft/test2 diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-res.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-res.yaml index e7349b987..b314503da 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-res.yaml +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-res.yaml @@ -33,7 +33,7 @@ resources: type: binary data: IXN0cmluZ2RhdGE= -componentReferences: +references: - name: ref version: v1 componentName: github.com/mandelsoft/test2 diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-src.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-src.yaml index 5179cb01f..05444e9c9 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-src.yaml +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/component-dup-src.yaml @@ -40,7 +40,7 @@ resources: type: binary data: IXN0cmluZ2RhdGE= -componentReferences: +references: - name: ref version: v1 componentName: github.com/mandelsoft/test2 diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/components-dup.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/components-dup.yaml index 7b48dec46..d887b9600 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/testdata/components-dup.yaml +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/components-dup.yaml @@ -27,7 +27,7 @@ components: input: type: binary data: IXN0cmluZ2RhdGE= - componentReferences: + references: - name: ref version: v1 componentName: github.com/mandelsoft/test2 diff --git a/cmds/ocm/commands/ocmcmds/components/add/testdata/components.yaml b/cmds/ocm/commands/ocmcmds/components/add/testdata/components.yaml index c19b40404..3933e6a4f 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/testdata/components.yaml +++ b/cmds/ocm/commands/ocmcmds/components/add/testdata/components.yaml @@ -27,7 +27,7 @@ components: input: type: binary data: IXN0cmluZ2RhdGE= - componentReferences: + references: - name: ref version: v1 componentName: github.com/mandelsoft/test2 \ No newline at end of file diff --git a/components/helmdemo/component-constructor.yaml b/components/helmdemo/component-constructor.yaml index 11f1c78a6..36725845e 100644 --- a/components/helmdemo/component-constructor.yaml +++ b/components/helmdemo/component-constructor.yaml @@ -5,7 +5,7 @@ components: name: (( values.PROVIDER)) # use all platforms and create a resource for each # ADD back once https://github.com/open-component-model/ocm/issues/1041 is fixed - componentReferences: + references: - name: installer componentName: (( values.HELMINSTCOMP )) version: (( values.HELMINSTVERSION )) diff --git a/components/subchartsdemo/component-constructor.yaml b/components/subchartsdemo/component-constructor.yaml index 7f0a7ec51..8a469048d 100644 --- a/components/subchartsdemo/component-constructor.yaml +++ b/components/subchartsdemo/component-constructor.yaml @@ -7,7 +7,7 @@ components: version: ${VERSION} provider: name: ${PROVIDER} - componentReferences: + references: - name: echoserver componentName: ${COMPONENT_PREFIX}/echoserver version: "${ECHO_VERSION}"