-
Notifications
You must be signed in to change notification settings - Fork 87
Add conditions.agent.version into integration and input manifest spec with validation
#999
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
Merged
teresaromero
merged 19 commits into
elastic:main
from
teresaromero:970-new-agent-version-condition
Oct 23, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
aecf519
Add Elastic Agent conditions to manifest specification
teresaromero 4770a5c
Add validation for minimum agent version condition in manifest
teresaromero 19e1259
Add minimum agent version validation to package specifications
teresaromero 5418745
Add validation for agent version definition in package manifest
teresaromero 0d42370
Add support for integration types in minimum agent version validation
teresaromero 88c8ce5
Add comments to clarify the purpose of ValidateMinimumAgentVersion fu…
teresaromero 21c7c22
Reorder import statements in validate_agent_version_required_test.go
teresaromero 45bed14
Update agent version validation and manifest specifications
teresaromero c631173
Rename file removing required
teresaromero 663d681
Patch integration manifest to remove required before 3.6 and ref only…
teresaromero cf21ece
Add a newline in import section of validate_agent_version.go for bett…
teresaromero c7738d4
Refactor agent version validation logic for clarity
teresaromero 64d90f2
Remove unnecessary types specification from ValidateMinimumAgentVersi…
teresaromero a86c664
Remove conditions requirement from package manifest for compatibility
teresaromero 2e8f570
Remove conditions requirement from package manifest for compatibility
teresaromero 49363fe
Update changelog to require agent version constraints in input and in…
teresaromero 18633cc
Merge branch 'main' into 970-new-agent-version-condition
teresaromero d35f37d
Add failing test case for agent validation
teresaromero a9b27d2
Update error message for agent version validation and add missing age…
teresaromero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
code/go/internal/validator/semantic/validate_agent_version.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package semantic | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
|
|
||
| "github.com/elastic/package-spec/v3/code/go/internal/fspath" | ||
| "github.com/elastic/package-spec/v3/code/go/internal/pkgpath" | ||
| "github.com/elastic/package-spec/v3/code/go/pkg/specerrors" | ||
| ) | ||
|
|
||
| var ( | ||
| errInvalidAgentVersionCondition = fmt.Errorf("invalid agent.version condition") | ||
| errAgentVersionIncorrectType = fmt.Errorf("manifest agent version is not a string") | ||
| ) | ||
|
|
||
| // ValidateMinimumAgentVersion checks that the package manifest includes the agent.version condition. | ||
| func ValidateMinimumAgentVersion(fsys fspath.FS) specerrors.ValidationErrors { | ||
| manifest, err := readManifest(fsys) | ||
| if err != nil { | ||
| return specerrors.ValidationErrors{specerrors.NewStructuredError(err, specerrors.UnassignedCode)} | ||
| } | ||
|
|
||
| agentVersionCondition, err := getAgentVersionCondition(*manifest) | ||
| if err != nil { | ||
| return specerrors.ValidationErrors{specerrors.NewStructuredError(err, specerrors.UnassignedCode)} | ||
| } | ||
|
|
||
| if agentVersionCondition != "" { | ||
| if _, err := semver.NewConstraint(agentVersionCondition); err != nil { | ||
| return specerrors.ValidationErrors{specerrors.NewStructuredError(errors.Join(err, errInvalidAgentVersionCondition), specerrors.UnassignedCode)} | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func getAgentVersionCondition(manifest pkgpath.File) (string, error) { | ||
| val, err := manifest.Values("$.conditions[\"agent.version\"]") | ||
| if err != nil { | ||
| val, err = manifest.Values("$.conditions.agent.version") | ||
| if err != nil { | ||
| return "", nil | ||
| } | ||
| } | ||
|
|
||
| sVal, ok := val.(string) | ||
| if !ok { | ||
| return "", errAgentVersionIncorrectType | ||
| } | ||
|
|
||
| return sVal, nil | ||
| } | ||
87 changes: 87 additions & 0 deletions
87
code/go/internal/validator/semantic/validate_agent_version_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package semantic | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/elastic/package-spec/v3/code/go/internal/fspath" | ||
| ) | ||
|
|
||
| func TestValidateMinimumAgentVersion(t *testing.T) { | ||
| cases := []struct { | ||
| title string | ||
| manifestYAML string | ||
| expectedErr error | ||
| }{ | ||
| { | ||
| title: "valid - agent.version condition is present", | ||
| manifestYAML: ` | ||
| name: test-package | ||
| version: 1.0.0 | ||
| conditions: | ||
| agent: | ||
| version: "^8.0.0" | ||
| `, | ||
| expectedErr: nil, | ||
| }, | ||
| { | ||
| title: "invalid - agent.version condition is missing", | ||
| manifestYAML: ` | ||
| name: test-package | ||
| version: 1.0.0 | ||
| conditions: | ||
| some.other.condition: "value" | ||
| `, | ||
| expectedErr: nil, | ||
| }, | ||
| { | ||
| title: "invalid - agent.version condition is not a string", | ||
| manifestYAML: ` | ||
| name: test-package | ||
| version: 1.0.0 | ||
| conditions: | ||
| agent.version: | ||
| min: "^8.0.0" | ||
| `, | ||
| expectedErr: errAgentVersionIncorrectType, | ||
| }, | ||
| { | ||
| title: "invalid - agent.version condition is not a constraint", | ||
| manifestYAML: ` | ||
| name: test-package | ||
| version: 1.0.0 | ||
| conditions: | ||
| agent.version: test | ||
| `, | ||
| expectedErr: errInvalidAgentVersionCondition, | ||
| }, | ||
| } | ||
|
|
||
| for _, c := range cases { | ||
| t.Run(c.title, func(t *testing.T) { | ||
| tempDir := t.TempDir() | ||
|
|
||
| manifestPath := filepath.Join(tempDir, "manifest.yml") | ||
| err := os.WriteFile(manifestPath, []byte(c.manifestYAML), 0644) | ||
| require.NoError(t, err) | ||
|
|
||
| fsys := fspath.DirFS(tempDir) | ||
| errs := ValidateMinimumAgentVersion(fsys) | ||
|
|
||
| if c.expectedErr != nil { | ||
| require.Len(t, errs, 1) | ||
| require.ErrorIs(t, errs[0], c.expectedErr) | ||
| } else { | ||
| require.Empty(t, errs) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.