Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 Oct 15, 2025
4770a5c
Add validation for minimum agent version condition in manifest
teresaromero Oct 16, 2025
19e1259
Add minimum agent version validation to package specifications
teresaromero Oct 16, 2025
5418745
Add validation for agent version definition in package manifest
teresaromero Oct 16, 2025
0d42370
Add support for integration types in minimum agent version validation
teresaromero Oct 16, 2025
88c8ce5
Add comments to clarify the purpose of ValidateMinimumAgentVersion fu…
teresaromero Oct 16, 2025
21c7c22
Reorder import statements in validate_agent_version_required_test.go
teresaromero Oct 16, 2025
45bed14
Update agent version validation and manifest specifications
teresaromero Oct 17, 2025
c631173
Rename file removing required
teresaromero Oct 17, 2025
663d681
Patch integration manifest to remove required before 3.6 and ref only…
teresaromero Oct 17, 2025
cf21ece
Add a newline in import section of validate_agent_version.go for bett…
teresaromero Oct 17, 2025
c7738d4
Refactor agent version validation logic for clarity
teresaromero Oct 20, 2025
64d90f2
Remove unnecessary types specification from ValidateMinimumAgentVersi…
teresaromero Oct 20, 2025
a86c664
Remove conditions requirement from package manifest for compatibility
teresaromero Oct 20, 2025
2e8f570
Remove conditions requirement from package manifest for compatibility
teresaromero Oct 20, 2025
49363fe
Update changelog to require agent version constraints in input and in…
teresaromero Oct 20, 2025
18633cc
Merge branch 'main' into 970-new-agent-version-condition
teresaromero Oct 23, 2025
d35f37d
Add failing test case for agent validation
teresaromero Oct 23, 2025
a9b27d2
Update error message for agent version validation and add missing age…
teresaromero Oct 23, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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 (
"fmt"

"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 (
errAgentVersionConditionMissing = fmt.Errorf("agent.version condition is required")
errAgentVersionIncorrectType = fmt.Errorf("manifest agent version is not a string")
)

// ValidateMinimumAgentVersion checks that the package manifest includes the agent.version condition.
// This is required for integration packages since version 3.6.0 of the spec.
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 == "" {
return specerrors.ValidationErrors{specerrors.NewStructuredError(errAgentVersionConditionMissing, 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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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: errAgentVersionConditionMissing,
},
{
title: "invalid - conditions block is missing",
manifestYAML: `
name: test-package
version: 1.0.0
`,
expectedErr: errAgentVersionConditionMissing,
},
{
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,
},
}

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.ErrorContains(t, errs, c.expectedErr.Error())
} else {
require.Empty(t, errs)
}
})
}

}
1 change: 1 addition & 0 deletions code/go/internal/validator/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (s Spec) rules(pkgType string, rootSpec spectypes.ItemSpec) validationRules
{fn: semantic.ValidateDocsStructure},
{fn: semantic.ValidateDeploymentModes, types: []string{"integration"}},
{fn: semantic.ValidateDurationVariables, since: semver.MustParse("3.5.0")},
{fn: semantic.ValidateMinimumAgentVersion, types: []string{"integration"}, since: semver.MustParse("3.6.0")},
}

var validationRules validationRules
Expand Down
3 changes: 3 additions & 0 deletions spec/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- description: Add support for semantic_text field definition.
type: enhancement
link: https://github.com/elastic/package-spec/pull/807
- description: Add validation to ensure that the agent version is defined in the package manifest.
type: enhancement
link: https://github.com/elastic/package-spec/pull/999
- version: 3.5.1-next
changes:
- description: Input packages don't require to define fields.
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/manifest.spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ spec:
description: Kibana versions compatible with this package.
examples:
- ">=7.9.0"
agent:
description: Elastic Agent conditions
type: object
additionalProperties: false
properties:
version:
type: string
description: Elastic Agent versions compatible with this package.
examples:
- ">=9.1.5"
description:
description: >
A longer description of the package. It should describe, at least all the kinds of
Expand Down Expand Up @@ -692,6 +702,10 @@ spec:

# JSON patches for newer versions should be placed on top
versions:
- before: 3.6.0
patch:
- op: remove
path: "/definitions/conditions/properties/agent/properties/version"
- before: 3.3.2
patch:
- op: remove
Expand Down
2 changes: 2 additions & 0 deletions test/packages/good_content/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ conditions:
subscription: 'basic'
capabilities:
- security
agent:
version: '9.1.5'
discovery:
fields:
- name: process.pid
Expand Down
2 changes: 2 additions & 0 deletions test/packages/good_v3/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ conditions:
capabilities:
- observability
- security
agent:
version: '9.1.5'
vars:
- name: package_password
type: password
Expand Down