diff --git a/pkg/testing/ess/create_deployment_request.tmpl.json b/pkg/testing/ess/create_deployment_request.tmpl.json index daa97eae262..3ef93868708 100644 --- a/pkg/testing/ess/create_deployment_request.tmpl.json +++ b/pkg/testing/ess/create_deployment_request.tmpl.json @@ -96,6 +96,7 @@ }, "name": "{{ .request.Name }}", "metadata": { - "system_owned": false + "system_owned": false, + "tags": {{ json .request.Tags }} } } \ No newline at end of file diff --git a/pkg/testing/ess/deployment.go b/pkg/testing/ess/deployment.go index 35a315d166c..2295383c631 100644 --- a/pkg/testing/ess/deployment.go +++ b/pkg/testing/ess/deployment.go @@ -10,19 +10,25 @@ import ( _ "embed" "encoding/json" "fmt" - "html/template" "net/http" "net/url" "strings" + "text/template" "time" "gopkg.in/yaml.v2" ) +type Tag struct { + Key string `json:"key"` + Value string `json:"value"` +} + type CreateDeploymentRequest struct { Name string `json:"name"` Region string `json:"region"` Version string `json:"version"` + Tags []Tag `json:"tags"` } type CreateDeploymentResponse struct { @@ -324,7 +330,9 @@ func generateCreateDeploymentRequestBody(req CreateDeploymentRequest) ([]byte, e return nil, fmt.Errorf("creating request template context: %w", err) } - tpl, err := template.New("create_deployment_request").Parse(createDeploymentRequestTemplate) + tpl, err := template.New("create_deployment_request"). + Funcs(template.FuncMap{"json": jsonMarshal}). + Parse(createDeploymentRequestTemplate) if err != nil { return nil, fmt.Errorf("unable to parse deployment creation template: %w", err) } @@ -337,6 +345,15 @@ func generateCreateDeploymentRequestBody(req CreateDeploymentRequest) ([]byte, e return bBuf.Bytes(), nil } +func jsonMarshal(in any) (string, error) { + jsonBytes, err := json.Marshal(in) + if err != nil { + return "", err + } + + return fmt.Sprintf("%s", jsonBytes), nil +} + func createDeploymentTemplateContext(csp string, req CreateDeploymentRequest) (map[string]any, error) { cspSpecificContext, err := loadCspValues(csp) if err != nil { diff --git a/pkg/testing/ess/provisioner.go b/pkg/testing/ess/provisioner.go index 6ebade07569..b309fdf9b66 100644 --- a/pkg/testing/ess/provisioner.go +++ b/pkg/testing/ess/provisioner.go @@ -67,7 +67,7 @@ func (p *provisioner) Provision(ctx context.Context, requests []runner.StackRequ for _, r := range requests { // allow up to 2 minutes for each create request createCtx, createCancel := context.WithTimeout(ctx, 2*time.Minute) - resp, err := p.createDeployment(createCtx, r, map[string]string{"elastic-agent-integration-tests": "true"}) + resp, err := p.createDeployment(createCtx, r, map[string]string{"elastic-agent-integration-tests": "true", "team": "elastic-agent"}) createCancel() if err != nil { return nil, err @@ -131,18 +131,28 @@ func (p *provisioner) Clean(ctx context.Context, stacks []runner.Stack) error { return nil } -func (p *provisioner) createDeployment(ctx context.Context, r runner.StackRequest, _ map[string]string) (*CreateDeploymentResponse, error) { +func (p *provisioner) createDeployment(ctx context.Context, r runner.StackRequest, tags map[string]string) (*CreateDeploymentResponse, error) { ctx, cancel := context.WithTimeout(ctx, 1*time.Minute) defer cancel() p.logger.Logf("Creating stack %s (%s)", r.Version, r.ID) name := fmt.Sprintf("%s-%s", strings.Replace(p.cfg.Identifier, ".", "-", -1), r.ID) + + // prepare tags + tagArray := make([]Tag, 0, len(tags)) + for k, v := range tags { + tagArray = append(tagArray, Tag{ + Key: k, + Value: v, + }) + } + createDeploymentRequest := CreateDeploymentRequest{ Name: name, Region: p.cfg.Region, Version: r.Version, + Tags: tagArray, } - //TODO handle tags resp, err := p.client.CreateDeployment(ctx, createDeploymentRequest) if err != nil {