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

Repository Contexts #1150

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 18 additions & 37 deletions pkg/components/blueprinthandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,24 @@ import (
. "github.com/onsi/gomega"
"github.com/open-component-model/ocm/pkg/contexts/datacontext"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/runtime"
. "github.com/open-component-model/ocm/pkg/testutils"

"github.com/gardener/landscaper/apis/config"
"github.com/gardener/landscaper/apis/core/v1alpha1"
"github.com/gardener/landscaper/controller-utils/pkg/logging"
"github.com/gardener/landscaper/pkg/components/model"
"github.com/gardener/landscaper/pkg/components/model/types"
"github.com/gardener/landscaper/pkg/components/ocmlib"
"github.com/gardener/landscaper/pkg/components/testutils"
"github.com/gardener/landscaper/pkg/utils/blueprints"
)

var (
LOCALCNUDIEREPOPATH_WITH_BLUEPRINTS = "./testdata/localcnudierepos/components-with-blueprints"
LOCALOCMREPOPATH_WITH_BLUEPRINTS = "./testdata/localocmrepos/components-with-blueprints"

withBlueprintsComponentReference = `
{
"repositoryContext": {
"type": "local",
"filePath": "./"
},
"componentName": "example.com/landscaper-component-with-blueprints",
"version": "1.0.0"
}
`
blueprintsComponentVersionKey = types.ComponentVersionKey{
Name: "example.com/landscaper-component-with-blueprints",
Version: "1.0.0",
}
)

var _ = Describe("facade implementation compatibility tests", func() {
Expand Down Expand Up @@ -67,12 +60,9 @@ var _ = Describe("facade implementation compatibility tests", func() {
// Blueprint Handler
// The ocmlib backed implementation can automatically convert a directory to a tar, this functionality is tested
DescribeTable("resolve blueprint dir", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withBlueprintsComponentReference), cdref))

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())
compvers := Must(registryAccess.GetComponentVersion(ctx, &blueprintsComponentVersionKey))
res := Must(compvers.GetResource("blueprint-dir", nil))

typedContent, err := res.GetTypedContent(ctx)
Expand All @@ -93,12 +83,9 @@ var _ = Describe("facade implementation compatibility tests", func() {

// Both implementations should be able to resolve blueprints in several representations
DescribeTable("resolve blueprint", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withBlueprintsComponentReference), cdref))

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())
compvers := Must(registryAccess.GetComponentVersion(ctx, &blueprintsComponentVersionKey))

bptar := Must(compvers.GetResource("blueprint-tar", nil))
typedContentTar, err := bptar.GetTypedContent(ctx)
Expand Down Expand Up @@ -131,12 +118,9 @@ var _ = Describe("facade implementation compatibility tests", func() {
)

DescribeTable("error with corrupted blueprint", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withBlueprintsComponentReference), cdref))

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())
compvers := Must(registryAccess.GetComponentVersion(ctx, &blueprintsComponentVersionKey))
res := Must(compvers.GetResource("corrupted-blueprint", nil))

typedContent, err := res.GetTypedContent(ctx)
Expand All @@ -149,12 +133,9 @@ var _ = Describe("facade implementation compatibility tests", func() {

// Here, the error is not that it is not a valid tar
DescribeTable("error with corrupted blueprint tar", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withBlueprintsComponentReference), cdref))

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())
compvers := Must(registryAccess.GetComponentVersion(ctx, &blueprintsComponentVersionKey))
res := Must(compvers.GetResource("corrupted-blueprint-tar", nil))

typedContent, err := res.GetTypedContent(ctx)
Expand Down
79 changes: 49 additions & 30 deletions pkg/components/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gardener/landscaper/pkg/components/model"
"github.com/gardener/landscaper/pkg/components/model/types"
"github.com/gardener/landscaper/pkg/components/ocmlib"
"github.com/gardener/landscaper/pkg/components/testutils"
"github.com/gardener/landscaper/pkg/utils/blueprints"
)

Expand Down Expand Up @@ -157,13 +158,17 @@ var _ = Describe("facade implementation compatibility tests", func() {
It("compatibility of facade implementations and component descriptor versions", func() {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(componentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

oRaForCnudie := Must(ocmfactory.NewRegistryAccess(ctx, nil, nil, nil, &config.LocalRegistryConfiguration{RootPath: LOCALCNUDIEREPOPATH_VALID}, nil, nil))
oRaForOcm := Must(ocmfactory.NewRegistryAccess(ctx, nil, nil, nil, &config.LocalRegistryConfiguration{RootPath: LOCALOCMREPOPATH_VALID}, nil, nil))
oRaForCnudie, err := testutils.NewLocalRegistryAccess(ctx, LOCALCNUDIEREPOPATH_VALID)
Expect(err).ToNot(HaveOccurred())

oRaForOcm, err := testutils.NewLocalRegistryAccess(ctx, LOCALOCMREPOPATH_VALID)
Expect(err).ToNot(HaveOccurred())

// the 3 registry accesses should all behave the same and the interface methods should return the same data
oRaForCnudieCv := Must(oRaForCnudie.GetComponentVersion(ctx, cdref))
oRaForOcmCv := Must(oRaForOcm.GetComponentVersion(ctx, cdref))
oRaForCnudieCv := Must(oRaForCnudie.GetComponentVersion(ctx, compKey))
oRaForOcmCv := Must(oRaForOcm.GetComponentVersion(ctx, compKey))

Expect(oRaForCnudieCv.GetName()).To(Equal(oRaForOcmCv.GetName()))

Expand Down Expand Up @@ -211,7 +216,7 @@ var _ = Describe("facade implementation compatibility tests", func() {
// Resolve component referenced by an inline component descriptor
// Resolving of references cannot really be unit tested as the component descriptors v2 mandate that the
// repositoryContext is of type ociRegistry, but this is also the context that is evaluated to resolve the reference
DescribeTable("resolve reference based on the inline descriptors repository context", func(factory model.Factory, repoCtx string) {
XDescribeTable("resolve reference based on the inline descriptors repository context", func(factory model.Factory, repoCtx string) {
rctx := &cdv2.UnstructuredTypedObject{}
Expect(rctx.UnmarshalJSON([]byte(repoCtx))).To(Succeed())

Expand All @@ -238,10 +243,11 @@ var _ = Describe("facade implementation compatibility tests", func() {
ComponentName: "example.com/inline-component-descriptor",
Version: "1.0.0",
}
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
registryAccess := Must(factory.CreateRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: "./"}, nil, inlineDescriptor))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
compvers := Must(registryAccess.GetComponentVersion(ctx, compKey))
Expect(compvers.GetComponentDescriptor()).To(YAMLEqual(inlineDescriptor))
},
Entry("with ocm and v2 descriptors", model.Factory(ocmfactory), inlineRepoCtxCnudie),
Expand All @@ -251,10 +257,12 @@ var _ = Describe("facade implementation compatibility tests", func() {
DescribeTable("error when trying to access unknown resource", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(referencedComponentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
compvers := Must(registryAccess.GetComponentVersion(ctx, compKey))
res, err := compvers.GetResource("non-existent-resource", nil)
Expect(err).To(HaveOccurred())
Expect(res).To(BeNil())
Expand All @@ -268,10 +276,12 @@ var _ = Describe("facade implementation compatibility tests", func() {
DescribeTable("error when accessing resources with unknown resource type", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(referencedComponentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

compvers := Must(registryAccess.GetComponentVersion(ctx, compKey))
res := Must(compvers.GetResource(GENERIC_RESOURCE_NAME, nil))

typedContent, err := res.GetTypedContent(ctx)
Expand All @@ -288,10 +298,12 @@ var _ = Describe("facade implementation compatibility tests", func() {
DescribeTable("error when component descriptor has no repository context", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withoutRepoctxComponentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers, err := registryAccess.GetComponentVersion(ctx, cdref)
compvers, err := registryAccess.GetComponentVersion(ctx, compKey)
Expect(err).To(HaveOccurred())
Expect(compvers).To(BeNil())
},
Expand All @@ -302,10 +314,12 @@ var _ = Describe("facade implementation compatibility tests", func() {
DescribeTable("error when component descriptor has invalid access type", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withInvalidAccessTypeComponentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers, err := registryAccess.GetComponentVersion(ctx, cdref)
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

compvers, err := registryAccess.GetComponentVersion(ctx, compKey)
Expect(err).ToNot(HaveOccurred())
Expect(compvers).ToNot(BeNil())

Expand All @@ -324,10 +338,12 @@ var _ = Describe("facade implementation compatibility tests", func() {
DescribeTable("error when component descriptor has invalid reference", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withInvalidReferenceComponentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers, err := registryAccess.GetComponentVersion(ctx, cdref)
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

compvers, err := registryAccess.GetComponentVersion(ctx, compKey)
Expect(err).ToNot(HaveOccurred())
Expect(compvers).ToNot(BeNil())

Expand All @@ -351,10 +367,12 @@ var _ = Describe("facade implementation compatibility tests", func() {
DescribeTable("error when component descriptor is invalid (does not adhere to its json schema)", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(invalidComponentComponentReference), cdref))
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers, err := registryAccess.GetComponentVersion(ctx, cdref)
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

compvers, err := registryAccess.GetComponentVersion(ctx, compKey)
Expect(err).To(HaveOccurred())
Expect(compvers).To(BeNil())
},
Expand All @@ -365,9 +383,9 @@ var _ = Describe("facade implementation compatibility tests", func() {
// Check nil argument handling of facade methods
DescribeTable("prevent null pointer exceptions", func(factory model.Factory, registryRootPath string) {
// Test registry access
registryAccess, err := factory.NewRegistryAccess(ctx, nil, nil, nil, nil, nil, nil, nil)
Expect(registryAccess).ToNot(BeNil())
registryAccess, err := factory.NewRegistryAccess(ctx, &model.RegistryAccessOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(registryAccess).ToNot(BeNil())

compvers, err := registryAccess.GetComponentVersion(ctx, nil)
Expect(compvers).To(BeNil())
Expand All @@ -376,12 +394,13 @@ var _ = Describe("facade implementation compatibility tests", func() {
// Organize a valid component version
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(componentReference), cdref))
registryAccess, err = factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil)
compKey := types.ComponentVersionKeyFromReference(cdref)

registryAccess, err = testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(registryAccess).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())

compvers = Must(registryAccess.GetComponentVersion(ctx, cdref))
compvers = Must(registryAccess.GetComponentVersion(ctx, compKey))

// Test component version
res, err := compvers.GetResource("", nil)
Expand Down
36 changes: 13 additions & 23 deletions pkg/components/jsonschemahandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package components_test
import (
"context"

"github.com/gardener/landscaper/pkg/components/model/types"
"github.com/gardener/landscaper/pkg/components/testutils"

"github.com/open-component-model/ocm/pkg/contexts/datacontext"
"github.com/open-component-model/ocm/pkg/contexts/ocm"

Expand All @@ -16,30 +19,21 @@ import (
"github.com/mandelsoft/vfs/pkg/vfs"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/open-component-model/ocm/pkg/runtime"
. "github.com/open-component-model/ocm/pkg/testutils"

"github.com/gardener/landscaper/pkg/components/model"

"github.com/gardener/landscaper/apis/config"
"github.com/gardener/landscaper/apis/core/v1alpha1"
"github.com/gardener/landscaper/pkg/components/ocmlib"
)

var (
LOCALCNUDIEREPOPATH_WITH_JSONSCHEMAS = "./testdata/localcnudierepos/components-with-jsonschemas"
LOCALOCMREPOPATH_WITH_JSONSCHEMAS = "./testdata/localocmrepos/components-with-jsonschemas"

withJSONSchemasComponentReference = `
{
"repositoryContext": {
"type": "local",
"filePath": "./"
},
"componentName": "example.com/landscaper-component-with-jsonschemas",
"version": "1.0.0"
}
`
jsonSchemaComponentVersionKey = types.ComponentVersionKey{
Name: "example.com/landscaper-component-with-jsonschemas",
Version: "1.0.0",
}
)

var _ = Describe("facade implementation compatibility tests", func() {
Expand All @@ -58,12 +52,10 @@ var _ = Describe("facade implementation compatibility tests", func() {

// JsonSchema Handler
DescribeTable("resolve jsonschema", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withJSONSchemasComponentReference), cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
compvers := Must(registryAccess.GetComponentVersion(ctx, &jsonSchemaComponentVersionKey))

jsonschema := Must(compvers.GetResource("jsonschema", nil))
typedContent, err := jsonschema.GetTypedContent(ctx)
Expand All @@ -88,12 +80,10 @@ var _ = Describe("facade implementation compatibility tests", func() {
)

DescribeTable("resolve jsonschema with unknown mediatype with ocmlib facade implementation", func(factory model.Factory, registryRootPath string) {
cdref := &v1alpha1.ComponentDescriptorReference{}
MustBeSuccessful(runtime.DefaultYAMLEncoding.Unmarshal([]byte(withJSONSchemasComponentReference), cdref))
registryAccess, err := testutils.NewLocalRegistryAccess(ctx, registryRootPath)
Expect(err).ToNot(HaveOccurred())

registryAccess := Must(factory.NewRegistryAccess(ctx, nil, nil, nil,
&config.LocalRegistryConfiguration{RootPath: registryRootPath}, nil, nil))
compvers := Must(registryAccess.GetComponentVersion(ctx, cdref))
compvers := Must(registryAccess.GetComponentVersion(ctx, &jsonSchemaComponentVersionKey))

jsonschemaUnknown := Must(compvers.GetResource("jsonschema-unknown-mediatype", nil))
typedContentUnknown, err := jsonschemaUnknown.GetTypedContent(ctx)
Expand Down
Loading