Skip to content

feat: 743 constructor semver#1317

Merged
matthiasbruns merged 9 commits into
open-component-model:mainfrom
matthiasbruns:fix/743_add_cv_version_regexp_constructor
Dec 5, 2025
Merged

feat: 743 constructor semver#1317
matthiasbruns merged 9 commits into
open-component-model:mainfrom
matthiasbruns:fix/743_add_cv_version_regexp_constructor

Conversation

@matthiasbruns

@matthiasbruns matthiasbruns commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

Adds semver checks to ocm add cv analog to ocm get cv

Which issue(s) this PR fixes

Contributes open-component-model/ocm-project#743

Check #1341 how it is integrated

@github-actions github-actions Bot added kind/feature new feature, enhancement, improvement, extension size/s Small labels Dec 1, 2025
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch 2 times, most recently from 5c96e2f to 06974ad Compare December 1, 2025 15:05
@matthiasbruns matthiasbruns marked this pull request as ready for review December 1, 2025 15:07
@matthiasbruns matthiasbruns requested a review from a team as a code owner December 1, 2025 15:07
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch from 06974ad to 68502a1 Compare December 1, 2025 15:08
Comment thread bindings/go/constructor/construct.go Outdated
@matthiasbruns matthiasbruns marked this pull request as draft December 1, 2025 15:24
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch 2 times, most recently from 6f979ca to 146cf24 Compare December 1, 2025 15:35
Comment thread bindings/go/constructor/construct.go Outdated
@matthiasbruns matthiasbruns marked this pull request as ready for review December 1, 2025 15:47
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch 2 times, most recently from 6605a0f to 15bafd8 Compare December 1, 2025 16:04
@github-actions github-actions Bot added the size/m Medium label Dec 1, 2025
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch 2 times, most recently from 1514b90 to d378932 Compare December 2, 2025 05:53
Comment thread bindings/go/constructor/construct.go Outdated
@fabianburth

Copy link
Copy Markdown
Contributor

Just wondering, instead of having concrete semver checks, shouldn't we rather try to have a thorough json schema for the constructor and validate the entire constructors against that json schema?

@matthiasbruns

Copy link
Copy Markdown
Contributor Author

Just wondering, instead of having concrete semver checks, shouldn't we rather try to have a thorough json schema for the constructor and validate the entire constructors against that json schema?

something like this?

// Component defines a named and versioned component containing dependencies such as sources, resources and
// references pointing to further component versions.
// +k8s:deepcopy-gen=true
type Component struct {
	ComponentMeta `json:",inline"`
	Provider      Provider    `json:"-"`
	Resources     []Resource  `json:"-"`
	Sources       []Source    `json:"-"`
	References    []Reference `json:"-"`
}

func (a *Component) Validate() error {
	if _, err := semver.NewConstraint(a.Version); err != nil {
		return errors.Join(ErrInvalidSemverVersion, fmt.Errorf("component %q has invalid semver version %q: %w", a.Name, a.Version, err))
	}
	return nil
}

@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch 2 times, most recently from 5a079c8 to 51b0470 Compare December 2, 2025 09:27
@matthiasbruns

matthiasbruns commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author
	if err := constructorv1.ValidateRawYAML(constructorData); err != nil {
		return nil, fmt.Errorf("validating component constructor %q failed: %w", path, err)
	}

I tried to validate the constructor against the existing schema and it fails with basically every existing cli test

Error: getting component constructor failed: validating component constructor "/var/folders/vp/119yd9r50j7_bszfqvsyk8500000gn/T/Test_Add_Component_Version2597195195/001/component-constructor.yaml" failed: jsonschema validation failed with 'open-component-model/cli/cmd/resources/schema-2020-12.json#'
- at '': 'oneOf' failed, none matched
  - at '': missing property 'components'
  - at '/resources/0': 'oneOf' failed, none matched
    - at '/resources/0': missing properties 'version', 'relation', 'access'
    - at '/resources/0': missing property 'relation'

@jakobmoellerdev since you built the schema - how to proceed here? should I update every existing cli test or revisit the schema since it's not really in use right now afaik

https://github.com/open-component-model/open-component-model/pull/1316/files#diff-5a9e426f588a47f64ab19f8b5fd53025f85dc02d3aac6a681b420a8c07948906R368

@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch from 2db203a to 52993c0 Compare December 3, 2025 07:03
On-behalf-of: SAP <matthias.bruns@sap.com>

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
On-behalf-of: SAP <matthias.bruns@sap.com>

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch from 76d5472 to b2a4819 Compare December 3, 2025 08:05
jakobmoellerdev
jakobmoellerdev previously approved these changes Dec 3, 2025

@jakobmoellerdev jakobmoellerdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note. are you sure that this shouldnt just be a call on the data in the cli? otherwise everyone will loose to read a constructor that does not conform to the schema (i.e. when they want to build them together step by step from fragments)

@matthiasbruns

Copy link
Copy Markdown
Contributor Author

Just a note. are you sure that this shouldnt just be a call on the data in the cli? otherwise everyone will loose to read a constructor that does not conform to the schema (i.e. when they want to build them together step by step from fragments)

haven't thought about it - wdyt? I am usually for more strict handling everywhere than fragmented behaviour. I can only check it in CLI for now, but since we have a spec, and we are parsing from it, I'd assume that we would do the check at this point for every model tbh

Comment thread bindings/go/constructor/spec/v1/schema_test.go
On-behalf-of: SAP <matthias.bruns@sap.com>

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@jakobmoellerdev

Copy link
Copy Markdown
Member

Just a note. are you sure that this shouldnt just be a call on the data in the cli? otherwise everyone will loose to read a constructor that does not conform to the schema (i.e. when they want to build them together step by step from fragments)

haven't thought about it - wdyt? I am usually for more strict handling everywhere than fragmented behaviour. I can only check it in CLI for now, but since we have a spec, and we are parsing from it, I'd assume that we would do the check at this point for every model tbh

In general this is great but you have to remember that were currently restricting marshalling itself. I am happy to default to use this marshaller but be able to have an unsafe version as well. since this lib is so foundational we must assume folks want to get unfinished constructors into the lib

On-behalf-of: SAP <matthias.bruns@sap.com>

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns

Copy link
Copy Markdown
Contributor Author

Just a note. are you sure that this shouldnt just be a call on the data in the cli? otherwise everyone will loose to read a constructor that does not conform to the schema (i.e. when they want to build them together step by step from fragments)

haven't thought about it - wdyt? I am usually for more strict handling everywhere than fragmented behaviour. I can only check it in CLI for now, but since we have a spec, and we are parsing from it, I'd assume that we would do the check at this point for every model tbh

In general this is great but you have to remember that were currently restricting marshalling itself. I am happy to default to use this marshaller but be able to have an unsafe version as well. since this lib is so foundational we must assume folks want to get unfinished constructors into the lib

Added https://github.com/open-component-model/open-component-model/pull/1317/files#diff-35b4b1f537a1b2d5258b540d47da10402c97cf1dc45bcacf82009cff106a0700R51 and tests for it

Comment thread bindings/go/constructor/spec/v1/constructor.go
On-behalf-of: SAP <matthias.bruns@sap.com>

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
@matthiasbruns matthiasbruns force-pushed the fix/743_add_cv_version_regexp_constructor branch from fd34b01 to 5d9297d Compare December 5, 2025 07:43

@fabianburth fabianburth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR linked in your PR description does not contain any additional information.

@matthiasbruns

Copy link
Copy Markdown
Contributor Author

The PR linked in your PR description does not contain any additional information.

added a bit info to the cli pr

@matthiasbruns matthiasbruns enabled auto-merge (squash) December 5, 2025 08:59
@matthiasbruns matthiasbruns merged commit 40ef3dd into open-component-model:main Dec 5, 2025
14 of 17 checks passed
matthiasbruns added a commit that referenced this pull request Dec 11, 2025
<!-- markdownlint-disable MD041 -->
#### What this PR does / why we need it
Adds semver checks to `ocm add cv` analog to `ocm get cv`

- This PR will only update cli and add tests when
#1317
is merged to verify, that the constructor validation works as expected
- This Pr also reduces the logging level in `get cv` when requesting an
invalid version
#1393

#### Which issue(s) this PR fixes
Fixes: open-component-model/ocm-project#743
Fixes: open-component-model/ocm-project#752

---------

Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Co-authored-by: ocmbot[bot] <125909804+ocmbot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature new feature, enhancement, improvement, extension size/m Medium size/s Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants