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

serverless-agent: expose priorities control #483

Merged
merged 3 commits into from
Mar 21, 2024
Merged
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
20 changes: 19 additions & 1 deletion sysdig/data_source_sysdig_fargate_ECS_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func getKiltRecipe(t *testing.T) string {
CollectorHost: "collector_host",
CollectorPort: "collector_port",
SysdigLogging: "sysdig_logging",
Priority: "priority",
}

jsonRecipeConfig, err := json.Marshal(&recipeConfig)
Expand Down Expand Up @@ -121,6 +122,12 @@ func TestNewPatchOptions(t *testing.T) {
},
},
},
"priority": {
Type: schema.TypeString,
Description: "The priority of the agent. Can be 'security' or 'availability'",
Default: "availability",
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -164,13 +171,24 @@ func TestNewPatchOptions(t *testing.T) {
"stream_prefix": "fried",
"region": "chicken",
},
Essential: true,
Essential: false,
}
actualPatchOptions := newPatchOptions(data)

if !reflect.DeepEqual(expectedPatchOptions, actualPatchOptions) {
t.Errorf("patcConfigurations are not equal. Expected: %v, Actual: %v", expectedPatchOptions, actualPatchOptions)
}

err = data.Set("priority", "security")
if err != nil {
assert.FailNow(t, fmt.Sprintf("Could not set priority, got error: %v", err))
}
expectedPatchOptions.Essential = true
actualPatchOptions = newPatchOptions(data)

if !reflect.DeepEqual(expectedPatchOptions, actualPatchOptions) {
t.Errorf("patcConfigurations are not equal. Expected: %v, Actual: %v", expectedPatchOptions, actualPatchOptions)
}
}

func getSidecarConfig() string {
Expand Down
22 changes: 18 additions & 4 deletions sysdig/data_source_sysdig_fargate_workload_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const agentinoKiltDefinition = `build {
"SYSDIG_ACCESS_KEY": ${config.sysdig_access_key}
"SYSDIG_LOGGING": ${config.sysdig_logging}
"SYSDIG_SIDECAR": ${config.sidecar}
"SYSDIG_PRIORITY": ${config.priority}
}
capabilities: ["SYS_PTRACE"]
mount: [
Expand Down Expand Up @@ -129,14 +130,19 @@ func dataSourceSysdigFargateWorkloadAgent() *schema.Resource {
"sidecar": {
Type: schema.TypeString,
Description: "Sidecar mode: auto/force/(empty string)",
Default: "", // we will want to change this to "auto" eventually
Default: "auto",
Optional: true,
},
"priority": {
Type: schema.TypeString,
Description: "The priority of the agent. Can be 'security' or 'availability'",
Default: "availability",
Optional: true,
},

"instrumentation_essential": {
Type: schema.TypeBool,
Description: "Should the instrumentation container be marked as essential",
Default: true,
Default: false,
Optional: true,
},
"instrumentation_cpu": {
Expand Down Expand Up @@ -362,6 +368,7 @@ type KiltRecipeConfig struct {
CollectorPort string `json:"collector_port"`
SysdigLogging string `json:"sysdig_logging"`
Sidecar string `json:"sidecar"`
Priority string `json:"priority"`
}

type patchOptions struct {
Expand Down Expand Up @@ -404,7 +411,8 @@ func newPatchOptions(d *schema.ResourceData) *patchOptions {
if essential := d.Get("instrumentation_essential"); essential != nil {
opts.Essential = essential.(bool)
} else {
opts.Essential = true
priority := d.Get("priority").(string)
opts.Essential = priority == "security"
}

if cpuShares := d.Get("instrumentation_cpu"); cpuShares != nil {
Expand All @@ -429,6 +437,11 @@ func newPatchOptions(d *schema.ResourceData) *patchOptions {
}

func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
priority := d.Get("priority").(string)
if priority != "security" && priority != "availability" {
return diag.Errorf("Invalid priority: %s. must be either \"security\" or \"availability\"", priority)
}

recipeConfig := KiltRecipeConfig{
SysdigAccessKey: d.Get("sysdig_access_key").(string),
AgentImage: d.Get("workload_agent_image").(string),
Expand All @@ -438,6 +451,7 @@ func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.Res
CollectorPort: d.Get("collector_port").(string),
SysdigLogging: d.Get("sysdig_logging").(string),
Sidecar: d.Get("sidecar").(string),
Priority: priority,
}

jsonConf, err := json.Marshal(&recipeConfig)
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/ECSInstrumented.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -90,6 +94,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
12 changes: 12 additions & 0 deletions sysdig/testfiles/fargate_bare_pdig_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -90,6 +94,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -172,6 +180,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_cmd_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -85,6 +89,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_combined_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -97,6 +101,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_entrypoint_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -82,6 +86,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_env_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -90,6 +94,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
12 changes: 12 additions & 0 deletions sysdig/testfiles/fargate_field_case_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -82,6 +86,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -135,6 +143,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -96,6 +100,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_linuxparameters_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -85,6 +89,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_log_group_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -94,6 +98,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
8 changes: 8 additions & 0 deletions sysdig/testfiles/fargate_volumesfrom_test_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down Expand Up @@ -89,6 +93,10 @@
"Name": "SYSDIG_LOGGING",
"Value": "sysdig_logging"
},
{
"Name": "SYSDIG_PRIORITY",
"Value": "priority"
},
{
"Name": "SYSDIG_SIDECAR",
"Value": ""
Expand Down
Loading