Skip to content

Commit 4b02087

Browse files
mvicknrclaude
andauthored
chore: Fix agent control definitions based on new requirements (#23)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2844f9d commit 4b02087

File tree

13 files changed

+1384
-566
lines changed

13 files changed

+1384
-566
lines changed

CLAUDE.md

Lines changed: 236 additions & 48 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,32 @@ jobs:
7373

7474
### Configuration File Format (Agent Scenario)
7575

76-
For the agent scenario, the action expects a YAML file at `.fleetControl/configurationDefinitions.yml` with the following structure:
76+
For the agent scenario, the action expects YAML files at
77+
`.fleetControl/configurationDefinitions.yml` and
78+
`.fleetControl/agentControlDefinitions.yml`
79+
with the following structures:
7780

7881
```yaml
7982
configurationDefinitions:
80-
- platform: "KUBERNETESCLUSTER" # or "HOST" or "ALL" if there is no distinction
81-
description: "Description of the configuration"
82-
type: "agent-config"
83-
version: "1.0.0" -- config schema version
84-
format: "yml" -- format of the agent config file
85-
schema: "./schemas/config-schema.json"
83+
- platform: KUBERNETESCLUSTER # or "HOST" or "ALL" if there is no distinction
84+
description: Description of the configuration
85+
type: agent-config
86+
version: 1.0.0 -- config schema version
87+
format: yml -- format of the agent config file
88+
schema: ./schemas/config-schema.json
8689
```
8790

91+
```yaml
92+
agentControlDefinitions:
93+
- platform: KUBERNETES # "ALL" is not an option
94+
supportFromAgent: 1.0.0
95+
supportFromAgentControl: 1.0.0
96+
content: ./agentControl/agent-schema-for-agent-control.yml
97+
```
8898

8999
**Dec 2025 - schema temporarily optional until full functionality is ready
90100

91-
**Schema paths must be relative to the `.fleetControl` directory and cannot use directory traversal (`..`) for security.
101+
**Paths must be relative to the `.fleetControl` directory and cannot use directory traversal (`..`) for security.
92102

93103
## Building
94104

cmd/agent-metadata-action/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ func runAgentFlow(ctx context.Context, client metadataClient, workspace, agentTy
9090
}
9191
fmt.Printf("::notice::Loaded %d configuration definitions\n", len(configs))
9292

93-
// Load agent control (optional)
94-
agentControl, err := loader.LoadAndEncodeAgentControl(workspace)
93+
// Load agent control definitions (optional)
94+
agentControl, err := loader.ReadAgentControlDefinitions(workspace)
9595
if err != nil {
96-
fmt.Println("::warn::Unable to load agent control files - continuing without them")
96+
fmt.Printf("::warn::Unable to load agent control definitions: %v - continuing without them\n", err)
97+
agentControl = nil
9798
} else {
98-
fmt.Printf("::notice::Loaded %d agent control files\n", len(agentControl))
99+
fmt.Printf("::notice::Loaded %d agent control definitions\n", len(agentControl))
99100
}
100101

101102
// Build metadata

cmd/agent-metadata-action/main_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,40 @@ version: 1.3.1
387387
assert.Contains(t, outputStr, "::warn::Failed to send metadata")
388388
}
389389

390+
func TestRunAgentFlow_AgentControlDefinitionsError(t *testing.T) {
391+
workspace := t.TempDir()
392+
fleetControlPath := filepath.Join(workspace, ".fleetControl")
393+
require.NoError(t, os.MkdirAll(fleetControlPath, 0755))
394+
395+
// Create valid configurationDefinitions.yml
396+
configFile := filepath.Join(fleetControlPath, "configurationDefinitions.yml")
397+
configContent := `configurationDefinitions:
398+
- name: test-config
399+
type: string
400+
`
401+
require.NoError(t, os.WriteFile(configFile, []byte(configContent), 0644))
402+
403+
// Create invalid agentControlDefinitions.yml (invalid YAML)
404+
agentControlFile := filepath.Join(fleetControlPath, "agentControlDefinitions.yml")
405+
require.NoError(t, os.WriteFile(agentControlFile, []byte("invalid: yaml: ["), 0644))
406+
407+
ctx := context.Background()
408+
mockClient := &mockMetadataClient{}
409+
410+
getStdout, _ := testutil.CaptureOutput(t)
411+
412+
// method under test
413+
err := runAgentFlow(ctx, mockClient, workspace, "java", "1.0.0")
414+
415+
// Should succeed despite agentControlDefinitions error
416+
assert.NoError(t, err)
417+
418+
// Verify warning was logged
419+
outputStr := getStdout()
420+
assert.Contains(t, outputStr, "::warn::Unable to load agent control definitions")
421+
assert.Contains(t, outputStr, "continuing without them")
422+
}
423+
390424
func TestSendDocsMetadata(t *testing.T) {
391425
tests := []struct {
392426
name string
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
agentControlDefinitions:
2+
- platform: KUBERNETES
3+
supportFromAgent: 1.0.0
4+
supportFromAgentControl: 1.0.0
5+
content: ./agentControl/agent-schema-for-agent-control.yml

internal/client/instrumentation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ func TestSendMetadata_WithConfigurationDefinitionsAndAgentControl(t *testing.T)
391391
},
392392
AgentControlDefinitions: []models.AgentControlDefinition{
393393
{
394-
Platform: "all",
395-
Content: "base64content",
394+
"platform": "all",
395+
"content": "base64content",
396396
},
397397
},
398398
}

internal/config/dirs.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ func GetConfigurationDefinitionsFilename() string {
1616
return "configurationDefinitions.yml"
1717
}
1818

19-
// GetAgentControlFolderForAgentRepo loads the folder holding the agent control definitions
20-
func GetAgentControlFolderForAgentRepo() string {
21-
return filepath.Join(GetRootFolderForAgentRepo(), "agentControl")
19+
// GetAgentControlDefinitionsFilepath returns the path to the agentControlDefinitions.yml file
20+
func GetAgentControlDefinitionsFilepath() string {
21+
return filepath.Join(GetRootFolderForAgentRepo(), GetAgentControlDefinitionsFilename())
22+
}
23+
24+
func GetAgentControlDefinitionsFilename() string {
25+
return "agentControlDefinitions.yml"
2226
}
2327

2428
func GetReleaseNotesDirectory() string {

internal/loader/configuration_definitions.go

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)